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