HAL_dac.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /**
  2. ******************************************************************************
  3. * @file HAL_dac.h
  4. * @author AE Team
  5. * @version V1.0.0
  6. * @date 28/7/2017
  7. * @brief This file contains all the functions prototypes for the DAC firmware
  8. * library.
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2017 MindMotion</center></h2>
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __HAL_DAC_H
  23. #define __HAL_DAC_H
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "HAL_device.h"
  26. /** @addtogroup StdPeriph_Driver
  27. * @{
  28. */
  29. /** @addtogroup DAC
  30. * @{
  31. */
  32. /** @defgroup DAC_Exported_Types
  33. * @{
  34. */
  35. /**
  36. * @brief DAC Init structure definition
  37. */
  38. typedef struct
  39. {
  40. uint32_t DAC_Trigger;
  41. uint32_t DAC_WaveGeneration;
  42. uint32_t DAC_LFSRUnmask_TriangleAmplitude;
  43. uint32_t DAC_OutputBuffer;
  44. }DAC_InitTypeDef;
  45. /**
  46. * @}
  47. */
  48. /** @defgroup DAC_Exported_Constants
  49. * @{
  50. */
  51. /** @defgroup DAC_trigger_selection
  52. * @{
  53. */
  54. #define DAC_Trigger_None ((uint32_t)0x00000000)
  55. #define DAC_Trigger_T1_TRGO ((uint32_t)0x00000004)
  56. #define DAC_Trigger_T3_TRGO ((uint32_t)0x0000000C)
  57. #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024)
  58. #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C)
  59. #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034)
  60. #define DAC_Trigger_Software ((uint32_t)0x0000003C)
  61. #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
  62. ((TRIGGER) == DAC_Trigger_T1_TRGO) || \
  63. ((TRIGGER) == DAC_Trigger_T3_TRGO) || \
  64. ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
  65. ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
  66. ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
  67. ((TRIGGER) == DAC_Trigger_Software))
  68. /**
  69. * @}
  70. */
  71. /** @defgroup DAC_wave_generation
  72. * @{
  73. */
  74. #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
  75. #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
  76. #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
  77. #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
  78. ((WAVE) == DAC_WaveGeneration_Noise) || \
  79. ((WAVE) == DAC_WaveGeneration_Triangle))
  80. /**
  81. * @}
  82. */
  83. /** @defgroup DAC_noise_wave_generation_mask_triangle_wave_generation_max_amplitude
  84. * @{
  85. */
  86. #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000)
  87. #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100)
  88. #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200)
  89. #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300)
  90. #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400)
  91. #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500)
  92. #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600)
  93. #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700)
  94. #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800)
  95. #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900)
  96. #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00)
  97. #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00)
  98. #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000)
  99. #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100)
  100. #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200)
  101. #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300)
  102. #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400)
  103. #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500)
  104. #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600)
  105. #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700)
  106. #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800)
  107. #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900)
  108. #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00)
  109. #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00)
  110. #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
  111. ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
  112. ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
  113. ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
  114. ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
  115. ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
  116. ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
  117. ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
  118. ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
  119. ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
  120. ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
  121. ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
  122. ((VALUE) == DAC_TriangleAmplitude_1) || \
  123. ((VALUE) == DAC_TriangleAmplitude_3) || \
  124. ((VALUE) == DAC_TriangleAmplitude_7) || \
  125. ((VALUE) == DAC_TriangleAmplitude_15) || \
  126. ((VALUE) == DAC_TriangleAmplitude_31) || \
  127. ((VALUE) == DAC_TriangleAmplitude_63) || \
  128. ((VALUE) == DAC_TriangleAmplitude_127) || \
  129. ((VALUE) == DAC_TriangleAmplitude_255) || \
  130. ((VALUE) == DAC_TriangleAmplitude_511) || \
  131. ((VALUE) == DAC_TriangleAmplitude_1023) || \
  132. ((VALUE) == DAC_TriangleAmplitude_2047) || \
  133. ((VALUE) == DAC_TriangleAmplitude_4095))
  134. /**
  135. * @}
  136. */
  137. /** @defgroup DAC_output_buffer
  138. * @{
  139. */
  140. #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
  141. #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
  142. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
  143. ((STATE) == DAC_OutputBuffer_Disable))
  144. /**
  145. * @}
  146. */
  147. /** @defgroup DAC_Channel_selection
  148. * @{
  149. */
  150. #define DAC_Channel_1 ((uint32_t)0x00000000)
  151. #define DAC_Channel_2 ((uint32_t)0x00000010)
  152. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
  153. ((CHANNEL) == DAC_Channel_2))
  154. /**
  155. * @}
  156. */
  157. /** @defgroup DAC_data_alignement
  158. * @{
  159. */
  160. #define DAC_Align_12b_R ((uint32_t)0x00000000)
  161. #define DAC_Align_12b_L ((uint32_t)0x00000004)
  162. #define DAC_Align_8b_R ((uint32_t)0x00000008)
  163. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
  164. ((ALIGN) == DAC_Align_12b_L) || \
  165. ((ALIGN) == DAC_Align_8b_R))
  166. /**
  167. * @}
  168. */
  169. /** @defgroup DAC_wave_generation
  170. * @{
  171. */
  172. #define DAC_Wave_Noise ((uint32_t)0x00000040)
  173. #define DAC_Wave_Triangle ((uint32_t)0x00000080)
  174. #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
  175. ((WAVE) == DAC_Wave_Triangle))
  176. /**
  177. * @}
  178. */
  179. /** @defgroup DAC_data
  180. * @{
  181. */
  182. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup DAC_Exported_Macros
  190. * @{
  191. */
  192. /**
  193. * @}
  194. */
  195. /** @defgroup DAC_Exported_Functions
  196. * @{
  197. */
  198. void DAC_DeInit(void);
  199. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
  200. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
  201. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
  202. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
  203. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
  204. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
  205. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
  206. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
  207. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
  208. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
  209. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
  210. #endif /*__HAL_DAC_H */
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/