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.

stm32l1xx_hal_dac.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_dac.h
  4. * @author MCD Application Team
  5. * @brief Header file of DAC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32L1xx_HAL_DAC_H
  21. #define STM32L1xx_HAL_DAC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /** @addtogroup STM32L1xx_HAL_Driver
  26. * @{
  27. */
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32l1xx_hal_def.h"
  30. #if defined(DAC1)
  31. /** @addtogroup DAC
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /** @defgroup DAC_Exported_Types DAC Exported Types
  36. * @{
  37. */
  38. /**
  39. * @brief HAL State structures definition
  40. */
  41. typedef enum
  42. {
  43. HAL_DAC_STATE_RESET = 0x00U, /*!< DAC not yet initialized or disabled */
  44. HAL_DAC_STATE_READY = 0x01U, /*!< DAC initialized and ready for use */
  45. HAL_DAC_STATE_BUSY = 0x02U, /*!< DAC internal processing is ongoing */
  46. HAL_DAC_STATE_TIMEOUT = 0x03U, /*!< DAC timeout state */
  47. HAL_DAC_STATE_ERROR = 0x04U /*!< DAC error state */
  48. } HAL_DAC_StateTypeDef;
  49. /**
  50. * @brief DAC handle Structure definition
  51. */
  52. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  53. typedef struct __DAC_HandleTypeDef
  54. #else
  55. typedef struct
  56. #endif
  57. {
  58. DAC_TypeDef *Instance; /*!< Register base address */
  59. __IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */
  60. HAL_LockTypeDef Lock; /*!< DAC locking object */
  61. DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */
  62. DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */
  63. __IO uint32_t ErrorCode; /*!< DAC Error code */
  64. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  65. void (* ConvCpltCallbackCh1)(struct __DAC_HandleTypeDef *hdac);
  66. void (* ConvHalfCpltCallbackCh1)(struct __DAC_HandleTypeDef *hdac);
  67. void (* ErrorCallbackCh1)(struct __DAC_HandleTypeDef *hdac);
  68. void (* DMAUnderrunCallbackCh1)(struct __DAC_HandleTypeDef *hdac);
  69. void (* ConvCpltCallbackCh2)(struct __DAC_HandleTypeDef *hdac);
  70. void (* ConvHalfCpltCallbackCh2)(struct __DAC_HandleTypeDef *hdac);
  71. void (* ErrorCallbackCh2)(struct __DAC_HandleTypeDef *hdac);
  72. void (* DMAUnderrunCallbackCh2)(struct __DAC_HandleTypeDef *hdac);
  73. void (* MspInitCallback)(struct __DAC_HandleTypeDef *hdac);
  74. void (* MspDeInitCallback)(struct __DAC_HandleTypeDef *hdac);
  75. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  76. } DAC_HandleTypeDef;
  77. /**
  78. * @brief DAC Configuration regular Channel structure definition
  79. */
  80. typedef struct
  81. {
  82. uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
  83. This parameter can be a value of @ref DAC_trigger_selection */
  84. uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  85. This parameter can be a value of @ref DAC_output_buffer */
  86. } DAC_ChannelConfTypeDef;
  87. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  88. /**
  89. * @brief HAL DAC Callback ID enumeration definition
  90. */
  91. typedef enum
  92. {
  93. HAL_DAC_CH1_COMPLETE_CB_ID = 0x00U, /*!< DAC CH1 Complete Callback ID */
  94. HAL_DAC_CH1_HALF_COMPLETE_CB_ID = 0x01U, /*!< DAC CH1 half Complete Callback ID */
  95. HAL_DAC_CH1_ERROR_ID = 0x02U, /*!< DAC CH1 error Callback ID */
  96. HAL_DAC_CH1_UNDERRUN_CB_ID = 0x03U, /*!< DAC CH1 underrun Callback ID */
  97. HAL_DAC_CH2_COMPLETE_CB_ID = 0x04U, /*!< DAC CH2 Complete Callback ID */
  98. HAL_DAC_CH2_HALF_COMPLETE_CB_ID = 0x05U, /*!< DAC CH2 half Complete Callback ID */
  99. HAL_DAC_CH2_ERROR_ID = 0x06U, /*!< DAC CH2 error Callback ID */
  100. HAL_DAC_CH2_UNDERRUN_CB_ID = 0x07U, /*!< DAC CH2 underrun Callback ID */
  101. HAL_DAC_MSPINIT_CB_ID = 0x08U, /*!< DAC MspInit Callback ID */
  102. HAL_DAC_MSPDEINIT_CB_ID = 0x09U, /*!< DAC MspDeInit Callback ID */
  103. HAL_DAC_ALL_CB_ID = 0x0AU /*!< DAC All ID */
  104. } HAL_DAC_CallbackIDTypeDef;
  105. /**
  106. * @brief HAL DAC Callback pointer definition
  107. */
  108. typedef void (*pDAC_CallbackTypeDef)(DAC_HandleTypeDef *hdac);
  109. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  110. /**
  111. * @}
  112. */
  113. /* Exported constants --------------------------------------------------------*/
  114. /** @defgroup DAC_Exported_Constants DAC Exported Constants
  115. * @{
  116. */
  117. /** @defgroup DAC_Error_Code DAC Error Code
  118. * @{
  119. */
  120. #define HAL_DAC_ERROR_NONE 0x00U /*!< No error */
  121. #define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x01U /*!< DAC channel1 DMA underrun error */
  122. #define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x02U /*!< DAC channel2 DMA underrun error */
  123. #define HAL_DAC_ERROR_DMA 0x04U /*!< DMA error */
  124. #define HAL_DAC_ERROR_TIMEOUT 0x08U /*!< Timeout error */
  125. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  126. #define HAL_DAC_ERROR_INVALID_CALLBACK 0x10U /*!< Invalid callback error */
  127. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  128. /**
  129. * @}
  130. */
  131. /** @defgroup DAC_trigger_selection DAC trigger selection
  132. * @{
  133. */
  134. #define DAC_TRIGGER_NONE 0x00000000U /*!< Conversion is automatic once the DAC1_DHRxxxx register has been loaded, and not by external trigger */
  135. #define DAC_TRIGGER_T6_TRGO (DAC_CR_TEN1) /*!< Conversion started by software trigger for DAC channel */
  136. #define DAC_TRIGGER_T7_TRGO ( DAC_CR_TSEL1_1 | DAC_CR_TEN1) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
  137. #define DAC_TRIGGER_T9_TRGO ( DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1) /*!< TIM9 TRGO selected as external conversion trigger for DAC channel */
  138. #define DAC_TRIGGER_T2_TRGO (DAC_CR_TSEL1_2 | DAC_CR_TEN1) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
  139. #define DAC_TRIGGER_T4_TRGO (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0 | DAC_CR_TEN1) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
  140. #define DAC_TRIGGER_EXT_IT9 (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
  141. #define DAC_TRIGGER_SOFTWARE (DAC_CR_TSEL1 | DAC_CR_TEN1) /*!< Conversion started by software trigger for DAC channel */
  142. /**
  143. * @}
  144. */
  145. /** @defgroup DAC_output_buffer DAC output buffer
  146. * @{
  147. */
  148. #define DAC_OUTPUTBUFFER_ENABLE 0x00000000U
  149. #define DAC_OUTPUTBUFFER_DISABLE (DAC_CR_BOFF1)
  150. /**
  151. * @}
  152. */
  153. /** @defgroup DAC_Channel_selection DAC Channel selection
  154. * @{
  155. */
  156. #define DAC_CHANNEL_1 0x00000000U
  157. #define DAC_CHANNEL_2 0x00000010U
  158. /**
  159. * @}
  160. */
  161. /** @defgroup DAC_data_alignment DAC data alignment
  162. * @{
  163. */
  164. #define DAC_ALIGN_12B_R 0x00000000U
  165. #define DAC_ALIGN_12B_L 0x00000004U
  166. #define DAC_ALIGN_8B_R 0x00000008U
  167. /**
  168. * @}
  169. */
  170. /** @defgroup DAC_flags_definition DAC flags definition
  171. * @{
  172. */
  173. #define DAC_FLAG_DMAUDR1 (DAC_SR_DMAUDR1)
  174. #define DAC_FLAG_DMAUDR2 (DAC_SR_DMAUDR2)
  175. /**
  176. * @}
  177. */
  178. /** @defgroup DAC_IT_definition DAC IT definition
  179. * @{
  180. */
  181. #define DAC_IT_DMAUDR1 (DAC_SR_DMAUDR1)
  182. #define DAC_IT_DMAUDR2 (DAC_SR_DMAUDR2)
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @}
  188. */
  189. /* Exported macro ------------------------------------------------------------*/
  190. /** @defgroup DAC_Exported_Macros DAC Exported Macros
  191. * @{
  192. */
  193. /** @brief Reset DAC handle state.
  194. * @param __HANDLE__ specifies the DAC handle.
  195. * @retval None
  196. */
  197. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  198. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) do { \
  199. (__HANDLE__)->State = HAL_DAC_STATE_RESET; \
  200. (__HANDLE__)->MspInitCallback = NULL; \
  201. (__HANDLE__)->MspDeInitCallback = NULL; \
  202. } while(0)
  203. #else
  204. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
  205. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  206. /** @brief Enable the DAC channel.
  207. * @param __HANDLE__ specifies the DAC handle.
  208. * @param __DAC_Channel__ specifies the DAC channel
  209. * @retval None
  210. */
  211. #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \
  212. ((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << ((__DAC_Channel__) & 0x10UL)))
  213. /** @brief Disable the DAC channel.
  214. * @param __HANDLE__ specifies the DAC handle
  215. * @param __DAC_Channel__ specifies the DAC channel.
  216. * @retval None
  217. */
  218. #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \
  219. ((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << ((__DAC_Channel__) & 0x10UL)))
  220. /** @brief Set DHR12R1 alignment.
  221. * @param __ALIGNMENT__ specifies the DAC alignment
  222. * @retval None
  223. */
  224. #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (0x00000008U + (__ALIGNMENT__))
  225. /** @brief Set DHR12R2 alignment.
  226. * @param __ALIGNMENT__ specifies the DAC alignment
  227. * @retval None
  228. */
  229. #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (0x00000014U + (__ALIGNMENT__))
  230. /** @brief Set DHR12RD alignment.
  231. * @param __ALIGNMENT__ specifies the DAC alignment
  232. * @retval None
  233. */
  234. #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (0x00000020U + (__ALIGNMENT__))
  235. /** @brief Enable the DAC interrupt.
  236. * @param __HANDLE__ specifies the DAC handle
  237. * @param __INTERRUPT__ specifies the DAC interrupt.
  238. * This parameter can be any combination of the following values:
  239. * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  240. * @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  241. * @retval None
  242. */
  243. #define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
  244. /** @brief Disable the DAC interrupt.
  245. * @param __HANDLE__ specifies the DAC handle
  246. * @param __INTERRUPT__ specifies the DAC interrupt.
  247. * This parameter can be any combination of the following values:
  248. * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  249. * @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  250. * @retval None
  251. */
  252. #define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
  253. /** @brief Check whether the specified DAC interrupt source is enabled or not.
  254. * @param __HANDLE__ DAC handle
  255. * @param __INTERRUPT__ DAC interrupt source to check
  256. * This parameter can be any combination of the following values:
  257. * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  258. * @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  259. * @retval State of interruption (SET or RESET)
  260. */
  261. #define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
  262. /** @brief Get the selected DAC's flag status.
  263. * @param __HANDLE__ specifies the DAC handle.
  264. * @param __FLAG__ specifies the DAC flag to get.
  265. * This parameter can be any combination of the following values:
  266. * @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
  267. * @arg DAC_FLAG_DMAUDR2: DAC channel 2 DMA underrun flag
  268. * @retval None
  269. */
  270. #define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  271. /** @brief Clear the DAC's flag.
  272. * @param __HANDLE__ specifies the DAC handle.
  273. * @param __FLAG__ specifies the DAC flag to clear.
  274. * This parameter can be any combination of the following values:
  275. * @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
  276. * @arg DAC_FLAG_DMAUDR2: DAC channel 2 DMA underrun flag
  277. * @retval None
  278. */
  279. #define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__))
  280. /**
  281. * @}
  282. */
  283. /* Private macro -------------------------------------------------------------*/
  284. /** @defgroup DAC_Private_Macros DAC Private Macros
  285. * @{
  286. */
  287. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
  288. ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
  289. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
  290. ((CHANNEL) == DAC_CHANNEL_2))
  291. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
  292. ((ALIGN) == DAC_ALIGN_12B_L) || \
  293. ((ALIGN) == DAC_ALIGN_8B_R))
  294. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
  295. /**
  296. * @}
  297. */
  298. /* Include DAC HAL Extended module */
  299. #include "stm32l1xx_hal_dac_ex.h"
  300. /* Exported functions --------------------------------------------------------*/
  301. /** @addtogroup DAC_Exported_Functions
  302. * @{
  303. */
  304. /** @addtogroup DAC_Exported_Functions_Group1
  305. * @{
  306. */
  307. /* Initialization and de-initialization functions *****************************/
  308. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef *hdac);
  309. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef *hdac);
  310. void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac);
  311. void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac);
  312. /**
  313. * @}
  314. */
  315. /** @addtogroup DAC_Exported_Functions_Group2
  316. * @{
  317. */
  318. /* IO operation functions *****************************************************/
  319. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef *hdac, uint32_t Channel);
  320. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef *hdac, uint32_t Channel);
  321. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length,
  322. uint32_t Alignment);
  323. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel);
  324. void HAL_DAC_IRQHandler(DAC_HandleTypeDef *hdac);
  325. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
  326. void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac);
  327. void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac);
  328. void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
  329. void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac);
  330. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  331. /* DAC callback registering/unregistering */
  332. HAL_StatusTypeDef HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID,
  333. pDAC_CallbackTypeDef pCallback);
  334. HAL_StatusTypeDef HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID);
  335. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  336. /**
  337. * @}
  338. */
  339. /** @addtogroup DAC_Exported_Functions_Group3
  340. * @{
  341. */
  342. /* Peripheral Control functions ***********************************************/
  343. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef *hdac, uint32_t Channel);
  344. HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel);
  345. /**
  346. * @}
  347. */
  348. /** @addtogroup DAC_Exported_Functions_Group4
  349. * @{
  350. */
  351. /* Peripheral State and Error functions ***************************************/
  352. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac);
  353. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
  354. /**
  355. * @}
  356. */
  357. /**
  358. * @}
  359. */
  360. /** @defgroup DAC_Private_Functions DAC Private Functions
  361. * @{
  362. */
  363. void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
  364. void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
  365. void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
  366. /**
  367. * @}
  368. */
  369. /**
  370. * @}
  371. */
  372. #endif /* DAC1 */
  373. /**
  374. * @}
  375. */
  376. #ifdef __cplusplus
  377. }
  378. #endif
  379. #endif /*STM32L1xx_HAL_DAC_H */
  380. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/