1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_comp.c
4 * @author MCD Application Team
5 * @brief COMP LL module driver
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 #if defined(USE_FULL_LL_DRIVER)
19
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32f3xx_ll_comp.h"
22
23 #ifdef USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif
28
29 /** @addtogroup STM32F3xx_LL_Driver
30 * @{
31 */
32
33 /* Note: Devices of STM32F3 series embed 1 out of 2 different comparator IP. */
34 /* - STM32F30x, STM32F31x, STM32F32x, STM32F33x, STM32F35x, STM32F39x: */
35 /* COMP IP from 3 to 7 instances and other specific features */
36 /* (comparator output blanking, ...) (refer to reference manual). */
37 /* - STM32F37x: */
38 /* COMP IP with 2 instances */
39 /* This file contains the drivers of these COMP IP, located in 2 area */
40 /* delimited by compilation switches. */
41
42 #if defined(COMP_V1_3_0_0)
43
44 #if defined (COMP1) || defined (COMP2) || defined (COMP3) || defined (COMP4) || defined (COMP5) || defined (COMP6) || defined (COMP7)
45
46 /** @addtogroup COMP_LL COMP
47 * @{
48 */
49
50 /* Private types -------------------------------------------------------------*/
51 /* Private variables ---------------------------------------------------------*/
52 /* Private constants ---------------------------------------------------------*/
53 /* Private macros ------------------------------------------------------------*/
54
55 /** @addtogroup COMP_LL_Private_Macros
56 * @{
57 */
58
59 /* Check of parameters for configuration of COMP hierarchical scope: */
60 /* COMP instance. */
61
62 #if defined(COMP_CSR_COMPxMODE)
63 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
64 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
65 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
66 || ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
67 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
68 )
69 #else
70 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
71 ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED)
72 #endif
73
74 /* Note: On this STM32 series, comparator input plus parameters are */
75 /* the same on all COMP instances. */
76 /* However, comparator instance kept as macro parameter for */
77 /* compatibility with other STM32 families. */
78 #if defined(COMP_CSR_COMPxNONINSEL) && defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1)
79 /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
80 /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
81 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
82 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
83 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
84 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1) \
85 )
86 #elif defined(COMP_CSR_COMPxNONINSEL) && defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2)
87 /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
88 /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
89 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
90 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
91 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
92 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2) \
93 )
94 #elif defined(COMP_CSR_COMPxNONINSEL)
95 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
96 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
97 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
98 )
99 #elif defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2)
100 /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
101 /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
102 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
103 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
104 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2) \
105 )
106 #else
107 /* Note: Device without comparator input plus configurable: corresponds to */
108 /* setting "LL_COMP_INPUT_PLUS_IO1" or "LL_COMP_INPUT_PLUS_IO2" */
109 /* compared to other STM32F3 devices, depending on comparator instance */
110 /* (refer to reference manual). */
111 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
112 ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1)
113 #endif
114
115 #if defined(STM32F303xC) || defined(STM32F358xx) || defined(STM32F303xE) || defined(STM32F398xx)
116 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
117 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
118 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
119 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
120 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
121 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
122 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
123 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
124 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
125 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
126 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
127 )
128 #elif defined(STM32F303x8) || defined(STM32F328xx) || defined(STM32F334x8)
129 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
130 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
131 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
132 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
133 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
134 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
135 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
136 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
137 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
138 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
139 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) \
140 )
141 #elif defined(STM32F302xC) || defined(STM32F302xE)
142 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
143 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
144 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
145 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
146 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
147 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
148 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
149 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
150 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
151 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
152 )
153 #else /* STM32F301x8 || STM32F318xx || STM32F302x8 */
154 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
155 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
156 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
157 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
158 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
159 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
160 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
161 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
162 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
163 )
164 #endif
165
166 #if defined(COMP_CSR_COMPxHYST)
167 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
168 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
169 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
170 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
171 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
172 )
173 #else
174 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
175 ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE)
176 #endif
177
178 #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
179 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
180 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
181 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
182 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
183 ) \
184 ? ( \
185 (1U) \
186 ) \
187 : \
188 (((__COMP_INSTANCE__) == COMP2) \
189 ? ( \
190 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP2) \
191 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP2) \
192 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP2) \
193 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP2) \
194 ) \
195 : \
196 (((__COMP_INSTANCE__) == COMP4) \
197 ? ( \
198 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
199 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
200 ) \
201 : \
202 ( \
203 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
204 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
205 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
206 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
207 ) \
208 ) \
209 ) \
210 )
211 #elif defined(STM32F303x8) || defined(STM32F328xx) || defined(STM32F334x8)
212 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
213 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
214 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
215 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
216 ) \
217 ? ( \
218 (1U) \
219 ) \
220 : \
221 (((__COMP_INSTANCE__) == COMP2) \
222 ? ( \
223 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2_4) \
224 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP2) \
225 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP2) \
226 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP2) \
227 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP2) \
228 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP2) \
229 ) \
230 : \
231 (((__COMP_INSTANCE__) == COMP4) \
232 ? ( \
233 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2_4)\
234 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
235 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
236 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
237 ) \
238 : \
239 ( \
240 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
241 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
242 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
243 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
244 ) \
245 ) \
246 ) \
247 )
248 #elif defined(STM32F302xC) || defined(STM32F302xE)
249 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
250 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
251 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
252 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
253 ) \
254 ? ( \
255 (1U) \
256 ) \
257 : \
258 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
259 ? ( \
260 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
261 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
262 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
263 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2) \
264 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2) \
265 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
266 ) \
267 : \
268 (((__COMP_INSTANCE__) == COMP4) \
269 ? ( \
270 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
271 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
272 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
273 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
274 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
275 ) \
276 : \
277 ( \
278 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
279 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
280 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
281 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
282 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
283 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
284 ) \
285 ) \
286 ) \
287 )
288 #elif defined(STM32F303xC) || defined(STM32F358xx)
289 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
290 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
291 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
292 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
293 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_BKIN2) \
294 ) \
295 ? ( \
296 (1U) \
297 ) \
298 : \
299 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
300 ? ( \
301 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
302 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
303 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
304 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
305 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
306 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
307 ) \
308 : \
309 (((__COMP_INSTANCE__) == COMP3) \
310 ? ( \
311 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
312 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
313 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC2_COMP3) \
314 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1_COMP3) \
315 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC1_COMP3) \
316 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_BKIN) \
317 ) \
318 : \
319 (((__COMP_INSTANCE__) == COMP4) \
320 ? ( \
321 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
322 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
323 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
324 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
325 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
326 ) \
327 : \
328 (((__COMP_INSTANCE__) == COMP5) \
329 ? ( \
330 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
331 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
332 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC1_COMP5) \
333 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC3_COMP5) \
334 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_IC1_COMP5) \
335 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
336 ) \
337 : \
338 (((__COMP_INSTANCE__) == COMP6) \
339 ? ( \
340 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
341 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
342 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
343 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
344 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
345 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
346 ) \
347 : \
348 ( \
349 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
350 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
351 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC2_COMP7) \
352 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC3_COMP7) \
353 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_OCCLR_COMP7) \
354 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_BKIN) \
355 ) \
356 ) \
357 ) \
358 ) \
359 ) \
360 ) \
361 )
362 #elif defined(STM32F303xE) || defined(STM32F398xx)
363 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
364 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
365 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
366 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
367 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_BKIN2) \
368 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_BKIN) \
369 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_BKIN2) \
370 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_TIM20_BKIN2) \
371 ) \
372 ? ( \
373 (1U) \
374 ) \
375 : \
376 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
377 ? ( \
378 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
379 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
380 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
381 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
382 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
383 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
384 || (((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_OCCLR_COMP2) \
385 && ((__COMP_INSTANCE__) == COMP2) ) \
386 ) \
387 : \
388 (((__COMP_INSTANCE__) == COMP3) \
389 ? ( \
390 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
391 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
392 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC2_COMP3) \
393 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1_COMP3) \
394 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC1_COMP3) \
395 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_BKIN) \
396 ) \
397 : \
398 (((__COMP_INSTANCE__) == COMP4) \
399 ? ( \
400 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
401 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
402 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
403 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
404 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
405 ) \
406 : \
407 (((__COMP_INSTANCE__) == COMP5) \
408 ? ( \
409 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
410 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
411 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC1_COMP5) \
412 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC3_COMP5) \
413 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_IC1_COMP5) \
414 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
415 ) \
416 : \
417 (((__COMP_INSTANCE__) == COMP6) \
418 ? ( \
419 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
420 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
421 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
422 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
423 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
424 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
425 ) \
426 : \
427 ( \
428 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
429 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
430 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC2_COMP7) \
431 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC3_COMP7) \
432 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_OCCLR_COMP7) \
433 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_BKIN) \
434 ) \
435 ) \
436 ) \
437 ) \
438 ) \
439 ) \
440 )
441 #endif
442
443 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
444 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
445 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
446 )
447
448 #if defined(COMP_CSR_COMPxBLANKING)
449 #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
450 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
451 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
452 ? ( \
453 (1U) \
454 ) \
455 : \
456 (((__COMP_INSTANCE__) == COMP2) \
457 ? ( \
458 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) \
459 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) \
460 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) \
461 ) \
462 : \
463 (((__COMP_INSTANCE__) == COMP4) \
464 ? ( \
465 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
466 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
467 ) \
468 : \
469 ( \
470 (((__COMP_INSTANCE__) == COMP6) \
471 ? ( \
472 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) \
473 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6) \
474 ) \
475 : \
476 ( \
477 (0U) \
478 ) \
479 ) \
480 ) \
481 ) \
482 ) \
483 )
484 #elif defined(STM32F302xE) || defined(STM32F302xC)
485 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
486 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
487 ? ( \
488 (1U) \
489 ) \
490 : \
491 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
492 ? ( \
493 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2) \
494 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1_2) \
495 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1_2) \
496 ) \
497 : \
498 (((__COMP_INSTANCE__) == COMP4) \
499 ? ( \
500 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
501 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
502 ) \
503 : \
504 ( \
505 (((__COMP_INSTANCE__) == COMP6) \
506 ? ( \
507 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) \
508 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6) \
509 ) \
510 : \
511 ( \
512 (0U) \
513 ) \
514 ) \
515 ) \
516 ) \
517 ) \
518 )
519 #elif defined(STM32F303xE) || defined(STM32F398xx) || defined(STM32F303xC) || defined(STM32F358xx)
520 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
521 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
522 ? ( \
523 (1U) \
524 ) \
525 : \
526 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
527 ? ( \
528 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2_7) \
529 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1_2) \
530 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1_2) \
531 ) \
532 : \
533 (((__COMP_INSTANCE__) == COMP3) \
534 ? ( \
535 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3_6) \
536 ) \
537 : \
538 (((__COMP_INSTANCE__) == COMP4) \
539 ? ( \
540 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
541 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
542 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
543 ) \
544 : \
545 (((__COMP_INSTANCE__) == COMP5) \
546 ? ( \
547 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
548 ) \
549 : \
550 (((__COMP_INSTANCE__) == COMP6) \
551 ? ( \
552 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
553 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3_6) \
554 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6_7) \
555 ) \
556 : \
557 ( \
558 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
559 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2_7) \
560 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6_7) \
561 ) \
562 ) \
563 ) \
564 ) \
565 ) \
566 ) \
567 )
568 #endif
569 #else
570 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
571 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)
572 #endif
573 /**
574 * @}
575 */
576
577
578 /* Private function prototypes -----------------------------------------------*/
579
580 /* Exported functions --------------------------------------------------------*/
581 /** @addtogroup COMP_LL_Exported_Functions
582 * @{
583 */
584
585 /** @addtogroup COMP_LL_EF_Init
586 * @{
587 */
588
589 /**
590 * @brief De-initialize registers of the selected COMP instance
591 * to their default reset values.
592 * @note If comparator is locked, de-initialization by software is
593 * not possible.
594 * The only way to unlock the comparator is a device hardware reset.
595 * @param COMPx COMP instance
596 * @retval An ErrorStatus enumeration value:
597 * - SUCCESS: COMP registers are de-initialized
598 * - ERROR: COMP registers are not de-initialized
599 */
LL_COMP_DeInit(COMP_TypeDef * COMPx)600 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
601 {
602 ErrorStatus status = SUCCESS;
603
604 /* Check the parameters */
605 assert_param(IS_COMP_ALL_INSTANCE(COMPx));
606
607 /* Note: Hardware constraint (refer to description of this function): */
608 /* COMP instance must not be locked. */
609 if (LL_COMP_IsLocked(COMPx) == 0U)
610 {
611 LL_COMP_WriteReg(COMPx, CSR, 0x00000000U);
612 }
613 else
614 {
615 /* Comparator instance is locked: de-initialization by software is */
616 /* not possible. */
617 /* The only way to unlock the comparator is a device hardware reset. */
618 status = ERROR;
619 }
620
621 return status;
622 }
623
624 /**
625 * @brief Initialize some features of COMP instance.
626 * @note This function configures features of the selected COMP instance.
627 * Some features are also available at scope COMP common instance
628 * (common to several COMP instances).
629 * Refer to functions having argument "COMPxy_COMMON" as parameter.
630 * @param COMPx COMP instance
631 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
632 * @retval An ErrorStatus enumeration value:
633 * - SUCCESS: COMP registers are initialized
634 * - ERROR: COMP registers are not initialized
635 */
LL_COMP_Init(COMP_TypeDef * COMPx,LL_COMP_InitTypeDef * COMP_InitStruct)636 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
637 {
638 ErrorStatus status = SUCCESS;
639
640 /* Check the parameters */
641 assert_param(IS_COMP_ALL_INSTANCE(COMPx));
642 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
643 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
644 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
645 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
646 assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMPx, COMP_InitStruct->OutputSelection));
647 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
648 assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMPx, COMP_InitStruct->OutputBlankingSource));
649
650 /* Note: Hardware constraint (refer to description of this function) */
651 /* COMP instance must not be locked. */
652 if (LL_COMP_IsLocked(COMPx) == 0U)
653 {
654 /* Configuration of comparator instance : */
655 /* - PowerMode */
656 /* - InputPlus */
657 /* - InputMinus */
658 /* - InputHysteresis */
659 /* - OutputSelection */
660 /* - OutputPolarity */
661 /* - OutputBlankingSource */
662 MODIFY_REG(COMPx->CSR,
663 ((uint32_t)0x00000000U)
664 #if defined(COMP_CSR_COMPxMODE)
665 | COMP_CSR_COMPxMODE
666 #endif
667 #if defined(COMP_CSR_COMPxNONINSEL)
668 | COMP_CSR_COMPxNONINSEL
669 #endif
670 | COMP_CSR_COMPxINSEL
671 #if defined(COMP_CSR_COMPxHYST)
672 | COMP_CSR_COMPxHYST
673 #endif
674 | COMP_CSR_COMPxOUTSEL
675 | COMP_CSR_COMPxPOL
676 | COMP_CSR_COMPxBLANKING
677 ,
678 ((uint32_t)0x00000000U)
679 #if defined(COMP_CSR_COMPxMODE)
680 | COMP_InitStruct->PowerMode
681 #endif
682 #if defined(COMP_CSR_COMPxNONINSEL)
683 | COMP_InitStruct->InputPlus
684 #endif
685 | COMP_InitStruct->InputMinus
686 #if defined(COMP_CSR_COMPxHYST)
687 | COMP_InitStruct->InputHysteresis
688 #endif
689 | COMP_InitStruct->OutputSelection
690 | COMP_InitStruct->OutputPolarity
691 | COMP_InitStruct->OutputBlankingSource
692 );
693
694 }
695 else
696 {
697 /* Initialization error: COMP instance is locked. */
698 status = ERROR;
699 }
700
701 return status;
702 }
703
704 /**
705 * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
706 * @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
707 * whose fields will be set to default values.
708 * @retval None
709 */
LL_COMP_StructInit(LL_COMP_InitTypeDef * COMP_InitStruct)710 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
711 {
712 /* Set COMP_InitStruct fields to default values */
713 /* Note: Comparator power mode "high speed" is the only mode */
714 /* available on all STMF3 devices. */
715 COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_HIGHSPEED;
716 COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
717 COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
718 COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
719 COMP_InitStruct->OutputSelection = LL_COMP_OUTPUT_NONE;
720 COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
721 COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
722 }
723
724 /**
725 * @}
726 */
727
728 /**
729 * @}
730 */
731
732 /**
733 * @}
734 */
735
736 #endif /* COMP1 || COMP2 || COMP3 || COMP4 || COMP5 || COMP6 || COMP7 */
737
738
739 #endif /* STM32F301x8 || STM32F302x8 || STM32F302xC || STM32F302xE || STM32F303x8 || STM32F303xC || STM32F303xE || STM32F318xx || STM32F328xx || STM32F334x8 || STM32F358xx || STM32F398xx */
740
741 #if defined (COMP_V1_1_0_0)
742
743 #if defined (COMP1) || defined (COMP2)
744
745 /** @addtogroup COMP_LL COMP
746 * @{
747 */
748
749 /* Private types -------------------------------------------------------------*/
750 /* Private variables ---------------------------------------------------------*/
751 /* Private constants ---------------------------------------------------------*/
752 /* Private macros ------------------------------------------------------------*/
753
754 /** @addtogroup COMP_LL_Private_Macros
755 * @{
756 */
757
758 /* Check of parameters for configuration of COMP hierarchical scope: */
759 /* COMP instance. */
760
761 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
762 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
763 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
764 || ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
765 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
766 )
767
768 /* Note: On this STM32 series, comparator input plus parameters are */
769 /* the different depending on COMP instances. */
770 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
771 (((__COMP_INSTANCE__) == COMP1) \
772 ? ( \
773 ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
774 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1) \
775 ) \
776 : \
777 ( \
778 ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
779 ) \
780 )
781
782 /* Note: On this STM32 series, comparator input minus parameters are */
783 /* the same on all COMP instances. */
784 /* However, comparator instance kept as macro parameter for */
785 /* compatibility with other STM32 families. */
786 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
787 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
788 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
789 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
790 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
791 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
792 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
793 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
794 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
795 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
796 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
797 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) \
798 )
799
800 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
801 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
802 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
803 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
804 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
805 )
806
807 /* Note: Output redirection is specific to COMP instances but is checked */
808 /* with literals of instance COMP2 (no differentiation possible since */
809 /* literals of COMP1 and COMP2 share the same values range). */
810 #define IS_LL_COMP_OUTPUT_SELECTION(__OUTPUT_SELECTION__) \
811 ( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
812 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
813 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1) \
814 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_OCCLR) \
815 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4) \
816 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR) \
817 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP2) \
818 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2) \
819 )
820
821 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
822 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
823 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
824 )
825
826 /**
827 * @}
828 */
829
830
831 /* Private function prototypes -----------------------------------------------*/
832
833 /* Exported functions --------------------------------------------------------*/
834 /** @addtogroup COMP_LL_Exported_Functions
835 * @{
836 */
837
838 /** @addtogroup COMP_LL_EF_Init
839 * @{
840 */
841
842 /**
843 * @brief De-initialize registers of the selected COMP instance
844 * to their default reset values.
845 * @note If comparator is locked, de-initialization by software is
846 * not possible.
847 * The only way to unlock the comparator is a device hardware reset.
848 * @param COMPx COMP instance
849 * @retval An ErrorStatus enumeration value:
850 * - SUCCESS: COMP registers are de-initialized
851 * - ERROR: COMP registers are not de-initialized
852 */
LL_COMP_DeInit(COMP_TypeDef * COMPx)853 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
854 {
855 ErrorStatus status = SUCCESS;
856
857 /* Check the parameters */
858 assert_param(IS_COMP_ALL_INSTANCE(COMPx));
859
860 /* Note: Hardware constraint (refer to description of this function): */
861 /* COMP instance must not be locked. */
862 if (LL_COMP_IsLocked(COMPx) == 0U)
863 {
864 /* Note: Connection switch is applicable only to COMP instance COMP1, */
865 /* therefore is COMP2 is selected the equivalent bit is */
866 /* kept unmodified. */
867 if (COMPx == COMP1)
868 {
869 CLEAR_BIT(COMP->CSR,
870 ( COMP_CSR_COMP1MODE
871 | COMP_CSR_COMP1INSEL
872 | COMP_CSR_COMP1SW1
873 | COMP_CSR_COMP1OUTSEL
874 | COMP_CSR_COMP1HYST
875 | COMP_CSR_COMP1POL
876 | COMP_CSR_COMP1EN
877 ) << __COMP_BITOFFSET_INSTANCE(COMPx)
878 );
879 }
880 else
881 {
882 CLEAR_BIT(COMP->CSR,
883 ( COMP_CSR_COMP1MODE
884 | COMP_CSR_COMP1INSEL
885 | COMP_CSR_COMP1OUTSEL
886 | COMP_CSR_COMP1HYST
887 | COMP_CSR_COMP1POL
888 | COMP_CSR_COMP1EN
889 ) << __COMP_BITOFFSET_INSTANCE(COMPx)
890 );
891 }
892
893 }
894 else
895 {
896 /* Comparator instance is locked: de-initialization by software is */
897 /* not possible. */
898 /* The only way to unlock the comparator is a device hardware reset. */
899 status = ERROR;
900 }
901
902 return status;
903 }
904
905 /**
906 * @brief Initialize some features of COMP instance.
907 * @note This function configures features of the selected COMP instance.
908 * Some features are also available at scope COMP common instance
909 * (common to several COMP instances).
910 * Refer to functions having argument "COMPxy_COMMON" as parameter.
911 * @param COMPx COMP instance
912 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
913 * @retval An ErrorStatus enumeration value:
914 * - SUCCESS: COMP registers are initialized
915 * - ERROR: COMP registers are not initialized
916 */
LL_COMP_Init(COMP_TypeDef * COMPx,LL_COMP_InitTypeDef * COMP_InitStruct)917 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
918 {
919 ErrorStatus status = SUCCESS;
920
921 /* Check the parameters */
922 assert_param(IS_COMP_ALL_INSTANCE(COMPx));
923 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
924 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
925 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
926 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
927 assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMP_InitStruct->OutputSelection));
928 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
929
930 /* Note: Hardware constraint (refer to description of this function) */
931 /* COMP instance must not be locked. */
932 if (LL_COMP_IsLocked(COMPx) == 0U)
933 {
934 /* Configuration of comparator instance : */
935 /* - PowerMode */
936 /* - InputPlus */
937 /* - InputMinus */
938 /* - InputHysteresis */
939 /* - OutputSelection */
940 /* - OutputPolarity */
941 /* Note: Connection switch is applicable only to COMP instance COMP1, */
942 /* therefore is COMP2 is selected the equivalent bit is */
943 /* kept unmodified. */
944 if (COMPx == COMP1)
945 {
946 MODIFY_REG(COMP->CSR,
947 ( COMP_CSR_COMP1MODE
948 | COMP_CSR_COMP1INSEL
949 | COMP_CSR_COMP1SW1
950 | COMP_CSR_COMP1OUTSEL
951 | COMP_CSR_COMP1HYST
952 | COMP_CSR_COMP1POL
953 ) << __COMP_BITOFFSET_INSTANCE(COMPx)
954 ,
955 ( COMP_InitStruct->PowerMode
956 | COMP_InitStruct->InputPlus
957 | COMP_InitStruct->InputMinus
958 | COMP_InitStruct->InputHysteresis
959 | COMP_InitStruct->OutputSelection
960 | COMP_InitStruct->OutputPolarity
961 ) << __COMP_BITOFFSET_INSTANCE(COMPx)
962 );
963 }
964 else
965 {
966 MODIFY_REG(COMP->CSR,
967 ( COMP_CSR_COMP1MODE
968 | COMP_CSR_COMP1INSEL
969 | COMP_CSR_COMP1OUTSEL
970 | COMP_CSR_COMP1HYST
971 | COMP_CSR_COMP1POL
972 ) << __COMP_BITOFFSET_INSTANCE(COMPx)
973 ,
974 ( COMP_InitStruct->PowerMode
975 | COMP_InitStruct->InputPlus
976 | COMP_InitStruct->InputMinus
977 | COMP_InitStruct->InputHysteresis
978 | COMP_InitStruct->OutputSelection
979 | COMP_InitStruct->OutputPolarity
980 ) << __COMP_BITOFFSET_INSTANCE(COMPx)
981 );
982 }
983
984 }
985 else
986 {
987 /* Initialization error: COMP instance is locked. */
988 status = ERROR;
989 }
990
991 return status;
992 }
993
994 /**
995 * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
996 * @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
997 * whose fields will be set to default values.
998 * @retval None
999 */
LL_COMP_StructInit(LL_COMP_InitTypeDef * COMP_InitStruct)1000 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
1001 {
1002 /* Set COMP_InitStruct fields to default values */
1003 COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER;
1004 COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
1005 COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
1006 COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
1007 COMP_InitStruct->OutputSelection = LL_COMP_OUTPUT_NONE;
1008 COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
1009 }
1010
1011 /**
1012 * @}
1013 */
1014
1015 /**
1016 * @}
1017 */
1018
1019 /**
1020 * @}
1021 */
1022
1023 #endif /* COMP1 || COMP2 */
1024
1025
1026 #endif /* STM32F373xC || STM32F378xx */
1027
1028 /**
1029 * @}
1030 */
1031
1032 #endif /* USE_FULL_LL_DRIVER */
1033
1034