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.
 
 
 

396 lines
13 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_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</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F0xx_HAL_DAC_H
  37. #define __STM32F0xx_HAL_DAC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /** @addtogroup STM32F0xx_HAL_Driver
  42. * @{
  43. */
  44. #if defined(STM32F051x8) || defined(STM32F058xx) || \
  45. defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
  46. defined(STM32F091xC) || defined(STM32F098xx)
  47. /* Includes ------------------------------------------------------------------*/
  48. #include "stm32f0xx_hal_def.h"
  49. /** @addtogroup DAC
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /** @defgroup DAC_Exported_Types DAC Exported Types
  54. * @{
  55. */
  56. /**
  57. * @brief HAL State structures definition
  58. */
  59. typedef enum
  60. {
  61. HAL_DAC_STATE_RESET = 0x00U, /*!< DAC not yet initialized or disabled */
  62. HAL_DAC_STATE_READY = 0x01U, /*!< DAC initialized and ready for use */
  63. HAL_DAC_STATE_BUSY = 0x02U, /*!< DAC internal processing is ongoing */
  64. HAL_DAC_STATE_TIMEOUT = 0x03U, /*!< DAC timeout state */
  65. HAL_DAC_STATE_ERROR = 0x04U /*!< DAC error state */
  66. }HAL_DAC_StateTypeDef;
  67. /**
  68. * @brief DAC handle Structure definition
  69. */
  70. typedef struct
  71. {
  72. DAC_TypeDef *Instance; /*!< Register base address */
  73. __IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */
  74. HAL_LockTypeDef Lock; /*!< DAC locking object */
  75. DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */
  76. DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */
  77. __IO uint32_t ErrorCode; /*!< DAC Error code */
  78. }DAC_HandleTypeDef;
  79. /**
  80. * @brief DAC Configuration regular Channel structure definition
  81. */
  82. typedef struct
  83. {
  84. uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
  85. This parameter can be a value of @ref DAC_trigger_selection */
  86. uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  87. This parameter can be a value of @ref DAC_output_buffer */
  88. }DAC_ChannelConfTypeDef;
  89. /**
  90. * @}
  91. */
  92. /* Exported constants --------------------------------------------------------*/
  93. /** @defgroup DAC_Exported_Constants DAC Exported Constants
  94. * @{
  95. */
  96. /** @defgroup DAC_Error_Code DAC Error Code
  97. * @{
  98. */
  99. #define HAL_DAC_ERROR_NONE 0x00U /*!< No error */
  100. #define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x01U /*!< DAC channel1 DMA underrun error */
  101. #define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x02U /*!< DAC channel2 DMA underrun error */
  102. #define HAL_DAC_ERROR_DMA 0x04U /*!< DMA error */
  103. /**
  104. * @}
  105. */
  106. /** @defgroup DAC_output_buffer DAC output buffer
  107. * @{
  108. */
  109. #define DAC_OUTPUTBUFFER_ENABLE (0x00000000U)
  110. #define DAC_OUTPUTBUFFER_DISABLE ((uint32_t)DAC_CR_BOFF1)
  111. /**
  112. * @}
  113. */
  114. /** @defgroup DAC_data_alignment DAC data alignment
  115. * @{
  116. */
  117. #define DAC_ALIGN_12B_R (0x00000000U)
  118. #define DAC_ALIGN_12B_L (0x00000004U)
  119. #define DAC_ALIGN_8B_R (0x00000008U)
  120. /**
  121. * @}
  122. */
  123. /** @defgroup DAC_flags_definition DAC flags definition
  124. * @{
  125. */
  126. #define DAC_FLAG_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1)
  127. #define DAC_FLAG_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2)
  128. /**
  129. * @}
  130. */
  131. /** @defgroup DAC_IT_definition DAC IT definition
  132. * @{
  133. */
  134. #define DAC_IT_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1)
  135. #define DAC_IT_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2)
  136. /**
  137. * @}
  138. */
  139. /**
  140. * @}
  141. */
  142. /* Exported macro ------------------------------------------------------------*/
  143. /** @defgroup DAC_Exported_Macros DAC Exported Macros
  144. * @{
  145. */
  146. /** @brief Reset DAC handle state
  147. * @param __HANDLE__ specifies the DAC handle.
  148. * @retval None
  149. */
  150. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
  151. /** @brief Enable the DAC channel
  152. * @param __HANDLE__ specifies the DAC handle.
  153. * @param __DAC_Channel__ specifies the DAC channel
  154. * @retval None
  155. */
  156. #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \
  157. ((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << (__DAC_Channel__)))
  158. /** @brief Disable the DAC channel
  159. * @param __HANDLE__ specifies the DAC handle
  160. * @param __DAC_Channel__ specifies the DAC channel.
  161. * @retval None
  162. */
  163. #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \
  164. ((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << (__DAC_Channel__)))
  165. /** @brief Enable the DAC interrupt
  166. * @param __HANDLE__ specifies the DAC handle
  167. * @param __INTERRUPT__ specifies the DAC interrupt.
  168. * This parameter can be any combination of the following values:
  169. * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  170. * @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  171. * @retval None
  172. */
  173. #define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
  174. /** @brief Disable the DAC interrupt
  175. * @param __HANDLE__ specifies the DAC handle
  176. * @param __INTERRUPT__ specifies the DAC interrupt.
  177. * This parameter can be any combination of the following values:
  178. * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  179. * @retval None
  180. */
  181. #define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
  182. /** @brief Check whether the specified DAC interrupt source is enabled or not
  183. * @param __HANDLE__ DAC handle
  184. * @param __INTERRUPT__ DAC interrupt source to check
  185. * This parameter can be any combination of the following values:
  186. * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  187. * @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  188. * @retval State of interruption (SET or RESET)
  189. */
  190. #define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
  191. /** @brief Get the selected DAC's flag status
  192. * @param __HANDLE__ specifies the DAC handle.
  193. * @param __FLAG__ specifies the DAC flag to get.
  194. * This parameter can be any combination of the following values:
  195. * @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
  196. * @retval None
  197. */
  198. #define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  199. /** @brief Clear the DAC's flag
  200. * @param __HANDLE__ specifies the DAC handle.
  201. * @param __FLAG__ specifies the DAC flag to clear.
  202. * This parameter can be any combination of the following values:
  203. * @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
  204. * @retval None
  205. */
  206. #define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__))
  207. /**
  208. * @}
  209. */
  210. /* Private macro -------------------------------------------------------------*/
  211. /** @addtogroup DAC_Private_Macros
  212. * @{
  213. */
  214. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
  215. ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
  216. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
  217. defined(STM32F091xC) || defined(STM32F098xx)
  218. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
  219. ((CHANNEL) == DAC_CHANNEL_2))
  220. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
  221. /* STM32F091xC || STM32F098xx */
  222. #if defined(STM32F051x8) || defined(STM32F058xx)
  223. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1))
  224. #endif /* STM32F051x8 || STM32F058xx */
  225. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
  226. ((ALIGN) == DAC_ALIGN_12B_L) || \
  227. ((ALIGN) == DAC_ALIGN_8B_R))
  228. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
  229. /** @brief Set DHR12R1 alignment
  230. * @param __ALIGNMENT__ specifies the DAC alignment
  231. * @retval None
  232. */
  233. #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) ((0x00000008U) + (__ALIGNMENT__))
  234. /** @brief Set DHR12R2 alignment
  235. * @param __ALIGNMENT__ specifies the DAC alignment
  236. * @retval None
  237. */
  238. #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) ((0x00000014U) + (__ALIGNMENT__))
  239. /** @brief Set DHR12RD alignment
  240. * @param __ALIGNMENT__ specifies the DAC alignment
  241. * @retval None
  242. */
  243. #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) ((0x00000020U) + (__ALIGNMENT__))
  244. /**
  245. * @}
  246. */
  247. /* Include DAC HAL Extension module */
  248. #include "stm32f0xx_hal_dac_ex.h"
  249. /* Exported functions --------------------------------------------------------*/
  250. /** @addtogroup DAC_Exported_Functions
  251. * @{
  252. */
  253. /** @addtogroup DAC_Exported_Functions_Group1
  254. * @{
  255. */
  256. /* Initialization and de-initialization functions *****************************/
  257. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac);
  258. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac);
  259. void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac);
  260. void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac);
  261. /**
  262. * @}
  263. */
  264. /** @addtogroup DAC_Exported_Functions_Group2
  265. * @{
  266. */
  267. /* IO operation functions *****************************************************/
  268. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
  269. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel);
  270. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment);
  271. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel);
  272. void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac);
  273. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
  274. void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac);
  275. void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac);
  276. void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
  277. void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac);
  278. /**
  279. * @}
  280. */
  281. /** @addtogroup DAC_Exported_Functions_Group3
  282. * @{
  283. */
  284. /* Peripheral Control functions ***********************************************/
  285. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel);
  286. HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel);
  287. /**
  288. * @}
  289. */
  290. /** @addtogroup DAC_Exported_Functions_Group4
  291. * @{
  292. */
  293. /* Peripheral State and Error functions ***************************************/
  294. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac);
  295. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
  296. /**
  297. * @}
  298. */
  299. /**
  300. * @}
  301. */
  302. /**
  303. * @}
  304. */
  305. #endif /* STM32F051x8 || STM32F058xx || */
  306. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  307. /* STM32F091xC || STM32F098xx */
  308. /**
  309. * @}
  310. */
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314. #endif /*__STM32F0xx_HAL_DAC_H */
  315. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/