1 /**
2 ******************************************************************************
3 * @file stm32l4xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2017 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
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L4xx_LL_COMP_H
21 #define STM32L4xx_LL_COMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l4xx.h"
29
30 /** @addtogroup STM32L4xx_LL_Driver
31 * @{
32 */
33
34 #if defined (COMP1) || defined (COMP2)
35
36 /** @defgroup COMP_LL COMP
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /** @defgroup COMP_LL_Private_Constants COMP Private Constants
44 * @{
45 */
46
47 /* COMP registers bits positions */
48 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
49
50 /**
51 * @}
52 */
53
54 /* Private macros ------------------------------------------------------------*/
55 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
56 * @{
57 */
58
59 /**
60 * @}
61 */
62
63 /* Exported types ------------------------------------------------------------*/
64 #if defined(USE_FULL_LL_DRIVER)
65 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
66 * @{
67 */
68
69 /**
70 * @brief Structure definition of some features of COMP instance.
71 */
72 typedef struct
73 {
74 uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
75 This parameter can be a value of @ref COMP_LL_EC_POWERMODE
76 This feature can be modified afterwards using unitary
77 function @ref LL_COMP_SetPowerMode(). */
78
79 uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
80 This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
81 This feature can be modified afterwards using unitary function
82 @ref LL_COMP_SetInputPlus(). */
83
84 uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
85 This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
86 This feature can be modified afterwards using unitary function
87 @ref LL_COMP_SetInputMinus(). */
88
89 uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
90 This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
91 This feature can be modified afterwards using unitary function
92 @ref LL_COMP_SetInputHysteresis(). */
93
94 uint32_t OutputPolarity; /*!< Set comparator output polarity.
95 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
96 This feature can be modified afterwards using unitary function
97 @ref LL_COMP_SetOutputPolarity(). */
98
99 uint32_t OutputBlankingSource; /*!< Set comparator blanking source.
100 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
101 This feature can be modified afterwards using unitary function
102 @ref LL_COMP_SetOutputBlankingSource(). */
103
104 } LL_COMP_InitTypeDef;
105
106 /**
107 * @}
108 */
109 #endif /* USE_FULL_LL_DRIVER */
110
111 /* Exported constants --------------------------------------------------------*/
112 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
113 * @{
114 */
115
116
117 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
118 * @{
119 */
120 #if defined(COMP2)
121 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
122 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
123 #endif /* COMP2 */
124 /**
125 * @}
126 */
127
128
129
130 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
131 * @{
132 */
133 #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
134 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */
135 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0) /*!< COMP power mode to ultra-low power */
136 /**
137 * @}
138 */
139
140 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
141 * @{
142 */
143 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
144 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
145 #if defined(COMP_CSR_INPSEL_1)
146 #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
147 #endif /* COMP_CSR_INPSEL_1 */
148 /**
149 * @}
150 */
151
152 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
153 * @{
154 */
155 #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
156 #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
157 #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
158 #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */
159 #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
160 #define LL_COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
161 #define LL_COMP_INPUT_MINUS_IO1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */
162 #define LL_COMP_INPUT_MINUS_IO2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */
163 #if defined(COMP_CSR_INMESEL_1)
164 #define LL_COMP_INPUT_MINUS_IO3 ( COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
165 #define LL_COMP_INPUT_MINUS_IO4 (COMP_CSR_INMESEL_1 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO4 (pin PA4 for COMP1, pin PA4 for COMP2) */
166 #define LL_COMP_INPUT_MINUS_IO5 (COMP_CSR_INMESEL_1 | COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO5 (pin PA5 for COMP1, pin PA5 for COMP2) */
167 #endif
168 /**
169 * @}
170 */
171
172 /** @defgroup COMP_LL_EC_INPUT_LEGACY Comparator inputs legacy literals name
173 * @{
174 */
175 #define LL_COMP_WINDOWMODE_ENABLE LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
176
177 #define LL_COMP_INVERTINGINPUT_1_4VREFINT LL_COMP_INPUT_MINUS_1_4VREFINT
178 #define LL_COMP_INVERTINGINPUT_1_2VREFINT LL_COMP_INPUT_MINUS_1_2VREFINT
179 #define LL_COMP_INVERTINGINPUT_3_4VREFINT LL_COMP_INPUT_MINUS_3_4VREFINT
180 #define LL_COMP_INVERTINGINPUT_VREFINT LL_COMP_INPUT_MINUS_VREFINT
181 #define LL_COMP_INVERTINGINPUT_DAC1 LL_COMP_INPUT_MINUS_DAC1_CH1
182 #define LL_COMP_INVERTINGINPUT_DAC2 LL_COMP_INPUT_MINUS_DAC1_CH2
183 #define LL_COMP_INVERTINGINPUT_IO1 LL_COMP_INPUT_MINUS_IO1
184 #define LL_COMP_INVERTINGINPUT_IO2 LL_COMP_INPUT_MINUS_IO2
185 #if defined(COMP_CSR_INMESEL_1)
186 #define LL_COMP_INVERTINGINPUT_IO3 LL_COMP_INPUT_MINUS_IO3
187 #define LL_COMP_INVERTINGINPUT_IO4 LL_COMP_INPUT_MINUS_IO4
188 #define LL_COMP_INVERTINGINPUT_IO5 LL_COMP_INPUT_MINUS_IO5
189 #endif /* COMP_CSR_INMESEL_1 */
190
191 #define LL_COMP_NONINVERTINGINPUT_IO1 LL_COMP_INPUT_PLUS_IO1
192 #define LL_COMP_NONINVERTINGINPUT_IO2 LL_COMP_INPUT_PLUS_IO2
193 #if defined(COMP_CSR_INPSEL_1)
194 #define LL_COMP_NONINVERTINGINPUT_IO3 LL_COMP_INPUT_PLUS_IO3
195 #endif /* COMP_CSR_INPSEL_1 */
196 /**
197 * @}
198 */
199
200 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
201 * @{
202 */
203 #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
204 #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
205 #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
206 #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
207 /**
208 * @}
209 */
210
211 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
212 * @{
213 */
214 #define LL_COMP_OUTPUTPOL_NONINVERTED (0x00000000UL) /*!< COMP output polarity is not inverted: comparator output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */
215 #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY) /*!< COMP output polarity is inverted: comparator output is low when the plus (non-inverting) input is at a lower voltage than the minus (inverting) input */
216 /**
217 * @}
218 */
219
220 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
221 * @{
222 */
223 #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
224 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
225 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
226 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
227 #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
228 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
229 #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
230 /**
231 * @}
232 */
233
234 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE_LEGACY Comparator output blanking source legacy literals name
235 * @{
236 */
237 #define LL_COMP_BLANKINGSRC_TIM1_OC5 (LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1)
238 #define LL_COMP_BLANKINGSRC_TIM2_OC3 (LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1)
239 #define LL_COMP_BLANKINGSRC_TIM3_OC3 (LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1)
240
241 #define LL_COMP_BLANKINGSRC_TIM3_OC4 (LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2)
242 #define LL_COMP_BLANKINGSRC_TIM8_OC5 (LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2)
243 #define LL_COMP_BLANKINGSRC_TIM15_OC1 (LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2)
244 /**
245 * @}
246 */
247
248 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
249 * @{
250 */
251 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
252 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
253 /**
254 * @}
255 */
256
257 /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
258 * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
259 * not timeout values.
260 * For details on delays values, refer to descriptions in source code
261 * above each literal definition.
262 * @{
263 */
264
265 /* Delay for comparator startup time. */
266 /* Note: Delay required to reach propagation delay specification. */
267 /* Literal set to maximum value (refer to device datasheet, */
268 /* parameter "tSTART"). */
269 /* Unit: us */
270 #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
271
272 /* Delay for comparator voltage scaler stabilization time. */
273 /* Note: Voltage scaler is used when selecting comparator input */
274 /* based on VrefInt: VrefInt or subdivision of VrefInt. */
275 /* Literal set to maximum value (refer to device datasheet, */
276 /* parameter "tSTART_SCALER"). */
277 /* Unit: us */
278 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
279
280 /**
281 * @}
282 */
283
284 /**
285 * @}
286 */
287
288 /* Exported macro ------------------------------------------------------------*/
289 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
290 * @{
291 */
292 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
293 * @{
294 */
295
296 /**
297 * @brief Write a value in COMP register
298 * @param __INSTANCE__ comparator instance
299 * @param __REG__ Register to be written
300 * @param __VALUE__ Value to be written in the register
301 * @retval None
302 */
303 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
304
305 /**
306 * @brief Read a value in COMP register
307 * @param __INSTANCE__ comparator instance
308 * @param __REG__ Register to be read
309 * @retval Register value
310 */
311 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
312 /**
313 * @}
314 */
315
316 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
317 * @{
318 */
319
320 /**
321 * @brief Helper macro to select the COMP common instance
322 * to which is belonging the selected COMP instance.
323 * @note COMP common register instance can be used to
324 * set parameters common to several COMP instances.
325 * Refer to functions having argument "COMPxy_COMMON" as parameter.
326 * @param __COMPx__ COMP instance
327 * @retval COMP common instance or value "0" if there is no COMP common instance.
328 */
329 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) (COMP12_COMMON)
330
331 /**
332 * @}
333 */
334
335 /**
336 * @}
337 */
338
339 /* Exported functions --------------------------------------------------------*/
340 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
341 * @{
342 */
343
344 #if defined(COMP2)
345 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope:
346 * common to several COMP instances
347 * @{
348 */
349
350 /**
351 * @brief Set window mode of a pair of comparators instances
352 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
353 * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
354 * @param COMPxy_COMMON Comparator common instance
355 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
356 * @param WindowMode This parameter can be one of the following values:
357 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
358 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
359 * @retval None
360 */
LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowMode)361 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
362 {
363 /* Note: On this STM32 series, window mode can be set only */
364 /* from COMP instance: COMP2. */
365 MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WINMODE, WindowMode);
366 }
367
368 /**
369 * @brief Get window mode of a pair of comparators instances
370 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
371 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
372 * @param COMPxy_COMMON Comparator common instance
373 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
374 * @retval Returned value can be one of the following values:
375 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
376 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
377 */
LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef * COMPxy_COMMON)378 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef *COMPxy_COMMON)
379 {
380 return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WINMODE));
381 }
382
383 /**
384 * @}
385 */
386
387 #endif /* COMP2 */
388 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
389 * @{
390 */
391
392 /**
393 * @brief Set comparator instance operating mode to adjust power and speed.
394 * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode
395 * @param COMPx Comparator instance
396 * @param PowerMode This parameter can be one of the following values:
397 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
398 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
399 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
400 * @retval None
401 */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)402 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
403 {
404 MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
405 }
406
407 /**
408 * @brief Get comparator instance operating mode to adjust power and speed.
409 * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode
410 * @param COMPx Comparator instance
411 * @retval Returned value can be one of the following values:
412 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
413 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
414 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
415 */
LL_COMP_GetPowerMode(const COMP_TypeDef * COMPx)416 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(const COMP_TypeDef *COMPx)
417 {
418 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
419 }
420
421 /**
422 * @}
423 */
424
425 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
426 * @{
427 */
428
429 /**
430 * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
431 * @note In case of comparator input selected to be connected to IO:
432 * GPIO pins are specific to each comparator instance.
433 * Refer to description of parameters or to reference manual.
434 * @note On this STM32 series, scaler bridge is configurable:
435 * to optimize power consumption, this function enables the
436 * voltage scaler bridge only when required
437 * (when selecting comparator input based on VrefInt: VrefInt or
438 * subdivision of VrefInt).
439 * - For scaler bridge power consumption values,
440 * refer to device datasheet, parameter "IDDA(SCALER)".
441 * - Voltage scaler requires a delay for voltage stabilization.
442 * Refer to device datasheet, parameter "tSTART_SCALER".
443 * - Scaler bridge is common for all comparator instances,
444 * therefore if at least one of the comparator instance
445 * is requiring the scaler bridge, it remains enabled.
446 * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
447 * CSR INPSEL LL_COMP_ConfigInputs\n
448 * CSR BRGEN LL_COMP_ConfigInputs\n
449 * CSR SCALEN LL_COMP_ConfigInputs
450 * @param COMPx Comparator instance
451 * @param InputMinus This parameter can be one of the following values:
452 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
453 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
454 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
455 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
456 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
457 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (*)
458 * @arg @ref LL_COMP_INPUT_MINUS_IO1
459 * @arg @ref LL_COMP_INPUT_MINUS_IO2
460 * @arg @ref LL_COMP_INPUT_MINUS_IO3 (*)
461 * @arg @ref LL_COMP_INPUT_MINUS_IO4 (*)
462 * @arg @ref LL_COMP_INPUT_MINUS_IO5 (*)
463 *
464 * (*) Parameter not available on all devices.
465 * @param InputPlus This parameter can be one of the following values:
466 * @arg @ref LL_COMP_INPUT_PLUS_IO1
467 * @arg @ref LL_COMP_INPUT_PLUS_IO2
468 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (*)
469 *
470 * (*) Parameter not available on all devices.
471 * @retval None
472 */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)473 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
474 {
475 #if defined(COMP_CSR_INMESEL_1)
476 MODIFY_REG(COMPx->CSR,
477 COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
478 InputMinus | InputPlus);
479 #else
480 MODIFY_REG(COMPx->CSR,
481 COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
482 InputMinus | InputPlus);
483 #endif
484 }
485
486 /**
487 * @brief Set comparator input plus (non-inverting).
488 * @note In case of comparator input selected to be connected to IO:
489 * GPIO pins are specific to each comparator instance.
490 * Refer to description of parameters or to reference manual.
491 * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
492 * @param COMPx Comparator instance
493 * @param InputPlus This parameter can be one of the following values:
494 * @arg @ref LL_COMP_INPUT_PLUS_IO1
495 * @arg @ref LL_COMP_INPUT_PLUS_IO2
496 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (*)
497 *
498 * (*) Parameter not available on all devices.
499 * @retval None
500 */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)501 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
502 {
503 MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
504 }
505
506 /**
507 * @brief Get comparator input plus (non-inverting).
508 * @note In case of comparator input selected to be connected to IO:
509 * GPIO pins are specific to each comparator instance.
510 * Refer to description of parameters or to reference manual.
511 * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
512 * @param COMPx Comparator instance
513 * @retval Returned value can be one of the following values:
514 * @arg @ref LL_COMP_INPUT_PLUS_IO1
515 * @arg @ref LL_COMP_INPUT_PLUS_IO2
516 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (*)
517 *
518 * (*) Parameter not available on all devices.
519 */
LL_COMP_GetInputPlus(const COMP_TypeDef * COMPx)520 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(const COMP_TypeDef *COMPx)
521 {
522 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
523 }
524
525 /**
526 * @brief Set comparator input minus (inverting).
527 * @note In case of comparator input selected to be connected to IO:
528 * GPIO pins are specific to each comparator instance.
529 * Refer to description of parameters or to reference manual.
530 * @note On this STM32 series, scaler bridge is configurable:
531 * to optimize power consumption, this function enables the
532 * voltage scaler bridge only when required
533 * (when selecting comparator input based on VrefInt: VrefInt or
534 * subdivision of VrefInt).
535 * - For scaler bridge power consumption values,
536 * refer to device datasheet, parameter "IDDA(SCALER)".
537 * - Voltage scaler requires a delay for voltage stabilization.
538 * Refer to device datasheet, parameter "tSTART_SCALER".
539 * - Scaler bridge is common for all comparator instances,
540 * therefore if at least one of the comparator instance
541 * is requiring the scaler bridge, it remains enabled.
542 * @rmtoll CSR INMSEL LL_COMP_SetInputMinus\n
543 * CSR BRGEN LL_COMP_SetInputMinus\n
544 * CSR SCALEN LL_COMP_SetInputMinus
545 * @param COMPx Comparator instance
546 * @param InputMinus This parameter can be one of the following values:
547 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
548 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
549 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
550 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
551 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
552 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (*)
553 * @arg @ref LL_COMP_INPUT_MINUS_IO1
554 * @arg @ref LL_COMP_INPUT_MINUS_IO2
555 * @arg @ref LL_COMP_INPUT_MINUS_IO3 (*)
556 * @arg @ref LL_COMP_INPUT_MINUS_IO4 (*)
557 * @arg @ref LL_COMP_INPUT_MINUS_IO5 (*)
558 *
559 * (*) Parameter not available on all devices.
560 * @retval None
561 */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)562 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
563 {
564 #if defined(COMP_CSR_INMESEL_1)
565 MODIFY_REG(COMPx->CSR, COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
566 #else
567 MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
568 #endif /* COMP_CSR_INMESEL_1 */
569 }
570
571 /**
572 * @brief Get comparator input minus (inverting).
573 * @note In case of comparator input selected to be connected to IO:
574 * GPIO pins are specific to each comparator instance.
575 * Refer to description of parameters or to reference manual.
576 * @rmtoll CSR INMSEL LL_COMP_GetInputMinus\n
577 * CSR BRGEN LL_COMP_GetInputMinus\n
578 * CSR SCALEN LL_COMP_GetInputMinus
579 * @param COMPx Comparator instance
580 * @retval Returned value can be one of the following values:
581 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
582 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
583 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
584 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
585 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
586 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (*)
587 * @arg @ref LL_COMP_INPUT_MINUS_IO1
588 * @arg @ref LL_COMP_INPUT_MINUS_IO2
589 * @arg @ref LL_COMP_INPUT_MINUS_IO3 (*)
590 * @arg @ref LL_COMP_INPUT_MINUS_IO4 (*)
591 * @arg @ref LL_COMP_INPUT_MINUS_IO5 (*)
592 *
593 * (*) Parameter not available on all devices.
594 */
LL_COMP_GetInputMinus(const COMP_TypeDef * COMPx)595 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(const COMP_TypeDef *COMPx)
596 {
597 #if defined(COMP_CSR_INMESEL_1)
598 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
599 #else
600 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
601 #endif /* COMP_CSR_INMESEL_1 */
602 }
603
604 /**
605 * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
606 * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
607 * @param COMPx Comparator instance
608 * @param InputHysteresis This parameter can be one of the following values:
609 * @arg @ref LL_COMP_HYSTERESIS_NONE
610 * @arg @ref LL_COMP_HYSTERESIS_LOW
611 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
612 * @arg @ref LL_COMP_HYSTERESIS_HIGH
613 * @retval None
614 */
LL_COMP_SetInputHysteresis(COMP_TypeDef * COMPx,uint32_t InputHysteresis)615 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
616 {
617 MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
618 }
619
620 /**
621 * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
622 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
623 * @param COMPx Comparator instance
624 * @retval Returned value can be one of the following values:
625 * @arg @ref LL_COMP_HYSTERESIS_NONE
626 * @arg @ref LL_COMP_HYSTERESIS_LOW
627 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
628 * @arg @ref LL_COMP_HYSTERESIS_HIGH
629 */
LL_COMP_GetInputHysteresis(const COMP_TypeDef * COMPx)630 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(const COMP_TypeDef *COMPx)
631 {
632 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
633 }
634
635 /**
636 * @}
637 */
638
639 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
640 * @{
641 */
642
643 /**
644 * @brief Set comparator instance output polarity.
645 * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
646 * @param COMPx Comparator instance
647 * @param OutputPolarity This parameter can be one of the following values:
648 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
649 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
650 * @retval None
651 */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)652 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
653 {
654 MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
655 }
656
657 /**
658 * @brief Get comparator instance output polarity.
659 * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
660 * @param COMPx Comparator instance
661 * @retval Returned value can be one of the following values:
662 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
663 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
664 */
LL_COMP_GetOutputPolarity(const COMP_TypeDef * COMPx)665 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(const COMP_TypeDef *COMPx)
666 {
667 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
668 }
669
670 /**
671 * @brief Set comparator instance blanking source.
672 * @note Blanking source may be specific to each comparator instance.
673 * Refer to description of parameters or to reference manual.
674 * @note Availability of parameters of blanking source from timer
675 * depends on timers availability on the selected device.
676 * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource
677 * @param COMPx Comparator instance
678 * @param BlankingSource This parameter can be one of the following values:
679 * @arg @ref LL_COMP_BLANKINGSRC_NONE
680 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (1)(2)
681 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (1)(2)
682 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (1)(2)
683 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (1)(3)
684 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (1)(3)
685 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3)
686 *
687 * (1) Parameter availability depending on timer availability
688 * on the selected device.
689 * (2) On STM32L4, parameter available only on comparator instance: COMP1.
690 * (3) On STM32L4, parameter available only on comparator instance: COMP2.
691 * @retval None
692 */
LL_COMP_SetOutputBlankingSource(COMP_TypeDef * COMPx,uint32_t BlankingSource)693 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
694 {
695 MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
696 }
697
698 /**
699 * @brief Get comparator instance blanking source.
700 * @note Availability of parameters of blanking source from timer
701 * depends on timers availability on the selected device.
702 * @note Blanking source may be specific to each comparator instance.
703 * Refer to description of parameters or to reference manual.
704 * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource
705 * @param COMPx Comparator instance
706 * @retval Returned value can be one of the following values:
707 * @arg @ref LL_COMP_BLANKINGSRC_NONE
708 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (1)(2)
709 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (1)(2)
710 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (1)(2)
711 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (1)(3)
712 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (1)(3)
713 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3)
714 *
715 * (1) Parameter availability depending on timer availability
716 * on the selected device.
717 * (2) On STM32L4, parameter available only on comparator instance: COMP1.
718 * (3) On STM32L4, parameter available only on comparator instance: COMP2.
719 */
LL_COMP_GetOutputBlankingSource(const COMP_TypeDef * COMPx)720 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(const COMP_TypeDef *COMPx)
721 {
722 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
723 }
724
725 /**
726 * @}
727 */
728
729 /** @defgroup COMP_LL_EF_Configuration_Legacy_Functions Configuration of COMP, legacy functions name
730 * @{
731 */
732 /* Old functions name kept for legacy purpose, to be replaced by the */
733 /* current functions name. */
LL_COMP_SetInputNonInverting(COMP_TypeDef * COMPx,uint32_t InputNonInverting)734 __STATIC_INLINE void LL_COMP_SetInputNonInverting(COMP_TypeDef *COMPx, uint32_t InputNonInverting)
735 {
736 LL_COMP_SetInputPlus(COMPx, InputNonInverting);
737 }
LL_COMP_GetInputNonInverting(const COMP_TypeDef * COMPx)738 __STATIC_INLINE uint32_t LL_COMP_GetInputNonInverting(const COMP_TypeDef *COMPx)
739 {
740 return LL_COMP_GetInputPlus(COMPx);
741 }
742
LL_COMP_SetInputInverting(COMP_TypeDef * COMPx,uint32_t InputInverting)743 __STATIC_INLINE void LL_COMP_SetInputInverting(COMP_TypeDef *COMPx, uint32_t InputInverting)
744 {
745 LL_COMP_SetInputMinus(COMPx, InputInverting);
746 }
LL_COMP_GetInputInverting(const COMP_TypeDef * COMPx)747 __STATIC_INLINE uint32_t LL_COMP_GetInputInverting(const COMP_TypeDef *COMPx)
748 {
749 return LL_COMP_GetInputMinus(COMPx);
750 }
751
752 /**
753 * @}
754 */
755
756 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
757 * @{
758 */
759
760 /**
761 * @brief Enable comparator instance.
762 * @note After enable from off state, comparator requires a delay
763 * to reach reach propagation delay specification.
764 * Refer to device datasheet, parameter "tSTART".
765 * @rmtoll CSR EN LL_COMP_Enable
766 * @param COMPx Comparator instance
767 * @retval None
768 */
LL_COMP_Enable(COMP_TypeDef * COMPx)769 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
770 {
771 SET_BIT(COMPx->CSR, COMP_CSR_EN);
772 }
773
774 /**
775 * @brief Disable comparator instance.
776 * @rmtoll CSR EN LL_COMP_Disable
777 * @param COMPx Comparator instance
778 * @retval None
779 */
LL_COMP_Disable(COMP_TypeDef * COMPx)780 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
781 {
782 CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
783 }
784
785 /**
786 * @brief Get comparator enable state
787 * (0: COMP is disabled, 1: COMP is enabled)
788 * @rmtoll CSR EN LL_COMP_IsEnabled
789 * @param COMPx Comparator instance
790 * @retval State of bit (1 or 0).
791 */
LL_COMP_IsEnabled(const COMP_TypeDef * COMPx)792 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(const COMP_TypeDef *COMPx)
793 {
794 return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
795 }
796
797 /**
798 * @brief Lock comparator instance.
799 * @note Once locked, comparator configuration can be accessed in read-only.
800 * @note The only way to unlock the comparator is a device hardware reset.
801 * @rmtoll CSR LOCK LL_COMP_Lock
802 * @param COMPx Comparator instance
803 * @retval None
804 */
LL_COMP_Lock(COMP_TypeDef * COMPx)805 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
806 {
807 SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
808 }
809
810 /**
811 * @brief Get comparator lock state
812 * (0: COMP is unlocked, 1: COMP is locked).
813 * @note Once locked, comparator configuration can be accessed in read-only.
814 * @note The only way to unlock the comparator is a device hardware reset.
815 * @rmtoll CSR LOCK LL_COMP_IsLocked
816 * @param COMPx Comparator instance
817 * @retval State of bit (1 or 0).
818 */
LL_COMP_IsLocked(const COMP_TypeDef * COMPx)819 __STATIC_INLINE uint32_t LL_COMP_IsLocked(const COMP_TypeDef *COMPx)
820 {
821 return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
822 }
823
824 /**
825 * @brief Read comparator instance output level.
826 * @note The comparator output level depends on the selected polarity
827 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
828 * If the comparator polarity is not inverted:
829 * - Comparator output is low when the input plus
830 * is at a lower voltage than the input minus
831 * - Comparator output is high when the input plus
832 * is at a higher voltage than the input minus
833 * If the comparator polarity is inverted:
834 * - Comparator output is high when the input plus
835 * is at a lower voltage than the input minus
836 * - Comparator output is low when the input plus
837 * is at a higher voltage than the input minus
838 * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
839 * @param COMPx Comparator instance
840 * @retval Returned value can be one of the following values:
841 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
842 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
843 */
LL_COMP_ReadOutputLevel(const COMP_TypeDef * COMPx)844 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(const COMP_TypeDef *COMPx)
845 {
846 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
847 >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
848 }
849
850 /**
851 * @}
852 */
853
854 #if defined(USE_FULL_LL_DRIVER)
855 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
856 * @{
857 */
858
859 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
860 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct);
861 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
862
863 /**
864 * @}
865 */
866 #endif /* USE_FULL_LL_DRIVER */
867
868 /**
869 * @}
870 */
871
872 /**
873 * @}
874 */
875
876 /**
877 * @}
878 */
879
880 #endif /* COMP1 || COMP2 */
881
882 /**
883 * @}
884 */
885
886 #ifdef __cplusplus
887 }
888 #endif
889
890 #endif /* STM32L4xx_LL_COMP_H */
891