1 | /**
|
---|
2 | ******************************************************************************
|
---|
3 | * @file stm32f4xx_ll_dac.c
|
---|
4 | * @author MCD Application Team
|
---|
5 | * @brief DAC LL module driver
|
---|
6 | ******************************************************************************
|
---|
7 | * @attention
|
---|
8 | *
|
---|
9 | * <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
---|
10 | * All rights reserved.</center></h2>
|
---|
11 | *
|
---|
12 | * This software component is licensed by ST under BSD 3-Clause license,
|
---|
13 | * the "License"; You may not use this file except in compliance with the
|
---|
14 | * License. You may obtain a copy of the License at:
|
---|
15 | * opensource.org/licenses/BSD-3-Clause
|
---|
16 | *
|
---|
17 | ******************************************************************************
|
---|
18 | */
|
---|
19 | #if defined(USE_FULL_LL_DRIVER)
|
---|
20 |
|
---|
21 | /* Includes ------------------------------------------------------------------*/
|
---|
22 | #include "stm32f4xx_ll_dac.h"
|
---|
23 | #include "stm32f4xx_ll_bus.h"
|
---|
24 |
|
---|
25 | #ifdef USE_FULL_ASSERT
|
---|
26 | #include "stm32_assert.h"
|
---|
27 | #else
|
---|
28 | #define assert_param(expr) ((void)0U)
|
---|
29 | #endif /* USE_FULL_ASSERT */
|
---|
30 |
|
---|
31 | /** @addtogroup STM32F4xx_LL_Driver
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 |
|
---|
35 | #if defined(DAC)
|
---|
36 |
|
---|
37 | /** @addtogroup DAC_LL DAC
|
---|
38 | * @{
|
---|
39 | */
|
---|
40 |
|
---|
41 | /* Private types -------------------------------------------------------------*/
|
---|
42 | /* Private variables ---------------------------------------------------------*/
|
---|
43 | /* Private constants ---------------------------------------------------------*/
|
---|
44 | /* Private macros ------------------------------------------------------------*/
|
---|
45 |
|
---|
46 | /** @addtogroup DAC_LL_Private_Macros
|
---|
47 | * @{
|
---|
48 | */
|
---|
49 | #if defined(DAC_CHANNEL2_SUPPORT)
|
---|
50 | #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
|
---|
51 | ( \
|
---|
52 | ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
|
---|
53 | || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
|
---|
54 | )
|
---|
55 | #else
|
---|
56 | #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
|
---|
57 | ( \
|
---|
58 | ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
|
---|
59 | )
|
---|
60 | #endif /* DAC_CHANNEL2_SUPPORT */
|
---|
61 |
|
---|
62 | #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
|
---|
63 | ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
|
---|
64 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
|
---|
65 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
|
---|
66 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
|
---|
67 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
|
---|
68 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
|
---|
69 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
|
---|
70 | || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
|
---|
71 | )
|
---|
72 |
|
---|
73 | #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
|
---|
74 | ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
|
---|
75 | || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
|
---|
76 | || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
|
---|
77 | )
|
---|
78 |
|
---|
79 | #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__) \
|
---|
80 | ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
|
---|
81 | && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
|
---|
82 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
|
---|
83 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
|
---|
84 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
|
---|
85 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
|
---|
86 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
|
---|
87 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
|
---|
88 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
|
---|
89 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
|
---|
90 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
|
---|
91 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
|
---|
92 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0)) \
|
---|
93 | ) \
|
---|
94 | ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
|
---|
95 | && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
|
---|
96 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
|
---|
97 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
|
---|
98 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
|
---|
99 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
|
---|
100 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
|
---|
101 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
|
---|
102 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
|
---|
103 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
|
---|
104 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
|
---|
105 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
|
---|
106 | || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095)) \
|
---|
107 | ) \
|
---|
108 | )
|
---|
109 |
|
---|
110 | #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
|
---|
111 | ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
|
---|
112 | || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
|
---|
113 | )
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * @}
|
---|
117 | */
|
---|
118 |
|
---|
119 |
|
---|
120 | /* Private function prototypes -----------------------------------------------*/
|
---|
121 |
|
---|
122 | /* Exported functions --------------------------------------------------------*/
|
---|
123 | /** @addtogroup DAC_LL_Exported_Functions
|
---|
124 | * @{
|
---|
125 | */
|
---|
126 |
|
---|
127 | /** @addtogroup DAC_LL_EF_Init
|
---|
128 | * @{
|
---|
129 | */
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * @brief De-initialize registers of the selected DAC instance
|
---|
133 | * to their default reset values.
|
---|
134 | * @param DACx DAC instance
|
---|
135 | * @retval An ErrorStatus enumeration value:
|
---|
136 | * - SUCCESS: DAC registers are de-initialized
|
---|
137 | * - ERROR: not applicable
|
---|
138 | */
|
---|
139 | ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
|
---|
140 | {
|
---|
141 | /* Check the parameters */
|
---|
142 | assert_param(IS_DAC_ALL_INSTANCE(DACx));
|
---|
143 |
|
---|
144 | /* Force reset of DAC clock */
|
---|
145 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
|
---|
146 |
|
---|
147 | /* Release reset of DAC clock */
|
---|
148 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
|
---|
149 |
|
---|
150 | return SUCCESS;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * @brief Initialize some features of DAC channel.
|
---|
155 | * @note @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel.
|
---|
156 | * Leaving it ready to be enabled and output:
|
---|
157 | * a level by calling one of
|
---|
158 | * @ref LL_DAC_ConvertData12RightAligned
|
---|
159 | * @ref LL_DAC_ConvertData12LeftAligned
|
---|
160 | * @ref LL_DAC_ConvertData8RightAligned
|
---|
161 | * or one of the supported autogenerated wave.
|
---|
162 | * @note This function allows configuration of:
|
---|
163 | * - Output mode
|
---|
164 | * - Trigger
|
---|
165 | * - Wave generation
|
---|
166 | * @note The setting of these parameters by function @ref LL_DAC_Init()
|
---|
167 | * is conditioned to DAC state:
|
---|
168 | * DAC channel must be disabled.
|
---|
169 | * @param DACx DAC instance
|
---|
170 | * @param DAC_Channel This parameter can be one of the following values:
|
---|
171 | * @arg @ref LL_DAC_CHANNEL_1
|
---|
172 | * @arg @ref LL_DAC_CHANNEL_2 (1)
|
---|
173 | *
|
---|
174 | * (1) On this STM32 serie, parameter not available on all devices.
|
---|
175 | * Refer to device datasheet for channels availability.
|
---|
176 | * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
|
---|
177 | * @retval An ErrorStatus enumeration value:
|
---|
178 | * - SUCCESS: DAC registers are initialized
|
---|
179 | * - ERROR: DAC registers are not initialized
|
---|
180 | */
|
---|
181 | ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
|
---|
182 | {
|
---|
183 | ErrorStatus status = SUCCESS;
|
---|
184 |
|
---|
185 | /* Check the parameters */
|
---|
186 | assert_param(IS_DAC_ALL_INSTANCE(DACx));
|
---|
187 | assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel));
|
---|
188 | assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
|
---|
189 | assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
|
---|
190 | assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
|
---|
191 | if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
|
---|
192 | {
|
---|
193 | assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration,
|
---|
194 | DAC_InitStruct->WaveAutoGenerationConfig));
|
---|
195 | }
|
---|
196 |
|
---|
197 | /* Note: Hardware constraint (refer to description of this function) */
|
---|
198 | /* DAC instance must be disabled. */
|
---|
199 | if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0UL)
|
---|
200 | {
|
---|
201 | /* Configuration of DAC channel: */
|
---|
202 | /* - TriggerSource */
|
---|
203 | /* - WaveAutoGeneration */
|
---|
204 | /* - OutputBuffer */
|
---|
205 | /* - OutputMode */
|
---|
206 | if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
|
---|
207 | {
|
---|
208 | MODIFY_REG(DACx->CR,
|
---|
209 | (DAC_CR_TSEL1
|
---|
210 | | DAC_CR_WAVE1
|
---|
211 | | DAC_CR_MAMP1
|
---|
212 | | DAC_CR_BOFF1
|
---|
213 | ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
|
---|
214 | ,
|
---|
215 | (DAC_InitStruct->TriggerSource
|
---|
216 | | DAC_InitStruct->WaveAutoGeneration
|
---|
217 | | DAC_InitStruct->WaveAutoGenerationConfig
|
---|
218 | | DAC_InitStruct->OutputBuffer
|
---|
219 | ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
|
---|
220 | );
|
---|
221 | }
|
---|
222 | else
|
---|
223 | {
|
---|
224 | MODIFY_REG(DACx->CR,
|
---|
225 | (DAC_CR_TSEL1
|
---|
226 | | DAC_CR_WAVE1
|
---|
227 | | DAC_CR_BOFF1
|
---|
228 | ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
|
---|
229 | ,
|
---|
230 | (DAC_InitStruct->TriggerSource
|
---|
231 | | LL_DAC_WAVE_AUTO_GENERATION_NONE
|
---|
232 | | DAC_InitStruct->OutputBuffer
|
---|
233 | ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
|
---|
234 | );
|
---|
235 | }
|
---|
236 | }
|
---|
237 | else
|
---|
238 | {
|
---|
239 | /* Initialization error: DAC instance is not disabled. */
|
---|
240 | status = ERROR;
|
---|
241 | }
|
---|
242 | return status;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
|
---|
247 | * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
|
---|
248 | * whose fields will be set to default values.
|
---|
249 | * @retval None
|
---|
250 | */
|
---|
251 | void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
|
---|
252 | {
|
---|
253 | /* Set DAC_InitStruct fields to default values */
|
---|
254 | DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE;
|
---|
255 | DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
|
---|
256 | /* Note: Parameter discarded if wave auto generation is disabled, */
|
---|
257 | /* set anyway to its default value. */
|
---|
258 | DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
|
---|
259 | DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
|
---|
260 | }
|
---|
261 |
|
---|
262 | /**
|
---|
263 | * @}
|
---|
264 | */
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * @}
|
---|
268 | */
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * @}
|
---|
272 | */
|
---|
273 |
|
---|
274 | #endif /* DAC */
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * @}
|
---|
278 | */
|
---|
279 |
|
---|
280 | #endif /* USE_FULL_LL_DRIVER */
|
---|
281 |
|
---|
282 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|