1 /**
2 ******************************************************************************
3 * @file stm32g4xx_ll_dac.c
4 * @author MCD Application Team
5 * @brief DAC LL module driver
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2019 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 #if defined(USE_FULL_LL_DRIVER)
19
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32g4xx_ll_dac.h"
22 #include "stm32g4xx_ll_bus.h"
23
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif /* USE_FULL_ASSERT */
29
30 /** @addtogroup STM32G4xx_LL_Driver
31 * @{
32 */
33
34 #if defined(DAC1) || defined(DAC2) || defined(DAC3) ||defined (DAC4)
35
36 /** @addtogroup DAC_LL DAC
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44
45 /** @addtogroup DAC_LL_Private_Macros
46 * @{
47 */
48 #if defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
49 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
50 (((__DACX__) == DAC2) ? \
51 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
52 : \
53 (((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
54 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2)) \
55 )
56 #else
57 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
58 (((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
59 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
60 )
61 #endif
62
63 #if defined(STM32G474xx) || defined(STM32G484xx)
64 #define IS_LL_DAC_TRIGGER_SOURCE(__DACX__, __TRIGGER_SOURCE__) \
65 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
66 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
67 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
68 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
69 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
70 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
71 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
72 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
73 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_RST_TRG1) \
74 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_RST_TRG2) \
75 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_RST_TRG3) \
76 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_RST_TRG4) \
77 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_RST_TRG5) \
78 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_RST_TRG6) \
79 || (((__DACX__) == DAC3) ? ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
80 : ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO)) \
81 || (((__DACX__) == DAC1) && ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_TRGO1))\
82 || (((__DACX__) == DAC2) && ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_TRGO2))\
83 || (((__DACX__) == DAC3) && ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_TRGO3))\
84 || (((__DACX__) == DAC4) && ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_TRGO1))\
85 )
86 #else
87 #define IS_LL_DAC_TRIGGER_SOURCE(__DACX__, __TRIGGER_SOURCE__) \
88 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
89 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
90 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
91 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
92 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
93 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
94 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
95 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
96 || (((__DACX__) == DAC3) ? ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
97 : ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO)) \
98 )
99 #endif
100
101 #if defined(STM32G474xx) || defined(STM32G484xx)
102 #define IS_LL_DAC_TRIGGER_SOURCE2(__DACX__, __TRIGGER_SOURCE__) \
103 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
104 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
105 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
106 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
107 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
108 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE10) \
109 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
110 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
111 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_STEP_TRG1) \
112 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_STEP_TRG2) \
113 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_STEP_TRG3) \
114 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_STEP_TRG4) \
115 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_STEP_TRG5) \
116 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_STEP_TRG6) \
117 || (((__DACX__) == DAC3) ? ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
118 : ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO)) \
119 )
120 #else
121 #define IS_LL_DAC_TRIGGER_SOURCE2(__DACX__, __TRIGGER_SOURCE__) \
122 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
123 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
124 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
125 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
126 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
127 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE10) \
128 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
129 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
130 || (((__DACX__) == DAC3) ? ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
131 : ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO)) \
132 )
133 #endif
134
135 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
136 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
137 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
138 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
139 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_SAWTOOTH) \
140 )
141 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__) \
142 ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
143 && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
144 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
145 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
146 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
147 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
148 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
149 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
150 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
151 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
152 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
153 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
154 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0)) \
155 ) \
156 ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
157 && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
158 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
159 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
160 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
161 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
162 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
163 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
164 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
165 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
166 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
167 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
168 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095)) \
169 ) \
170 ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_SAWTOOTH) \
171 && (((__WAVE_AUTO_GENERATION_CONFIG__) & ~(DAC_STR1_STINCDATA1|DAC_STR1_STDIR1|DAC_STR1_STRSTDATA1)) \
172 == 0UL) \
173 ) \
174 )
175
176 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
177 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
178 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
179 )
180
181 #define IS_LL_DAC_OUTPUT_CONNECTION(__OUTPUT_CONNECTION__) \
182 ( ((__OUTPUT_CONNECTION__) == LL_DAC_OUTPUT_CONNECT_GPIO) \
183 || ((__OUTPUT_CONNECTION__) == LL_DAC_OUTPUT_CONNECT_INTERNAL) \
184 )
185
186 #define IS_LL_DAC_OUTPUT_MODE(__OUTPUT_MODE__) \
187 ( ((__OUTPUT_MODE__) == LL_DAC_OUTPUT_MODE_NORMAL) \
188 || ((__OUTPUT_MODE__) == LL_DAC_OUTPUT_MODE_SAMPLE_AND_HOLD) \
189 )
190
191 /**
192 * @}
193 */
194
195
196 /* Private function prototypes -----------------------------------------------*/
197
198 /* Exported functions --------------------------------------------------------*/
199 /** @addtogroup DAC_LL_Exported_Functions
200 * @{
201 */
202
203 /** @addtogroup DAC_LL_EF_Init
204 * @{
205 */
206
207 /**
208 * @brief De-initialize registers of the selected DAC instance
209 * to their default reset values.
210 * @param DACx DAC instance
211 * @retval An ErrorStatus enumeration value:
212 * - SUCCESS: DAC registers are de-initialized
213 * - ERROR: not applicable
214 */
LL_DAC_DeInit(DAC_TypeDef * DACx)215 ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
216 {
217 /* Check the parameters */
218 assert_param(IS_DAC_ALL_INSTANCE(DACx));
219
220 #ifdef DAC1
221 if (DACx == DAC1)
222 {
223 /* Force reset of DAC clock */
224 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_DAC1);
225
226 /* Release reset of DAC clock */
227 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_DAC1);
228 }
229 #endif
230 #ifdef DAC2
231 if (DACx == DAC2)
232 {
233 /* Force reset of DAC clock */
234 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_DAC2);
235
236 /* Release reset of DAC clock */
237 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_DAC2);
238 }
239 #endif
240 #ifdef DAC3
241 if (DACx == DAC3)
242 {
243 /* Force reset of DAC clock */
244 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_DAC3);
245
246 /* Release reset of DAC clock */
247 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_DAC3);
248 }
249 #endif
250 #ifdef DAC4
251 if (DACx == DAC4)
252 {
253 /* Force reset of DAC clock */
254 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_DAC4);
255
256 /* Release reset of DAC clock */
257 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_DAC4);
258 }
259 #endif
260
261 return SUCCESS;
262 }
263
264 /**
265 * @brief Initialize some features of DAC channel.
266 * @note @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel.
267 * Leaving it ready to be enabled and output:
268 * a level by calling one of
269 * @ref LL_DAC_ConvertData12RightAligned
270 * @ref LL_DAC_ConvertData12LeftAligned
271 * @ref LL_DAC_ConvertData8RightAligned
272 * or one of the supported autogenerated wave.
273 * @note This function allows configuration of:
274 * - Output mode
275 * - Trigger
276 * - Wave generation
277 * @note The setting of these parameters by function @ref LL_DAC_Init()
278 * is conditioned to DAC state:
279 * DAC channel must be disabled.
280 * @param DACx DAC instance
281 * @param DAC_Channel This parameter can be one of the following values:
282 * @arg @ref LL_DAC_CHANNEL_1
283 * @arg @ref LL_DAC_CHANNEL_2 (1)
284 *
285 * (1) On this STM32 series, parameter not available on all instances.
286 * Refer to device datasheet for channels availability.
287 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
288 * @retval An ErrorStatus enumeration value:
289 * - SUCCESS: DAC registers are initialized
290 * - ERROR: DAC registers are not initialized
291 */
LL_DAC_Init(DAC_TypeDef * DACx,uint32_t DAC_Channel,LL_DAC_InitTypeDef * DAC_InitStruct)292 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
293 {
294 ErrorStatus status = SUCCESS;
295
296 /* Check the parameters */
297 assert_param(IS_DAC_ALL_INSTANCE(DACx));
298 assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel));
299 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DACx, DAC_InitStruct->TriggerSource));
300 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
301 assert_param(IS_LL_DAC_OUTPUT_CONNECTION(DAC_InitStruct->OutputConnection));
302 assert_param(IS_LL_DAC_OUTPUT_MODE(DAC_InitStruct->OutputMode));
303 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
304 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
305 {
306 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration,
307 DAC_InitStruct->WaveAutoGenerationConfig));
308 }
309
310 /* Note: Hardware constraint (refer to description of this function) */
311 /* DAC instance must be disabled. */
312 if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0UL)
313 {
314 /* Configuration of DAC channel: */
315 /* - TriggerSource */
316 /* - WaveAutoGeneration */
317 /* - OutputBuffer */
318 /* - OutputConnection */
319 /* - OutputMode */
320 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
321 {
322 if (DAC_InitStruct->WaveAutoGeneration == LL_DAC_WAVE_AUTO_GENERATION_SAWTOOTH)
323 {
324 assert_param(IS_LL_DAC_TRIGGER_SOURCE2(DACx, DAC_InitStruct->TriggerSource2));
325
326 MODIFY_REG(DACx->CR,
327 DAC_CR_WAVE1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
328 DAC_InitStruct->WaveAutoGeneration << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
329 );
330 MODIFY_REG(DACx->STMODR,
331 (DAC_STMODR_STINCTRIGSEL1 | DAC_STMODR_STRSTTRIGSEL1) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
332 (
333 ((DAC_InitStruct->TriggerSource >> DAC_CR_TSEL1_Pos) << DAC_STMODR_STRSTTRIGSEL1_Pos)
334 | ((DAC_InitStruct->TriggerSource2 >> DAC_CR_TSEL1_Pos) << DAC_STMODR_STINCTRIGSEL1_Pos)
335 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
336 );
337 WRITE_REG(*(__DAC_PTR_REG_OFFSET(DACx->STR1, (DAC_Channel >> DAC_REG_STRX_REGOFFSET_BITOFFSET_POS) & DAC_REG_STRX_REGOFFSET_MASK_POSBIT0)),
338 DAC_InitStruct->WaveAutoGenerationConfig);
339 }
340 else
341 {
342 MODIFY_REG(DACx->CR,
343 (DAC_CR_TSEL1
344 | DAC_CR_WAVE1
345 | DAC_CR_MAMP1
346 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
347 ,
348 (DAC_InitStruct->TriggerSource
349 | DAC_InitStruct->WaveAutoGeneration
350 | DAC_InitStruct->WaveAutoGenerationConfig
351 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
352 );
353 }
354 }
355 else
356 {
357 MODIFY_REG(DACx->CR,
358 (DAC_CR_TSEL1
359 | DAC_CR_WAVE1
360 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
361 ,
362 (DAC_InitStruct->TriggerSource
363 | LL_DAC_WAVE_AUTO_GENERATION_NONE
364 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
365 );
366 }
367 MODIFY_REG(DACx->MCR,
368 (DAC_MCR_MODE1_1
369 | DAC_MCR_MODE1_0
370 | DAC_MCR_MODE1_2
371 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
372 ,
373 (DAC_InitStruct->OutputBuffer
374 | DAC_InitStruct->OutputConnection
375 | DAC_InitStruct->OutputMode
376 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
377 );
378 }
379 else
380 {
381 /* Initialization error: DAC instance is not disabled. */
382 status = ERROR;
383 }
384 return status;
385 }
386
387 /**
388 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
389 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
390 * whose fields will be set to default values.
391 * @retval None
392 */
LL_DAC_StructInit(LL_DAC_InitTypeDef * DAC_InitStruct)393 void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
394 {
395 /* Set DAC_InitStruct fields to default values */
396 DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE;
397 DAC_InitStruct->TriggerSource2 = LL_DAC_TRIG_SOFTWARE;
398 DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
399 /* Note: Parameter discarded if wave auto generation is disabled, */
400 /* set anyway to its default value. */
401 DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
402 DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
403 DAC_InitStruct->OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO;
404 DAC_InitStruct->OutputMode = LL_DAC_OUTPUT_MODE_NORMAL;
405 }
406
407 /**
408 * @}
409 */
410
411 /**
412 * @}
413 */
414
415 /**
416 * @}
417 */
418
419 #endif /* DAC1 || DAC2 || DAC3 || DAC4 */
420
421 /**
422 * @}
423 */
424
425 #endif /* USE_FULL_LL_DRIVER */
426
427