1 /**
2 ******************************************************************************
3 * @file stm32f0xx_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
12 *
13 *
14 @verbatim
15 ==============================================================================
16 ##### DAC Peripheral features #####
17 ==============================================================================
18 [..]
19 *** DAC Channels ***
20 ====================
21 [..]
22 STM32F0 devices integrates no, one or two 12-bit Digital Analog Converters.
23 STM32F05x devices have one converter (channel1)
24 STM32F07x & STM32F09x devices have two converters (i.e. channel1 & channel2)
25
26 When 2 converters are present (i.e. channel1 & channel2) they
27 can be used independently or simultaneously (dual mode):
28 (#) DAC channel1 with DAC_OUT1 (PA4) as output
29 (#) DAC channel2 with DAC_OUT2 (PA5) as output
30
31 *** DAC Triggers ***
32 ====================
33 [..]
34 Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE
35 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register.
36 [..]
37 Digital to Analog conversion can be triggered by:
38 (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9.
39 The used pin (GPIOx_PIN_9) must be configured in input mode.
40
41 (#) Timers TRGO: TIM2, TIM3, TIM6, and TIM15
42 (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T3_TRGO...)
43
44 (#) Software using DAC_TRIGGER_SOFTWARE
45
46 *** DAC Buffer mode feature ***
47 ===============================
48 [..]
49 Each DAC channel integrates an output buffer that can be used to
50 reduce the output impedance, and to drive external loads directly
51 without having to add an external operational amplifier.
52 To enable, the output buffer use
53 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
54 [..]
55 (@) Refer to the device datasheet for more details about output
56 impedance value with and without output buffer.
57
58 *** GPIO configurations guidelines ***
59 =====================
60 [..]
61 When a DAC channel is used (ex channel1 on PA4) and the other is not
62 (ex channel1 on PA5 is configured in Analog and disabled).
63 Channel1 may disturb channel2 as coupling effect.
64 Note that there is no coupling on channel2 as soon as channel2 is turned on.
65 Coupling on adjacent channel could be avoided as follows:
66 when unused PA5 is configured as INPUT PULL-UP or DOWN.
67 PA5 is configured in ANALOG just before it is turned on.
68
69 *** DAC wave generation feature ***
70 ===================================
71 [..]
72 Both DAC channels can be used to generate
73 (#) Noise wave
74 (#) Triangle wave
75
76 *** DAC data format ***
77 =======================
78 [..]
79 The DAC data format can be:
80 (#) 8-bit right alignment using DAC_ALIGN_8B_R
81 (#) 12-bit left alignment using DAC_ALIGN_12B_L
82 (#) 12-bit right alignment using DAC_ALIGN_12B_R
83
84 *** DAC data value to voltage correspondance ***
85 ================================================
86 [..]
87 The analog output voltage on each DAC channel pin is determined
88 by the following equation:
89 [..]
90 DAC_OUTx = VREF+ * DOR / 4095
91 (+) with DOR is the Data Output Register
92 [..]
93 VEF+ is the input voltage reference (refer to the device datasheet)
94 [..]
95 e.g. To set DAC_OUT1 to 0.7V, use
96 (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
97
98 *** DMA requests ***
99 =====================
100 [..]
101 A DMA1 request can be generated when an external trigger (but not
102 a software trigger) occurs if DMA1 requests are enabled using
103 HAL_DAC_Start_DMA()
104 [..]
105 DMA1 requests are mapped as following:
106 (#) DAC channel1 : mapped on DMA1 channel3 which must be
107 already configured
108 (#) DAC channel2 : mapped on DMA1 channel4 which must be
109 already configured
110
111 (@) For Dual mode and specific signal (Triangle and noise) generation please
112 refer to Extended Features Driver description
113 STM32F0 devices with one channel (one converting capability) does not
114 support Dual mode and specific signal (Triangle and noise) generation.
115
116 ##### How to use this driver #####
117 ==============================================================================
118 [..]
119 (+) DAC APB clock must be enabled to get write access to DAC
120 registers using HAL_DAC_Init()
121 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
122 (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function.
123 (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA() functions.
124
125 *** Polling mode IO operation ***
126 =================================
127 [..]
128 (+) Start the DAC peripheral using HAL_DAC_Start()
129 (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function.
130 (+) Stop the DAC peripheral using HAL_DAC_Stop()
131
132 *** DMA mode IO operation ***
133 ==============================
134 [..]
135 (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length
136 of data to be transferred at each end of conversion
137 (+) At the middle of data transfer HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
138 function is executed and user can add his own code by customization of function pointer
139 HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
140 (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
141 function is executed and user can add his own code by customization of function pointer
142 HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
143 (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can
144 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1
145 (+) In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler.
146 HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2()
147 function is executed and user can add his own code by customization of function pointer
148 HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() and
149 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1()
150 (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA()
151
152 *** DAC HAL driver macros list ***
153 =============================================
154 [..]
155 Below the list of most used macros in DAC HAL driver.
156
157 (+) __HAL_DAC_ENABLE : Enable the DAC peripheral
158 (+) __HAL_DAC_DISABLE : Disable the DAC peripheral
159 (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags
160 (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status
161
162 [..]
163 (@) You can refer to the DAC HAL driver header file for more useful macros
164
165 @endverbatim
166 ******************************************************************************
167 * @attention
168 *
169 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
170 *
171 * Redistribution and use in source and binary forms, with or without modification,
172 * are permitted provided that the following conditions are met:
173 * 1. Redistributions of source code must retain the above copyright notice,
174 * this list of conditions and the following disclaimer.
175 * 2. Redistributions in binary form must reproduce the above copyright notice,
176 * this list of conditions and the following disclaimer in the documentation
177 * and/or other materials provided with the distribution.
178 * 3. Neither the name of STMicroelectronics nor the names of its contributors
179 * may be used to endorse or promote products derived from this software
180 * without specific prior written permission.
181 *
182 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
183 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
185 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
186 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
187 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
188 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
189 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
190 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
191 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192 *
193 ******************************************************************************
194 */
195
196
197 /* Includes ------------------------------------------------------------------*/
198 #include "stm32f0xx_hal.h"
199
200 /** @addtogroup STM32F0xx_HAL_Driver
201 * @{
202 */
203
204 #ifdef HAL_DAC_MODULE_ENABLED
205
206 #if defined(STM32F051x8) || defined(STM32F058xx) || \
207 defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
208 defined(STM32F091xC) || defined (STM32F098xx)
209
210 /** @defgroup DAC DAC
211 * @brief DAC driver modules
212 * @{
213 */
214
215 /* Private typedef -----------------------------------------------------------*/
216 /* Private define ------------------------------------------------------------*/
217 /* Private macro -------------------------------------------------------------*/
218 /** @defgroup DAC_Private_Macros DAC Private Macros
219 * @{
220 */
221 /**
222 * @}
223 */
224
225 /* Private variables ---------------------------------------------------------*/
226 /* Private function prototypes -----------------------------------------------*/
227 /** @defgroup DAC_Private_Functions DAC Private Functions
228 * @{
229 */
230 /**
231 * @}
232 */
233
234 /* Exported functions -------------------------------------------------------*/
235
236 /** @defgroup DAC_Exported_Functions DAC Exported Functions
237 * @{
238 */
239
240 /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions
241 * @brief Initialization and Configuration functions
242 *
243 @verbatim
244 ==============================================================================
245 ##### Initialization and de-initialization functions #####
246 ==============================================================================
247 [..] This section provides functions allowing to:
248 (+) Initialize and configure the DAC.
249 (+) De-initialize the DAC.
250
251 @endverbatim
252 * @{
253 */
254
255 /**
256 * @brief Initialize the DAC peripheral according to the specified parameters
257 * in the DAC_InitStruct and initialize the associated handle.
258 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
259 * the configuration information for the specified DAC.
260 * @retval HAL status
261 */
HAL_DAC_Init(DAC_HandleTypeDef * hdac)262 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
263 {
264 /* Check DAC handle */
265 if(hdac == NULL)
266 {
267 return HAL_ERROR;
268 }
269 /* Check the parameters */
270 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
271
272 if(hdac->State == HAL_DAC_STATE_RESET)
273 {
274 /* Allocate lock resource and initialize it */
275 hdac->Lock = HAL_UNLOCKED;
276
277 /* Init the low level hardware */
278 HAL_DAC_MspInit(hdac);
279 }
280
281 /* Initialize the DAC state*/
282 hdac->State = HAL_DAC_STATE_BUSY;
283
284 /* Set DAC error code to none */
285 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
286
287 /* Initialize the DAC state*/
288 hdac->State = HAL_DAC_STATE_READY;
289
290 /* Return function status */
291 return HAL_OK;
292 }
293
294 /**
295 * @brief Deinitialize the DAC peripheral registers to their default reset values.
296 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
297 * the configuration information for the specified DAC.
298 * @retval HAL status
299 */
HAL_DAC_DeInit(DAC_HandleTypeDef * hdac)300 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
301 {
302 /* Check DAC handle */
303 if(hdac == NULL)
304 {
305 return HAL_ERROR;
306 }
307
308 /* Check the parameters */
309 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
310
311 /* Change DAC state */
312 hdac->State = HAL_DAC_STATE_BUSY;
313
314 /* DeInit the low level hardware */
315 HAL_DAC_MspDeInit(hdac);
316
317 /* Set DAC error code to none */
318 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
319
320 /* Change DAC state */
321 hdac->State = HAL_DAC_STATE_RESET;
322
323 /* Release Lock */
324 __HAL_UNLOCK(hdac);
325
326 /* Return function status */
327 return HAL_OK;
328 }
329
330 /**
331 * @brief Initialize the DAC MSP.
332 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
333 * the configuration information for the specified DAC.
334 * @retval None
335 */
HAL_DAC_MspInit(DAC_HandleTypeDef * hdac)336 __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
337 {
338 /* Prevent unused argument(s) compilation warning */
339 UNUSED(hdac);
340
341 /* NOTE : This function should not be modified, when the callback is needed,
342 the HAL_DAC_MspInit could be implemented in the user file
343 */
344 }
345
346 /**
347 * @brief DeInitialize the DAC MSP.
348 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
349 * the configuration information for the specified DAC.
350 * @retval None
351 */
HAL_DAC_MspDeInit(DAC_HandleTypeDef * hdac)352 __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
353 {
354 /* Prevent unused argument(s) compilation warning */
355 UNUSED(hdac);
356
357 /* NOTE : This function should not be modified, when the callback is needed,
358 the HAL_DAC_MspDeInit could be implemented in the user file
359 */
360 }
361
362 /**
363 * @}
364 */
365
366 /** @defgroup DAC_Exported_Functions_Group2 IO operation functions
367 * @brief IO operation functions
368 *
369 @verbatim
370 ==============================================================================
371 ##### IO operation functions #####
372 ==============================================================================
373 [..] This section provides functions allowing to:
374 (+) Start conversion.
375 (+) Stop conversion.
376 (+) Start conversion and enable DMA transfer.
377 (+) Stop conversion and disable DMA transfer.
378 (+) Set the specified data holding register value for DAC channel.
379
380 @endverbatim
381 * @{
382 */
383
384 /**
385 * @brief Enables DAC and starts conversion of channel.
386 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
387 * the configuration information for the specified DAC.
388 * @param Channel The selected DAC channel.
389 * This parameter can be one of the following values:
390 * @arg DAC_CHANNEL_1: DAC Channel1 selected
391 * @arg DAC_CHANNEL_2: DAC Channel2 selected
392 * @retval HAL status
393 */
HAL_DAC_Start(DAC_HandleTypeDef * hdac,uint32_t Channel)394 __weak HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
395 {
396 /* Prevent unused argument(s) compilation warning */
397 UNUSED(hdac);
398 UNUSED(Channel);
399
400 /* Note : This function is defined into this file for library reference. */
401 /* Function content is located into file stm32f0xx_hal_dac_ex.c */
402
403 /* Return error status as not implemented here */
404 return HAL_ERROR;
405 }
406
407 /**
408 * @brief Disables DAC and stop conversion of channel.
409 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
410 * the configuration information for the specified DAC.
411 * @param Channel The selected DAC channel.
412 * This parameter can be one of the following values:
413 * @arg DAC_CHANNEL_1: DAC Channel1 selected
414 * @arg DAC_CHANNEL_2: DAC Channel2 selected
415 * @retval HAL status
416 */
HAL_DAC_Stop(DAC_HandleTypeDef * hdac,uint32_t Channel)417 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
418 {
419 /* Check the parameters */
420 assert_param(IS_DAC_CHANNEL(Channel));
421
422 /* Disable the Peripheral */
423 __HAL_DAC_DISABLE(hdac, Channel);
424
425 /* Change DAC state */
426 hdac->State = HAL_DAC_STATE_READY;
427
428 /* Return function status */
429 return HAL_OK;
430 }
431
432 /**
433 * @brief Enables DAC and starts conversion of channel.
434 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
435 * the configuration information for the specified DAC.
436 * @param Channel The selected DAC channel.
437 * This parameter can be one of the following values:
438 * @arg DAC_CHANNEL_1: DAC Channel1 selected
439 * @arg DAC_CHANNEL_2: DAC Channel2 selected
440 * @param pData The destination peripheral Buffer address.
441 * @param Length The length of data to be transferred from memory to DAC peripheral
442 * @param Alignment Specifies the data alignment for DAC channel.
443 * This parameter can be one of the following values:
444 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
445 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
446 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
447 * @retval HAL status
448 */
HAL_DAC_Start_DMA(DAC_HandleTypeDef * hdac,uint32_t Channel,uint32_t * pData,uint32_t Length,uint32_t Alignment)449 __weak HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
450 {
451 /* Prevent unused argument(s) compilation warning */
452 UNUSED(hdac);
453 UNUSED(Channel);
454 UNUSED(pData);
455 UNUSED(Length);
456 UNUSED(Alignment);
457
458 /* Note : This function is defined into this file for library reference. */
459 /* Function content is located into file stm32f0xx_hal_dac_ex.c */
460
461 /* Return error status as not implemented here */
462 return HAL_ERROR;
463 }
464
465 /**
466 * @brief Disables DAC and stop conversion of channel.
467 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
468 * the configuration information for the specified DAC.
469 * @param Channel The selected DAC channel.
470 * This parameter can be one of the following values:
471 * @arg DAC_CHANNEL_1: DAC Channel1 selected
472 * @arg DAC_CHANNEL_2: DAC Channel2 selected
473 * @retval HAL status
474 */
HAL_DAC_Stop_DMA(DAC_HandleTypeDef * hdac,uint32_t Channel)475 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
476 {
477 HAL_StatusTypeDef status = HAL_OK;
478
479 /* Check the parameters */
480 assert_param(IS_DAC_CHANNEL(Channel));
481
482 /* Disable the selected DAC channel DMA request */
483 hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
484
485 /* Disable the Peripheral */
486 __HAL_DAC_DISABLE(hdac, Channel);
487
488 /* Disable the DMA channel */
489 /* Channel1 is used */
490 if (Channel == DAC_CHANNEL_1)
491 {
492 /* Disable the DMA channel */
493 status = HAL_DMA_Abort(hdac->DMA_Handle1);
494
495 /* Disable the DAC DMA underrun interrupt */
496 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1);
497 }
498
499 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
500 defined(STM32F091xC) || defined (STM32F098xx)
501 /* Does not apply to STM32F051x8 & STM32F058xx */
502
503 else /* Channel2 is used for */
504 {
505 /* Disable the DMA channel */
506 status = HAL_DMA_Abort(hdac->DMA_Handle2);
507
508 /* Disable the DAC DMA underrun interrupt */
509 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2);
510 }
511 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
512 /* STM32F091xC || STM32F098xx */
513
514 /* Check if DMA Channel effectively disabled */
515 if (status != HAL_OK)
516 {
517 /* Update DAC state machine to error */
518 hdac->State = HAL_DAC_STATE_ERROR;
519 }
520 else
521 {
522 /* Change DAC state */
523 hdac->State = HAL_DAC_STATE_READY;
524 }
525
526 /* Return function status */
527 return status;
528 }
529
530 /**
531 * @brief Handles DAC interrupt request
532 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
533 * the configuration information for the specified DAC.
534 * @retval None
535 */
HAL_DAC_IRQHandler(DAC_HandleTypeDef * hdac)536 __weak void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
537 {
538 /* Prevent unused argument(s) compilation warning */
539 UNUSED(hdac);
540
541 /* Note : This function is defined into this file for library reference. */
542 /* Function content is located into file stm32f0xx_hal_dac_ex.c */
543 }
544
545 /**
546 * @brief Set the specified data holding register value for DAC channel.
547 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
548 * the configuration information for the specified DAC.
549 * @param Channel The selected DAC channel.
550 * This parameter can be one of the following values:
551 * @arg DAC_CHANNEL_1: DAC Channel1 selected
552 * @arg DAC_CHANNEL_2: DAC Channel2 selected
553 * @param Alignment Specifies the data alignment.
554 * This parameter can be one of the following values:
555 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
556 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
557 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
558 * @param Data Data to be loaded in the selected data holding register.
559 * @retval HAL status
560 */
HAL_DAC_SetValue(DAC_HandleTypeDef * hdac,uint32_t Channel,uint32_t Alignment,uint32_t Data)561 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
562 {
563 __IO uint32_t tmp = 0;
564
565 /* Check the parameters */
566 assert_param(IS_DAC_CHANNEL(Channel));
567 assert_param(IS_DAC_ALIGN(Alignment));
568 assert_param(IS_DAC_DATA(Data));
569
570 tmp = (uint32_t)hdac->Instance;
571 if(Channel == DAC_CHANNEL_1)
572 {
573 tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
574 }
575 else
576 {
577 tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
578 }
579
580 /* Set the DAC channel1 selected data holding register */
581 *(__IO uint32_t *) tmp = Data;
582
583 /* Return function status */
584 return HAL_OK;
585 }
586
587 /**
588 * @brief Conversion complete callback in non blocking mode for Channel1
589 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
590 * the configuration information for the specified DAC.
591 * @retval None
592 */
HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef * hdac)593 __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
594 {
595 /* Prevent unused argument(s) compilation warning */
596 UNUSED(hdac);
597
598 /* NOTE : This function should not be modified, when the callback is needed,
599 the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file
600 */
601 }
602
603 /**
604 * @brief Conversion half DMA transfer callback in non-blocking mode for Channel1
605 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
606 * the configuration information for the specified DAC.
607 * @retval None
608 */
HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef * hdac)609 __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
610 {
611 /* Prevent unused argument(s) compilation warning */
612 UNUSED(hdac);
613
614 /* NOTE : This function should not be modified, when the callback is needed,
615 the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file
616 */
617 }
618
619 /**
620 * @brief Error DAC callback for Channel1.
621 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
622 * the configuration information for the specified DAC.
623 * @retval None
624 */
HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef * hdac)625 __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
626 {
627 /* Prevent unused argument(s) compilation warning */
628 UNUSED(hdac);
629
630 /* NOTE : This function should not be modified, when the callback is needed,
631 the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file
632 */
633 }
634
635 /**
636 * @brief DMA underrun DAC callback for channel1.
637 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
638 * the configuration information for the specified DAC.
639 * @retval None
640 */
HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef * hdac)641 __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
642 {
643 /* Prevent unused argument(s) compilation warning */
644 UNUSED(hdac);
645
646 /* NOTE : This function should not be modified, when the callback is needed,
647 the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file
648 */
649 }
650
651 /**
652 * @}
653 */
654
655 /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions
656 * @brief Peripheral Control functions
657 *
658 @verbatim
659 ==============================================================================
660 ##### Peripheral Control functions #####
661 ==============================================================================
662 [..] This section provides functions allowing to:
663 (+) Configure channels.
664 (+) Get result of conversion.
665
666 @endverbatim
667 * @{
668 */
669
670 /**
671 * @brief Returns the last data output value of the selected DAC channel.
672 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
673 * the configuration information for the specified DAC.
674 * @param Channel The selected DAC channel.
675 * This parameter can be one of the following values:
676 * @arg DAC_CHANNEL_1: DAC Channel1 selected
677 * @arg DAC_CHANNEL_2: DAC Channel2 selected
678 * @retval The selected DAC channel data output value.
679 */
HAL_DAC_GetValue(DAC_HandleTypeDef * hdac,uint32_t Channel)680 __weak uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
681 {
682 /* Prevent unused argument(s) compilation warning */
683 UNUSED(hdac);
684 UNUSED(Channel);
685
686 /* Note : This function is defined into this file for library reference. */
687 /* Function content is located into file stm32f0xx_hal_dac_ex.c */
688
689 /* Return error status as not implemented here */
690 return HAL_ERROR;
691 }
692
693 /**
694 * @brief Configures the selected DAC channel.
695 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
696 * the configuration information for the specified DAC.
697 * @param sConfig DAC configuration structure.
698 * @param Channel The selected DAC channel.
699 * This parameter can be one of the following values:
700 * @arg DAC_CHANNEL_1: DAC Channel1 selected
701 * @arg DAC_CHANNEL_2: DAC Channel2 selected
702 * @retval HAL status
703 */
HAL_DAC_ConfigChannel(DAC_HandleTypeDef * hdac,DAC_ChannelConfTypeDef * sConfig,uint32_t Channel)704 __weak HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
705 {
706 /* Prevent unused argument(s) compilation warning */
707 UNUSED(hdac);
708 UNUSED(sConfig);
709 UNUSED(Channel);
710
711 /* Note : This function is defined into this file for library reference. */
712 /* Function content is located into file stm32f0xx_hal_dac_ex.c */
713
714 /* Return error status as not implemented here */
715 return HAL_ERROR;
716 }
717
718 /**
719 * @}
720 */
721
722 /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
723 * @brief Peripheral State and Errors functions
724 *
725 @verbatim
726 ==============================================================================
727 ##### Peripheral State and Errors functions #####
728 ==============================================================================
729 [..]
730 This subsection provides functions allowing to
731 (+) Check the DAC state.
732 (+) Check the DAC Errors.
733
734 @endverbatim
735 * @{
736 */
737
738 /**
739 * @brief return the DAC handle state
740 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
741 * the configuration information for the specified DAC.
742 * @retval HAL state
743 */
HAL_DAC_GetState(DAC_HandleTypeDef * hdac)744 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
745 {
746 /* Return DAC handle state */
747 return hdac->State;
748 }
749
750
751 /**
752 * @brief Return the DAC error code
753 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
754 * the configuration information for the specified DAC.
755 * @retval DAC Error Code
756 */
HAL_DAC_GetError(DAC_HandleTypeDef * hdac)757 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
758 {
759 return hdac->ErrorCode;
760 }
761
762 /**
763 * @}
764 */
765
766
767 /**
768 * @}
769 */
770
771 /**
772 * @}
773 */
774 #endif /* STM32F051x8 || STM32F058xx || */
775 /* STM32F071xB || STM32F072xB || STM32F078xx || */
776 /* STM32F091xC || STM32F098xx */
777
778 #endif /* HAL_DAC_MODULE_ENABLED */
779
780 /**
781 * @}
782 */
783
784
785 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
786