提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file stm32f0xx_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</center></h2> |
|
10 |
* |
|
11 |
* Redistribution and use in source and binary forms, with or without modification, |
|
12 |
* are permitted provided that the following conditions are met: |
|
13 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer. |
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
16 |
* this list of conditions and the following disclaimer in the documentation |
|
17 |
* and/or other materials provided with the distribution. |
|
18 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
19 |
* may be used to endorse or promote products derived from this software |
|
20 |
* without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
23 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
25 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
28 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
30 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
31 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
* |
|
33 |
****************************************************************************** |
|
34 |
*/ |
|
35 |
#if defined(USE_FULL_LL_DRIVER) |
|
36 |
|
|
37 |
/* Includes ------------------------------------------------------------------*/ |
|
38 |
#include "stm32f0xx_ll_dac.h" |
|
39 |
#include "stm32f0xx_ll_bus.h" |
|
40 |
|
|
41 |
#ifdef USE_FULL_ASSERT |
|
42 |
#include "stm32_assert.h" |
|
43 |
#else |
|
44 |
#define assert_param(expr) ((void)0U) |
|
45 |
#endif |
|
46 |
|
|
47 |
/** @addtogroup STM32F0xx_LL_Driver |
|
48 |
* @{ |
|
49 |
*/ |
|
50 |
|
|
51 |
#if defined (DAC1) |
|
52 |
|
|
53 |
/** @addtogroup DAC_LL DAC |
|
54 |
* @{ |
|
55 |
*/ |
|
56 |
|
|
57 |
/* Private types -------------------------------------------------------------*/ |
|
58 |
/* Private variables ---------------------------------------------------------*/ |
|
59 |
/* Private constants ---------------------------------------------------------*/ |
|
60 |
/* Private macros ------------------------------------------------------------*/ |
|
61 |
|
|
62 |
/** @addtogroup DAC_LL_Private_Macros |
|
63 |
* @{ |
|
64 |
*/ |
|
65 |
|
|
66 |
#if defined(DAC_CHANNEL2_SUPPORT) |
|
67 |
#define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \ |
|
68 |
( \ |
|
69 |
((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \ |
|
70 |
|| ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \ |
|
71 |
) |
|
72 |
#else |
|
73 |
#define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \ |
|
74 |
( \ |
|
75 |
((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \ |
|
76 |
) |
|
77 |
#endif /* DAC_CHANNEL2_SUPPORT */ |
|
78 |
|
|
79 |
#define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \ |
|
80 |
( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \ |
|
81 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \ |
|
82 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \ |
|
83 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \ |
|
84 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \ |
|
85 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \ |
|
86 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \ |
|
87 |
|| ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \ |
|
88 |
) |
|
89 |
|
|
90 |
#if defined(DAC_CR_WAVE1) |
|
91 |
#define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \ |
|
92 |
( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \ |
|
93 |
|| ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \ |
|
94 |
|| ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \ |
|
95 |
) |
|
96 |
|
|
97 |
#define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \ |
|
98 |
( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \ |
|
99 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \ |
|
100 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \ |
|
101 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \ |
|
102 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \ |
|
103 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \ |
|
104 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \ |
|
105 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \ |
|
106 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \ |
|
107 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \ |
|
108 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \ |
|
109 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \ |
|
110 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \ |
|
111 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \ |
|
112 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \ |
|
113 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \ |
|
114 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \ |
|
115 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \ |
|
116 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \ |
|
117 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \ |
|
118 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \ |
|
119 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \ |
|
120 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \ |
|
121 |
|| ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \ |
|
122 |
) |
|
123 |
#endif |
|
124 |
|
|
125 |
#define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \ |
|
126 |
( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \ |
|
127 |
|| ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \ |
|
128 |
) |
|
129 |
|
|
130 |
/** |
|
131 |
* @} |
|
132 |
*/ |
|
133 |
|
|
134 |
|
|
135 |
/* Private function prototypes -----------------------------------------------*/ |
|
136 |
|
|
137 |
/* Exported functions --------------------------------------------------------*/ |
|
138 |
/** @addtogroup DAC_LL_Exported_Functions |
|
139 |
* @{ |
|
140 |
*/ |
|
141 |
|
|
142 |
/** @addtogroup DAC_LL_EF_Init |
|
143 |
* @{ |
|
144 |
*/ |
|
145 |
|
|
146 |
/** |
|
147 |
* @brief De-initialize registers of the selected DAC instance |
|
148 |
* to their default reset values. |
|
149 |
* @param DACx DAC instance |
|
150 |
* @retval An ErrorStatus enumeration value: |
|
151 |
* - SUCCESS: DAC registers are de-initialized |
|
152 |
* - ERROR: not applicable |
|
153 |
*/ |
|
154 |
ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx) |
|
155 |
{ |
|
156 |
/* Check the parameters */ |
|
157 |
assert_param(IS_DAC_ALL_INSTANCE(DACx)); |
|
158 |
|
|
159 |
/* Force reset of DAC clock */ |
|
160 |
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1); |
|
161 |
|
|
162 |
/* Release reset of DAC clock */ |
|
163 |
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1); |
|
164 |
|
|
165 |
return SUCCESS; |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* @brief Initialize some features of DAC instance. |
|
170 |
* @note The setting of these parameters by function @ref LL_DAC_Init() |
|
171 |
* is conditioned to DAC state: |
|
172 |
* DAC instance must be disabled. |
|
173 |
* @param DACx DAC instance |
|
174 |
* @param DAC_Channel This parameter can be one of the following values: |
|
175 |
* @arg @ref LL_DAC_CHANNEL_1 |
|
176 |
* @arg @ref LL_DAC_CHANNEL_2 (1) |
|
177 |
* |
|
178 |
* (1) On this STM32 serie, parameter not available on all devices. |
|
179 |
* Refer to device datasheet for channels availability. |
|
180 |
* @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure |
|
181 |
* @retval An ErrorStatus enumeration value: |
|
182 |
* - SUCCESS: DAC registers are initialized |
|
183 |
* - ERROR: DAC registers are not initialized |
|
184 |
*/ |
|
185 |
ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct) |
|
186 |
{ |
|
187 |
ErrorStatus status = SUCCESS; |
|
188 |
|
|
189 |
/* Check the parameters */ |
|
190 |
assert_param(IS_DAC_ALL_INSTANCE(DACx)); |
|
191 |
assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel)); |
|
192 |
assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource)); |
|
193 |
assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer)); |
|
194 |
#if defined(DAC_CR_WAVE1) |
|
195 |
assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration)); |
|
196 |
if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) |
|
197 |
{ |
|
198 |
assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGenerationConfig)); |
|
199 |
} |
|
200 |
#endif |
|
201 |
|
|
202 |
/* Note: Hardware constraint (refer to description of this function) */ |
|
203 |
/* DAC instance must be disabled. */ |
|
204 |
if(LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U) |
|
205 |
{ |
|
206 |
/* Configuration of DAC channel: */ |
|
207 |
/* - TriggerSource */ |
|
208 |
#if defined(DAC_CR_WAVE1) |
|
209 |
/* - WaveAutoGeneration */ |
|
210 |
#endif |
|
211 |
/* - OutputBuffer */ |
|
212 |
#if defined(DAC_CR_WAVE1) |
|
213 |
if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) |
|
214 |
{ |
|
215 |
MODIFY_REG(DACx->CR, |
|
216 |
( DAC_CR_TSEL1 |
|
217 |
| DAC_CR_WAVE1 |
|
218 |
| DAC_CR_MAMP1 |
|
219 |
| DAC_CR_BOFF1 |
|
220 |
) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) |
|
221 |
, |
|
222 |
( DAC_InitStruct->TriggerSource |
|
223 |
| DAC_InitStruct->WaveAutoGeneration |
|
224 |
| DAC_InitStruct->WaveAutoGenerationConfig |
|
225 |
| DAC_InitStruct->OutputBuffer |
|
226 |
) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) |
|
227 |
); |
|
228 |
} |
|
229 |
else |
|
230 |
{ |
|
231 |
MODIFY_REG(DACx->CR, |
|
232 |
( DAC_CR_TSEL1 |
|
233 |
| DAC_CR_WAVE1 |
|
234 |
| DAC_CR_BOFF1 |
|
235 |
) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) |
|
236 |
, |
|
237 |
( DAC_InitStruct->TriggerSource |
|
238 |
| LL_DAC_WAVE_AUTO_GENERATION_NONE |
|
239 |
| DAC_InitStruct->OutputBuffer |
|
240 |
) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) |
|
241 |
); |
|
242 |
} |
|
243 |
#endif |
|
244 |
} |
|
245 |
else |
|
246 |
{ |
|
247 |
/* Initialization error: DAC instance is not disabled. */ |
|
248 |
status = ERROR; |
|
249 |
} |
|
250 |
return status; |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* @brief Set each @ref LL_DAC_InitTypeDef field to default value. |
|
255 |
* @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure |
|
256 |
* whose fields will be set to default values. |
|
257 |
* @retval None |
|
258 |
*/ |
|
259 |
void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct) |
|
260 |
{ |
|
261 |
/* Set DAC_InitStruct fields to default values */ |
|
262 |
DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE; |
|
263 |
#if defined(DAC_CR_WAVE1) |
|
264 |
DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE; |
|
265 |
/* Note: Parameter discarded if wave auto generation is disabled, */ |
|
266 |
/* set anyway to its default value. */ |
|
267 |
DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0; |
|
268 |
#endif |
|
269 |
DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE; |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* @} |
|
274 |
*/ |
|
275 |
|
|
276 |
/** |
|
277 |
* @} |
|
278 |
*/ |
|
279 |
|
|
280 |
/** |
|
281 |
* @} |
|
282 |
*/ |
|
283 |
|
|
284 |
#endif /* DAC1 */ |
|
285 |
|
|
286 |
/** |
|
287 |
* @} |
|
288 |
*/ |
|
289 |
|
|
290 |
#endif /* USE_FULL_LL_DRIVER */ |
|
291 |
|
|
292 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |