Updated and Validated
[betaflight.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_hal_dac.c
blob42b6d0834c087876a90efaecf933ead0c2fa6446
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_dac.c
4 * @author MCD Application Team
5 * @brief DAC HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Digital to Analog Converter (DAC) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral Control functions
11 * + Peripheral State and Errors functions
14 @verbatim
15 ==============================================================================
16 ##### DAC Peripheral features #####
17 ==============================================================================
18 [..]
19 *** DAC Channels ***
20 ====================
21 [..]
22 The device integrates two 12-bit Digital Analog Converters that can
23 be used independently or simultaneously (dual mode):
24 (#) DAC channel1 with DAC_OUT1 (PA4) as output
25 (#) DAC channel2 with DAC_OUT2 (PA5) as output
27 *** DAC Triggers ***
28 ====================
29 [..]
30 Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE
31 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register.
32 [..]
33 Digital to Analog conversion can be triggered by:
34 (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_TRIGGER_EXT_IT9.
35 The used pin (GPIOx_Pin9) must be configured in input mode.
37 (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8
38 (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...)
40 (#) Software using DAC_TRIGGER_SOFTWARE
42 *** DAC Buffer mode feature ***
43 ===============================
44 [..]
45 Each DAC channel integrates an output buffer that can be used to
46 reduce the output impedance, and to drive external loads directly
47 without having to add an external operational amplifier.
48 To enable, the output buffer use
49 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
50 [..]
51 (@) Refer to the device datasheet for more details about output
52 impedance value with and without output buffer.
54 *** DAC wave generation feature ***
55 ===================================
56 [..]
57 Both DAC channels can be used to generate
58 (#) Noise wave using HAL_DACEx_NoiseWaveGenerate()
59 (#) Triangle wave using HAL_DACEx_TriangleWaveGenerate()
61 *** DAC data format ***
62 =======================
63 [..]
64 The DAC data format can be:
65 (#) 8-bit right alignment using DAC_ALIGN_8B_R
66 (#) 12-bit left alignment using DAC_ALIGN_12B_L
67 (#) 12-bit right alignment using DAC_ALIGN_12B_R
69 *** DAC data value to voltage correspondence ***
70 ================================================
71 [..]
72 The analog output voltage on each DAC channel pin is determined
73 by the following equation:
74 DAC_OUTx = VREF+ * DOR / 4095
75 with DOR is the Data Output Register
76 VEF+ is the input voltage reference (refer to the device datasheet)
77 e.g. To set DAC_OUT1 to 0.7V, use
78 Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
80 *** DMA requests ***
81 =====================
82 [..]
83 A DMA1 request can be generated when an external trigger (but not
84 a software trigger) occurs if DMA1 requests are enabled using
85 HAL_DAC_Start_DMA()
86 [..]
87 DMA1 requests are mapped as following:
88 (#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be
89 already configured
90 (#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be
91 already configured
93 -@- For Dual mode and specific signal (Triangle and noise) generation please
94 refer to Extension Features Driver description
97 ##### How to use this driver #####
98 ==============================================================================
99 [..]
100 (+) DAC APB clock must be enabled to get write access to DAC
101 registers using HAL_DAC_Init()
102 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
103 (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function.
104 (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions
106 *** Polling mode IO operation ***
107 =================================
108 [..]
109 (+) Start the DAC peripheral using HAL_DAC_Start()
110 (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function.
111 (+) Stop the DAC peripheral using HAL_DAC_Stop()
114 *** DMA mode IO operation ***
115 ==============================
116 [..]
117 (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length
118 of data to be transferred at each end of conversion
119 (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2()
120 function is executed and user can add his own code by customization of function pointer
121 HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2
122 (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can
123 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1
124 (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA()
126 *** Callback registration ***
127 =============================================
128 [..]
129 The compilation define USE_HAL_DAC_REGISTER_CALLBACKS when set to 1
130 allows the user to configure dynamically the driver callbacks.
132 Use Functions @ref HAL_DAC_RegisterCallback() to register a user callback,
133 it allows to register following callbacks:
134 (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1.
135 (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1.
136 (+) ErrorCallbackCh1 : callback when an error occurs on Ch1.
137 (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1.
138 (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2.
139 (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2.
140 (+) ErrorCallbackCh2 : callback when an error occurs on Ch2.
141 (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2.
142 (+) MspInitCallback : DAC MspInit.
143 (+) MspDeInitCallback : DAC MspdeInit.
144 This function takes as parameters the HAL peripheral handle, the Callback ID
145 and a pointer to the user callback function.
147 Use function @ref HAL_DAC_UnRegisterCallback() to reset a callback to the default
148 weak (surcharged) function. It allows to reset following callbacks:
149 (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1.
150 (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1.
151 (+) ErrorCallbackCh1 : callback when an error occurs on Ch1.
152 (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1.
153 (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2.
154 (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2.
155 (+) ErrorCallbackCh2 : callback when an error occurs on Ch2.
156 (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2.
157 (+) MspInitCallback : DAC MspInit.
158 (+) MspDeInitCallback : DAC MspdeInit.
159 (+) All Callbacks
160 This function) takes as parameters the HAL peripheral handle and the Callback ID.
162 By default, after the @ref HAL_DAC_Init and if the state is HAL_DAC_STATE_RESET
163 all callbacks are reset to the corresponding legacy weak (surcharged) functions.
164 Exception done for MspInit and MspDeInit callbacks that are respectively
165 reset to the legacy weak (surcharged) functions in the @ref HAL_DAC_Init
166 and @ref HAL_DAC_DeInit only when these callbacks are null (not registered beforehand).
167 If not, MspInit or MspDeInit are not null, the @ref HAL_DAC_Init and @ref HAL_DAC_DeInit
168 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
170 Callbacks can be registered/unregistered in READY state only.
171 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
172 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
173 during the Init/DeInit.
174 In that case first register the MspInit/MspDeInit user callbacks
175 using @ref HAL_DAC_RegisterCallback before calling @ref HAL_DAC_DeInit
176 or @ref HAL_DAC_Init function.
178 When The compilation define USE_HAL_DAC_REGISTER_CALLBACKS is set to 0 or
179 not defined, the callback registering feature is not available
180 and weak (surcharged) callbacks are used.
182 *** DAC HAL driver macros list ***
183 =============================================
184 [..]
185 Below the list of most used macros in DAC HAL driver.
187 (+) __HAL_DAC_ENABLE : Enable the DAC peripheral
188 (+) __HAL_DAC_DISABLE : Disable the DAC peripheral
189 (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags
190 (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status
192 [..]
193 (@) You can refer to the DAC HAL driver header file for more useful macros
195 @endverbatim
196 ******************************************************************************
197 * @attention
199 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
200 * All rights reserved.</center></h2>
202 * This software component is licensed by ST under BSD 3-Clause license,
203 * the "License"; You may not use this file except in compliance with the
204 * License. You may obtain a copy of the License at:
205 * opensource.org/licenses/BSD-3-Clause
207 ******************************************************************************
211 /* Includes ------------------------------------------------------------------*/
212 #include "stm32f7xx_hal.h"
214 /** @addtogroup STM32F7xx_HAL_Driver
215 * @{
218 /** @defgroup DAC DAC
219 * @brief DAC driver modules
220 * @{
223 #ifdef HAL_DAC_MODULE_ENABLED
225 /* Private typedef -----------------------------------------------------------*/
226 /* Private define ------------------------------------------------------------*/
227 /* Private macro -------------------------------------------------------------*/
228 /* Private variables ---------------------------------------------------------*/
229 /** @addtogroup DAC_Private_Functions
230 * @{
232 /* Private function prototypes -----------------------------------------------*/
233 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
234 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
235 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
237 * @}
240 /* Exported functions --------------------------------------------------------*/
241 /** @defgroup DAC_Exported_Functions DAC Exported Functions
242 * @{
245 /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions
246 * @brief Initialization and Configuration functions
248 @verbatim
249 ==============================================================================
250 ##### Initialization and de-initialization functions #####
251 ==============================================================================
252 [..] This section provides functions allowing to:
253 (+) Initialize and configure the DAC.
254 (+) De-initialize the DAC.
256 @endverbatim
257 * @{
261 * @brief Initializes the DAC peripheral according to the specified parameters
262 * in the DAC_InitStruct.
263 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
264 * the configuration information for the specified DAC.
265 * @retval HAL status
267 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
269 /* Check DAC handle */
270 if(hdac == NULL)
272 return HAL_ERROR;
274 /* Check the parameters */
275 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
277 if(hdac->State == HAL_DAC_STATE_RESET)
279 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
280 /* Init the DAC Callback settings */
281 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1;
282 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1;
283 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1;
284 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1;
286 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2;
287 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2;
288 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2;
289 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2;
291 if(hdac->MspInitCallback == NULL)
293 hdac->MspInitCallback = HAL_DAC_MspInit;
295 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
296 /* Allocate lock resource and initialize it */
297 hdac->Lock = HAL_UNLOCKED;
298 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
299 /* Init the low level hardware */
300 hdac->MspInitCallback(hdac);
301 #else
302 /* Init the low level hardware */
303 HAL_DAC_MspInit(hdac);
304 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
307 /* Initialize the DAC state*/
308 hdac->State = HAL_DAC_STATE_BUSY;
310 /* Set DAC error code to none */
311 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
313 /* Initialize the DAC state*/
314 hdac->State = HAL_DAC_STATE_READY;
316 /* Return function status */
317 return HAL_OK;
321 * @brief Deinitializes the DAC peripheral registers to their default reset values.
322 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
323 * the configuration information for the specified DAC.
324 * @retval HAL status
326 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
328 /* Check DAC handle */
329 if(hdac == NULL)
331 return HAL_ERROR;
334 /* Check the parameters */
335 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
337 /* Change DAC state */
338 hdac->State = HAL_DAC_STATE_BUSY;
340 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
341 if(hdac->MspDeInitCallback == NULL)
343 hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
345 /* DeInit the low level hardware */
346 hdac->MspDeInitCallback(hdac);
347 #else
348 /* DeInit the low level hardware */
349 HAL_DAC_MspDeInit(hdac);
350 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
352 /* Set DAC error code to none */
353 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
355 /* Change DAC state */
356 hdac->State = HAL_DAC_STATE_RESET;
358 /* Release Lock */
359 __HAL_UNLOCK(hdac);
361 /* Return function status */
362 return HAL_OK;
366 * @brief Initializes the DAC MSP.
367 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
368 * the configuration information for the specified DAC.
369 * @retval None
371 __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
373 /* Prevent unused argument(s) compilation warning */
374 UNUSED(hdac);
376 /* NOTE : This function Should not be modified, when the callback is needed,
377 the HAL_DAC_MspInit could be implemented in the user file
382 * @brief DeInitializes the DAC MSP.
383 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
384 * the configuration information for the specified DAC.
385 * @retval None
387 __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
389 /* Prevent unused argument(s) compilation warning */
390 UNUSED(hdac);
392 /* NOTE : This function Should not be modified, when the callback is needed,
393 the HAL_DAC_MspDeInit could be implemented in the user file
398 * @}
401 /** @defgroup DAC_Exported_Functions_Group2 IO operation functions
402 * @brief IO operation functions
404 @verbatim
405 ==============================================================================
406 ##### IO operation functions #####
407 ==============================================================================
408 [..] This section provides functions allowing to:
409 (+) Start conversion.
410 (+) Stop conversion.
411 (+) Start conversion and enable DMA transfer.
412 (+) Stop conversion and disable DMA transfer.
413 (+) Get result of conversion.
415 @endverbatim
416 * @{
420 * @brief Enables DAC and starts conversion of channel.
421 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
422 * the configuration information for the specified DAC.
423 * @param Channel: The selected DAC channel.
424 * This parameter can be one of the following values:
425 * @arg DAC_CHANNEL_1: DAC Channel1 selected
426 * @arg DAC_CHANNEL_2: DAC Channel2 selected
427 * @retval HAL status
429 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
431 uint32_t tmp1 = 0, tmp2 = 0;
433 /* Check the parameters */
434 assert_param(IS_DAC_CHANNEL(Channel));
436 /* Process locked */
437 __HAL_LOCK(hdac);
439 /* Change DAC state */
440 hdac->State = HAL_DAC_STATE_BUSY;
442 /* Enable the Peripheral */
443 __HAL_DAC_ENABLE(hdac, Channel);
445 if(Channel == DAC_CHANNEL_1)
447 tmp1 = hdac->Instance->CR & DAC_CR_TEN1;
448 tmp2 = hdac->Instance->CR & DAC_CR_TSEL1;
449 /* Check if software trigger enabled */
450 if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1))
452 /* Enable the selected DAC software conversion */
453 hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1;
456 else
458 tmp1 = hdac->Instance->CR & DAC_CR_TEN2;
459 tmp2 = hdac->Instance->CR & DAC_CR_TSEL2;
460 /* Check if software trigger enabled */
461 if((tmp1 == DAC_CR_TEN2) && (tmp2 == DAC_CR_TSEL2))
463 /* Enable the selected DAC software conversion*/
464 hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG2;
468 /* Change DAC state */
469 hdac->State = HAL_DAC_STATE_READY;
471 /* Process unlocked */
472 __HAL_UNLOCK(hdac);
474 /* Return function status */
475 return HAL_OK;
479 * @brief Disables DAC and stop conversion of channel.
480 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
481 * the configuration information for the specified DAC.
482 * @param Channel: The selected DAC channel.
483 * This parameter can be one of the following values:
484 * @arg DAC_CHANNEL_1: DAC Channel1 selected
485 * @arg DAC_CHANNEL_2: DAC Channel2 selected
486 * @retval HAL status
488 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
490 /* Check the parameters */
491 assert_param(IS_DAC_CHANNEL(Channel));
493 /* Disable the Peripheral */
494 __HAL_DAC_DISABLE(hdac, Channel);
496 /* Change DAC state */
497 hdac->State = HAL_DAC_STATE_READY;
499 /* Return function status */
500 return HAL_OK;
504 * @brief Enables DAC and starts conversion of channel.
505 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
506 * the configuration information for the specified DAC.
507 * @param Channel: The selected DAC channel.
508 * This parameter can be one of the following values:
509 * @arg DAC_CHANNEL_1: DAC Channel1 selected
510 * @arg DAC_CHANNEL_2: DAC Channel2 selected
511 * @param pData: The Source memory Buffer address.
512 * @param Length: The length of data to be transferred from memory to DAC peripheral
513 * @param Alignment: Specifies the data alignment for DAC channel.
514 * This parameter can be one of the following values:
515 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
516 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
517 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
518 * @retval HAL status
520 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
522 uint32_t tmpreg = 0;
524 /* Check the parameters */
525 assert_param(IS_DAC_CHANNEL(Channel));
526 assert_param(IS_DAC_ALIGN(Alignment));
528 /* Process locked */
529 __HAL_LOCK(hdac);
531 /* Change DAC state */
532 hdac->State = HAL_DAC_STATE_BUSY;
534 if(Channel == DAC_CHANNEL_1)
536 /* Set the DMA transfer complete callback for channel1 */
537 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
539 /* Set the DMA half transfer complete callback for channel1 */
540 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
542 /* Set the DMA error callback for channel1 */
543 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
545 /* Enable the selected DAC channel1 DMA request */
546 hdac->Instance->CR |= DAC_CR_DMAEN1;
548 /* Case of use of channel 1 */
549 switch(Alignment)
551 case DAC_ALIGN_12B_R:
552 /* Get DHR12R1 address */
553 tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
554 break;
555 case DAC_ALIGN_12B_L:
556 /* Get DHR12L1 address */
557 tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
558 break;
559 case DAC_ALIGN_8B_R:
560 /* Get DHR8R1 address */
561 tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
562 break;
563 default:
564 break;
567 else
569 /* Set the DMA transfer complete callback for channel2 */
570 hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
572 /* Set the DMA half transfer complete callback for channel2 */
573 hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
575 /* Set the DMA error callback for channel2 */
576 hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
578 /* Enable the selected DAC channel2 DMA request */
579 hdac->Instance->CR |= DAC_CR_DMAEN2;
581 /* Case of use of channel 2 */
582 switch(Alignment)
584 case DAC_ALIGN_12B_R:
585 /* Get DHR12R2 address */
586 tmpreg = (uint32_t)&hdac->Instance->DHR12R2;
587 break;
588 case DAC_ALIGN_12B_L:
589 /* Get DHR12L2 address */
590 tmpreg = (uint32_t)&hdac->Instance->DHR12L2;
591 break;
592 case DAC_ALIGN_8B_R:
593 /* Get DHR8R2 address */
594 tmpreg = (uint32_t)&hdac->Instance->DHR8R2;
595 break;
596 default:
597 break;
601 /* Enable the DMA Stream */
602 if(Channel == DAC_CHANNEL_1)
604 /* Enable the DAC DMA underrun interrupt */
605 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
607 /* Enable the DMA Stream */
608 HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
610 else
612 /* Enable the DAC DMA underrun interrupt */
613 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
615 /* Enable the DMA Stream */
616 HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
619 /* Enable the Peripheral */
620 __HAL_DAC_ENABLE(hdac, Channel);
622 /* Process Unlocked */
623 __HAL_UNLOCK(hdac);
625 /* Return function status */
626 return HAL_OK;
630 * @brief Disables DAC and stop conversion of channel.
631 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
632 * the configuration information for the specified DAC.
633 * @param Channel: The selected DAC channel.
634 * This parameter can be one of the following values:
635 * @arg DAC_CHANNEL_1: DAC Channel1 selected
636 * @arg DAC_CHANNEL_2: DAC Channel2 selected
637 * @retval HAL status
639 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
641 HAL_StatusTypeDef status = HAL_OK;
643 /* Check the parameters */
644 assert_param(IS_DAC_CHANNEL(Channel));
646 /* Disable the selected DAC channel DMA request */
647 hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
649 /* Disable the Peripheral */
650 __HAL_DAC_DISABLE(hdac, Channel);
652 /* Disable the DMA Channel */
653 /* Channel1 is used */
654 if(Channel == DAC_CHANNEL_1)
656 status = HAL_DMA_Abort(hdac->DMA_Handle1);
658 else /* Channel2 is used for */
660 status = HAL_DMA_Abort(hdac->DMA_Handle2);
663 /* Check if DMA Channel effectively disabled */
664 if(status != HAL_OK)
666 /* Update DAC state machine to error */
667 hdac->State = HAL_DAC_STATE_ERROR;
669 else
671 /* Change DAC state */
672 hdac->State = HAL_DAC_STATE_READY;
675 /* Return function status */
676 return status;
680 * @brief Returns the last data output value of the selected DAC channel.
681 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
682 * the configuration information for the specified DAC.
683 * @param Channel: The selected DAC channel.
684 * This parameter can be one of the following values:
685 * @arg DAC_CHANNEL_1: DAC Channel1 selected
686 * @arg DAC_CHANNEL_2: DAC Channel2 selected
687 * @retval The selected DAC channel data output value.
689 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
691 /* Check the parameters */
692 assert_param(IS_DAC_CHANNEL(Channel));
694 /* Returns the DAC channel data output register value */
695 if(Channel == DAC_CHANNEL_1)
697 return hdac->Instance->DOR1;
699 else
701 return hdac->Instance->DOR2;
706 * @brief Handles DAC interrupt request
707 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
708 * the configuration information for the specified DAC.
709 * @retval None
711 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
713 /* Check underrun channel 1 flag */
714 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
716 /* Change DAC state to error state */
717 hdac->State = HAL_DAC_STATE_ERROR;
719 /* Set DAC error code to channel1 DMA underrun error */
720 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
722 /* Clear the underrun flag */
723 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
725 /* Disable the selected DAC channel1 DMA request */
726 hdac->Instance->CR &= ~DAC_CR_DMAEN1;
728 /* Error callback */
729 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
730 hdac->DMAUnderrunCallbackCh1(hdac);
731 #else
732 HAL_DAC_DMAUnderrunCallbackCh1(hdac);
733 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
735 /* Check underrun channel 2 flag */
736 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2))
738 /* Change DAC state to error state */
739 hdac->State = HAL_DAC_STATE_ERROR;
741 /* Set DAC error code to channel2 DMA underrun error */
742 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2;
744 /* Clear the underrun flag */
745 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
747 /* Disable the selected DAC channel1 DMA request */
748 hdac->Instance->CR &= ~DAC_CR_DMAEN2;
750 /* Error callback */
751 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
752 hdac->DMAUnderrunCallbackCh2(hdac);
753 #else
754 HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
755 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
760 * @brief Conversion complete callback in non blocking mode for Channel1
761 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
762 * the configuration information for the specified DAC.
763 * @retval None
765 __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
767 /* Prevent unused argument(s) compilation warning */
768 UNUSED(hdac);
770 /* NOTE : This function Should not be modified, when the callback is needed,
771 the HAL_DAC_ConvCpltCallback could be implemented in the user file
776 * @brief Conversion half DMA transfer callback in non blocking mode for Channel1
777 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
778 * the configuration information for the specified DAC.
779 * @retval None
781 __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
783 /* Prevent unused argument(s) compilation warning */
784 UNUSED(hdac);
786 /* NOTE : This function Should not be modified, when the callback is needed,
787 the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file
792 * @brief Error DAC callback for Channel1.
793 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
794 * the configuration information for the specified DAC.
795 * @retval None
797 __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
799 /* Prevent unused argument(s) compilation warning */
800 UNUSED(hdac);
802 /* NOTE : This function Should not be modified, when the callback is needed,
803 the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file
808 * @brief DMA underrun DAC callback for channel1.
809 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
810 * the configuration information for the specified DAC.
811 * @retval None
813 __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
815 /* Prevent unused argument(s) compilation warning */
816 UNUSED(hdac);
818 /* NOTE : This function Should not be modified, when the callback is needed,
819 the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file
824 * @}
827 /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions
828 * @brief Peripheral Control functions
830 @verbatim
831 ==============================================================================
832 ##### Peripheral Control functions #####
833 ==============================================================================
834 [..] This section provides functions allowing to:
835 (+) Configure channels.
836 (+) Set the specified data holding register value for DAC channel.
838 @endverbatim
839 * @{
843 * @brief Configures the selected DAC channel.
844 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
845 * the configuration information for the specified DAC.
846 * @param sConfig: DAC configuration structure.
847 * @param Channel: The selected DAC channel.
848 * This parameter can be one of the following values:
849 * @arg DAC_CHANNEL_1: DAC Channel1 selected
850 * @arg DAC_CHANNEL_2: DAC Channel2 selected
851 * @retval HAL status
853 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
855 uint32_t tmpreg1 = 0, tmpreg2 = 0;
857 /* Check the DAC parameters */
858 assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
859 assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
860 assert_param(IS_DAC_CHANNEL(Channel));
862 /* Process locked */
863 __HAL_LOCK(hdac);
865 /* Change DAC state */
866 hdac->State = HAL_DAC_STATE_BUSY;
868 /* Get the DAC CR value */
869 tmpreg1 = hdac->Instance->CR;
870 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
871 tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
872 /* Configure for the selected DAC channel: buffer output, trigger */
873 /* Set TSELx and TENx bits according to DAC_Trigger value */
874 /* Set BOFFx bit according to DAC_OutputBuffer value */
875 tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
876 /* Calculate CR register value depending on DAC_Channel */
877 tmpreg1 |= tmpreg2 << Channel;
878 /* Write to DAC CR */
879 hdac->Instance->CR = tmpreg1;
880 /* Disable wave generation */
881 hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel);
883 /* Change DAC state */
884 hdac->State = HAL_DAC_STATE_READY;
886 /* Process unlocked */
887 __HAL_UNLOCK(hdac);
889 /* Return function status */
890 return HAL_OK;
894 * @brief Set the specified data holding register value for DAC channel.
895 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
896 * the configuration information for the specified DAC.
897 * @param Channel: The selected DAC channel.
898 * This parameter can be one of the following values:
899 * @arg DAC_CHANNEL_1: DAC Channel1 selected
900 * @arg DAC_CHANNEL_2: DAC Channel2 selected
901 * @param Alignment: Specifies the data alignment.
902 * This parameter can be one of the following values:
903 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
904 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
905 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
906 * @param Data: Data to be loaded in the selected data holding register.
907 * @retval HAL status
909 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
911 __IO uint32_t tmp = 0;
913 /* Check the parameters */
914 assert_param(IS_DAC_CHANNEL(Channel));
915 assert_param(IS_DAC_ALIGN(Alignment));
916 assert_param(IS_DAC_DATA(Data));
918 tmp = (uint32_t)hdac->Instance;
919 if(Channel == DAC_CHANNEL_1)
921 tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
923 else
925 tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
928 /* Set the DAC channel1 selected data holding register */
929 *(__IO uint32_t *) tmp = Data;
931 /* Return function status */
932 return HAL_OK;
936 * @}
939 /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
940 * @brief Peripheral State and Errors functions
942 @verbatim
943 ==============================================================================
944 ##### Peripheral State and Errors functions #####
945 ==============================================================================
946 [..]
947 This subsection provides functions allowing to
948 (+) Check the DAC state.
949 (+) Check the DAC Errors.
951 @endverbatim
952 * @{
956 * @brief return the DAC state
957 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
958 * the configuration information for the specified DAC.
959 * @retval HAL state
961 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
963 /* Return DAC state */
964 return hdac->State;
969 * @brief Return the DAC error code
970 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
971 * the configuration information for the specified DAC.
972 * @retval DAC Error Code
974 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
976 return hdac->ErrorCode;
980 * @}
984 * @}
987 /** @addtogroup DAC_Exported_Functions
988 * @{
991 /** @addtogroup DAC_Exported_Functions_Group1
992 * @{
994 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
996 * @brief Register a User DAC Callback
997 * To be used instead of the weak (surcharged) predefined callback
998 * @param hdac DAC handle
999 * @param CallbackID ID of the callback to be registered
1000 * This parameter can be one of the following values:
1001 * @arg @ref HAL_DAC_ERROR_INVALID_CALLBACK DAC Error Callback ID
1002 * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 Complete Callback ID
1003 * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID
1004 * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID
1005 * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID
1006 * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID
1007 * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID
1008 * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID
1009 * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID
1010 * @arg @ref HAL_DAC_MSP_INIT_CB_ID DAC MSP Init Callback ID
1011 * @arg @ref HAL_DAC_MSP_DEINIT_CB_ID DAC MSP DeInit Callback ID
1013 * @param pCallback pointer to the Callback function
1014 * @retval status
1016 HAL_StatusTypeDef HAL_DAC_RegisterCallback (DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID, pDAC_CallbackTypeDef pCallback)
1018 HAL_StatusTypeDef status = HAL_OK;
1020 if(pCallback == NULL)
1022 /* Update the error code */
1023 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1024 return HAL_ERROR;
1027 /* Process locked */
1028 __HAL_LOCK(hdac);
1030 if(hdac->State == HAL_DAC_STATE_READY)
1032 switch (CallbackID)
1034 case HAL_DAC_CH1_COMPLETE_CB_ID :
1035 hdac->ConvCpltCallbackCh1 = pCallback;
1036 break;
1037 case HAL_DAC_CH1_HALF_COMPLETE_CB_ID :
1038 hdac->ConvHalfCpltCallbackCh1 = pCallback;
1039 break;
1040 case HAL_DAC_CH1_ERROR_ID :
1041 hdac->ErrorCallbackCh1 = pCallback;
1042 break;
1043 case HAL_DAC_CH1_UNDERRUN_CB_ID :
1044 hdac->DMAUnderrunCallbackCh1 = pCallback;
1045 break;
1046 case HAL_DAC_CH2_COMPLETE_CB_ID :
1047 hdac->ConvCpltCallbackCh2 = pCallback;
1048 break;
1049 case HAL_DAC_CH2_HALF_COMPLETE_CB_ID :
1050 hdac->ConvHalfCpltCallbackCh2 = pCallback;
1051 break;
1052 case HAL_DAC_CH2_ERROR_ID :
1053 hdac->ErrorCallbackCh2 = pCallback;
1054 break;
1055 case HAL_DAC_CH2_UNDERRUN_CB_ID :
1056 hdac->DMAUnderrunCallbackCh2 = pCallback;
1057 break;
1058 case HAL_DAC_MSP_INIT_CB_ID :
1059 hdac->MspInitCallback = pCallback;
1060 break;
1061 case HAL_DAC_MSP_DEINIT_CB_ID :
1062 hdac->MspDeInitCallback = pCallback;
1063 break;
1064 default :
1065 /* Update the error code */
1066 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1067 /* update return status */
1068 status = HAL_ERROR;
1069 break;
1072 else if (hdac->State == HAL_DAC_STATE_RESET)
1074 switch (CallbackID)
1076 case HAL_DAC_MSP_INIT_CB_ID :
1077 hdac->MspInitCallback = pCallback;
1078 break;
1079 case HAL_DAC_MSP_DEINIT_CB_ID :
1080 hdac->MspDeInitCallback = pCallback;
1081 break;
1082 default :
1083 /* Update the error code */
1084 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1085 /* update return status */
1086 status = HAL_ERROR;
1087 break;
1090 else
1092 /* Update the error code */
1093 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1094 /* update return status */
1095 status = HAL_ERROR;
1098 /* Release Lock */
1099 __HAL_UNLOCK(hdac);
1100 return status;
1104 * @brief Unregister a User DAC Callback
1105 * DAC Callback is redirected to the weak (surcharged) predefined callback
1106 * @param hdac DAC handle
1107 * @param CallbackID ID of the callback to be unregistered
1108 * This parameter can be one of the following values:
1109 * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 tranfer Complete Callback ID
1110 * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID
1111 * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID
1112 * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID
1113 * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID
1114 * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID
1115 * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID
1116 * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID
1117 * @arg @ref HAL_DAC_MSP_INIT_CB_ID DAC MSP Init Callback ID
1118 * @arg @ref HAL_DAC_MSP_DEINIT_CB_ID DAC MSP DeInit Callback ID
1119 * @arg @ref HAL_DAC_ALL_CB_ID DAC All callbacks
1120 * @retval status
1122 HAL_StatusTypeDef HAL_DAC_UnRegisterCallback (DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID)
1124 HAL_StatusTypeDef status = HAL_OK;
1126 /* Process locked */
1127 __HAL_LOCK(hdac);
1129 if(hdac->State == HAL_DAC_STATE_READY)
1131 switch (CallbackID)
1133 case HAL_DAC_CH1_COMPLETE_CB_ID :
1134 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1;
1135 break;
1136 case HAL_DAC_CH1_HALF_COMPLETE_CB_ID :
1137 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1;
1138 break;
1139 case HAL_DAC_CH1_ERROR_ID :
1140 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1;
1141 break;
1142 case HAL_DAC_CH1_UNDERRUN_CB_ID :
1143 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1;
1144 break;
1145 case HAL_DAC_CH2_COMPLETE_CB_ID :
1146 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2;
1147 break;
1148 case HAL_DAC_CH2_HALF_COMPLETE_CB_ID :
1149 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2;
1150 break;
1151 case HAL_DAC_CH2_ERROR_ID :
1152 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2;
1153 break;
1154 case HAL_DAC_CH2_UNDERRUN_CB_ID :
1155 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2;
1156 break;
1157 case HAL_DAC_MSP_INIT_CB_ID :
1158 hdac->MspInitCallback = HAL_DAC_MspInit;
1159 break;
1160 case HAL_DAC_MSP_DEINIT_CB_ID :
1161 hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
1162 break;
1163 case HAL_DAC_ALL_CB_ID :
1164 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1;
1165 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1;
1166 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1;
1167 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1;
1168 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2;
1169 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2;
1170 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2;
1171 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2;
1172 hdac->MspInitCallback = HAL_DAC_MspInit;
1173 hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
1174 break;
1175 default :
1176 /* Update the error code */
1177 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1178 /* update return status */
1179 status = HAL_ERROR;
1180 break;
1183 else if (hdac->State == HAL_DAC_STATE_RESET)
1185 switch (CallbackID)
1187 case HAL_DAC_MSP_INIT_CB_ID :
1188 hdac->MspInitCallback = HAL_DAC_MspInit;
1189 break;
1190 case HAL_DAC_MSP_DEINIT_CB_ID :
1191 hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
1192 break;
1193 default :
1194 /* Update the error code */
1195 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1196 /* update return status */
1197 status = HAL_ERROR;
1198 break;
1201 else
1203 /* Update the error code */
1204 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
1205 /* update return status */
1206 status = HAL_ERROR;
1209 /* Release Lock */
1210 __HAL_UNLOCK(hdac);
1211 return status;
1213 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
1216 * @}
1220 * @}
1223 /** @addtogroup DAC_Private_Functions
1224 * @{
1228 * @brief DMA conversion complete callback.
1229 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1230 * the configuration information for the specified DMA module.
1231 * @retval None
1233 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
1235 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1237 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
1238 hdac->ConvCpltCallbackCh1(hdac);
1239 #else
1240 HAL_DAC_ConvCpltCallbackCh1(hdac);
1241 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
1243 hdac->State= HAL_DAC_STATE_READY;
1247 * @brief DMA half transfer complete callback.
1248 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1249 * the configuration information for the specified DMA module.
1250 * @retval None
1252 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
1254 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1255 /* Conversion complete callback */
1256 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
1257 hdac->ConvHalfCpltCallbackCh1(hdac);
1258 #else
1259 HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
1260 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
1264 * @brief DMA error callback
1265 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1266 * the configuration information for the specified DMA module.
1267 * @retval None
1269 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
1271 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1273 /* Set DAC error code to DMA error */
1274 hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
1276 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
1277 hdac->ErrorCallbackCh1(hdac);
1278 #else
1279 HAL_DAC_ErrorCallbackCh1(hdac);
1280 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
1282 hdac->State= HAL_DAC_STATE_READY;
1286 * @}
1289 #endif /* HAL_DAC_MODULE_ENABLED */
1292 * @}
1296 * @}
1299 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/