2 ******************************************************************************
3 * @file stm32f3xx_ll_comp.c
4 * @author MCD Application Team
5 * @brief COMP LL module driver
6 ******************************************************************************
9 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
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.
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.
33 ******************************************************************************
35 #if defined(USE_FULL_LL_DRIVER)
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f3xx_ll_comp.h"
40 #ifdef USE_FULL_ASSERT
41 #include "stm32_assert.h"
43 #define assert_param(expr) ((void)0U)
46 /** @addtogroup STM32F3xx_LL_Driver
50 /* Note: Devices of STM32F3 serie embed 1 out of 2 different comparator IP. */
51 /* - STM32F30x, STM32F31x, STM32F32x, STM32F33x, STM32F35x, STM32F39x: */
52 /* COMP IP from 3 to 7 instances and other specific features */
53 /* (comparator output blanking, ...) (refer to reference manual). */
55 /* COMP IP with 2 instances */
56 /* This file contains the drivers of these COMP IP, located in 2 area */
57 /* delimited by compilation switches. */
59 #if defined(COMP_V1_3_0_0)
61 #if defined (COMP1) || defined (COMP2) || defined (COMP3) || defined (COMP4) || defined (COMP5) || defined (COMP6) || defined (COMP7)
63 /** @addtogroup COMP_LL COMP
67 /* Private types -------------------------------------------------------------*/
68 /* Private variables ---------------------------------------------------------*/
69 /* Private constants ---------------------------------------------------------*/
70 /* Private macros ------------------------------------------------------------*/
72 /** @addtogroup COMP_LL_Private_Macros
76 /* Check of parameters for configuration of COMP hierarchical scope: */
79 #if defined(COMP_CSR_COMPxMODE)
80 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
81 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
82 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
83 || ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
84 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
87 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
88 ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED)
91 /* Note: On this STM32 serie, comparator input plus parameters are */
92 /* the same on all COMP instances. */
93 /* However, comparator instance kept as macro parameter for */
94 /* compatibility with other STM32 families. */
95 #if defined(COMP_CSR_COMPxNONINSEL) && defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1)
96 /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
97 /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
98 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
99 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
100 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
101 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1) \
103 #elif defined(COMP_CSR_COMPxNONINSEL) && defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2)
104 /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
105 /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
106 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
107 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
108 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
109 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2) \
111 #elif defined(COMP_CSR_COMPxNONINSEL)
112 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
113 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
114 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
116 #elif defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2)
117 /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
118 /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
119 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
120 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
121 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2) \
124 /* Note: Device without comparator input plus configurable: corresponds to */
125 /* setting "LL_COMP_INPUT_PLUS_IO1" or "LL_COMP_INPUT_PLUS_IO2" */
126 /* compared to other STM32F3 devices, depending on comparator instance */
127 /* (refer to reference manual). */
128 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
129 ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1)
132 #if defined(STM32F303xC) || defined(STM32F358xx) || defined(STM32F303xE) || defined(STM32F398xx)
133 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
134 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
135 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
136 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
137 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
138 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
139 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
140 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
141 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
142 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
143 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
145 #elif defined(STM32F303x8) || defined(STM32F328xx) || defined(STM32F334x8)
146 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
147 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
148 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
149 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
150 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
151 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
152 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
153 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
154 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
155 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
156 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) \
158 #elif defined(STM32F302xC) || defined(STM32F302xE)
159 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
160 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
161 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
162 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
163 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
164 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
165 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
166 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
167 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
168 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
170 #else /* STM32F301x8 || STM32F318xx || STM32F302x8 */
171 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
172 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
173 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
174 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
175 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
176 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
177 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
178 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
179 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
183 #if defined(COMP_CSR_COMPxHYST)
184 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
185 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
186 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
187 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
188 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
191 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
192 ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE)
195 #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
196 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
197 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
198 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
199 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
205 (((__COMP_INSTANCE__) == COMP2) \
207 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP2) \
208 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP2) \
209 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP2) \
210 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP2) \
213 (((__COMP_INSTANCE__) == COMP4) \
215 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
216 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
220 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
221 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
222 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
223 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
228 #elif defined(STM32F303x8) || defined(STM32F328xx) || defined(STM32F334x8)
229 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
230 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
231 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
232 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
238 (((__COMP_INSTANCE__) == COMP2) \
240 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2_4) \
241 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP2) \
242 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP2) \
243 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP2) \
244 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP2) \
245 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP2) \
248 (((__COMP_INSTANCE__) == COMP4) \
250 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2_4)\
251 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
252 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
253 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
257 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
258 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
259 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
260 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
265 #elif defined(STM32F302xC) || defined(STM32F302xE)
266 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
267 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
268 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
269 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
275 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
277 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
278 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
279 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
280 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2) \
281 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2) \
282 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
285 (((__COMP_INSTANCE__) == COMP4) \
287 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
288 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
289 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
290 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
291 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
295 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
296 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
297 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
298 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
299 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
300 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
305 #elif defined(STM32F303xC) || defined(STM32F358xx)
306 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
307 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
308 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
309 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
310 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_BKIN2) \
316 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
318 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
319 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
320 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
321 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
322 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
323 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
326 (((__COMP_INSTANCE__) == COMP3) \
328 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
329 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
330 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC2_COMP3) \
331 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1_COMP3) \
332 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC1_COMP3) \
333 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_BKIN) \
336 (((__COMP_INSTANCE__) == COMP4) \
338 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
339 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
340 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
341 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
342 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
345 (((__COMP_INSTANCE__) == COMP5) \
347 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
348 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
349 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC1_COMP5) \
350 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC3_COMP5) \
351 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_IC1_COMP5) \
352 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
355 (((__COMP_INSTANCE__) == COMP6) \
357 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
358 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
359 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
360 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
361 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
362 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
366 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
367 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
368 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC2_COMP7) \
369 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC3_COMP7) \
370 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_OCCLR_COMP7) \
371 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_BKIN) \
379 #elif defined(STM32F303xE) || defined(STM32F398xx)
380 #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
381 (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
382 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
383 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
384 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_BKIN2) \
385 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_BKIN) \
386 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_BKIN2) \
387 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_TIM20_BKIN2) \
393 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
395 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
396 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
397 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
398 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
399 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
400 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
401 || (((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_OCCLR_COMP2) \
402 && ((__COMP_INSTANCE__) == COMP2) ) \
405 (((__COMP_INSTANCE__) == COMP3) \
407 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
408 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
409 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC2_COMP3) \
410 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1_COMP3) \
411 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC1_COMP3) \
412 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_BKIN) \
415 (((__COMP_INSTANCE__) == COMP4) \
417 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
418 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
419 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
420 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
421 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
424 (((__COMP_INSTANCE__) == COMP5) \
426 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
427 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
428 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC1_COMP5) \
429 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC3_COMP5) \
430 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_IC1_COMP5) \
431 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
434 (((__COMP_INSTANCE__) == COMP6) \
436 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
437 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
438 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
439 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
440 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
441 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
445 ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
446 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
447 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC2_COMP7) \
448 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC3_COMP7) \
449 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_OCCLR_COMP7) \
450 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_BKIN) \
460 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
461 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
462 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
465 #if defined(COMP_CSR_COMPxBLANKING)
466 #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
467 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
468 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
473 (((__COMP_INSTANCE__) == COMP2) \
475 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) \
476 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) \
477 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) \
480 (((__COMP_INSTANCE__) == COMP4) \
482 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
483 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
487 (((__COMP_INSTANCE__) == COMP6) \
489 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) \
490 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6) \
501 #elif defined(STM32F302xE) || defined(STM32F302xC)
502 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
503 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
508 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
510 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2) \
511 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1_2) \
512 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1_2) \
515 (((__COMP_INSTANCE__) == COMP4) \
517 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
518 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
522 (((__COMP_INSTANCE__) == COMP6) \
524 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) \
525 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6) \
536 #elif defined(STM32F303xE) || defined(STM32F398xx) || defined(STM32F303xC) || defined(STM32F358xx)
537 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
538 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
543 ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
545 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2_7) \
546 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1_2) \
547 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1_2) \
550 (((__COMP_INSTANCE__) == COMP3) \
552 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3_6) \
555 (((__COMP_INSTANCE__) == COMP4) \
557 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
558 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
559 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
562 (((__COMP_INSTANCE__) == COMP5) \
564 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
567 (((__COMP_INSTANCE__) == COMP6) \
569 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
570 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3_6) \
571 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6_7) \
575 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
576 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2_7) \
577 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6_7) \
587 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
588 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)
595 /* Private function prototypes -----------------------------------------------*/
597 /* Exported functions --------------------------------------------------------*/
598 /** @addtogroup COMP_LL_Exported_Functions
602 /** @addtogroup COMP_LL_EF_Init
607 * @brief De-initialize registers of the selected COMP instance
608 * to their default reset values.
609 * @note If comparator is locked, de-initialization by software is
611 * The only way to unlock the comparator is a device hardware reset.
612 * @param COMPx COMP instance
613 * @retval An ErrorStatus enumeration value:
614 * - SUCCESS: COMP registers are de-initialized
615 * - ERROR: COMP registers are not de-initialized
617 ErrorStatus
LL_COMP_DeInit(COMP_TypeDef
*COMPx
)
619 ErrorStatus status
= SUCCESS
;
621 /* Check the parameters */
622 assert_param(IS_COMP_ALL_INSTANCE(COMPx
));
624 /* Note: Hardware constraint (refer to description of this function): */
625 /* COMP instance must not be locked. */
626 if(LL_COMP_IsLocked(COMPx
) == 0U)
628 LL_COMP_WriteReg(COMPx
, CSR
, 0x00000000U
);
632 /* Comparator instance is locked: de-initialization by software is */
634 /* The only way to unlock the comparator is a device hardware reset. */
642 * @brief Initialize some features of COMP instance.
643 * @note This function configures features of the selected COMP instance.
644 * Some features are also available at scope COMP common instance
645 * (common to several COMP instances).
646 * Refer to functions having argument "COMPxy_COMMON" as parameter.
647 * @param COMPx COMP instance
648 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
649 * @retval An ErrorStatus enumeration value:
650 * - SUCCESS: COMP registers are initialized
651 * - ERROR: COMP registers are not initialized
653 ErrorStatus
LL_COMP_Init(COMP_TypeDef
*COMPx
, LL_COMP_InitTypeDef
*COMP_InitStruct
)
655 ErrorStatus status
= SUCCESS
;
657 /* Check the parameters */
658 assert_param(IS_COMP_ALL_INSTANCE(COMPx
));
659 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct
->PowerMode
));
660 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx
, COMP_InitStruct
->InputPlus
));
661 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx
, COMP_InitStruct
->InputMinus
));
662 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct
->InputHysteresis
));
663 assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMPx
, COMP_InitStruct
->OutputSelection
));
664 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct
->OutputPolarity
));
665 assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMPx
, COMP_InitStruct
->OutputBlankingSource
));
667 /* Note: Hardware constraint (refer to description of this function) */
668 /* COMP instance must not be locked. */
669 if(LL_COMP_IsLocked(COMPx
) == 0U)
671 /* Configuration of comparator instance : */
675 /* - InputHysteresis */
676 /* - OutputSelection */
677 /* - OutputPolarity */
678 /* - OutputBlankingSource */
679 MODIFY_REG(COMPx
->CSR
,
680 ((uint32_t)0x00000000U
)
681 #if defined(COMP_CSR_COMPxMODE)
684 #if defined(COMP_CSR_COMPxNONINSEL)
685 | COMP_CSR_COMPxNONINSEL
687 | COMP_CSR_COMPxINSEL
688 #if defined(COMP_CSR_COMPxHYST)
691 | COMP_CSR_COMPxOUTSEL
693 | COMP_CSR_COMPxBLANKING
695 ((uint32_t)0x00000000U
)
696 #if defined(COMP_CSR_COMPxMODE)
697 | COMP_InitStruct
->PowerMode
699 #if defined(COMP_CSR_COMPxNONINSEL)
700 | COMP_InitStruct
->InputPlus
702 | COMP_InitStruct
->InputMinus
703 #if defined(COMP_CSR_COMPxHYST)
704 | COMP_InitStruct
->InputHysteresis
706 | COMP_InitStruct
->OutputSelection
707 | COMP_InitStruct
->OutputPolarity
708 | COMP_InitStruct
->OutputBlankingSource
714 /* Initialization error: COMP instance is locked. */
722 * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
723 * @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
724 * whose fields will be set to default values.
727 void LL_COMP_StructInit(LL_COMP_InitTypeDef
*COMP_InitStruct
)
729 /* Set COMP_InitStruct fields to default values */
730 /* Note: Comparator power mode "high speed" is the only mode */
731 /* available on all STMF3 devices. */
732 COMP_InitStruct
->PowerMode
= LL_COMP_POWERMODE_HIGHSPEED
;
733 COMP_InitStruct
->InputPlus
= LL_COMP_INPUT_PLUS_IO1
;
734 COMP_InitStruct
->InputMinus
= LL_COMP_INPUT_MINUS_VREFINT
;
735 COMP_InitStruct
->InputHysteresis
= LL_COMP_HYSTERESIS_NONE
;
736 COMP_InitStruct
->OutputSelection
= LL_COMP_OUTPUT_NONE
;
737 COMP_InitStruct
->OutputPolarity
= LL_COMP_OUTPUTPOL_NONINVERTED
;
738 COMP_InitStruct
->OutputBlankingSource
= LL_COMP_BLANKINGSRC_NONE
;
753 #endif /* COMP1 || COMP2 || COMP3 || COMP4 || COMP5 || COMP6 || COMP7 */
756 #endif /* STM32F301x8 || STM32F302x8 || STM32F302xC || STM32F302xE || STM32F303x8 || STM32F303xC || STM32F303xE || STM32F318xx || STM32F328xx || STM32F334x8 || STM32F358xx || STM32F398xx */
758 #if defined (COMP_V1_1_0_0)
760 #if defined (COMP1) || defined (COMP2)
762 /** @addtogroup COMP_LL COMP
766 /* Private types -------------------------------------------------------------*/
767 /* Private variables ---------------------------------------------------------*/
768 /* Private constants ---------------------------------------------------------*/
769 /* Private macros ------------------------------------------------------------*/
771 /** @addtogroup COMP_LL_Private_Macros
775 /* Check of parameters for configuration of COMP hierarchical scope: */
778 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
779 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
780 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
781 || ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
782 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
785 /* Note: On this STM32 serie, comparator input plus parameters are */
786 /* the different depending on COMP instances. */
787 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
788 (((__COMP_INSTANCE__) == COMP1) \
790 ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
791 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1) \
795 ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
799 /* Note: On this STM32 serie, comparator input minus parameters are */
800 /* the same on all COMP instances. */
801 /* However, comparator instance kept as macro parameter for */
802 /* compatibility with other STM32 families. */
803 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
804 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
805 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
806 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
807 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
808 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
809 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
810 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
811 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
812 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
813 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
814 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) \
817 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
818 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
819 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
820 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
821 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
824 /* Note: Output redirection is specific to COMP instances but is checked */
825 /* with literals of instance COMP2 (no differentiation possible since */
826 /* literals of COMP1 and COMP2 share the same values range). */
827 #define IS_LL_COMP_OUTPUT_SELECTION(__OUTPUT_SELECTION__) \
828 ( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
829 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
830 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1) \
831 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_OCCLR) \
832 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4) \
833 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR) \
834 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP2) \
835 || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2) \
838 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
839 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
840 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
848 /* Private function prototypes -----------------------------------------------*/
850 /* Exported functions --------------------------------------------------------*/
851 /** @addtogroup COMP_LL_Exported_Functions
855 /** @addtogroup COMP_LL_EF_Init
860 * @brief De-initialize registers of the selected COMP instance
861 * to their default reset values.
862 * @note If comparator is locked, de-initialization by software is
864 * The only way to unlock the comparator is a device hardware reset.
865 * @param COMPx COMP instance
866 * @retval An ErrorStatus enumeration value:
867 * - SUCCESS: COMP registers are de-initialized
868 * - ERROR: COMP registers are not de-initialized
870 ErrorStatus
LL_COMP_DeInit(COMP_TypeDef
*COMPx
)
872 ErrorStatus status
= SUCCESS
;
874 /* Check the parameters */
875 assert_param(IS_COMP_ALL_INSTANCE(COMPx
));
877 /* Note: Hardware constraint (refer to description of this function): */
878 /* COMP instance must not be locked. */
879 if(LL_COMP_IsLocked(COMPx
) == 0U)
881 /* Note: Connection switch is applicable only to COMP instance COMP1, */
882 /* therefore is COMP2 is selected the equivalent bit is */
883 /* kept unmodified. */
888 | COMP_CSR_COMP1INSEL
890 | COMP_CSR_COMP1OUTSEL
894 ) << __COMP_BITOFFSET_INSTANCE(COMPx
)
901 | COMP_CSR_COMP1INSEL
902 | COMP_CSR_COMP1OUTSEL
906 ) << __COMP_BITOFFSET_INSTANCE(COMPx
)
913 /* Comparator instance is locked: de-initialization by software is */
915 /* The only way to unlock the comparator is a device hardware reset. */
923 * @brief Initialize some features of COMP instance.
924 * @note This function configures features of the selected COMP instance.
925 * Some features are also available at scope COMP common instance
926 * (common to several COMP instances).
927 * Refer to functions having argument "COMPxy_COMMON" as parameter.
928 * @param COMPx COMP instance
929 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
930 * @retval An ErrorStatus enumeration value:
931 * - SUCCESS: COMP registers are initialized
932 * - ERROR: COMP registers are not initialized
934 ErrorStatus
LL_COMP_Init(COMP_TypeDef
*COMPx
, LL_COMP_InitTypeDef
*COMP_InitStruct
)
936 ErrorStatus status
= SUCCESS
;
938 /* Check the parameters */
939 assert_param(IS_COMP_ALL_INSTANCE(COMPx
));
940 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct
->PowerMode
));
941 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx
, COMP_InitStruct
->InputPlus
));
942 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx
, COMP_InitStruct
->InputMinus
));
943 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct
->InputHysteresis
));
944 assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMP_InitStruct
->OutputSelection
));
945 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct
->OutputPolarity
));
947 /* Note: Hardware constraint (refer to description of this function) */
948 /* COMP instance must not be locked. */
949 if(LL_COMP_IsLocked(COMPx
) == 0U)
951 /* Configuration of comparator instance : */
955 /* - InputHysteresis */
956 /* - OutputSelection */
957 /* - OutputPolarity */
958 /* Note: Connection switch is applicable only to COMP instance COMP1, */
959 /* therefore is COMP2 is selected the equivalent bit is */
960 /* kept unmodified. */
963 MODIFY_REG(COMP
->CSR
,
965 | COMP_CSR_COMP1INSEL
967 | COMP_CSR_COMP1OUTSEL
970 ) << __COMP_BITOFFSET_INSTANCE(COMPx
)
972 ( COMP_InitStruct
->PowerMode
973 | COMP_InitStruct
->InputPlus
974 | COMP_InitStruct
->InputMinus
975 | COMP_InitStruct
->InputHysteresis
976 | COMP_InitStruct
->OutputSelection
977 | COMP_InitStruct
->OutputPolarity
978 ) << __COMP_BITOFFSET_INSTANCE(COMPx
)
983 MODIFY_REG(COMP
->CSR
,
985 | COMP_CSR_COMP1INSEL
986 | COMP_CSR_COMP1OUTSEL
989 ) << __COMP_BITOFFSET_INSTANCE(COMPx
)
991 ( COMP_InitStruct
->PowerMode
992 | COMP_InitStruct
->InputPlus
993 | COMP_InitStruct
->InputMinus
994 | COMP_InitStruct
->InputHysteresis
995 | COMP_InitStruct
->OutputSelection
996 | COMP_InitStruct
->OutputPolarity
997 ) << __COMP_BITOFFSET_INSTANCE(COMPx
)
1004 /* Initialization error: COMP instance is locked. */
1012 * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
1013 * @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
1014 * whose fields will be set to default values.
1017 void LL_COMP_StructInit(LL_COMP_InitTypeDef
*COMP_InitStruct
)
1019 /* Set COMP_InitStruct fields to default values */
1020 COMP_InitStruct
->PowerMode
= LL_COMP_POWERMODE_ULTRALOWPOWER
;
1021 COMP_InitStruct
->InputPlus
= LL_COMP_INPUT_PLUS_IO1
;
1022 COMP_InitStruct
->InputMinus
= LL_COMP_INPUT_MINUS_VREFINT
;
1023 COMP_InitStruct
->InputHysteresis
= LL_COMP_HYSTERESIS_NONE
;
1024 COMP_InitStruct
->OutputSelection
= LL_COMP_OUTPUT_NONE
;
1025 COMP_InitStruct
->OutputPolarity
= LL_COMP_OUTPUTPOL_NONINVERTED
;
1040 #endif /* COMP1 || COMP2 */
1043 #endif /* STM32F373xC || STM32F378xx */
1049 #endif /* USE_FULL_LL_DRIVER */
1051 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/