1 /**
2 ******************************************************************************
3 * @file stm32l5xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2019 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 STM32L5xx_LL_COMP_H
21 #define STM32L5xx_LL_COMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l5xx.h"
29
30 /** @addtogroup STM32L5xx_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
77 This feature can be modified afterwards using unitary 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
82 This feature can be modified afterwards using unitary function @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
87 This feature can be modified afterwards using unitary function @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
92 This feature can be modified afterwards using unitary function @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
97 This feature can be modified afterwards using unitary function @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
102 This feature can be modified afterwards using unitary function @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 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
117 * @{
118 */
119 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
120 #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). */
121 /**
122 * @}
123 */
124
125 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
126 * @{
127 */
128 #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
129 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */
130 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0) /*!< COMP power mode to ultra-low power */
131 /**
132 * @}
133 */
134
135 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
136 * @{
137 */
138 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
139 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
140 #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA2 for COMP1, not available for COMP2) */
141 /**
142 * @}
143 */
144
145 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
146 * @{
147 */
148 #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
149 #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 */
150 #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 */
151 #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */
152 #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
153 #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) */
154 #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) */
155 #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) */
156 /**
157 * @}
158 */
159
160 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
161 * @{
162 */
163 #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
164 #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
165 #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
166 #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
167 /**
168 * @}
169 */
170
171 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
172 * @{
173 */
174 #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 */
175 #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 */
176 /**
177 * @}
178 */
179
180 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
181 * @{
182 */
183 #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
184 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
185 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
186 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
187 #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
188 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
189 #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
190 /**
191 * @}
192 */
193
194 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
195 * @{
196 */
197 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
198 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
199 /**
200 * @}
201 */
202
203 /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
204 * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
205 * not timeout values.
206 * For details on delays values, refer to descriptions in source code
207 * above each literal definition.
208 * @{
209 */
210
211 /* Delay for comparator startup time. */
212 /* Note: Delay required to reach propagation delay specification. */
213 /* Literal set to maximum value (refer to device datasheet, */
214 /* parameter "tSTART"). */
215 /* Unit: us */
216 #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
217
218 /* Delay for comparator voltage scaler stabilization time. */
219 /* Note: Voltage scaler is used when selecting comparator input */
220 /* based on VrefInt: VrefInt or subdivision of VrefInt. */
221 /* Literal set to maximum value (refer to device datasheet, */
222 /* parameter "tSTART_SCALER"). */
223 /* Unit: us */
224 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
225
226 /**
227 * @}
228 */
229
230 /**
231 * @}
232 */
233
234 /* Exported macro ------------------------------------------------------------*/
235 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
236 * @{
237 */
238 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
239 * @{
240 */
241
242 /**
243 * @brief Write a value in COMP register
244 * @param __INSTANCE__ comparator instance
245 * @param __REG__ Register to be written
246 * @param __VALUE__ Value to be written in the register
247 * @retval None
248 */
249 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
250
251 /**
252 * @brief Read a value in COMP register
253 * @param __INSTANCE__ comparator instance
254 * @param __REG__ Register to be read
255 * @retval Register value
256 */
257 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
258 /**
259 * @}
260 */
261
262 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
263 * @{
264 */
265
266 /**
267 * @brief Helper macro to select the COMP common instance
268 * to which is belonging the selected COMP instance.
269 * @note COMP common register instance can be used to
270 * set parameters common to several COMP instances.
271 * Refer to functions having argument "COMPxy_COMMON" as parameter.
272 * @param __COMPx__ COMP instance
273 * @retval COMP common instance or value "0" if there is no COMP common instance.
274 */
275 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
276 (COMP12_COMMON)
277
278 /**
279 * @}
280 */
281
282 /**
283 * @}
284 */
285
286 /* Exported functions --------------------------------------------------------*/
287 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
288 * @{
289 */
290
291 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
292 * @{
293 */
294
295 /**
296 * @brief Set window mode of a pair of comparators instances
297 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
298 * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
299 * @param COMPxy_COMMON Comparator common instance
300 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
301 * @param WindowMode This parameter can be one of the following values:
302 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
303 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
304 * @retval None
305 */
LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowMode)306 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
307 {
308 /* Note: On this STM32 series, window mode can be set only */
309 /* from COMP instance: COMP2. */
310 MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WINMODE, WindowMode);
311 }
312
313 /**
314 * @brief Get window mode of a pair of comparators instances
315 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
316 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
317 * @param COMPxy_COMMON Comparator common instance
318 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
319 * @retval Returned value can be one of the following values:
320 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
321 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
322 */
LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef * COMPxy_COMMON)323 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef *COMPxy_COMMON)
324 {
325 return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WINMODE));
326 }
327
328 /**
329 * @}
330 */
331
332 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
333 * @{
334 */
335
336 /**
337 * @brief Set comparator instance operating mode to adjust power and speed.
338 * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode
339 * @param COMPx Comparator instance
340 * @param PowerMode This parameter can be one of the following values:
341 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
342 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
343 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
344 * @retval None
345 */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)346 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
347 {
348 MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
349 }
350
351 /**
352 * @brief Get comparator instance operating mode to adjust power and speed.
353 * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode
354 * @param COMPx Comparator instance
355 * @retval Returned value can be one of the following values:
356 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
357 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
358 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
359 */
LL_COMP_GetPowerMode(const COMP_TypeDef * COMPx)360 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(const COMP_TypeDef *COMPx)
361 {
362 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
363 }
364
365 /**
366 * @}
367 */
368
369 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
370 * @{
371 */
372
373 /**
374 * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
375 * @note In case of comparator input selected to be connected to IO:
376 * GPIO pins are specific to each comparator instance.
377 * Refer to description of parameters or to reference manual.
378 * @note On this STM32 series, scaler bridge is configurable:
379 * to optimize power consumption, this function enables the
380 * voltage scaler bridge only when required
381 * (when selecting comparator input based on VrefInt: VrefInt or
382 * subdivision of VrefInt).
383 * - For scaler bridge power consumption values,
384 * refer to device datasheet, parameter "IDDA(SCALER)".
385 * - Voltage scaler requires a delay for voltage stabilization.
386 * Refer to device datasheet, parameter "tSTART_SCALER".
387 * - Scaler bridge is common for all comparator instances,
388 * therefore if at least one of the comparator instance
389 * is requiring the scaler bridge, it remains enabled.
390 * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
391 * CSR INPSEL LL_COMP_ConfigInputs\n
392 * CSR BRGEN LL_COMP_ConfigInputs\n
393 * CSR SCALEN LL_COMP_ConfigInputs
394 * @param COMPx Comparator instance
395 * @param InputMinus This parameter can be one of the following values:
396 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
397 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
398 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
399 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
400 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
401 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
402 * @arg @ref LL_COMP_INPUT_MINUS_IO1
403 * @arg @ref LL_COMP_INPUT_MINUS_IO2
404 * @param InputPlus This parameter can be one of the following values:
405 * @arg @ref LL_COMP_INPUT_PLUS_IO1
406 * @arg @ref LL_COMP_INPUT_PLUS_IO2
407 * @retval None
408 */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)409 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
410 {
411 MODIFY_REG(COMPx->CSR,
412 COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
413 InputMinus | InputPlus);
414 }
415
416 /**
417 * @brief Set comparator input plus (non-inverting).
418 * @note In case of comparator input selected to be connected to IO:
419 * GPIO pins are specific to each comparator instance.
420 * Refer to description of parameters or to reference manual.
421 * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
422 * @param COMPx Comparator instance
423 * @param InputPlus This parameter can be one of the following values:
424 * @arg @ref LL_COMP_INPUT_PLUS_IO1
425 * @arg @ref LL_COMP_INPUT_PLUS_IO2
426 * @retval None
427 */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)428 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
429 {
430 MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
431 }
432
433 /**
434 * @brief Get comparator input plus (non-inverting).
435 * @note In case of comparator input selected to be connected to IO:
436 * GPIO pins are specific to each comparator instance.
437 * Refer to description of parameters or to reference manual.
438 * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
439 * @param COMPx Comparator instance
440 * @retval Returned value can be one of the following values:
441 * @arg @ref LL_COMP_INPUT_PLUS_IO1
442 * @arg @ref LL_COMP_INPUT_PLUS_IO2
443 */
LL_COMP_GetInputPlus(const COMP_TypeDef * COMPx)444 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(const COMP_TypeDef *COMPx)
445 {
446 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
447 }
448
449 /**
450 * @brief Set comparator input minus (inverting).
451 * @note In case of comparator input selected to be connected to IO:
452 * GPIO pins are specific to each comparator instance.
453 * Refer to description of parameters or to reference manual.
454 * @note On this STM32 series, scaler bridge is configurable:
455 * to optimize power consumption, this function enables the
456 * voltage scaler bridge only when required
457 * (when selecting comparator input based on VrefInt: VrefInt or
458 * subdivision of VrefInt).
459 * - For scaler bridge power consumption values,
460 * refer to device datasheet, parameter "IDDA(SCALER)".
461 * - Voltage scaler requires a delay for voltage stabilization.
462 * Refer to device datasheet, parameter "tSTART_SCALER".
463 * - Scaler bridge is common for all comparator instances,
464 * therefore if at least one of the comparator instance
465 * is requiring the scaler bridge, it remains enabled.
466 * @rmtoll CSR INMSEL LL_COMP_SetInputMinus\n
467 * CSR BRGEN LL_COMP_SetInputMinus\n
468 * CSR SCALEN LL_COMP_SetInputMinus
469 * @param COMPx Comparator instance
470 * @param InputMinus This parameter can be one of the following values:
471 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
472 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
473 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
474 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
475 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
476 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
477 * @arg @ref LL_COMP_INPUT_MINUS_IO1
478 * @arg @ref LL_COMP_INPUT_MINUS_IO2
479 * @retval None
480 */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)481 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
482 {
483 MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
484 }
485
486 /**
487 * @brief Get comparator input minus (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 INMSEL LL_COMP_GetInputMinus\n
492 * CSR BRGEN LL_COMP_GetInputMinus\n
493 * CSR SCALEN LL_COMP_GetInputMinus
494 * @param COMPx Comparator instance
495 * @retval Returned value can be one of the following values:
496 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
497 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
498 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
499 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
500 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
501 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
502 * @arg @ref LL_COMP_INPUT_MINUS_IO1
503 * @arg @ref LL_COMP_INPUT_MINUS_IO2
504 */
LL_COMP_GetInputMinus(const COMP_TypeDef * COMPx)505 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(const COMP_TypeDef *COMPx)
506 {
507 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
508 }
509
510 /**
511 * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
512 * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
513 * @param COMPx Comparator instance
514 * @param InputHysteresis This parameter can be one of the following values:
515 * @arg @ref LL_COMP_HYSTERESIS_NONE
516 * @arg @ref LL_COMP_HYSTERESIS_LOW
517 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
518 * @arg @ref LL_COMP_HYSTERESIS_HIGH
519 * @retval None
520 */
LL_COMP_SetInputHysteresis(COMP_TypeDef * COMPx,uint32_t InputHysteresis)521 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
522 {
523 MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
524 }
525
526 /**
527 * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
528 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
529 * @param COMPx Comparator instance
530 * @retval Returned value can be one of the following values:
531 * @arg @ref LL_COMP_HYSTERESIS_NONE
532 * @arg @ref LL_COMP_HYSTERESIS_LOW
533 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
534 * @arg @ref LL_COMP_HYSTERESIS_HIGH
535 */
LL_COMP_GetInputHysteresis(const COMP_TypeDef * COMPx)536 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(const COMP_TypeDef *COMPx)
537 {
538 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
539 }
540
541 /**
542 * @}
543 */
544
545 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
546 * @{
547 */
548
549 /**
550 * @brief Set comparator instance output polarity.
551 * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
552 * @param COMPx Comparator instance
553 * @param OutputPolarity This parameter can be one of the following values:
554 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
555 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
556 * @retval None
557 */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)558 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
559 {
560 MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
561 }
562
563 /**
564 * @brief Get comparator instance output polarity.
565 * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
566 * @param COMPx Comparator instance
567 * @retval Returned value can be one of the following values:
568 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
569 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
570 */
LL_COMP_GetOutputPolarity(const COMP_TypeDef * COMPx)571 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(const COMP_TypeDef *COMPx)
572 {
573 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
574 }
575
576 /**
577 * @brief Set comparator instance blanking source.
578 * @note Blanking source may be specific to each comparator instance.
579 * Refer to description of parameters or to reference manual.
580 * @note Availability of parameters of blanking source from timer
581 * depends on timers availability on the selected device.
582 * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource
583 * @param COMPx Comparator instance
584 * @param BlankingSource This parameter can be one of the following values:
585 * @arg @ref LL_COMP_BLANKINGSRC_NONE
586 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (1)(2)
587 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (1)(2)
588 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (1)(2)
589 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (1)(3)
590 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (1)(3)
591 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3)
592 *
593 * (1) Parameter availability depending on timer availability
594 * on the selected device.
595 * (2) On STM32L5, parameter available only on comparator instance: COMP1.
596 * (3) On STM32L5, parameter available only on comparator instance: COMP2.
597 * @retval None
598 */
LL_COMP_SetOutputBlankingSource(COMP_TypeDef * COMPx,uint32_t BlankingSource)599 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
600 {
601 MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
602 }
603
604 /**
605 * @brief Get comparator instance blanking source.
606 * @note Availability of parameters of blanking source from timer
607 * depends on timers availability on the selected device.
608 * @note Blanking source may be specific to each comparator instance.
609 * Refer to description of parameters or to reference manual.
610 * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource
611 * @param COMPx Comparator instance
612 * @retval Returned value can be one of the following values:
613 * @arg @ref LL_COMP_BLANKINGSRC_NONE
614 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (1)(2)
615 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (1)(2)
616 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (1)(2)
617 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (1)(3)
618 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (1)(3)
619 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3)
620 *
621 * (1) Parameter availability depending on timer availability
622 * on the selected device.
623 * (2) On STM32L5, parameter available only on comparator instance: COMP1.
624 * (3) On STM32L5, parameter available only on comparator instance: COMP2.
625 */
LL_COMP_GetOutputBlankingSource(const COMP_TypeDef * COMPx)626 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(const COMP_TypeDef *COMPx)
627 {
628 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
629 }
630
631 /**
632 * @}
633 */
634
635 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
636 * @{
637 */
638
639 /**
640 * @brief Enable comparator instance.
641 * @note After enable from off state, comparator requires a delay
642 * to reach reach propagation delay specification.
643 * Refer to device datasheet, parameter "tSTART".
644 * @rmtoll CSR EN LL_COMP_Enable
645 * @param COMPx Comparator instance
646 * @retval None
647 */
LL_COMP_Enable(COMP_TypeDef * COMPx)648 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
649 {
650 SET_BIT(COMPx->CSR, COMP_CSR_EN);
651 }
652
653 /**
654 * @brief Disable comparator instance.
655 * @rmtoll CSR EN LL_COMP_Disable
656 * @param COMPx Comparator instance
657 * @retval None
658 */
LL_COMP_Disable(COMP_TypeDef * COMPx)659 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
660 {
661 CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
662 }
663
664 /**
665 * @brief Get comparator enable state
666 * (0: COMP is disabled, 1: COMP is enabled)
667 * @rmtoll CSR EN LL_COMP_IsEnabled
668 * @param COMPx Comparator instance
669 * @retval State of bit (1 or 0).
670 */
LL_COMP_IsEnabled(const COMP_TypeDef * COMPx)671 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(const COMP_TypeDef *COMPx)
672 {
673 return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
674 }
675
676 /**
677 * @brief Lock comparator instance.
678 * @note Once locked, comparator configuration can be accessed in read-only.
679 * @note The only way to unlock the comparator is a device hardware reset.
680 * @rmtoll CSR LOCK LL_COMP_Lock
681 * @param COMPx Comparator instance
682 * @retval None
683 */
LL_COMP_Lock(COMP_TypeDef * COMPx)684 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
685 {
686 SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
687 }
688
689 /**
690 * @brief Get comparator lock state
691 * (0: COMP is unlocked, 1: COMP is locked).
692 * @note Once locked, comparator configuration can be accessed in read-only.
693 * @note The only way to unlock the comparator is a device hardware reset.
694 * @rmtoll CSR LOCK LL_COMP_IsLocked
695 * @param COMPx Comparator instance
696 * @retval State of bit (1 or 0).
697 */
LL_COMP_IsLocked(const COMP_TypeDef * COMPx)698 __STATIC_INLINE uint32_t LL_COMP_IsLocked(const COMP_TypeDef *COMPx)
699 {
700 return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
701 }
702
703 /**
704 * @brief Read comparator instance output level.
705 * @note The comparator output level depends on the selected polarity
706 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
707 * If the comparator polarity is not inverted:
708 * - Comparator output is low when the input plus
709 * is at a lower voltage than the input minus
710 * - Comparator output is high when the input plus
711 * is at a higher voltage than the input minus
712 * If the comparator polarity is inverted:
713 * - Comparator output is high when the input plus
714 * is at a lower voltage than the input minus
715 * - Comparator output is low when the input plus
716 * is at a higher voltage than the input minus
717 * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
718 * @param COMPx Comparator instance
719 * @retval Returned value can be one of the following values:
720 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
721 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
722 */
LL_COMP_ReadOutputLevel(const COMP_TypeDef * COMPx)723 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(const COMP_TypeDef *COMPx)
724 {
725 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
726 >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
727 }
728
729 /**
730 * @}
731 */
732
733 #if defined(USE_FULL_LL_DRIVER)
734 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
735 * @{
736 */
737
738 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
739 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct);
740 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
741
742 /**
743 * @}
744 */
745 #endif /* USE_FULL_LL_DRIVER */
746
747 /**
748 * @}
749 */
750
751 /**
752 * @}
753 */
754
755 /**
756 * @}
757 */
758
759 #endif /* COMP1 || COMP2 */
760
761 /**
762 * @}
763 */
764
765 #ifdef __cplusplus
766 }
767 #endif
768
769 #endif /* STM32L5xx_LL_COMP_H */
770