Moved IO_GPIOPortIdx to platform (#14127)
[betaflight.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Inc / stm32f7xx_hal_dac.h
blobb86205d5a6294eefd5504ec1238cdaff156054bc
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_dac.h
4 * @author MCD Application Team
5 * @brief Header file of DAC HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef __STM32F7xx_HAL_DAC_H
22 #define __STM32F7xx_HAL_DAC_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f7xx_hal_def.h"
31 /** @addtogroup STM32F7xx_HAL_Driver
32 * @{
35 /** @addtogroup DAC
36 * @{
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup DAC_Exported_Types DAC Exported Types
41 * @{
44 /**
45 * @brief HAL State structures definition
47 typedef enum
49 HAL_DAC_STATE_RESET = 0x00U, /*!< DAC not yet initialized or disabled */
50 HAL_DAC_STATE_READY = 0x01U, /*!< DAC initialized and ready for use */
51 HAL_DAC_STATE_BUSY = 0x02U, /*!< DAC internal processing is ongoing */
52 HAL_DAC_STATE_TIMEOUT = 0x03U, /*!< DAC timeout state */
53 HAL_DAC_STATE_ERROR = 0x04U /*!< DAC error state */
54 }HAL_DAC_StateTypeDef;
56 /**
57 * @brief DAC handle Structure definition
59 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
60 typedef struct __DAC_HandleTypeDef
61 #else
62 typedef struct
63 #endif
65 DAC_TypeDef *Instance; /*!< Register base address */
67 __IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */
69 HAL_LockTypeDef Lock; /*!< DAC locking object */
71 DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */
73 DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */
75 __IO uint32_t ErrorCode; /*!< DAC Error code */
76 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
77 void (* ConvCpltCallbackCh1) (struct __DAC_HandleTypeDef *hdac);
78 void (* ConvHalfCpltCallbackCh1) (struct __DAC_HandleTypeDef *hdac);
79 void (* ErrorCallbackCh1) (struct __DAC_HandleTypeDef *hdac);
80 void (* DMAUnderrunCallbackCh1) (struct __DAC_HandleTypeDef *hdac);
81 void (* ConvCpltCallbackCh2) (struct __DAC_HandleTypeDef* hdac);
82 void (* ConvHalfCpltCallbackCh2) (struct __DAC_HandleTypeDef* hdac);
83 void (* ErrorCallbackCh2) (struct __DAC_HandleTypeDef* hdac);
84 void (* DMAUnderrunCallbackCh2) (struct __DAC_HandleTypeDef* hdac);
86 void (* MspInitCallback) (struct __DAC_HandleTypeDef *hdac);
87 void (* MspDeInitCallback ) (struct __DAC_HandleTypeDef *hdac);
88 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
90 }DAC_HandleTypeDef;
92 /**
93 * @brief DAC Configuration regular Channel structure definition
95 typedef struct
97 uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
98 This parameter can be a value of @ref DAC_trigger_selection */
100 uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
101 This parameter can be a value of @ref DAC_output_buffer */
102 }DAC_ChannelConfTypeDef;
104 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
106 * @brief HAL DAC Callback ID enumeration definition
108 typedef enum
110 HAL_DAC_CH1_COMPLETE_CB_ID = 0x00U, /*!< DAC CH1 Complete Callback ID */
111 HAL_DAC_CH1_HALF_COMPLETE_CB_ID = 0x01U, /*!< DAC CH1 half Complete Callback ID */
112 HAL_DAC_CH1_ERROR_ID = 0x02U, /*!< DAC CH1 error Callback ID */
113 HAL_DAC_CH1_UNDERRUN_CB_ID = 0x03U, /*!< DAC CH1 underrun Callback ID */
114 HAL_DAC_CH2_COMPLETE_CB_ID = 0x04U, /*!< DAC CH2 Complete Callback ID */
115 HAL_DAC_CH2_HALF_COMPLETE_CB_ID = 0x05U, /*!< DAC CH2 half Complete Callback ID */
116 HAL_DAC_CH2_ERROR_ID = 0x06U, /*!< DAC CH2 error Callback ID */
117 HAL_DAC_CH2_UNDERRUN_CB_ID = 0x07U, /*!< DAC CH2 underrun Callback ID */
118 HAL_DAC_MSP_INIT_CB_ID = 0x08U, /*!< DAC MspInit Callback ID */
119 HAL_DAC_MSP_DEINIT_CB_ID = 0x09U, /*!< DAC MspDeInit Callback ID */
120 HAL_DAC_ALL_CB_ID = 0x0AU /*!< DAC All ID */
121 }HAL_DAC_CallbackIDTypeDef;
124 * @brief HAL DAC Callback pointer definition
126 typedef void (*pDAC_CallbackTypeDef)(DAC_HandleTypeDef *hdac);
127 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
129 * @}
132 /* Exported constants --------------------------------------------------------*/
133 /** @defgroup DAC_Exported_Constants DAC Exported Constants
134 * @{
137 /** @defgroup DAC_Error_Code DAC Error Code
138 * @{
140 #define HAL_DAC_ERROR_NONE 0x00U /*!< No error */
141 #define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x01U /*!< DAC channel1 DAM underrun error */
142 #define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x02U /*!< DAC channel2 DAM underrun error */
143 #define HAL_DAC_ERROR_DMA 0x04U /*!< DMA error */
144 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
145 #define HAL_DAC_ERROR_INVALID_CALLBACK 0x10U /*!< Invalid callback error */
146 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
148 * @}
151 /** @defgroup DAC_trigger_selection DAC Trigger Selection
152 * @{
155 #define DAC_TRIGGER_NONE ((uint32_t)0x00000000U) /*!< Conversion is automatic once the DAC1_DHRxxxx register
156 has been loaded, and not by external trigger */
157 #define DAC_TRIGGER_T2_TRGO ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
158 #define DAC_TRIGGER_T4_TRGO ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
159 #define DAC_TRIGGER_T5_TRGO ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */
160 #define DAC_TRIGGER_T6_TRGO ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
161 #define DAC_TRIGGER_T7_TRGO ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
162 #define DAC_TRIGGER_T8_TRGO ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel */
164 #define DAC_TRIGGER_EXT_IT9 ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
165 #define DAC_TRIGGER_SOFTWARE ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */
167 * @}
170 /** @defgroup DAC_output_buffer DAC Output Buffer
171 * @{
173 #define DAC_OUTPUTBUFFER_ENABLE ((uint32_t)0x00000000U)
174 #define DAC_OUTPUTBUFFER_DISABLE ((uint32_t)DAC_CR_BOFF1)
176 * @}
179 /** @defgroup DAC_Channel_selection DAC Channel Selection
180 * @{
182 #define DAC_CHANNEL_1 ((uint32_t)0x00000000U)
183 #define DAC_CHANNEL_2 ((uint32_t)0x00000010U)
185 * @}
188 /** @defgroup DAC_data_alignment DAC Data Alignment
189 * @{
191 #define DAC_ALIGN_12B_R ((uint32_t)0x00000000U)
192 #define DAC_ALIGN_12B_L ((uint32_t)0x00000004U)
193 #define DAC_ALIGN_8B_R ((uint32_t)0x00000008U)
195 * @}
198 /** @defgroup DAC_flags_definition DAC Flags Definition
199 * @{
201 #define DAC_FLAG_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1)
202 #define DAC_FLAG_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2)
204 * @}
207 /** @defgroup DAC_IT_definition DAC IT Definition
208 * @{
210 #define DAC_IT_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1)
211 #define DAC_IT_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2)
213 * @}
217 * @}
220 /* Exported macro ------------------------------------------------------------*/
221 /** @defgroup DAC_Exported_Macros DAC Exported Macros
222 * @{
225 /** @brief Reset DAC handle state
226 * @param __HANDLE__: specifies the DAC handle.
227 * @retval None
229 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
230 #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) do { \
231 (__HANDLE__)->State = HAL_DAC_STATE_RESET; \
232 (__HANDLE__)->MspInitCallback = NULL; \
233 (__HANDLE__)->MspDeInitCallback = NULL; \
234 } while(0)
235 #else
236 #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
237 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
239 /** @brief Enable the DAC channel
240 * @param __HANDLE__: specifies the DAC handle.
241 * @param __DAC_CHANNEL__: specifies the DAC channel
242 * @retval None
244 #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_CHANNEL__) \
245 ((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << (__DAC_CHANNEL__)))
247 /** @brief Disable the DAC channel
248 * @param __HANDLE__: specifies the DAC handle
249 * @param __DAC_CHANNEL__: specifies the DAC channel.
250 * @retval None
252 #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_CHANNEL__) \
253 ((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << (__DAC_CHANNEL__)))
256 /** @brief Enable the DAC interrupt
257 * @param __HANDLE__: specifies the DAC handle
258 * @param __INTERRUPT__: specifies the DAC interrupt.
259 * @retval None
261 #define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
263 /** @brief Disable the DAC interrupt
264 * @param __HANDLE__: specifies the DAC handle
265 * @param __INTERRUPT__: specifies the DAC interrupt.
266 * @retval None
268 #define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
270 /** @brief Checks if the specified DAC interrupt source is enabled or disabled.
271 * @param __HANDLE__: DAC handle
272 * @param __INTERRUPT__: DAC interrupt source to check
273 * This parameter can be any combination of the following values:
274 * @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
275 * @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
276 * @retval State of interruption (SET or RESET)
278 #define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
280 /** @brief Get the selected DAC's flag status.
281 * @param __HANDLE__: specifies the DAC handle.
282 * @param __FLAG__: specifies the flag to clear.
283 * This parameter can be any combination of the following values:
284 * @arg DAC_FLAG_DMAUDR1: DMA underrun 1 flag
285 * @arg DAC_FLAG_DMAUDR2: DMA underrun 2 flag
286 * @retval None
288 #define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
290 /** @brief Clear the DAC's flag.
291 * @param __HANDLE__: specifies the DAC handle.
292 * @param __FLAG__: specifies the flag to clear.
293 * This parameter can be any combination of the following values:
294 * @arg DAC_FLAG_DMAUDR1: DMA underrun 1 flag
295 * @arg DAC_FLAG_DMAUDR2: DMA underrun 2 flag
296 * @retval None
298 #define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__))
300 * @}
303 /* Include DAC HAL Extension module */
304 #include "stm32f7xx_hal_dac_ex.h"
306 /* Exported functions --------------------------------------------------------*/
307 /** @addtogroup DAC_Exported_Functions
308 * @{
311 /** @addtogroup DAC_Exported_Functions_Group1
312 * @{
314 /* Initialization/de-initialization functions *********************************/
315 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac);
316 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac);
317 void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac);
318 void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac);
320 * @}
323 /** @addtogroup DAC_Exported_Functions_Group2
324 * @{
326 /* I/O operation functions ****************************************************/
327 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
328 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel);
329 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment);
330 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel);
331 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel);
333 * @}
336 /** @addtogroup DAC_Exported_Functions_Group3
337 * @{
339 /* Peripheral Control functions ***********************************************/
340 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel);
341 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
343 * @}
346 /** @addtogroup DAC_Exported_Functions_Group4
347 * @{
349 /* Peripheral State functions *************************************************/
350 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac);
351 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac);
352 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
354 void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac);
355 void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac);
356 void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
357 void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac);
358 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
359 /* DAC callback registering/unregistering */
360 HAL_StatusTypeDef HAL_DAC_RegisterCallback (DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID, pDAC_CallbackTypeDef pCallback);
361 HAL_StatusTypeDef HAL_DAC_UnRegisterCallback (DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID);
362 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
364 * @}
368 * @}
370 /* Private types -------------------------------------------------------------*/
371 /* Private variables ---------------------------------------------------------*/
372 /* Private constants ---------------------------------------------------------*/
373 /** @defgroup DAC_Private_Constants DAC Private Constants
374 * @{
378 * @}
381 /* Private macros ------------------------------------------------------------*/
382 /** @defgroup DAC_Private_Macros DAC Private Macros
383 * @{
385 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
386 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
387 ((ALIGN) == DAC_ALIGN_12B_L) || \
388 ((ALIGN) == DAC_ALIGN_8B_R))
389 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
390 ((CHANNEL) == DAC_CHANNEL_2))
391 #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
392 ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
394 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
395 ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
396 ((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \
397 ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
398 ((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \
399 ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
400 ((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \
401 ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
402 ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
404 /** @brief Set DHR12R1 alignment
405 * @param __ALIGNMENT__: specifies the DAC alignment
406 * @retval None
408 #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000008U) + (__ALIGNMENT__))
410 /** @brief Set DHR12R2 alignment
411 * @param __ALIGNMENT__: specifies the DAC alignment
412 * @retval None
414 #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000014U) + (__ALIGNMENT__))
416 /** @brief Set DHR12RD alignment
417 * @param __ALIGNMENT__: specifies the DAC alignment
418 * @retval None
420 #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000020U) + (__ALIGNMENT__))
423 * @}
426 /* Private functions ---------------------------------------------------------*/
427 /** @defgroup DAC_Private_Functions DAC Private Functions
428 * @{
431 * @}
435 * @}
439 * @}
442 #ifdef __cplusplus
444 #endif
446 #endif /*__STM32F7xx_HAL_DAC_H */
448 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/