1 /**
2   ******************************************************************************
3   * @file    stm32f2xx_ll_dac.h
4   * @author  MCD Application Team
5   * @brief   Header file of DAC LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F2xx_LL_DAC_H
21 #define STM32F2xx_LL_DAC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f2xx.h"
29 
30 /** @addtogroup STM32F2xx_LL_Driver
31   * @{
32   */
33 
34 #if defined(DAC)
35 
36 /** @defgroup DAC_LL DAC
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup DAC_LL_Private_Constants DAC Private Constants
45   * @{
46   */
47 
48 /* Internal masks for DAC channels definition */
49 /* To select into literal LL_DAC_CHANNEL_x the relevant bits for:             */
50 /* - channel bits position into registers CR, MCR, CCR, SHHR, SHRR            */
51 /* - channel bits position into register SWTRIG                               */
52 /* - channel register offset of data holding register DHRx                    */
53 /* - channel register offset of data output register DORx                     */
54 #define DAC_CR_CH1_BITOFFSET           0UL   /* Position of channel bits into registers
55                                                 CR, MCR, CCR, SHHR, SHRR of channel 1 */
56 #define DAC_CR_CH2_BITOFFSET           16UL  /* Position of channel bits into registers
57                                                 CR, MCR, CCR, SHHR, SHRR of channel 2 */
58 #define DAC_CR_CHX_BITOFFSET_MASK      (DAC_CR_CH1_BITOFFSET | DAC_CR_CH2_BITOFFSET)
59 
60 #define DAC_SWTR_CH1                   (DAC_SWTRIGR_SWTRIG1) /* Channel bit into register SWTRIGR of channel 1. */
61 #define DAC_SWTR_CH2                   (DAC_SWTRIGR_SWTRIG2) /* Channel bit into register SWTRIGR of channel 2. */
62 #define DAC_SWTR_CHX_MASK              (DAC_SWTR_CH1 | DAC_SWTR_CH2)
63 
64 #define DAC_REG_DHR12R1_REGOFFSET      0x00000000UL            /* Register DHR12Rx channel 1 taken as reference */
65 #define DAC_REG_DHR12L1_REGOFFSET      0x00100000UL            /* Register offset of DHR12Lx channel 1 versus
66                                                                   DHR12Rx channel 1 (shifted left of 20 bits)   */
67 #define DAC_REG_DHR8R1_REGOFFSET       0x02000000UL            /* Register offset of DHR8Rx  channel 1 versus
68                                                                   DHR12Rx channel 1 (shifted left of 24 bits)   */
69 
70 #define DAC_REG_DHR12R2_REGOFFSET      0x00030000UL            /* Register offset of DHR12Rx channel 2 versus
71                                                                   DHR12Rx channel 1 (shifted left of 16 bits)   */
72 #define DAC_REG_DHR12L2_REGOFFSET      0x00400000UL            /* Register offset of DHR12Lx channel 2 versus
73                                                                   DHR12Rx channel 1 (shifted left of 20 bits)   */
74 #define DAC_REG_DHR8R2_REGOFFSET       0x05000000UL            /* Register offset of DHR8Rx  channel 2 versus
75                                                                   DHR12Rx channel 1 (shifted left of 24 bits)   */
76 
77 #define DAC_REG_DHR12RX_REGOFFSET_MASK 0x000F0000UL
78 #define DAC_REG_DHR12LX_REGOFFSET_MASK 0x00F00000UL
79 #define DAC_REG_DHR8RX_REGOFFSET_MASK  0x0F000000UL
80 #define DAC_REG_DHRX_REGOFFSET_MASK    (DAC_REG_DHR12RX_REGOFFSET_MASK\
81                                         | DAC_REG_DHR12LX_REGOFFSET_MASK | DAC_REG_DHR8RX_REGOFFSET_MASK)
82 
83 #define DAC_REG_DOR1_REGOFFSET         0x00000000UL            /* Register DORx channel 1 taken as reference */
84 
85 #define DAC_REG_DOR2_REGOFFSET         0x10000000UL            /* Register offset of DORx channel 1 versus
86                                                                   DORx channel 2 (shifted left of 28 bits)   */
87 #define DAC_REG_DORX_REGOFFSET_MASK    (DAC_REG_DOR1_REGOFFSET | DAC_REG_DOR2_REGOFFSET)
88 
89 
90 
91 #define DAC_REG_DHR_REGOFFSET_MASK_POSBIT0         0x0000000FUL /* Mask of data hold registers offset (DHR12Rx,
92                                                                    DHR12Lx, DHR8Rx, ...) when shifted to position 0 */
93 #define DAC_REG_DORX_REGOFFSET_MASK_POSBIT0        0x00000001UL /* Mask of DORx registers offset when shifted
94                                                                    to position 0                                    */
95 #define DAC_REG_SHSRX_REGOFFSET_MASK_POSBIT0       0x00000001UL /* Mask of SHSRx registers offset when shifted
96                                                                    to position 0                                    */
97 
98 #define DAC_REG_DHR12RX_REGOFFSET_BITOFFSET_POS           16UL  /* Position of bits register offset of DHR12Rx
99                                                                    channel 1 or 2 versus DHR12Rx channel 1
100                                                                    (shifted left of 16 bits)                   */
101 #define DAC_REG_DHR12LX_REGOFFSET_BITOFFSET_POS           20UL  /* Position of bits register offset of DHR12Lx
102                                                                    channel 1 or 2 versus DHR12Rx channel 1
103                                                                    (shifted left of 20 bits)                   */
104 #define DAC_REG_DHR8RX_REGOFFSET_BITOFFSET_POS            24UL  /* Position of bits register offset of DHR8Rx
105                                                                    channel 1 or 2 versus DHR12Rx channel 1
106                                                                    (shifted left of 24 bits)                   */
107 #define DAC_REG_DORX_REGOFFSET_BITOFFSET_POS              28UL  /* Position of bits register offset of DORx
108                                                                    channel 1 or 2 versus DORx channel 1
109                                                                    (shifted left of 28 bits)                   */
110 
111 /* DAC registers bits positions */
112 #define DAC_DHR12RD_DACC2DHR_BITOFFSET_POS                DAC_DHR12RD_DACC2DHR_Pos
113 #define DAC_DHR12LD_DACC2DHR_BITOFFSET_POS                DAC_DHR12LD_DACC2DHR_Pos
114 #define DAC_DHR8RD_DACC2DHR_BITOFFSET_POS                 DAC_DHR8RD_DACC2DHR_Pos
115 
116 /* Miscellaneous data */
117 #define DAC_DIGITAL_SCALE_12BITS                  4095UL   /* Full-scale digital value with a resolution of 12
118                                                               bits (voltage range determined by analog voltage
119                                                               references Vref+ and Vref-, refer to reference manual) */
120 
121 /**
122   * @}
123   */
124 
125 
126 /* Private macros ------------------------------------------------------------*/
127 /** @defgroup DAC_LL_Private_Macros DAC Private Macros
128   * @{
129   */
130 
131 /**
132   * @brief  Driver macro reserved for internal use: set a pointer to
133   *         a register from a register basis from which an offset
134   *         is applied.
135   * @param  __REG__ Register basis from which the offset is applied.
136   * @param  __REG_OFFFSET__ Offset to be applied (unit: number of registers).
137   * @retval Pointer to register address
138   */
139 #define __DAC_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__)                         \
140   ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
141 
142 /**
143   * @}
144   */
145 
146 
147 /* Exported types ------------------------------------------------------------*/
148 #if defined(USE_FULL_LL_DRIVER)
149 /** @defgroup DAC_LL_ES_INIT DAC Exported Init structure
150   * @{
151   */
152 
153 /**
154   * @brief  Structure definition of some features of DAC instance.
155   */
156 typedef struct
157 {
158   uint32_t TriggerSource;               /*!< Set the conversion trigger source for the selected DAC channel:
159                                              internal (SW start) or from external peripheral
160                                              (timer event, external interrupt line).
161                                              This parameter can be a value of @ref DAC_LL_EC_TRIGGER_SOURCE
162 
163                                              This feature can be modified afterwards using unitary
164                                              function @ref LL_DAC_SetTriggerSource(). */
165 
166   uint32_t WaveAutoGeneration;          /*!< Set the waveform automatic generation mode for the selected DAC channel.
167                                              This parameter can be a value of @ref DAC_LL_EC_WAVE_AUTO_GENERATION_MODE
168 
169                                              This feature can be modified afterwards using unitary
170                                              function @ref LL_DAC_SetWaveAutoGeneration(). */
171 
172   uint32_t WaveAutoGenerationConfig;    /*!< Set the waveform automatic generation mode for the selected DAC channel.
173                                              If waveform automatic generation mode is set to noise, this parameter
174                                              can be a value of @ref DAC_LL_EC_WAVE_NOISE_LFSR_UNMASK_BITS
175                                              If waveform automatic generation mode is set to triangle,
176                                              this parameter can be a value of @ref DAC_LL_EC_WAVE_TRIANGLE_AMPLITUDE
177                                              @note If waveform automatic generation mode is disabled,
178                                               this parameter is discarded.
179 
180                                              This feature can be modified afterwards using unitary
181                                              function @ref LL_DAC_SetWaveNoiseLFSR(),
182                                              @ref LL_DAC_SetWaveTriangleAmplitude()
183                                              depending on the wave automatic generation selected. */
184 
185   uint32_t OutputBuffer;                /*!< Set the output buffer for the selected DAC channel.
186                                              This parameter can be a value of @ref DAC_LL_EC_OUTPUT_BUFFER
187 
188                                              This feature can be modified afterwards using unitary
189                                              function @ref LL_DAC_SetOutputBuffer(). */
190 } LL_DAC_InitTypeDef;
191 
192 /**
193   * @}
194   */
195 #endif /* USE_FULL_LL_DRIVER */
196 
197 /* Exported constants --------------------------------------------------------*/
198 /** @defgroup DAC_LL_Exported_Constants DAC Exported Constants
199   * @{
200   */
201 
202 /** @defgroup DAC_LL_EC_GET_FLAG DAC flags
203   * @brief    Flags defines which can be used with LL_DAC_ReadReg function
204   * @{
205   */
206 /* DAC channel 1 flags */
207 #define LL_DAC_FLAG_DMAUDR1                (DAC_SR_DMAUDR1)   /*!< DAC channel 1 flag DMA underrun */
208 
209 /* DAC channel 2 flags */
210 #define LL_DAC_FLAG_DMAUDR2                (DAC_SR_DMAUDR2)   /*!< DAC channel 2 flag DMA underrun */
211 
212 /**
213   * @}
214   */
215 
216 /** @defgroup DAC_LL_EC_IT DAC interruptions
217   * @brief    IT defines which can be used with LL_DAC_ReadReg and  LL_DAC_WriteReg functions
218   * @{
219   */
220 #define LL_DAC_IT_DMAUDRIE1                (DAC_CR_DMAUDRIE1) /*!< DAC channel 1 interruption DMA underrun */
221 
222 #define LL_DAC_IT_DMAUDRIE2                (DAC_CR_DMAUDRIE2) /*!< DAC channel 2 interruption DMA underrun */
223 
224 /**
225   * @}
226   */
227 
228 /** @defgroup DAC_LL_EC_CHANNEL DAC channels
229   * @{
230   */
231 #define LL_DAC_CHANNEL_1                   (DAC_REG_DOR1_REGOFFSET | DAC_REG_DHR12R1_REGOFFSET | DAC_REG_DHR12L1_REGOFFSET | DAC_REG_DHR8R1_REGOFFSET | DAC_CR_CH1_BITOFFSET | DAC_SWTR_CH1) /*!< DAC channel 1 */
232 
233 #define LL_DAC_CHANNEL_2                   (DAC_REG_DOR2_REGOFFSET | DAC_REG_DHR12R2_REGOFFSET | DAC_REG_DHR12L2_REGOFFSET | DAC_REG_DHR8R2_REGOFFSET | DAC_CR_CH2_BITOFFSET | DAC_SWTR_CH2) /*!< DAC channel 2 */
234 
235 /**
236   * @}
237   */
238 
239 /** @defgroup DAC_LL_EC_TRIGGER_SOURCE DAC trigger source
240   * @{
241   */
242 #define LL_DAC_TRIG_SOFTWARE               (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger internal (SW start) */
243 #define LL_DAC_TRIG_EXT_TIM2_TRGO          (DAC_CR_TSEL1_2                                  ) /*!< DAC channel conversion trigger from external peripheral: TIM2 TRGO. */
244 #define LL_DAC_TRIG_EXT_TIM8_TRGO          (                                  DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM8 TRGO. */
245 #define LL_DAC_TRIG_EXT_TIM4_TRGO          (DAC_CR_TSEL1_2                  | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM4 TRGO. */
246 #define LL_DAC_TRIG_EXT_TIM6_TRGO          0x00000000UL                                       /*!< DAC channel conversion trigger from external peripheral: TIM6 TRGO. */
247 #define LL_DAC_TRIG_EXT_TIM7_TRGO          (                 DAC_CR_TSEL1_1                 ) /*!< DAC channel conversion trigger from external peripheral: TIM7 TRGO. */
248 #define LL_DAC_TRIG_EXT_TIM5_TRGO          (                 DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM5 TRGO. */
249 #define LL_DAC_TRIG_EXT_EXTI_LINE9         (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1                 ) /*!< DAC channel conversion trigger from external peripheral: external interrupt line 9. */
250 /**
251   * @}
252   */
253 
254 /** @defgroup DAC_LL_EC_WAVE_AUTO_GENERATION_MODE DAC waveform automatic generation mode
255   * @{
256   */
257 #define LL_DAC_WAVE_AUTO_GENERATION_NONE     0x00000000UL                    /*!< DAC channel wave auto generation mode disabled. */
258 #define LL_DAC_WAVE_AUTO_GENERATION_NOISE    (               DAC_CR_WAVE1_0) /*!< DAC channel wave auto generation mode enabled, set generated noise waveform. */
259 #define LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE (DAC_CR_WAVE1_1               ) /*!< DAC channel wave auto generation mode enabled, set generated triangle waveform. */
260 /**
261   * @}
262   */
263 
264 /** @defgroup DAC_LL_EC_WAVE_NOISE_LFSR_UNMASK_BITS DAC wave generation - Noise LFSR unmask bits
265   * @{
266   */
267 #define LL_DAC_NOISE_LFSR_UNMASK_BIT0      0x00000000UL                                                        /*!< Noise wave generation, unmask LFSR bit0, for the selected DAC channel */
268 #define LL_DAC_NOISE_LFSR_UNMASK_BITS1_0   (                                                   DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[1:0], for the selected DAC channel */
269 #define LL_DAC_NOISE_LFSR_UNMASK_BITS2_0   (                                  DAC_CR_MAMP1_1                 ) /*!< Noise wave generation, unmask LFSR bits[2:0], for the selected DAC channel */
270 #define LL_DAC_NOISE_LFSR_UNMASK_BITS3_0   (                                  DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[3:0], for the selected DAC channel */
271 #define LL_DAC_NOISE_LFSR_UNMASK_BITS4_0   (                 DAC_CR_MAMP1_2                                  ) /*!< Noise wave generation, unmask LFSR bits[4:0], for the selected DAC channel */
272 #define LL_DAC_NOISE_LFSR_UNMASK_BITS5_0   (                 DAC_CR_MAMP1_2                  | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[5:0], for the selected DAC channel */
273 #define LL_DAC_NOISE_LFSR_UNMASK_BITS6_0   (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1                 ) /*!< Noise wave generation, unmask LFSR bits[6:0], for the selected DAC channel */
274 #define LL_DAC_NOISE_LFSR_UNMASK_BITS7_0   (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[7:0], for the selected DAC channel */
275 #define LL_DAC_NOISE_LFSR_UNMASK_BITS8_0   (DAC_CR_MAMP1_3                                                   ) /*!< Noise wave generation, unmask LFSR bits[8:0], for the selected DAC channel */
276 #define LL_DAC_NOISE_LFSR_UNMASK_BITS9_0   (DAC_CR_MAMP1_3                                   | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[9:0], for the selected DAC channel */
277 #define LL_DAC_NOISE_LFSR_UNMASK_BITS10_0  (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1                 ) /*!< Noise wave generation, unmask LFSR bits[10:0], for the selected DAC channel */
278 #define LL_DAC_NOISE_LFSR_UNMASK_BITS11_0  (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[11:0], for the selected DAC channel */
279 /**
280   * @}
281   */
282 
283 /** @defgroup DAC_LL_EC_WAVE_TRIANGLE_AMPLITUDE DAC wave generation - Triangle amplitude
284   * @{
285   */
286 #define LL_DAC_TRIANGLE_AMPLITUDE_1        0x00000000UL                                                        /*!< Triangle wave generation, amplitude of 1 LSB of DAC output range, for the selected DAC channel */
287 #define LL_DAC_TRIANGLE_AMPLITUDE_3        (                                                   DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 3 LSB of DAC output range, for the selected DAC channel */
288 #define LL_DAC_TRIANGLE_AMPLITUDE_7        (                                  DAC_CR_MAMP1_1                 ) /*!< Triangle wave generation, amplitude of 7 LSB of DAC output range, for the selected DAC channel */
289 #define LL_DAC_TRIANGLE_AMPLITUDE_15       (                                  DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 15 LSB of DAC output range, for the selected DAC channel */
290 #define LL_DAC_TRIANGLE_AMPLITUDE_31       (                 DAC_CR_MAMP1_2                                  ) /*!< Triangle wave generation, amplitude of 31 LSB of DAC output range, for the selected DAC channel */
291 #define LL_DAC_TRIANGLE_AMPLITUDE_63       (                 DAC_CR_MAMP1_2                  | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 63 LSB of DAC output range, for the selected DAC channel */
292 #define LL_DAC_TRIANGLE_AMPLITUDE_127      (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1                 ) /*!< Triangle wave generation, amplitude of 127 LSB of DAC output range, for the selected DAC channel */
293 #define LL_DAC_TRIANGLE_AMPLITUDE_255      (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 255 LSB of DAC output range, for the selected DAC channel */
294 #define LL_DAC_TRIANGLE_AMPLITUDE_511      (DAC_CR_MAMP1_3                                                   ) /*!< Triangle wave generation, amplitude of 512 LSB of DAC output range, for the selected DAC channel */
295 #define LL_DAC_TRIANGLE_AMPLITUDE_1023     (DAC_CR_MAMP1_3                                   | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 1023 LSB of DAC output range, for the selected DAC channel */
296 #define LL_DAC_TRIANGLE_AMPLITUDE_2047     (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1                 ) /*!< Triangle wave generation, amplitude of 2047 LSB of DAC output range, for the selected DAC channel */
297 #define LL_DAC_TRIANGLE_AMPLITUDE_4095     (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 4095 LSB of DAC output range, for the selected DAC channel */
298 /**
299   * @}
300   */
301 
302 /** @defgroup DAC_LL_EC_OUTPUT_BUFFER DAC channel output buffer
303   * @{
304   */
305 #define LL_DAC_OUTPUT_BUFFER_ENABLE        0x00000000UL            /*!< The selected DAC channel output is buffered: higher drive current capability, but also higher current consumption */
306 #define LL_DAC_OUTPUT_BUFFER_DISABLE       (DAC_CR_BOFF1)          /*!< The selected DAC channel output is not buffered: lower drive current capability, but also lower current consumption */
307 /**
308   * @}
309   */
310 
311 /** @defgroup DAC_LL_EC_RESOLUTION  DAC channel output resolution
312   * @{
313   */
314 #define LL_DAC_RESOLUTION_12B              0x00000000UL            /*!< DAC channel resolution 12 bits */
315 #define LL_DAC_RESOLUTION_8B               0x00000002UL            /*!< DAC channel resolution 8 bits */
316 /**
317   * @}
318   */
319 
320 /** @defgroup DAC_LL_EC_REGISTERS  DAC registers compliant with specific purpose
321   * @{
322   */
323 /* List of DAC registers intended to be used (most commonly) with             */
324 /* DMA transfer.                                                              */
325 /* Refer to function @ref LL_DAC_DMA_GetRegAddr().                            */
326 #define LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED  DAC_REG_DHR12RX_REGOFFSET_BITOFFSET_POS /*!< DAC channel data holding register 12 bits right aligned */
327 #define LL_DAC_DMA_REG_DATA_12BITS_LEFT_ALIGNED   DAC_REG_DHR12LX_REGOFFSET_BITOFFSET_POS /*!< DAC channel data holding register 12 bits left aligned */
328 #define LL_DAC_DMA_REG_DATA_8BITS_RIGHT_ALIGNED   DAC_REG_DHR8RX_REGOFFSET_BITOFFSET_POS  /*!< DAC channel data holding register 8 bits right aligned */
329 /**
330   * @}
331   */
332 
333 /** @defgroup DAC_LL_EC_HW_DELAYS  Definitions of DAC hardware constraints delays
334   * @note   Only DAC peripheral HW delays are defined in DAC LL driver driver,
335   *         not timeout values.
336   *         For details on delays values, refer to descriptions in source code
337   *         above each literal definition.
338   * @{
339   */
340 
341 /* Delay for DAC channel voltage settling time from DAC channel startup       */
342 /* (transition from disable to enable).                                       */
343 /* Note: DAC channel startup time depends on board application environment:   */
344 /*       impedance connected to DAC channel output.                           */
345 /*       The delay below is specified under conditions:                       */
346 /*        - voltage maximum transition (lowest to highest value)              */
347 /*        - until voltage reaches final value +-1LSB                          */
348 /*        - DAC channel output buffer enabled                                 */
349 /*        - load impedance of 5kOhm (min), 50pF (max)                         */
350 /* Literal set to maximum value (refer to device datasheet,                   */
351 /* parameter "tWAKEUP").                                                      */
352 /* Unit: us                                                                   */
353 #define LL_DAC_DELAY_STARTUP_VOLTAGE_SETTLING_US             15UL /*!< Delay for DAC channel voltage settling time from DAC channel startup (transition from disable to enable) */
354 
355 /* Delay for DAC channel voltage settling time.                               */
356 /* Note: DAC channel startup time depends on board application environment:   */
357 /*       impedance connected to DAC channel output.                           */
358 /*       The delay below is specified under conditions:                       */
359 /*        - voltage maximum transition (lowest to highest value)              */
360 /*        - until voltage reaches final value +-1LSB                          */
361 /*        - DAC channel output buffer enabled                                 */
362 /*        - load impedance of 5kOhm min, 50pF max                             */
363 /* Literal set to maximum value (refer to device datasheet,                   */
364 /* parameter "tSETTLING").                                                    */
365 /* Unit: us                                                                   */
366 #define LL_DAC_DELAY_VOLTAGE_SETTLING_US                    12UL /*!< Delay for DAC channel voltage settling time */
367 
368 /**
369   * @}
370   */
371 
372 /**
373   * @}
374   */
375 
376 /* Exported macro ------------------------------------------------------------*/
377 /** @defgroup DAC_LL_Exported_Macros DAC Exported Macros
378   * @{
379   */
380 
381 /** @defgroup DAC_LL_EM_WRITE_READ Common write and read registers macros
382   * @{
383   */
384 
385 /**
386   * @brief  Write a value in DAC register
387   * @param  __INSTANCE__ DAC Instance
388   * @param  __REG__ Register to be written
389   * @param  __VALUE__ Value to be written in the register
390   * @retval None
391   */
392 #define LL_DAC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
393 
394 /**
395   * @brief  Read a value in DAC register
396   * @param  __INSTANCE__ DAC Instance
397   * @param  __REG__ Register to be read
398   * @retval Register value
399   */
400 #define LL_DAC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
401 
402 /**
403   * @}
404   */
405 
406 /** @defgroup DAC_LL_EM_HELPER_MACRO DAC helper macro
407   * @{
408   */
409 
410 /**
411   * @brief  Helper macro to get DAC channel number in decimal format
412   *         from literals LL_DAC_CHANNEL_x.
413   *         Example:
414   *            __LL_DAC_CHANNEL_TO_DECIMAL_NB(LL_DAC_CHANNEL_1)
415   *            will return decimal number "1".
416   * @note   The input can be a value from functions where a channel
417   *         number is returned.
418   * @param  __CHANNEL__ This parameter can be one of the following values:
419   *         @arg @ref LL_DAC_CHANNEL_1
420   *         @arg @ref LL_DAC_CHANNEL_2
421   * @retval 1...2
422   */
423 #define __LL_DAC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__)                            \
424   ((__CHANNEL__) & DAC_SWTR_CHX_MASK)
425 
426 /**
427   * @brief  Helper macro to get DAC channel in literal format LL_DAC_CHANNEL_x
428   *         from number in decimal format.
429   *         Example:
430   *           __LL_DAC_DECIMAL_NB_TO_CHANNEL(1)
431   *           will return a data equivalent to "LL_DAC_CHANNEL_1".
432   * @note  If the input parameter does not correspond to a DAC channel,
433   *        this macro returns value '0'.
434   * @param  __DECIMAL_NB__ 1...2
435   * @retval Returned value can be one of the following values:
436   *         @arg @ref LL_DAC_CHANNEL_1
437   *         @arg @ref LL_DAC_CHANNEL_2
438   */
439 #define __LL_DAC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__)\
440   (((__DECIMAL_NB__) == 1UL)? (LL_DAC_CHANNEL_1  ):(((__DECIMAL_NB__) == 2UL) ? ( LL_DAC_CHANNEL_2):(0UL)))
441 
442 /**
443   * @brief  Helper macro to define the DAC conversion data full-scale digital
444   *         value corresponding to the selected DAC resolution.
445   * @note   DAC conversion data full-scale corresponds to voltage range
446   *         determined by analog voltage references Vref+ and Vref-
447   *         (refer to reference manual).
448   * @param  __DAC_RESOLUTION__ This parameter can be one of the following values:
449   *         @arg @ref LL_DAC_RESOLUTION_12B
450   *         @arg @ref LL_DAC_RESOLUTION_8B
451   * @retval ADC conversion data equivalent voltage value (unit: mVolt)
452   */
453 #define __LL_DAC_DIGITAL_SCALE(__DAC_RESOLUTION__)                             \
454   ((0x00000FFFUL) >> ((__DAC_RESOLUTION__) << 1UL))
455 
456 /**
457   * @brief  Helper macro to calculate the DAC conversion data (unit: digital
458   *         value) corresponding to a voltage (unit: mVolt).
459   * @note   This helper macro is intended to provide input data in voltage
460   *         rather than digital value,
461   *         to be used with LL DAC functions such as
462   *         @ref LL_DAC_ConvertData12RightAligned().
463   * @note   Analog reference voltage (Vref+) must be either known from
464   *         user board environment or can be calculated using ADC measurement
465   *         and ADC helper macro __LL_ADC_CALC_VREFANALOG_VOLTAGE().
466   * @param  __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
467   * @param  __DAC_VOLTAGE__ Voltage to be generated by DAC channel
468   *                         (unit: mVolt).
469   * @param  __DAC_RESOLUTION__ This parameter can be one of the following values:
470   *         @arg @ref LL_DAC_RESOLUTION_12B
471   *         @arg @ref LL_DAC_RESOLUTION_8B
472   * @retval DAC conversion data (unit: digital value)
473   */
474 #define __LL_DAC_CALC_VOLTAGE_TO_DATA(__VREFANALOG_VOLTAGE__, __DAC_VOLTAGE__, __DAC_RESOLUTION__)   \
475   ((__DAC_VOLTAGE__) * __LL_DAC_DIGITAL_SCALE(__DAC_RESOLUTION__)                                      \
476    / (__VREFANALOG_VOLTAGE__)                                                                          \
477   )
478 
479 /**
480   * @}
481   */
482 
483 /**
484   * @}
485   */
486 
487 
488 /* Exported functions --------------------------------------------------------*/
489 /** @defgroup DAC_LL_Exported_Functions DAC Exported Functions
490   * @{
491   */
492 
493 /**
494   * @brief  Set the conversion trigger source for the selected DAC channel.
495   * @note   For conversion trigger source to be effective, DAC trigger
496   *         must be enabled using function @ref LL_DAC_EnableTrigger().
497   * @note   To set conversion trigger source, DAC channel must be disabled.
498   *         Otherwise, the setting is discarded.
499   * @note   Availability of parameters of trigger sources from timer
500   *         depends on timers availability on the selected device.
501   * @rmtoll CR       TSEL1          LL_DAC_SetTriggerSource\n
502   *         CR       TSEL2          LL_DAC_SetTriggerSource
503   * @param  DACx DAC instance
504   * @param  DAC_Channel This parameter can be one of the following values:
505   *         @arg @ref LL_DAC_CHANNEL_1
506   *         @arg @ref LL_DAC_CHANNEL_2
507   * @param  TriggerSource This parameter can be one of the following values:
508   *         @arg @ref LL_DAC_TRIG_SOFTWARE
509   *         @arg @ref LL_DAC_TRIG_EXT_TIM8_TRGO
510   *         @arg @ref LL_DAC_TRIG_EXT_TIM7_TRGO
511   *         @arg @ref LL_DAC_TRIG_EXT_TIM6_TRGO
512   *         @arg @ref LL_DAC_TRIG_EXT_TIM5_TRGO
513   *         @arg @ref LL_DAC_TRIG_EXT_TIM4_TRGO
514   *         @arg @ref LL_DAC_TRIG_EXT_TIM2_TRGO
515   *         @arg @ref LL_DAC_TRIG_EXT_EXTI_LINE9
516   * @retval None
517   */
LL_DAC_SetTriggerSource(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t TriggerSource)518 __STATIC_INLINE void LL_DAC_SetTriggerSource(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t TriggerSource)
519 {
520   MODIFY_REG(DACx->CR,
521              DAC_CR_TSEL1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
522              TriggerSource << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
523 }
524 
525 /**
526   * @brief  Get the conversion trigger source for the selected DAC channel.
527   * @note   For conversion trigger source to be effective, DAC trigger
528   *         must be enabled using function @ref LL_DAC_EnableTrigger().
529   * @note   Availability of parameters of trigger sources from timer
530   *         depends on timers availability on the selected device.
531   * @rmtoll CR       TSEL1          LL_DAC_GetTriggerSource\n
532   *         CR       TSEL2          LL_DAC_GetTriggerSource
533   * @param  DACx DAC instance
534   * @param  DAC_Channel This parameter can be one of the following values:
535   *         @arg @ref LL_DAC_CHANNEL_1
536   *         @arg @ref LL_DAC_CHANNEL_2
537   * @retval Returned value can be one of the following values:
538   *         @arg @ref LL_DAC_TRIG_SOFTWARE
539   *         @arg @ref LL_DAC_TRIG_EXT_TIM8_TRGO
540   *         @arg @ref LL_DAC_TRIG_EXT_TIM7_TRGO
541   *         @arg @ref LL_DAC_TRIG_EXT_TIM6_TRGO
542   *         @arg @ref LL_DAC_TRIG_EXT_TIM5_TRGO
543   *         @arg @ref LL_DAC_TRIG_EXT_TIM4_TRGO
544   *         @arg @ref LL_DAC_TRIG_EXT_TIM2_TRGO
545   *         @arg @ref LL_DAC_TRIG_EXT_EXTI_LINE9
546   */
LL_DAC_GetTriggerSource(const DAC_TypeDef * DACx,uint32_t DAC_Channel)547 __STATIC_INLINE uint32_t LL_DAC_GetTriggerSource(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
548 {
549   return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_TSEL1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
550                     >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
551                    );
552 }
553 
554 /**
555   * @brief  Set the waveform automatic generation mode
556   *         for the selected DAC channel.
557   * @rmtoll CR       WAVE1          LL_DAC_SetWaveAutoGeneration\n
558   *         CR       WAVE2          LL_DAC_SetWaveAutoGeneration
559   * @param  DACx DAC instance
560   * @param  DAC_Channel This parameter can be one of the following values:
561   *         @arg @ref LL_DAC_CHANNEL_1
562   *         @arg @ref LL_DAC_CHANNEL_2
563   * @param  WaveAutoGeneration This parameter can be one of the following values:
564   *         @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NONE
565   *         @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NOISE
566   *         @arg @ref LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE
567   * @retval None
568   */
LL_DAC_SetWaveAutoGeneration(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t WaveAutoGeneration)569 __STATIC_INLINE void LL_DAC_SetWaveAutoGeneration(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t WaveAutoGeneration)
570 {
571   MODIFY_REG(DACx->CR,
572              DAC_CR_WAVE1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
573              WaveAutoGeneration << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
574 }
575 
576 /**
577   * @brief  Get the waveform automatic generation mode
578   *         for the selected DAC channel.
579   * @rmtoll CR       WAVE1          LL_DAC_GetWaveAutoGeneration\n
580   *         CR       WAVE2          LL_DAC_GetWaveAutoGeneration
581   * @param  DACx DAC instance
582   * @param  DAC_Channel This parameter can be one of the following values:
583   *         @arg @ref LL_DAC_CHANNEL_1
584   *         @arg @ref LL_DAC_CHANNEL_2
585   * @retval Returned value can be one of the following values:
586   *         @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NONE
587   *         @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NOISE
588   *         @arg @ref LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE
589   */
LL_DAC_GetWaveAutoGeneration(const DAC_TypeDef * DACx,uint32_t DAC_Channel)590 __STATIC_INLINE uint32_t LL_DAC_GetWaveAutoGeneration(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
591 {
592   return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_WAVE1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
593                     >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
594                    );
595 }
596 
597 /**
598   * @brief  Set the noise waveform generation for the selected DAC channel:
599   *         Noise mode and parameters LFSR (linear feedback shift register).
600   * @note   For wave generation to be effective, DAC channel
601   *         wave generation mode must be enabled using
602   *         function @ref LL_DAC_SetWaveAutoGeneration().
603   * @note   This setting can be set when the selected DAC channel is disabled
604   *         (otherwise, the setting operation is ignored).
605   * @rmtoll CR       MAMP1          LL_DAC_SetWaveNoiseLFSR\n
606   *         CR       MAMP2          LL_DAC_SetWaveNoiseLFSR
607   * @param  DACx DAC instance
608   * @param  DAC_Channel This parameter can be one of the following values:
609   *         @arg @ref LL_DAC_CHANNEL_1
610   *         @arg @ref LL_DAC_CHANNEL_2
611   * @param  NoiseLFSRMask This parameter can be one of the following values:
612   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BIT0
613   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS1_0
614   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS2_0
615   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS3_0
616   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS4_0
617   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS5_0
618   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS6_0
619   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS7_0
620   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS8_0
621   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS9_0
622   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS10_0
623   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS11_0
624   * @retval None
625   */
LL_DAC_SetWaveNoiseLFSR(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t NoiseLFSRMask)626 __STATIC_INLINE void LL_DAC_SetWaveNoiseLFSR(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t NoiseLFSRMask)
627 {
628   MODIFY_REG(DACx->CR,
629              DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
630              NoiseLFSRMask << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
631 }
632 
633 /**
634   * @brief  Get the noise waveform generation for the selected DAC channel:
635   *         Noise mode and parameters LFSR (linear feedback shift register).
636   * @rmtoll CR       MAMP1          LL_DAC_GetWaveNoiseLFSR\n
637   *         CR       MAMP2          LL_DAC_GetWaveNoiseLFSR
638   * @param  DACx DAC instance
639   * @param  DAC_Channel This parameter can be one of the following values:
640   *         @arg @ref LL_DAC_CHANNEL_1
641   *         @arg @ref LL_DAC_CHANNEL_2
642   * @retval Returned value can be one of the following values:
643   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BIT0
644   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS1_0
645   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS2_0
646   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS3_0
647   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS4_0
648   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS5_0
649   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS6_0
650   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS7_0
651   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS8_0
652   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS9_0
653   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS10_0
654   *         @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS11_0
655   */
LL_DAC_GetWaveNoiseLFSR(const DAC_TypeDef * DACx,uint32_t DAC_Channel)656 __STATIC_INLINE uint32_t LL_DAC_GetWaveNoiseLFSR(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
657 {
658   return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
659                     >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
660                    );
661 }
662 
663 /**
664   * @brief  Set the triangle waveform generation for the selected DAC channel:
665   *         triangle mode and amplitude.
666   * @note   For wave generation to be effective, DAC channel
667   *         wave generation mode must be enabled using
668   *         function @ref LL_DAC_SetWaveAutoGeneration().
669   * @note   This setting can be set when the selected DAC channel is disabled
670   *         (otherwise, the setting operation is ignored).
671   * @rmtoll CR       MAMP1          LL_DAC_SetWaveTriangleAmplitude\n
672   *         CR       MAMP2          LL_DAC_SetWaveTriangleAmplitude
673   * @param  DACx DAC instance
674   * @param  DAC_Channel This parameter can be one of the following values:
675   *         @arg @ref LL_DAC_CHANNEL_1
676   *         @arg @ref LL_DAC_CHANNEL_2
677   * @param  TriangleAmplitude This parameter can be one of the following values:
678   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1
679   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_3
680   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_7
681   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_15
682   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_31
683   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_63
684   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_127
685   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_255
686   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_511
687   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1023
688   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_2047
689   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_4095
690   * @retval None
691   */
LL_DAC_SetWaveTriangleAmplitude(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t TriangleAmplitude)692 __STATIC_INLINE void LL_DAC_SetWaveTriangleAmplitude(DAC_TypeDef *DACx, uint32_t DAC_Channel,
693                                                      uint32_t TriangleAmplitude)
694 {
695   MODIFY_REG(DACx->CR,
696              DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
697              TriangleAmplitude << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
698 }
699 
700 /**
701   * @brief  Get the triangle waveform generation for the selected DAC channel:
702   *         triangle mode and amplitude.
703   * @rmtoll CR       MAMP1          LL_DAC_GetWaveTriangleAmplitude\n
704   *         CR       MAMP2          LL_DAC_GetWaveTriangleAmplitude
705   * @param  DACx DAC instance
706   * @param  DAC_Channel This parameter can be one of the following values:
707   *         @arg @ref LL_DAC_CHANNEL_1
708   *         @arg @ref LL_DAC_CHANNEL_2
709   * @retval Returned value can be one of the following values:
710   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1
711   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_3
712   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_7
713   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_15
714   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_31
715   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_63
716   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_127
717   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_255
718   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_511
719   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1023
720   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_2047
721   *         @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_4095
722   */
LL_DAC_GetWaveTriangleAmplitude(const DAC_TypeDef * DACx,uint32_t DAC_Channel)723 __STATIC_INLINE uint32_t LL_DAC_GetWaveTriangleAmplitude(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
724 {
725   return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
726                     >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
727                    );
728 }
729 
730 /**
731   * @brief  Set the output buffer for the selected DAC channel.
732   * @rmtoll CR       BOFF1          LL_DAC_SetOutputBuffer\n
733   *         CR       BOFF2          LL_DAC_SetOutputBuffer
734   * @param  DACx DAC instance
735   * @param  DAC_Channel This parameter can be one of the following values:
736   *         @arg @ref LL_DAC_CHANNEL_1
737   *         @arg @ref LL_DAC_CHANNEL_2
738   * @param  OutputBuffer This parameter can be one of the following values:
739   *         @arg @ref LL_DAC_OUTPUT_BUFFER_ENABLE
740   *         @arg @ref LL_DAC_OUTPUT_BUFFER_DISABLE
741   * @retval None
742   */
LL_DAC_SetOutputBuffer(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t OutputBuffer)743 __STATIC_INLINE void LL_DAC_SetOutputBuffer(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t OutputBuffer)
744 {
745   MODIFY_REG(DACx->CR,
746              DAC_CR_BOFF1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
747              OutputBuffer << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
748 }
749 
750 /**
751   * @brief  Get the output buffer state for the selected DAC channel.
752   * @rmtoll CR       BOFF1          LL_DAC_GetOutputBuffer\n
753   *         CR       BOFF2          LL_DAC_GetOutputBuffer
754   * @param  DACx DAC instance
755   * @param  DAC_Channel This parameter can be one of the following values:
756   *         @arg @ref LL_DAC_CHANNEL_1
757   *         @arg @ref LL_DAC_CHANNEL_2
758   * @retval Returned value can be one of the following values:
759   *         @arg @ref LL_DAC_OUTPUT_BUFFER_ENABLE
760   *         @arg @ref LL_DAC_OUTPUT_BUFFER_DISABLE
761   */
LL_DAC_GetOutputBuffer(const DAC_TypeDef * DACx,uint32_t DAC_Channel)762 __STATIC_INLINE uint32_t LL_DAC_GetOutputBuffer(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
763 {
764   return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_BOFF1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
765                     >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
766                    );
767 }
768 
769 /**
770   * @}
771   */
772 
773 /** @defgroup DAC_LL_EF_DMA_Management DMA Management
774   * @{
775   */
776 
777 /**
778   * @brief  Enable DAC DMA transfer request of the selected channel.
779   * @note   To configure DMA source address (peripheral address),
780   *         use function @ref LL_DAC_DMA_GetRegAddr().
781   * @rmtoll CR       DMAEN1         LL_DAC_EnableDMAReq\n
782   *         CR       DMAEN2         LL_DAC_EnableDMAReq
783   * @param  DACx DAC instance
784   * @param  DAC_Channel This parameter can be one of the following values:
785   *         @arg @ref LL_DAC_CHANNEL_1
786   *         @arg @ref LL_DAC_CHANNEL_2
787   * @retval None
788   */
LL_DAC_EnableDMAReq(DAC_TypeDef * DACx,uint32_t DAC_Channel)789 __STATIC_INLINE void LL_DAC_EnableDMAReq(DAC_TypeDef *DACx, uint32_t DAC_Channel)
790 {
791   SET_BIT(DACx->CR,
792           DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
793 }
794 
795 /**
796   * @brief  Disable DAC DMA transfer request of the selected channel.
797   * @note   To configure DMA source address (peripheral address),
798   *         use function @ref LL_DAC_DMA_GetRegAddr().
799   * @rmtoll CR       DMAEN1         LL_DAC_DisableDMAReq\n
800   *         CR       DMAEN2         LL_DAC_DisableDMAReq
801   * @param  DACx DAC instance
802   * @param  DAC_Channel This parameter can be one of the following values:
803   *         @arg @ref LL_DAC_CHANNEL_1
804   *         @arg @ref LL_DAC_CHANNEL_2
805   * @retval None
806   */
LL_DAC_DisableDMAReq(DAC_TypeDef * DACx,uint32_t DAC_Channel)807 __STATIC_INLINE void LL_DAC_DisableDMAReq(DAC_TypeDef *DACx, uint32_t DAC_Channel)
808 {
809   CLEAR_BIT(DACx->CR,
810             DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
811 }
812 
813 /**
814   * @brief  Get DAC DMA transfer request state of the selected channel.
815   *         (0: DAC DMA transfer request is disabled, 1: DAC DMA transfer request is enabled)
816   * @rmtoll CR       DMAEN1         LL_DAC_IsDMAReqEnabled\n
817   *         CR       DMAEN2         LL_DAC_IsDMAReqEnabled
818   * @param  DACx DAC instance
819   * @param  DAC_Channel This parameter can be one of the following values:
820   *         @arg @ref LL_DAC_CHANNEL_1
821   *         @arg @ref LL_DAC_CHANNEL_2
822   * @retval State of bit (1 or 0).
823   */
LL_DAC_IsDMAReqEnabled(const DAC_TypeDef * DACx,uint32_t DAC_Channel)824 __STATIC_INLINE uint32_t LL_DAC_IsDMAReqEnabled(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
825 {
826   return ((READ_BIT(DACx->CR,
827                     DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
828            == (DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))) ? 1UL : 0UL);
829 }
830 
831 /**
832   * @brief  Function to help to configure DMA transfer to DAC: retrieve the
833   *         DAC register address from DAC instance and a list of DAC registers
834   *         intended to be used (most commonly) with DMA transfer.
835   * @note   These DAC registers are data holding registers:
836   *         when DAC conversion is requested, DAC generates a DMA transfer
837   *         request to have data available in DAC data holding registers.
838   * @note   This macro is intended to be used with LL DMA driver, refer to
839   *         function "LL_DMA_ConfigAddresses()".
840   *         Example:
841   *           LL_DMA_ConfigAddresses(DMA1,
842   *                                  LL_DMA_CHANNEL_1,
843   *                                  (uint32_t)&< array or variable >,
844   *                                  LL_DAC_DMA_GetRegAddr(DAC1, LL_DAC_CHANNEL_1,
845   *                                  LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED),
846   *                                  LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
847   * @rmtoll DHR12R1  DACC1DHR       LL_DAC_DMA_GetRegAddr\n
848   *         DHR12L1  DACC1DHR       LL_DAC_DMA_GetRegAddr\n
849   *         DHR8R1   DACC1DHR       LL_DAC_DMA_GetRegAddr\n
850   *         DHR12R2  DACC2DHR       LL_DAC_DMA_GetRegAddr\n
851   *         DHR12L2  DACC2DHR       LL_DAC_DMA_GetRegAddr\n
852   *         DHR8R2   DACC2DHR       LL_DAC_DMA_GetRegAddr
853   * @param  DACx DAC instance
854   * @param  DAC_Channel This parameter can be one of the following values:
855   *         @arg @ref LL_DAC_CHANNEL_1
856   *         @arg @ref LL_DAC_CHANNEL_2
857   * @param  Register This parameter can be one of the following values:
858   *         @arg @ref LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED
859   *         @arg @ref LL_DAC_DMA_REG_DATA_12BITS_LEFT_ALIGNED
860   *         @arg @ref LL_DAC_DMA_REG_DATA_8BITS_RIGHT_ALIGNED
861   * @retval DAC register address
862   */
LL_DAC_DMA_GetRegAddr(const DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t Register)863 __STATIC_INLINE uint32_t LL_DAC_DMA_GetRegAddr(const DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Register)
864 {
865   /* Retrieve address of register DHR12Rx, DHR12Lx or DHR8Rx depending on     */
866   /* DAC channel selected.                                                    */
867   return ((uint32_t)(__DAC_PTR_REG_OFFSET((DACx)->DHR12R1, ((DAC_Channel >> (Register & 0x1FUL))
868                                                             & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0))));
869 }
870 /**
871   * @}
872   */
873 
874 /** @defgroup DAC_LL_EF_Operation Operation on DAC channels
875   * @{
876   */
877 
878 /**
879   * @brief  Enable DAC selected channel.
880   * @rmtoll CR       EN1            LL_DAC_Enable\n
881   *         CR       EN2            LL_DAC_Enable
882   * @note   After enable from off state, DAC channel requires a delay
883   *         for output voltage to reach accuracy +/- 1 LSB.
884   *         Refer to device datasheet, parameter "tWAKEUP".
885   * @param  DACx DAC instance
886   * @param  DAC_Channel This parameter can be one of the following values:
887   *         @arg @ref LL_DAC_CHANNEL_1
888   *         @arg @ref LL_DAC_CHANNEL_2
889   * @retval None
890   */
LL_DAC_Enable(DAC_TypeDef * DACx,uint32_t DAC_Channel)891 __STATIC_INLINE void LL_DAC_Enable(DAC_TypeDef *DACx, uint32_t DAC_Channel)
892 {
893   SET_BIT(DACx->CR,
894           DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
895 }
896 
897 /**
898   * @brief  Disable DAC selected channel.
899   * @rmtoll CR       EN1            LL_DAC_Disable\n
900   *         CR       EN2            LL_DAC_Disable
901   * @param  DACx DAC instance
902   * @param  DAC_Channel This parameter can be one of the following values:
903   *         @arg @ref LL_DAC_CHANNEL_1
904   *         @arg @ref LL_DAC_CHANNEL_2
905   * @retval None
906   */
LL_DAC_Disable(DAC_TypeDef * DACx,uint32_t DAC_Channel)907 __STATIC_INLINE void LL_DAC_Disable(DAC_TypeDef *DACx, uint32_t DAC_Channel)
908 {
909   CLEAR_BIT(DACx->CR,
910             DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
911 }
912 
913 /**
914   * @brief  Get DAC enable state of the selected channel.
915   *         (0: DAC channel is disabled, 1: DAC channel is enabled)
916   * @rmtoll CR       EN1            LL_DAC_IsEnabled\n
917   *         CR       EN2            LL_DAC_IsEnabled
918   * @param  DACx DAC instance
919   * @param  DAC_Channel This parameter can be one of the following values:
920   *         @arg @ref LL_DAC_CHANNEL_1
921   *         @arg @ref LL_DAC_CHANNEL_2
922   * @retval State of bit (1 or 0).
923   */
LL_DAC_IsEnabled(const DAC_TypeDef * DACx,uint32_t DAC_Channel)924 __STATIC_INLINE uint32_t LL_DAC_IsEnabled(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
925 {
926   return ((READ_BIT(DACx->CR,
927                     DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
928            == (DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))) ? 1UL : 0UL);
929 }
930 
931 /**
932   * @brief  Enable DAC trigger of the selected channel.
933   * @note   - If DAC trigger is disabled, DAC conversion is performed
934   *           automatically once the data holding register is updated,
935   *           using functions "LL_DAC_ConvertData{8; 12}{Right; Left} Aligned()":
936   *           @ref LL_DAC_ConvertData12RightAligned(), ...
937   *         - If DAC trigger is enabled, DAC conversion is performed
938   *           only when a hardware of software trigger event is occurring.
939   *           Select trigger source using
940   *           function @ref LL_DAC_SetTriggerSource().
941   * @rmtoll CR       TEN1           LL_DAC_EnableTrigger\n
942   *         CR       TEN2           LL_DAC_EnableTrigger
943   * @param  DACx DAC instance
944   * @param  DAC_Channel This parameter can be one of the following values:
945   *         @arg @ref LL_DAC_CHANNEL_1
946   *         @arg @ref LL_DAC_CHANNEL_2
947   * @retval None
948   */
LL_DAC_EnableTrigger(DAC_TypeDef * DACx,uint32_t DAC_Channel)949 __STATIC_INLINE void LL_DAC_EnableTrigger(DAC_TypeDef *DACx, uint32_t DAC_Channel)
950 {
951   SET_BIT(DACx->CR,
952           DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
953 }
954 
955 /**
956   * @brief  Disable DAC trigger of the selected channel.
957   * @rmtoll CR       TEN1           LL_DAC_DisableTrigger\n
958   *         CR       TEN2           LL_DAC_DisableTrigger
959   * @param  DACx DAC instance
960   * @param  DAC_Channel This parameter can be one of the following values:
961   *         @arg @ref LL_DAC_CHANNEL_1
962   *         @arg @ref LL_DAC_CHANNEL_2
963   * @retval None
964   */
LL_DAC_DisableTrigger(DAC_TypeDef * DACx,uint32_t DAC_Channel)965 __STATIC_INLINE void LL_DAC_DisableTrigger(DAC_TypeDef *DACx, uint32_t DAC_Channel)
966 {
967   CLEAR_BIT(DACx->CR,
968             DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
969 }
970 
971 /**
972   * @brief  Get DAC trigger state of the selected channel.
973   *         (0: DAC trigger is disabled, 1: DAC trigger is enabled)
974   * @rmtoll CR       TEN1           LL_DAC_IsTriggerEnabled\n
975   *         CR       TEN2           LL_DAC_IsTriggerEnabled
976   * @param  DACx DAC instance
977   * @param  DAC_Channel This parameter can be one of the following values:
978   *         @arg @ref LL_DAC_CHANNEL_1
979   *         @arg @ref LL_DAC_CHANNEL_2
980   * @retval State of bit (1 or 0).
981   */
LL_DAC_IsTriggerEnabled(const DAC_TypeDef * DACx,uint32_t DAC_Channel)982 __STATIC_INLINE uint32_t LL_DAC_IsTriggerEnabled(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
983 {
984   return ((READ_BIT(DACx->CR,
985                     DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
986            == (DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))) ? 1UL : 0UL);
987 }
988 
989 /**
990   * @brief  Trig DAC conversion by software for the selected DAC channel.
991   * @note   Preliminarily, DAC trigger must be set to software trigger
992   *         using function
993   *           @ref LL_DAC_Init()
994   *           @ref LL_DAC_SetTriggerSource()
995   *         with parameter "LL_DAC_TRIGGER_SOFTWARE".
996   *         and DAC trigger must be enabled using
997   *         function @ref LL_DAC_EnableTrigger().
998   * @note   For devices featuring DAC with 2 channels: this function
999   *         can perform a SW start of both DAC channels simultaneously.
1000   *         Two channels can be selected as parameter.
1001   *         Example: (LL_DAC_CHANNEL_1 | LL_DAC_CHANNEL_2)
1002   * @rmtoll SWTRIGR  SWTRIG1        LL_DAC_TrigSWConversion\n
1003   *         SWTRIGR  SWTRIG2        LL_DAC_TrigSWConversion
1004   * @param  DACx DAC instance
1005   * @param  DAC_Channel  This parameter can a combination of the following values:
1006   *         @arg @ref LL_DAC_CHANNEL_1
1007   *         @arg @ref LL_DAC_CHANNEL_2
1008   * @retval None
1009   */
LL_DAC_TrigSWConversion(DAC_TypeDef * DACx,uint32_t DAC_Channel)1010 __STATIC_INLINE void LL_DAC_TrigSWConversion(DAC_TypeDef *DACx, uint32_t DAC_Channel)
1011 {
1012   SET_BIT(DACx->SWTRIGR,
1013           (DAC_Channel & DAC_SWTR_CHX_MASK));
1014 }
1015 
1016 /**
1017   * @brief  Set the data to be loaded in the data holding register
1018   *         in format 12 bits left alignment (LSB aligned on bit 0),
1019   *         for the selected DAC channel.
1020   * @rmtoll DHR12R1  DACC1DHR       LL_DAC_ConvertData12RightAligned\n
1021   *         DHR12R2  DACC2DHR       LL_DAC_ConvertData12RightAligned
1022   * @param  DACx DAC instance
1023   * @param  DAC_Channel This parameter can be one of the following values:
1024   *         @arg @ref LL_DAC_CHANNEL_1
1025   *         @arg @ref LL_DAC_CHANNEL_2
1026   * @param  Data Value between Min_Data=0x000 and Max_Data=0xFFF
1027   * @retval None
1028   */
LL_DAC_ConvertData12RightAligned(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t Data)1029 __STATIC_INLINE void LL_DAC_ConvertData12RightAligned(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Data)
1030 {
1031   __IO uint32_t *preg = __DAC_PTR_REG_OFFSET(DACx->DHR12R1, (DAC_Channel >> DAC_REG_DHR12RX_REGOFFSET_BITOFFSET_POS)
1032                                              & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0);
1033 
1034   MODIFY_REG(*preg, DAC_DHR12R1_DACC1DHR, Data);
1035 }
1036 
1037 /**
1038   * @brief  Set the data to be loaded in the data holding register
1039   *         in format 12 bits left alignment (MSB aligned on bit 15),
1040   *         for the selected DAC channel.
1041   * @rmtoll DHR12L1  DACC1DHR       LL_DAC_ConvertData12LeftAligned\n
1042   *         DHR12L2  DACC2DHR       LL_DAC_ConvertData12LeftAligned
1043   * @param  DACx DAC instance
1044   * @param  DAC_Channel This parameter can be one of the following values:
1045   *         @arg @ref LL_DAC_CHANNEL_1
1046   *         @arg @ref LL_DAC_CHANNEL_2
1047   * @param  Data Value between Min_Data=0x000 and Max_Data=0xFFF
1048   * @retval None
1049   */
LL_DAC_ConvertData12LeftAligned(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t Data)1050 __STATIC_INLINE void LL_DAC_ConvertData12LeftAligned(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Data)
1051 {
1052   __IO uint32_t *preg = __DAC_PTR_REG_OFFSET(DACx->DHR12R1, (DAC_Channel >> DAC_REG_DHR12LX_REGOFFSET_BITOFFSET_POS)
1053                                              & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0);
1054 
1055   MODIFY_REG(*preg, DAC_DHR12L1_DACC1DHR, Data);
1056 }
1057 
1058 /**
1059   * @brief  Set the data to be loaded in the data holding register
1060   *         in format 8 bits left alignment (LSB aligned on bit 0),
1061   *         for the selected DAC channel.
1062   * @rmtoll DHR8R1   DACC1DHR       LL_DAC_ConvertData8RightAligned\n
1063   *         DHR8R2   DACC2DHR       LL_DAC_ConvertData8RightAligned
1064   * @param  DACx DAC instance
1065   * @param  DAC_Channel This parameter can be one of the following values:
1066   *         @arg @ref LL_DAC_CHANNEL_1
1067   *         @arg @ref LL_DAC_CHANNEL_2
1068   * @param  Data Value between Min_Data=0x00 and Max_Data=0xFF
1069   * @retval None
1070   */
LL_DAC_ConvertData8RightAligned(DAC_TypeDef * DACx,uint32_t DAC_Channel,uint32_t Data)1071 __STATIC_INLINE void LL_DAC_ConvertData8RightAligned(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Data)
1072 {
1073   __IO uint32_t *preg = __DAC_PTR_REG_OFFSET(DACx->DHR12R1, (DAC_Channel >> DAC_REG_DHR8RX_REGOFFSET_BITOFFSET_POS)
1074                                              & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0);
1075 
1076   MODIFY_REG(*preg, DAC_DHR8R1_DACC1DHR, Data);
1077 }
1078 
1079 
1080 /**
1081   * @brief  Set the data to be loaded in the data holding register
1082   *         in format 12 bits left alignment (LSB aligned on bit 0),
1083   *         for both DAC channels.
1084   * @rmtoll DHR12RD  DACC1DHR       LL_DAC_ConvertDualData12RightAligned\n
1085   *         DHR12RD  DACC2DHR       LL_DAC_ConvertDualData12RightAligned
1086   * @param  DACx DAC instance
1087   * @param  DataChannel1 Value between Min_Data=0x000 and Max_Data=0xFFF
1088   * @param  DataChannel2 Value between Min_Data=0x000 and Max_Data=0xFFF
1089   * @retval None
1090   */
LL_DAC_ConvertDualData12RightAligned(DAC_TypeDef * DACx,uint32_t DataChannel1,uint32_t DataChannel2)1091 __STATIC_INLINE void LL_DAC_ConvertDualData12RightAligned(DAC_TypeDef *DACx, uint32_t DataChannel1,
1092                                                           uint32_t DataChannel2)
1093 {
1094   MODIFY_REG(DACx->DHR12RD,
1095              (DAC_DHR12RD_DACC2DHR | DAC_DHR12RD_DACC1DHR),
1096              ((DataChannel2 << DAC_DHR12RD_DACC2DHR_BITOFFSET_POS) | DataChannel1));
1097 }
1098 
1099 /**
1100   * @brief  Set the data to be loaded in the data holding register
1101   *         in format 12 bits left alignment (MSB aligned on bit 15),
1102   *         for both DAC channels.
1103   * @rmtoll DHR12LD  DACC1DHR       LL_DAC_ConvertDualData12LeftAligned\n
1104   *         DHR12LD  DACC2DHR       LL_DAC_ConvertDualData12LeftAligned
1105   * @param  DACx DAC instance
1106   * @param  DataChannel1 Value between Min_Data=0x000 and Max_Data=0xFFF
1107   * @param  DataChannel2 Value between Min_Data=0x000 and Max_Data=0xFFF
1108   * @retval None
1109   */
LL_DAC_ConvertDualData12LeftAligned(DAC_TypeDef * DACx,uint32_t DataChannel1,uint32_t DataChannel2)1110 __STATIC_INLINE void LL_DAC_ConvertDualData12LeftAligned(DAC_TypeDef *DACx, uint32_t DataChannel1,
1111                                                          uint32_t DataChannel2)
1112 {
1113   /* Note: Data of DAC channel 2 shift value subtracted of 4 because          */
1114   /*       data on 16 bits and DAC channel 2 bits field is on the 12 MSB,     */
1115   /*       the 4 LSB must be taken into account for the shift value.          */
1116   MODIFY_REG(DACx->DHR12LD,
1117              (DAC_DHR12LD_DACC2DHR | DAC_DHR12LD_DACC1DHR),
1118              ((DataChannel2 << (DAC_DHR12LD_DACC2DHR_BITOFFSET_POS - 4U)) | DataChannel1));
1119 }
1120 
1121 /**
1122   * @brief  Set the data to be loaded in the data holding register
1123   *         in format 8 bits left alignment (LSB aligned on bit 0),
1124   *         for both DAC channels.
1125   * @rmtoll DHR8RD  DACC1DHR       LL_DAC_ConvertDualData8RightAligned\n
1126   *         DHR8RD  DACC2DHR       LL_DAC_ConvertDualData8RightAligned
1127   * @param  DACx DAC instance
1128   * @param  DataChannel1 Value between Min_Data=0x00 and Max_Data=0xFF
1129   * @param  DataChannel2 Value between Min_Data=0x00 and Max_Data=0xFF
1130   * @retval None
1131   */
LL_DAC_ConvertDualData8RightAligned(DAC_TypeDef * DACx,uint32_t DataChannel1,uint32_t DataChannel2)1132 __STATIC_INLINE void LL_DAC_ConvertDualData8RightAligned(DAC_TypeDef *DACx, uint32_t DataChannel1,
1133                                                          uint32_t DataChannel2)
1134 {
1135   MODIFY_REG(DACx->DHR8RD,
1136              (DAC_DHR8RD_DACC2DHR | DAC_DHR8RD_DACC1DHR),
1137              ((DataChannel2 << DAC_DHR8RD_DACC2DHR_BITOFFSET_POS) | DataChannel1));
1138 }
1139 
1140 
1141 /**
1142   * @brief  Retrieve output data currently generated for the selected DAC channel.
1143   * @note   Whatever alignment and resolution settings
1144   *         (using functions "LL_DAC_ConvertData{8; 12}{Right; Left} Aligned()":
1145   *         @ref LL_DAC_ConvertData12RightAligned(), ...),
1146   *         output data format is 12 bits right aligned (LSB aligned on bit 0).
1147   * @rmtoll DOR1     DACC1DOR       LL_DAC_RetrieveOutputData\n
1148   *         DOR2     DACC2DOR       LL_DAC_RetrieveOutputData
1149   * @param  DACx DAC instance
1150   * @param  DAC_Channel This parameter can be one of the following values:
1151   *         @arg @ref LL_DAC_CHANNEL_1
1152   *         @arg @ref LL_DAC_CHANNEL_2
1153   * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
1154   */
LL_DAC_RetrieveOutputData(const DAC_TypeDef * DACx,uint32_t DAC_Channel)1155 __STATIC_INLINE uint32_t LL_DAC_RetrieveOutputData(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
1156 {
1157   __IO uint32_t const *preg = __DAC_PTR_REG_OFFSET(DACx->DOR1, (DAC_Channel >> DAC_REG_DORX_REGOFFSET_BITOFFSET_POS)
1158                                                    & DAC_REG_DORX_REGOFFSET_MASK_POSBIT0);
1159 
1160   return (uint16_t) READ_BIT(*preg, DAC_DOR1_DACC1DOR);
1161 }
1162 
1163 /**
1164   * @}
1165   */
1166 
1167 /** @defgroup DAC_LL_EF_FLAG_Management FLAG Management
1168   * @{
1169   */
1170 
1171 /**
1172   * @brief  Get DAC underrun flag for DAC channel 1
1173   * @rmtoll SR       DMAUDR1        LL_DAC_IsActiveFlag_DMAUDR1
1174   * @param  DACx DAC instance
1175   * @retval State of bit (1 or 0).
1176   */
LL_DAC_IsActiveFlag_DMAUDR1(const DAC_TypeDef * DACx)1177 __STATIC_INLINE uint32_t LL_DAC_IsActiveFlag_DMAUDR1(const DAC_TypeDef *DACx)
1178 {
1179   return ((READ_BIT(DACx->SR, LL_DAC_FLAG_DMAUDR1) == (LL_DAC_FLAG_DMAUDR1)) ? 1UL : 0UL);
1180 }
1181 
1182 
1183 /**
1184   * @brief  Get DAC underrun flag for DAC channel 2
1185   * @rmtoll SR       DMAUDR2        LL_DAC_IsActiveFlag_DMAUDR2
1186   * @param  DACx DAC instance
1187   * @retval State of bit (1 or 0).
1188   */
LL_DAC_IsActiveFlag_DMAUDR2(const DAC_TypeDef * DACx)1189 __STATIC_INLINE uint32_t LL_DAC_IsActiveFlag_DMAUDR2(const DAC_TypeDef *DACx)
1190 {
1191   return ((READ_BIT(DACx->SR, LL_DAC_FLAG_DMAUDR2) == (LL_DAC_FLAG_DMAUDR2)) ? 1UL : 0UL);
1192 }
1193 
1194 
1195 /**
1196   * @brief  Clear DAC underrun flag for DAC channel 1
1197   * @rmtoll SR       DMAUDR1        LL_DAC_ClearFlag_DMAUDR1
1198   * @param  DACx DAC instance
1199   * @retval None
1200   */
LL_DAC_ClearFlag_DMAUDR1(DAC_TypeDef * DACx)1201 __STATIC_INLINE void LL_DAC_ClearFlag_DMAUDR1(DAC_TypeDef *DACx)
1202 {
1203   WRITE_REG(DACx->SR, LL_DAC_FLAG_DMAUDR1);
1204 }
1205 
1206 
1207 /**
1208   * @brief  Clear DAC underrun flag for DAC channel 2
1209   * @rmtoll SR       DMAUDR2        LL_DAC_ClearFlag_DMAUDR2
1210   * @param  DACx DAC instance
1211   * @retval None
1212   */
LL_DAC_ClearFlag_DMAUDR2(DAC_TypeDef * DACx)1213 __STATIC_INLINE void LL_DAC_ClearFlag_DMAUDR2(DAC_TypeDef *DACx)
1214 {
1215   WRITE_REG(DACx->SR, LL_DAC_FLAG_DMAUDR2);
1216 }
1217 
1218 
1219 /**
1220   * @}
1221   */
1222 
1223 /** @defgroup DAC_LL_EF_IT_Management IT management
1224   * @{
1225   */
1226 
1227 /**
1228   * @brief  Enable DMA underrun interrupt for DAC channel 1
1229   * @rmtoll CR       DMAUDRIE1      LL_DAC_EnableIT_DMAUDR1
1230   * @param  DACx DAC instance
1231   * @retval None
1232   */
LL_DAC_EnableIT_DMAUDR1(DAC_TypeDef * DACx)1233 __STATIC_INLINE void LL_DAC_EnableIT_DMAUDR1(DAC_TypeDef *DACx)
1234 {
1235   SET_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE1);
1236 }
1237 
1238 
1239 /**
1240   * @brief  Enable DMA underrun interrupt for DAC channel 2
1241   * @rmtoll CR       DMAUDRIE2      LL_DAC_EnableIT_DMAUDR2
1242   * @param  DACx DAC instance
1243   * @retval None
1244   */
LL_DAC_EnableIT_DMAUDR2(DAC_TypeDef * DACx)1245 __STATIC_INLINE void LL_DAC_EnableIT_DMAUDR2(DAC_TypeDef *DACx)
1246 {
1247   SET_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE2);
1248 }
1249 
1250 
1251 /**
1252   * @brief  Disable DMA underrun interrupt for DAC channel 1
1253   * @rmtoll CR       DMAUDRIE1      LL_DAC_DisableIT_DMAUDR1
1254   * @param  DACx DAC instance
1255   * @retval None
1256   */
LL_DAC_DisableIT_DMAUDR1(DAC_TypeDef * DACx)1257 __STATIC_INLINE void LL_DAC_DisableIT_DMAUDR1(DAC_TypeDef *DACx)
1258 {
1259   CLEAR_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE1);
1260 }
1261 
1262 
1263 /**
1264   * @brief  Disable DMA underrun interrupt for DAC channel 2
1265   * @rmtoll CR       DMAUDRIE2      LL_DAC_DisableIT_DMAUDR2
1266   * @param  DACx DAC instance
1267   * @retval None
1268   */
LL_DAC_DisableIT_DMAUDR2(DAC_TypeDef * DACx)1269 __STATIC_INLINE void LL_DAC_DisableIT_DMAUDR2(DAC_TypeDef *DACx)
1270 {
1271   CLEAR_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE2);
1272 }
1273 
1274 
1275 /**
1276   * @brief  Get DMA underrun interrupt for DAC channel 1
1277   * @rmtoll CR       DMAUDRIE1      LL_DAC_IsEnabledIT_DMAUDR1
1278   * @param  DACx DAC instance
1279   * @retval State of bit (1 or 0).
1280   */
LL_DAC_IsEnabledIT_DMAUDR1(const DAC_TypeDef * DACx)1281 __STATIC_INLINE uint32_t LL_DAC_IsEnabledIT_DMAUDR1(const DAC_TypeDef *DACx)
1282 {
1283   return ((READ_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE1) == (LL_DAC_IT_DMAUDRIE1)) ? 1UL : 0UL);
1284 }
1285 
1286 
1287 /**
1288   * @brief  Get DMA underrun interrupt for DAC channel 2
1289   * @rmtoll CR       DMAUDRIE2      LL_DAC_IsEnabledIT_DMAUDR2
1290   * @param  DACx DAC instance
1291   * @retval State of bit (1 or 0).
1292   */
LL_DAC_IsEnabledIT_DMAUDR2(const DAC_TypeDef * DACx)1293 __STATIC_INLINE uint32_t LL_DAC_IsEnabledIT_DMAUDR2(const DAC_TypeDef *DACx)
1294 {
1295   return ((READ_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE2) == (LL_DAC_IT_DMAUDRIE2)) ? 1UL : 0UL);
1296 }
1297 
1298 
1299 /**
1300   * @}
1301   */
1302 
1303 #if defined(USE_FULL_LL_DRIVER)
1304 /** @defgroup DAC_LL_EF_Init Initialization and de-initialization functions
1305   * @{
1306   */
1307 
1308 ErrorStatus LL_DAC_DeInit(const DAC_TypeDef *DACx);
1309 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, const LL_DAC_InitTypeDef *DAC_InitStruct);
1310 void        LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct);
1311 
1312 /**
1313   * @}
1314   */
1315 #endif /* USE_FULL_LL_DRIVER */
1316 
1317 /**
1318   * @}
1319   */
1320 
1321 /**
1322   * @}
1323   */
1324 
1325 #endif /* DAC */
1326 
1327 /**
1328   * @}
1329   */
1330 
1331 #ifdef __cplusplus
1332 }
1333 #endif
1334 
1335 #endif /* STM32F2xx_LL_DAC_H */
1336