stm32f1xx_hal_dac.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_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 __STM32F1xx_HAL_DAC_H
  37. #define __STM32F1xx_HAL_DAC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32f1xx_hal_def.h"
  44. /** @addtogroup STM32F1xx_HAL_Driver
  45. * @{
  46. */
  47. /** @addtogroup DAC
  48. * @{
  49. */
  50. /* Exported types ------------------------------------------------------------*/
  51. /** @defgroup DAC_Exported_Types DAC Exported Types
  52. * @{
  53. */
  54. /**
  55. * @brief HAL State structures definition
  56. */
  57. typedef enum
  58. {
  59. HAL_DAC_STATE_RESET = 0x00U, /*!< DAC not yet initialized or disabled */
  60. HAL_DAC_STATE_READY = 0x01U, /*!< DAC initialized and ready for use */
  61. HAL_DAC_STATE_BUSY = 0x02U, /*!< DAC internal processing is ongoing */
  62. HAL_DAC_STATE_TIMEOUT = 0x03U, /*!< DAC timeout state */
  63. HAL_DAC_STATE_ERROR = 0x04U /*!< DAC error state */
  64. }HAL_DAC_StateTypeDef;
  65. /**
  66. * @brief DAC handle Structure definition
  67. */
  68. typedef struct
  69. {
  70. DAC_TypeDef *Instance; /*!< Register base address */
  71. __IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */
  72. HAL_LockTypeDef Lock; /*!< DAC locking object */
  73. DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */
  74. DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */
  75. __IO uint32_t ErrorCode; /*!< DAC Error code */
  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 DACEx_trigger_selection
  84. Note: For STM32F100x high-density value line devices, additional trigger sources are available. */
  85. uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  86. This parameter can be a value of @ref DAC_output_buffer */
  87. }DAC_ChannelConfTypeDef;
  88. /**
  89. * @}
  90. */
  91. /* Exported constants --------------------------------------------------------*/
  92. /** @defgroup DAC_Exported_Constants DAC Exported Constants
  93. * @{
  94. */
  95. /** @defgroup DAC_Error_Code DAC Error Code
  96. * @{
  97. */
  98. #define HAL_DAC_ERROR_NONE 0x00000000U /*!< No error */
  99. #define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x00000001U /*!< DAC channel1 DMA underrun error */
  100. #define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x00000002U /*!< DAC channel2 DMA underrun error */
  101. #define HAL_DAC_ERROR_DMA 0x00000004U /*!< DMA error */
  102. /**
  103. * @}
  104. */
  105. /** @defgroup DAC_output_buffer DAC output buffer
  106. * @{
  107. */
  108. #define DAC_OUTPUTBUFFER_ENABLE 0x00000000U
  109. #define DAC_OUTPUTBUFFER_DISABLE ((uint32_t)DAC_CR_BOFF1)
  110. /**
  111. * @}
  112. */
  113. /** @defgroup DAC_Channel_selection DAC Channel selection
  114. * @{
  115. */
  116. #define DAC_CHANNEL_1 0x00000000U
  117. #define DAC_CHANNEL_2 0x00000010U
  118. /**
  119. * @}
  120. */
  121. /** @defgroup DAC_data_alignement DAC data alignement
  122. * @{
  123. */
  124. #define DAC_ALIGN_12B_R 0x00000000U
  125. #define DAC_ALIGN_12B_L 0x00000004U
  126. #define DAC_ALIGN_8B_R 0x00000008U
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /* Exported macro ------------------------------------------------------------*/
  134. /** @defgroup DAC_Exported_Macros DAC Exported Macros
  135. * @{
  136. */
  137. /** @brief Reset DAC handle state
  138. * @param __HANDLE__: specifies the DAC handle.
  139. * @retval None
  140. */
  141. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
  142. /** @brief Enable the DAC channel
  143. * @param __HANDLE__: specifies the DAC handle.
  144. * @param __DAC_Channel__: specifies the DAC channel
  145. * @retval None
  146. */
  147. #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \
  148. ((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << (__DAC_Channel__)))
  149. /** @brief Disable the DAC channel
  150. * @param __HANDLE__: specifies the DAC handle
  151. * @param __DAC_Channel__: specifies the DAC channel.
  152. * @retval None
  153. */
  154. #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \
  155. ((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << (__DAC_Channel__)))
  156. /**
  157. * @}
  158. */
  159. /* Private macro -------------------------------------------------------------*/
  160. /** @defgroup DAC_Private_Macros DAC Private Macros
  161. * @{
  162. */
  163. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
  164. ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
  165. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
  166. ((CHANNEL) == DAC_CHANNEL_2))
  167. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
  168. ((ALIGN) == DAC_ALIGN_12B_L) || \
  169. ((ALIGN) == DAC_ALIGN_8B_R))
  170. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
  171. #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (0x00000008U + (__ALIGNMENT__))
  172. #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (0x00000014U + (__ALIGNMENT__))
  173. #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (0x00000020U + (__ALIGNMENT__))
  174. /**
  175. * @}
  176. */
  177. /* Include DAC HAL Extension module */
  178. #include "stm32f1xx_hal_dac_ex.h"
  179. /* Exported functions --------------------------------------------------------*/
  180. /** @addtogroup DAC_Exported_Functions
  181. * @{
  182. */
  183. /** @addtogroup DAC_Exported_Functions_Group1
  184. * @{
  185. */
  186. /* Initialization and de-initialization functions *****************************/
  187. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac);
  188. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac);
  189. void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac);
  190. void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac);
  191. /**
  192. * @}
  193. */
  194. /** @addtogroup DAC_Exported_Functions_Group2
  195. * @{
  196. */
  197. /* IO operation functions *****************************************************/
  198. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
  199. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel);
  200. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment);
  201. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel);
  202. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
  203. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel);
  204. /**
  205. * @}
  206. */
  207. /** @addtogroup DAC_Exported_Functions_Group3
  208. * @{
  209. */
  210. /* Peripheral Control functions ***********************************************/
  211. HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel);
  212. /**
  213. * @}
  214. */
  215. /** @addtogroup DAC_Exported_Functions_Group4
  216. * @{
  217. */
  218. /* Peripheral State functions *************************************************/
  219. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac);
  220. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
  221. void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac);
  222. void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac);
  223. void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
  224. /**
  225. * @}
  226. */
  227. /**
  228. * @}
  229. */
  230. /** @addtogroup DAC_Private_Functions DAC Private Functions
  231. * @{
  232. */
  233. void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
  234. void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
  235. void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. #endif /* STM32F100xB || STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
  246. #ifdef __cplusplus
  247. }
  248. #endif
  249. #endif /*__STM32F1xx_HAL_DAC_H */
  250. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/