A bundled STM32F10x Std Periph and CMSIS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32f10x_dac.h 15 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_dac.h
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file contains all the functions prototypes for the DAC firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  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, STMICROELECTRONICS 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 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32F10x_DAC_H
  24. #define __STM32F10x_DAC_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f10x.h"
  30. #include "stm32f10x_assert.h"
  31. /** @addtogroup STM32F10x_StdPeriph_Driver
  32. * @{
  33. */
  34. /** @addtogroup DAC
  35. * @{
  36. */
  37. /** @defgroup DAC_Exported_Types
  38. * @{
  39. */
  40. /**
  41. * @brief DAC Init structure definition
  42. */
  43. typedef struct
  44. {
  45. uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
  46. This parameter can be a value of @ref DAC_trigger_selection */
  47. uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves
  48. are generated, or whether no wave is generated.
  49. This parameter can be a value of @ref DAC_wave_generation */
  50. uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
  51. the maximum amplitude triangle generation for the DAC channel.
  52. This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
  53. uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  54. This parameter can be a value of @ref DAC_output_buffer */
  55. }DAC_InitTypeDef;
  56. /**
  57. * @}
  58. */
  59. /** @defgroup DAC_Exported_Constants
  60. * @{
  61. */
  62. /** @defgroup DAC_trigger_selection
  63. * @{
  64. */
  65. #define DAC_Trigger_None ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
  66. has been loaded, and not by external trigger */
  67. #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
  68. #define DAC_Trigger_T8_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel
  69. only in High-density devices*/
  70. #define DAC_Trigger_T3_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel
  71. only in Connectivity line, Medium-density and Low-density Value Line devices */
  72. #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
  73. #define DAC_Trigger_T5_TRGO ((uint32_t)0x0000001C) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */
  74. #define DAC_Trigger_T15_TRGO ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC channel
  75. only in Medium-density and Low-density Value Line devices*/
  76. #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
  77. #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
  78. #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
  79. #define DAC_Trigger_Software ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */
  80. #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
  81. ((TRIGGER) == DAC_Trigger_T6_TRGO) || \
  82. ((TRIGGER) == DAC_Trigger_T8_TRGO) || \
  83. ((TRIGGER) == DAC_Trigger_T7_TRGO) || \
  84. ((TRIGGER) == DAC_Trigger_T5_TRGO) || \
  85. ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
  86. ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
  87. ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
  88. ((TRIGGER) == DAC_Trigger_Software))
  89. /**
  90. * @}
  91. */
  92. /** @defgroup DAC_wave_generation
  93. * @{
  94. */
  95. #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
  96. #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
  97. #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
  98. #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
  99. ((WAVE) == DAC_WaveGeneration_Noise) || \
  100. ((WAVE) == DAC_WaveGeneration_Triangle))
  101. /**
  102. * @}
  103. */
  104. /** @defgroup DAC_lfsrunmask_triangleamplitude
  105. * @{
  106. */
  107. #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
  108. #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
  109. #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
  110. #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
  111. #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
  112. #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
  113. #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
  114. #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
  115. #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
  116. #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
  117. #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
  118. #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
  119. #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
  120. #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
  121. #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
  122. #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
  123. #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
  124. #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
  125. #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
  126. #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
  127. #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
  128. #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
  129. #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
  130. #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
  131. #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
  132. ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
  133. ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
  134. ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
  135. ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
  136. ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
  137. ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
  138. ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
  139. ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
  140. ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
  141. ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
  142. ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
  143. ((VALUE) == DAC_TriangleAmplitude_1) || \
  144. ((VALUE) == DAC_TriangleAmplitude_3) || \
  145. ((VALUE) == DAC_TriangleAmplitude_7) || \
  146. ((VALUE) == DAC_TriangleAmplitude_15) || \
  147. ((VALUE) == DAC_TriangleAmplitude_31) || \
  148. ((VALUE) == DAC_TriangleAmplitude_63) || \
  149. ((VALUE) == DAC_TriangleAmplitude_127) || \
  150. ((VALUE) == DAC_TriangleAmplitude_255) || \
  151. ((VALUE) == DAC_TriangleAmplitude_511) || \
  152. ((VALUE) == DAC_TriangleAmplitude_1023) || \
  153. ((VALUE) == DAC_TriangleAmplitude_2047) || \
  154. ((VALUE) == DAC_TriangleAmplitude_4095))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup DAC_output_buffer
  159. * @{
  160. */
  161. #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
  162. #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
  163. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
  164. ((STATE) == DAC_OutputBuffer_Disable))
  165. /**
  166. * @}
  167. */
  168. /** @defgroup DAC_Channel_selection
  169. * @{
  170. */
  171. #define DAC_Channel_1 ((uint32_t)0x00000000)
  172. #define DAC_Channel_2 ((uint32_t)0x00000010)
  173. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
  174. ((CHANNEL) == DAC_Channel_2))
  175. /**
  176. * @}
  177. */
  178. /** @defgroup DAC_data_alignment
  179. * @{
  180. */
  181. #define DAC_Align_12b_R ((uint32_t)0x00000000)
  182. #define DAC_Align_12b_L ((uint32_t)0x00000004)
  183. #define DAC_Align_8b_R ((uint32_t)0x00000008)
  184. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
  185. ((ALIGN) == DAC_Align_12b_L) || \
  186. ((ALIGN) == DAC_Align_8b_R))
  187. /**
  188. * @}
  189. */
  190. /** @defgroup DAC_wave_generation
  191. * @{
  192. */
  193. #define DAC_Wave_Noise ((uint32_t)0x00000040)
  194. #define DAC_Wave_Triangle ((uint32_t)0x00000080)
  195. #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
  196. ((WAVE) == DAC_Wave_Triangle))
  197. /**
  198. * @}
  199. */
  200. /** @defgroup DAC_data
  201. * @{
  202. */
  203. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
  204. /**
  205. * @}
  206. */
  207. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  208. /** @defgroup DAC_interrupts_definition
  209. * @{
  210. */
  211. #define DAC_IT_DMAUDR ((uint32_t)0x00002000)
  212. #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
  213. /**
  214. * @}
  215. */
  216. /** @defgroup DAC_flags_definition
  217. * @{
  218. */
  219. #define DAC_FLAG_DMAUDR ((uint32_t)0x00002000)
  220. #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
  221. /**
  222. * @}
  223. */
  224. #endif
  225. /**
  226. * @}
  227. */
  228. /** @defgroup DAC_Exported_Macros
  229. * @{
  230. */
  231. /**
  232. * @}
  233. */
  234. /** @defgroup DAC_Exported_Functions
  235. * @{
  236. */
  237. void DAC_DeInit(void);
  238. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
  239. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
  240. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
  241. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  242. void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
  243. #endif
  244. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
  245. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
  246. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
  247. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
  248. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
  249. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
  250. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
  251. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
  252. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  253. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG);
  254. void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG);
  255. ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT);
  256. void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT);
  257. #endif
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif /*__STM32F10x_DAC_H */
  262. /**
  263. * @}
  264. */
  265. /**
  266. * @}
  267. */
  268. /**
  269. * @}
  270. */
  271. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/