]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32L152_Discovery_IAR/ST_Code/Libraries/STM32L1xx_StdPeriph_Driver/src/stm32l1xx_dac.c
1258382b457e8deb44fcf315cd5347d4c5d2921c
[freertos] / FreeRTOS / Demo / CORTEX_STM32L152_Discovery_IAR / ST_Code / Libraries / STM32L1xx_StdPeriph_Driver / src / stm32l1xx_dac.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l1xx_dac.c\r
4   * @author  MCD Application Team\r
5   * @version V1.1.1\r
6   * @date    05-March-2012\r
7   * @brief   This file provides firmware functions to manage the following \r
8   *          functionalities of the Digital-to-Analog Converter (DAC) peripheral: \r
9   *          + DAC channels configuration: trigger, output buffer, data format\r
10   *          + DMA management      \r
11   *          + Interrupts and flags management\r
12 \r
13   * @verbatim      \r
14   *   \r
15  ===============================================================================\r
16                         ##### DAC Peripheral features #####\r
17  ===============================================================================\r
18     [..] The device integrates two 12-bit Digital Analog Converters that can \r
19          be used independently or simultaneously (dual mode):\r
20          (#) DAC channel1 with DAC_OUT1 (PA4) as output.\r
21          (#) DAC channel2 with DAC_OUT2 (PA5) as output.\r
22   \r
23     [..] Digital to Analog conversion can be non-triggered using DAC_Trigger_None\r
24          and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register using \r
25          DAC_SetChannel1Data()/DAC_SetChannel2Data.\r
26   \r
27     [..] Digital to Analog conversion can be triggered by:\r
28          (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9.\r
29              The used pin (GPIOx_Pin9) must be configured in input mode.\r
30          (#) Timers TRGO: TIM2, TIM4, TIM6, TIM7 and TIM9 \r
31              (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...).\r
32              The timer TRGO event should be selected using TIM_SelectOutputTrigger()\r
33          (#) Software using DAC_Trigger_Software.\r
34   \r
35     [..] Each DAC channel integrates an output buffer that can be used to \r
36          reduce the output impedance, and to drive external loads directly\r
37          without having to add an external operational amplifier.\r
38          To enable, the output buffer use  \r
39          DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;\r
40             \r
41     [..] Refer to the device datasheet for more details about output impedance\r
42          value with and without output buffer.\r
43   \r
44     [..] Both DAC channels can be used to generate:\r
45          (#) Noise wave using DAC_WaveGeneration_Noise\r
46          (#) Triangle wave using DAC_WaveGeneration_Triangle\r
47   \r
48     [..] Wave generation can be disabled using DAC_WaveGeneration_None.\r
49   \r
50     [..] The DAC data format can be:\r
51          (#) 8-bit right alignment using DAC_Align_8b_R\r
52          (#) 12-bit left alignment using DAC_Align_12b_L\r
53          (#) 12-bit right alignment using DAC_Align_12b_R\r
54   \r
55     [..] The analog output voltage on each DAC channel pin is determined\r
56          by the following equation: DAC_OUTx = VREF+ * DOR / 4095\r
57          with  DOR is the Data Output Register.\r
58          VEF+ is the input voltage reference (refer to the device datasheet)\r
59          e.g. To set DAC_OUT1 to 0.7V, use\r
60          DAC_SetChannel1Data(DAC_Align_12b_R, 868);\r
61          Assuming that VREF+ = 3.3, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V.\r
62   \r
63     [..] A DMA1 request can be generated when an external trigger (but not\r
64          a software trigger) occurs if DMA1 requests are enabled using\r
65          DAC_DMACmd()\r
66     [..] DMA1 requests are mapped as following:\r
67          (#) DAC channel1 is mapped on DMA1 channel3 which must be already \r
68              configured.\r
69          (#) DAC channel2 is mapped on DMA1 channel4 which must be already \r
70              configured.\r
71   \r
72                       ##### How to use this driver #####\r
73  ===============================================================================\r
74     [..]\r
75         (+) DAC APB clock must be enabled to get write access to DAC registers using\r
76             RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)\r
77         (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.\r
78         (+) Configure the DAC channel using DAC_Init()\r
79         (+) Enable the DAC channel using DAC_Cmd()\r
80 \r
81    @endverbatim\r
82   *    \r
83   ******************************************************************************\r
84   * @attention\r
85   *\r
86   * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>\r
87   *\r
88   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");\r
89   * You may not use this file except in compliance with the License.\r
90   * You may obtain a copy of the License at:\r
91   *\r
92   *        http://www.st.com/software_license_agreement_liberty_v2\r
93   *\r
94   * Unless required by applicable law or agreed to in writing, software \r
95   * distributed under the License is distributed on an "AS IS" BASIS, \r
96   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
97   * See the License for the specific language governing permissions and\r
98   * limitations under the License.\r
99   *\r
100   ******************************************************************************\r
101   */\r
102 \r
103 /* Includes ------------------------------------------------------------------*/\r
104 #include "stm32l1xx_dac.h"\r
105 #include "stm32l1xx_rcc.h"\r
106 \r
107 /** @addtogroup STM32L1xx_StdPeriph_Driver\r
108   * @{\r
109   */\r
110 \r
111 /** @defgroup DAC \r
112   * @brief DAC driver modules\r
113   * @{\r
114   */ \r
115 \r
116 /* Private typedef -----------------------------------------------------------*/\r
117 /* Private define ------------------------------------------------------------*/\r
118 /* CR register Mask */\r
119 #define CR_CLEAR_MASK              ((uint32_t)0x00000FFE)\r
120 \r
121 /* DAC Dual Channels SWTRIG masks */\r
122 #define DUAL_SWTRIG_SET            ((uint32_t)0x00000003)\r
123 #define DUAL_SWTRIG_RESET          ((uint32_t)0xFFFFFFFC)\r
124 \r
125 /* DHR registers offsets */\r
126 #define DHR12R1_OFFSET             ((uint32_t)0x00000008)\r
127 #define DHR12R2_OFFSET             ((uint32_t)0x00000014)\r
128 #define DHR12RD_OFFSET             ((uint32_t)0x00000020)\r
129 \r
130 /* DOR register offset */\r
131 #define DOR_OFFSET                 ((uint32_t)0x0000002C)\r
132 \r
133 /* Private macro -------------------------------------------------------------*/\r
134 /* Private variables ---------------------------------------------------------*/\r
135 /* Private function prototypes -----------------------------------------------*/\r
136 /* Private functions ---------------------------------------------------------*/\r
137 \r
138 /** @defgroup DAC_Private_Functions\r
139   * @{\r
140   */ \r
141 \r
142 /** @defgroup DAC_Group1 DAC channels configuration\r
143  *  @brief   DAC channels configuration: trigger, output buffer, data format.\r
144  *\r
145 @verbatim\r
146  ===============================================================================\r
147   ##### DAC channels configuration: trigger, output buffer, data format #####\r
148  ===============================================================================\r
149 \r
150 @endverbatim\r
151   * @{\r
152   */\r
153 \r
154 /**\r
155   * @brief  Deinitializes the DAC peripheral registers to their default reset values.\r
156   * @param  None\r
157   * @retval None\r
158   */\r
159 void DAC_DeInit(void)\r
160 {\r
161   /* Enable DAC reset state */\r
162   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);\r
163   /* Release DAC from reset state */\r
164   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);\r
165 }\r
166 \r
167 /**\r
168   * @brief  Initializes the DAC peripheral according to the specified \r
169   *         parameters in the DAC_InitStruct.\r
170   * @param  DAC_Channel: the selected DAC channel.\r
171   *   This parameter can be one of the following values:\r
172   *     @arg DAC_Channel_1: DAC Channel1 selected.\r
173   *     @arg DAC_Channel_2: DAC Channel2 selected.\r
174   * @param  DAC_InitStruct: pointer to a DAC_InitTypeDef structure that\r
175   *         contains the configuration information for the specified DAC channel.\r
176   * @retval None\r
177   */\r
178 void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)\r
179 {\r
180   uint32_t tmpreg1 = 0, tmpreg2 = 0;\r
181 \r
182   /* Check the DAC parameters */\r
183   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
184   assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));\r
185   assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));\r
186   assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));\r
187   assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer));\r
188 \r
189 /*---------------------------- DAC CR Configuration --------------------------*/\r
190   /* Get the DAC CR value */\r
191   tmpreg1 = DAC->CR;\r
192   /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */\r
193   tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel);\r
194   /* Configure for the selected DAC channel: buffer output, trigger, wave generation,\r
195      mask/amplitude for wave generation */\r
196   /* Set TSELx and TENx bits according to DAC_Trigger value */\r
197   /* Set WAVEx bits according to DAC_WaveGeneration value */\r
198   /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */ \r
199   /* Set BOFFx bit according to DAC_OutputBuffer value */   \r
200   tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |\r
201              DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | DAC_InitStruct->DAC_OutputBuffer);\r
202   /* Calculate CR register value depending on DAC_Channel */\r
203   tmpreg1 |= tmpreg2 << DAC_Channel;\r
204   /* Write to DAC CR */\r
205   DAC->CR = tmpreg1;\r
206 }\r
207 \r
208 /**\r
209   * @brief  Fills each DAC_InitStruct member with its default value.\r
210   * @param  DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will \r
211   *         be initialized.\r
212   * @retval None\r
213   */\r
214 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct)\r
215 {\r
216 /*--------------- Reset DAC init structure parameters values -----------------*/\r
217   /* Initialize the DAC_Trigger member */\r
218   DAC_InitStruct->DAC_Trigger = DAC_Trigger_None;\r
219   /* Initialize the DAC_WaveGeneration member */\r
220   DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None;\r
221   /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */\r
222   DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;\r
223   /* Initialize the DAC_OutputBuffer member */\r
224   DAC_InitStruct->DAC_OutputBuffer = DAC_OutputBuffer_Enable;\r
225 }\r
226 \r
227 /**\r
228   * @brief  Enables or disables the specified DAC channel.\r
229   * @param  DAC_Channel: The selected DAC channel. \r
230   *   This parameter can be one of the following values:\r
231   *     @arg DAC_Channel_1: DAC Channel1 selected\r
232   *     @arg DAC_Channel_2: DAC Channel2 selected\r
233   * @param  NewState: new state of the DAC channel. \r
234   *      This parameter can be: ENABLE or DISABLE.\r
235   * @note When the DAC channel is enabled the trigger source can no more\r
236   *       be modified.\r
237   * @retval None\r
238   */\r
239 void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState)\r
240 {\r
241   /* Check the parameters */\r
242   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
243   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
244 \r
245   if (NewState != DISABLE)\r
246   {\r
247     /* Enable the selected DAC channel */\r
248     DAC->CR |= (DAC_CR_EN1 << DAC_Channel);\r
249   }\r
250   else\r
251   {\r
252     /* Disable the selected DAC channel */\r
253     DAC->CR &= (~(DAC_CR_EN1 << DAC_Channel));\r
254   }\r
255 }\r
256 \r
257 /**\r
258   * @brief  Enables or disables the selected DAC channel software trigger.\r
259   * @param  DAC_Channel: the selected DAC channel.\r
260   *   This parameter can be one of the following values:\r
261   *     @arg DAC_Channel_1: DAC Channel1 selected\r
262   *     @arg DAC_Channel_2: DAC Channel2 selected\r
263   * @param  NewState: new state of the selected DAC channel software trigger.\r
264   *   This parameter can be: ENABLE or DISABLE.\r
265   * @retval None\r
266   */\r
267 void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState)\r
268 {\r
269   /* Check the parameters */\r
270   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
271   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
272 \r
273   if (NewState != DISABLE)\r
274   {\r
275     /* Enable software trigger for the selected DAC channel */\r
276     DAC->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4);\r
277   }\r
278   else\r
279   {\r
280     /* Disable software trigger for the selected DAC channel */\r
281     DAC->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4));\r
282   }\r
283 }\r
284 \r
285 /**\r
286   * @brief  Enables or disables simultaneously the two DAC channels software\r
287   *         triggers.\r
288   * @param  NewState: new state of the DAC channels software triggers.\r
289   *   This parameter can be: ENABLE or DISABLE.\r
290   * @retval None\r
291   */\r
292 void DAC_DualSoftwareTriggerCmd(FunctionalState NewState)\r
293 {\r
294   /* Check the parameters */\r
295   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
296 \r
297   if (NewState != DISABLE)\r
298   {\r
299     /* Enable software trigger for both DAC channels */\r
300     DAC->SWTRIGR |= DUAL_SWTRIG_SET;\r
301   }\r
302   else\r
303   {\r
304     /* Disable software trigger for both DAC channels */\r
305     DAC->SWTRIGR &= DUAL_SWTRIG_RESET;\r
306   }\r
307 }\r
308 \r
309 /**\r
310   * @brief  Enables or disables the selected DAC channel wave generation.\r
311   * @param  DAC_Channel: the selected DAC channel.\r
312   *   This parameter can be one of the following values:\r
313   *     @arg DAC_Channel_1: DAC Channel1 selected\r
314   *     @arg DAC_Channel_2: DAC Channel2 selected\r
315   * @param  DAC_Wave: Specifies the wave type to enable or disable.\r
316   *   This parameter can be one of the following values:\r
317   *     @arg DAC_Wave_Noise: noise wave generation\r
318   *     @arg DAC_Wave_Triangle: triangle wave generation\r
319   * @param  NewState: new state of the selected DAC channel wave generation.\r
320   *   This parameter can be: ENABLE or DISABLE.\r
321   * @note   \r
322   * @retval None\r
323   */\r
324 void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)\r
325 {\r
326   /* Check the parameters */\r
327   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
328   assert_param(IS_DAC_WAVE(DAC_Wave)); \r
329   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
330 \r
331   if (NewState != DISABLE)\r
332   {\r
333     /* Enable the selected wave generation for the selected DAC channel */\r
334     DAC->CR |= DAC_Wave << DAC_Channel;\r
335   }\r
336   else\r
337   {\r
338     /* Disable the selected wave generation for the selected DAC channel */\r
339     DAC->CR &= ~(DAC_Wave << DAC_Channel);\r
340   }\r
341 }\r
342 \r
343 /**\r
344   * @brief  Set the specified data holding register value for DAC channel1.\r
345   * @param  DAC_Align: Specifies the data alignment for DAC channel1.\r
346   *   This parameter can be one of the following values:\r
347   *     @arg DAC_Align_8b_R: 8bit right data alignment selected\r
348   *     @arg DAC_Align_12b_L: 12bit left data alignment selected\r
349   *     @arg DAC_Align_12b_R: 12bit right data alignment selected\r
350   * @param  Data : Data to be loaded in the selected data holding register.\r
351   * @retval None\r
352   */\r
353 void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)\r
354 {  \r
355   __IO uint32_t tmp = 0;\r
356   \r
357   /* Check the parameters */\r
358   assert_param(IS_DAC_ALIGN(DAC_Align));\r
359   assert_param(IS_DAC_DATA(Data));\r
360   \r
361   tmp = (uint32_t)DAC_BASE; \r
362   tmp += DHR12R1_OFFSET + DAC_Align;\r
363 \r
364   /* Set the DAC channel1 selected data holding register */\r
365   *(__IO uint32_t *) tmp = Data;\r
366 }\r
367 \r
368 /**\r
369   * @brief  Set the specified data holding register value for DAC channel2.\r
370   * @param  DAC_Align: Specifies the data alignment for DAC channel2.\r
371   *   This parameter can be one of the following values:\r
372   *     @arg DAC_Align_8b_R: 8bit right data alignment selected\r
373   *     @arg DAC_Align_12b_L: 12bit left data alignment selected\r
374   *     @arg DAC_Align_12b_R: 12bit right data alignment selected\r
375   * @param  Data : Data to be loaded in the selected data holding register.\r
376   * @retval None\r
377   */\r
378 void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data)\r
379 {\r
380   __IO uint32_t tmp = 0;\r
381 \r
382   /* Check the parameters */\r
383   assert_param(IS_DAC_ALIGN(DAC_Align));\r
384   assert_param(IS_DAC_DATA(Data));\r
385   \r
386   tmp = (uint32_t)DAC_BASE;\r
387   tmp += DHR12R2_OFFSET + DAC_Align;\r
388 \r
389   /* Set the DAC channel2 selected data holding register */\r
390   *(__IO uint32_t *)tmp = Data;\r
391 }\r
392 \r
393 /**\r
394   * @brief  Set the specified data holding register value for dual channel DAC.\r
395   * @param  DAC_Align: Specifies the data alignment for dual channel DAC.\r
396   *   This parameter can be one of the following values:\r
397   *     @arg DAC_Align_8b_R: 8bit right data alignment selected\r
398   *     @arg DAC_Align_12b_L: 12bit left data alignment selected\r
399   *     @arg DAC_Align_12b_R: 12bit right data alignment selected\r
400   * @param  Data2: Data for DAC Channel2 to be loaded in the selected data \r
401   *         holding register.\r
402   * @param  Data1: Data for DAC Channel1 to be loaded in the selected data \r
403   *         holding register.\r
404   * @note In dual mode, a unique register access is required to write in both\r
405   *       DAC channels at the same time.\r
406   * @retval None\r
407   */\r
408 void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)\r
409 {\r
410   uint32_t data = 0, tmp = 0;\r
411   \r
412   /* Check the parameters */\r
413   assert_param(IS_DAC_ALIGN(DAC_Align));\r
414   assert_param(IS_DAC_DATA(Data1));\r
415   assert_param(IS_DAC_DATA(Data2));\r
416   \r
417   /* Calculate and set dual DAC data holding register value */\r
418   if (DAC_Align == DAC_Align_8b_R)\r
419   {\r
420     data = ((uint32_t)Data2 << 8) | Data1; \r
421   }\r
422   else\r
423   {\r
424     data = ((uint32_t)Data2 << 16) | Data1;\r
425   }\r
426   \r
427   tmp = (uint32_t)DAC_BASE;\r
428   tmp += DHR12RD_OFFSET + DAC_Align;\r
429 \r
430   /* Set the dual DAC selected data holding register */\r
431   *(__IO uint32_t *)tmp = data;\r
432 }\r
433 \r
434 /**\r
435   * @brief  Returns the last data output value of the selected DAC channel.\r
436   * @param  DAC_Channel: the selected DAC channel. \r
437   *   This parameter can be one of the following values:\r
438   *     @arg DAC_Channel_1: DAC Channel1 selected\r
439   *     @arg DAC_Channel_2: DAC Channel2 selected\r
440   * @retval The selected DAC channel data output value.\r
441   */\r
442 uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel)\r
443 {\r
444   __IO uint32_t tmp = 0;\r
445   \r
446   /* Check the parameters */\r
447   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
448   \r
449   tmp = (uint32_t) DAC_BASE ;\r
450   tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2);\r
451   \r
452   /* Returns the DAC channel data output register value */\r
453   return (uint16_t) (*(__IO uint32_t*) tmp);\r
454 }\r
455 \r
456 /**\r
457   * @}\r
458   */\r
459 \r
460 /** @defgroup DAC_Group2 DMA management functions\r
461  *  @brief   DMA management functions\r
462  *\r
463 @verbatim\r
464  ===============================================================================\r
465                     ##### DMA management functions #####\r
466  ===============================================================================\r
467 \r
468 @endverbatim\r
469   * @{\r
470   */\r
471 \r
472 /**\r
473   * @brief  Enables or disables the specified DAC channel DMA request.\r
474   *         When enabled DMA1 is generated when an external trigger (EXTI Line9,\r
475   *         TIM2, TIM4, TIM6, TIM7 or TIM9  but not a software trigger) occurs.\r
476   * @param  DAC_Channel: the selected DAC channel.\r
477   *   This parameter can be one of the following values:\r
478   *     @arg DAC_Channel_1: DAC Channel1 selected\r
479   *     @arg DAC_Channel_2: DAC Channel2 selected\r
480   * @param  NewState: new state of the selected DAC channel DMA request.\r
481   *         This parameter can be: ENABLE or DISABLE.\r
482   * @note The DAC channel1 (channel2) is mapped on DMA1 channel3 (channel4) which \r
483   *  must be already configured. \r
484   * @retval None\r
485   */\r
486 void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState)\r
487 {\r
488   /* Check the parameters */\r
489   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
490   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
491 \r
492   if (NewState != DISABLE)\r
493   {\r
494     /* Enable the selected DAC channel DMA request */\r
495     DAC->CR |= (DAC_CR_DMAEN1 << DAC_Channel);\r
496   }\r
497   else\r
498   {\r
499     /* Disable the selected DAC channel DMA request */\r
500     DAC->CR &= (~(DAC_CR_DMAEN1 << DAC_Channel));\r
501   }\r
502 }\r
503 \r
504 /**\r
505   * @}\r
506   */\r
507 \r
508 /** @defgroup DAC_Group3 Interrupts and flags management functions\r
509  *  @brief   Interrupts and flags management functions\r
510  *\r
511 @verbatim\r
512  ===============================================================================\r
513             ##### Interrupts and flags management functions #####\r
514  ===============================================================================\r
515 \r
516 @endverbatim\r
517   * @{\r
518   */\r
519 \r
520 /**\r
521   * @brief  Enables or disables the specified DAC interrupts.\r
522   * @param  DAC_Channel: the selected DAC channel. \r
523   *   This parameter can be one of the following values:\r
524   *     @arg DAC_Channel_1: DAC Channel1 selected\r
525   *     @arg DAC_Channel_2: DAC Channel2 selected\r
526   * @param  DAC_IT: specifies the DAC interrupt sources to be enabled or disabled. \r
527   *   This parameter can be the following value:\r
528   *     @arg DAC_IT_DMAUDR: DMA underrun interrupt mask\r
529   * @note The DMA underrun occurs when a second external trigger arrives before\r
530   *       the acknowledgement for the first external trigger is received (first request).\r
531   * @param  NewState: new state of the specified DAC interrupts.\r
532   *         This parameter can be: ENABLE or DISABLE.\r
533   * @retval None\r
534   */ \r
535 void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)  \r
536 {\r
537   /* Check the parameters */\r
538   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
539   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
540   assert_param(IS_DAC_IT(DAC_IT)); \r
541 \r
542   if (NewState != DISABLE)\r
543   {\r
544     /* Enable the selected DAC interrupts */\r
545     DAC->CR |=  (DAC_IT << DAC_Channel);\r
546   }\r
547   else\r
548   {\r
549     /* Disable the selected DAC interrupts */\r
550     DAC->CR &= (~(uint32_t)(DAC_IT << DAC_Channel));\r
551   }\r
552 }\r
553 \r
554 /**\r
555   * @brief  Checks whether the specified DAC flag is set or not.\r
556   * @param  DAC_Channel: thee selected DAC channel. \r
557   *   This parameter can be one of the following values:\r
558   *     @arg DAC_Channel_1: DAC Channel1 selected\r
559   *     @arg DAC_Channel_2: DAC Channel2 selected\r
560   * @param  DAC_FLAG: specifies the flag to check. \r
561   *   This parameter can be only of the following value:\r
562   *     @arg DAC_FLAG_DMAUDR: DMA underrun flag\r
563   * @note The DMA underrun occurs when a second external trigger arrives before\r
564   *       the acknowledgement for the first external trigger is received (first request).\r
565   * @retval The new state of DAC_FLAG (SET or RESET).\r
566   */\r
567 FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG)\r
568 {\r
569   FlagStatus bitstatus = RESET;\r
570   /* Check the parameters */\r
571   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
572   assert_param(IS_DAC_FLAG(DAC_FLAG));\r
573 \r
574   /* Check the status of the specified DAC flag */\r
575   if ((DAC->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET)\r
576   {\r
577     /* DAC_FLAG is set */\r
578     bitstatus = SET;\r
579   }\r
580   else\r
581   {\r
582     /* DAC_FLAG is reset */\r
583     bitstatus = RESET;\r
584   }\r
585   /* Return the DAC_FLAG status */\r
586   return  bitstatus;\r
587 }\r
588 \r
589 /**\r
590   * @brief  Clears the DAC channel's pending flags.\r
591   * @param  DAC_Channel: the selected DAC channel. \r
592   *   This parameter can be one of the following values:\r
593   *     @arg DAC_Channel_1: DAC Channel1 selected\r
594   *     @arg DAC_Channel_2: DAC Channel2 selected\r
595   * @param  DAC_FLAG: specifies the flag to clear. \r
596   *   This parameter can be the following value:\r
597   *     @arg DAC_FLAG_DMAUDR: DMA underrun flag\r
598   * @retval None\r
599   */\r
600 void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG)\r
601 {\r
602   /* Check the parameters */\r
603   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
604   assert_param(IS_DAC_FLAG(DAC_FLAG));\r
605 \r
606   /* Clear the selected DAC flags */\r
607   DAC->SR = (DAC_FLAG << DAC_Channel);\r
608 }\r
609 \r
610 /**\r
611   * @brief  Checks whether the specified DAC interrupt has occurred or not.\r
612   * @param  DAC_Channel: the selected DAC channel. \r
613   *   This parameter can be one of the following values:\r
614   *     @arg DAC_Channel_1: DAC Channel1 selected\r
615   *     @arg DAC_Channel_2: DAC Channel2 selected\r
616   * @param  DAC_IT: specifies the DAC interrupt source to check. \r
617   *   This parameter can be the following values:\r
618   *     @arg DAC_IT_DMAUDR: DMA underrun interrupt mask\r
619   * @note The DMA underrun occurs when a second external trigger arrives before\r
620   *       the acknowledgement for the first external trigger is received (first request).\r
621   * @retval The new state of DAC_IT (SET or RESET).\r
622   */\r
623 ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT)\r
624 {\r
625   ITStatus bitstatus = RESET;\r
626   uint32_t enablestatus = 0;\r
627   \r
628   /* Check the parameters */\r
629   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
630   assert_param(IS_DAC_IT(DAC_IT));\r
631 \r
632   /* Get the DAC_IT enable bit status */\r
633   enablestatus = (DAC->CR & (DAC_IT << DAC_Channel)) ;\r
634   \r
635   /* Check the status of the specified DAC interrupt */\r
636   if (((DAC->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus)\r
637   {\r
638     /* DAC_IT is set */\r
639     bitstatus = SET;\r
640   }\r
641   else\r
642   {\r
643     /* DAC_IT is reset */\r
644     bitstatus = RESET;\r
645   }\r
646   /* Return the DAC_IT status */\r
647   return  bitstatus;\r
648 }\r
649 \r
650 /**\r
651   * @brief  Clears the DAC channel's interrupt pending bits.\r
652   * @param  DAC_Channel: the selected DAC channel. \r
653   *   This parameter can be one of the following values:\r
654   *     @arg DAC_Channel_1: DAC Channel1 selected\r
655   *     @arg DAC_Channel_2: DAC Channel2 selected\r
656   * @param  DAC_IT: specifies the DAC interrupt pending bit to clear.\r
657   *   This parameter can be the following values:\r
658   *     @arg DAC_IT_DMAUDR: DMA underrun interrupt mask\r
659   * @retval None\r
660   */\r
661 void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT)\r
662 {\r
663   /* Check the parameters */\r
664   assert_param(IS_DAC_CHANNEL(DAC_Channel));\r
665   assert_param(IS_DAC_IT(DAC_IT)); \r
666 \r
667   /* Clear the selected DAC interrupt pending bits */\r
668   DAC->SR = (DAC_IT << DAC_Channel);\r
669 }\r
670 \r
671 /**\r
672   * @}\r
673   */\r
674 \r
675 /**\r
676   * @}\r
677   */ \r
678 \r
679 /**\r
680   * @}\r
681   */ \r
682 \r
683 /**\r
684   * @}\r
685   */ \r
686 \r
687 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r