1 /**
2 ******************************************************************************
3 * @file stm32l0xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2016 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef __STM32L0xx_LL_COMP_H
21 #define __STM32L0xx_LL_COMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l0xx.h"
29
30 /** @addtogroup STM32L0xx_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 (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_COMP1VALUE) */
49
50 /**
51 * @}
52 */
53
54 /* Private macros ------------------------------------------------------------*/
55 /* Exported types ------------------------------------------------------------*/
56 #if defined(USE_FULL_LL_DRIVER)
57 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
58 * @{
59 */
60
61 /**
62 * @brief Structure definition of some features of COMP instance.
63 */
64 typedef struct
65 {
66 uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
67 This parameter can be a value of @ref COMP_LL_EC_POWERMODE
68
69 This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
70
71 uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
72 This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
73
74 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
75
76 uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
77 This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
78
79 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
80
81 uint32_t OutputPolarity; /*!< Set comparator output polarity.
82 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
83
84 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
85
86 } LL_COMP_InitTypeDef;
87
88 /**
89 * @}
90 */
91 #endif /* USE_FULL_LL_DRIVER */
92
93 /* Exported constants --------------------------------------------------------*/
94 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
95 * @{
96 */
97
98 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
99 * @{
100 */
101 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
102 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_COMP1WM) /*!< 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). */
103 /**
104 * @}
105 */
106
107 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
108 * @{
109 */
110 #define LL_COMP_POWERMODE_ULTRALOWPOWER (0x00000000U) /*!< COMP power mode to low speed (specific to COMP instance: COMP2) */
111 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_COMP2SPEED) /*!< COMP power mode to fast speed (specific to COMP instance: COMP2) */
112 /**
113 * @}
114 */
115
116 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
117 * @{
118 */
119 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000U) /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA3 for COMP2) */
120 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB4 for COMP2) (specific to COMP instance: COMP2) */
121 #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA5 for COMP2) (specific to COMP instance: COMP2) */
122 #define LL_COMP_INPUT_PLUS_IO4 (COMP_CSR_COMP2INPSEL_0 | COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO4 (pin PB6 for COMP2) (specific to COMP instance: COMP2) */
123 #define LL_COMP_INPUT_PLUS_IO5 (COMP_CSR_COMP2INPSEL_2) /*!< Comparator input plus connected to IO5 (pin PB7 for COMP2) (specific to COMP instance: COMP2) */
124 #if defined (STM32L011xx) || defined (STM32L021xx)
125 #define LL_COMP_INPUT_PLUS_IO6 (COMP_CSR_COMP2INPSEL_2 | COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO6 (pin PA7 for COMP2) (specific to COMP instance: COMP2) (Available only on devices STM32L0 category 1) */
126 #endif
127 /**
128 * @}
129 */
130
131 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
132 * @{
133 */
134 #define LL_COMP_INPUT_MINUS_1_4VREFINT (COMP_CSR_COMP2INNSEL_2 ) /*!< Comparator input minus connected to 1/4 VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) (specific to COMP instance: COMP2) */
135 #define LL_COMP_INPUT_MINUS_1_2VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) (specific to COMP instance: COMP2) */
136 #define LL_COMP_INPUT_MINUS_3_4VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) (specific to COMP instance: COMP2) */
137 #define LL_COMP_INPUT_MINUS_VREFINT (0x00000000U) /*!< Comparator input minus connected to VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) */
138 #define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
139 #define LL_COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
140 #define LL_COMP_INPUT_MINUS_IO1 ( COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO1 (pin PA0 for COMP1, pin PA2 for COMP2) */
141 #define LL_COMP_INPUT_MINUS_IO2 (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO2 (pin PB3 for COMP2) (specific to COMP instance: COMP2) */
142 /**
143 * @}
144 */
145
146 /** @defgroup COMP_LL_EC_OUTPUT_SELECTION_LPTIM Comparator output - Output selection specific to LPTIM peripheral
147 * @{
148 */
149 #define LL_COMP_OUTPUT_LPTIM1_IN1_COMP1 (COMP_CSR_COMP1LPTIM1IN1) /*!< COMP output connected to TIM2 input capture 4 */
150 #define LL_COMP_OUTPUT_LPTIM1_IN1_COMP2 (COMP_CSR_COMP2LPTIM1IN1) /*!< COMP output connected to TIM2 input capture 4 */
151 #define LL_COMP_OUTPUT_LPTIM1_IN2_COMP2 (COMP_CSR_COMP2LPTIM1IN2) /*!< COMP output connected to TIM2 input capture 4 */
152 /**
153 * @}
154 */
155
156 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
157 * @{
158 */
159 #define LL_COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< 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 */
160 #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_COMP1POLARITY) /*!< 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 */
161
162 /**
163 * @}
164 */
165
166 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
167 * @{
168 */
169 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
170 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
171 /**
172 * @}
173 */
174
175 /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
176 * @note Only COMP IP HW delays are defined in COMP LL driver driver,
177 * not timeout values.
178 * For details on delays values, refer to descriptions in source code
179 * above each literal definition.
180 * @{
181 */
182
183 /* Delay for comparator startup time. */
184 /* Note: Delay required to reach propagation delay specification. */
185 /* Literal set to maximum value (refer to device datasheet, */
186 /* parameter "tSTART"). */
187 /* Unit: us */
188 #define LL_COMP_DELAY_STARTUP_US (25U) /*!< Delay for COMP startup time */
189
190 /* Delay for comparator voltage scaler stabilization time */
191 /* (voltage from VrefInt, delay based on VrefInt startup time). */
192 /* Literal set to maximum value (refer to device datasheet, */
193 /* parameter "TVREFINT"). */
194 /* Unit: us */
195 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US (3000U) /*!< Delay for COMP voltage scaler stabilization time */
196
197 /**
198 * @}
199 */
200
201 /**
202 * @}
203 */
204
205 /* Exported macro ------------------------------------------------------------*/
206 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
207 * @{
208 */
209 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
210 * @{
211 */
212
213 /**
214 * @brief Write a value in COMP register
215 * @param __INSTANCE__ comparator instance
216 * @param __REG__ Register to be written
217 * @param __VALUE__ Value to be written in the register
218 * @retval None
219 */
220 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
221
222 /**
223 * @brief Read a value in COMP register
224 * @param __INSTANCE__ comparator instance
225 * @param __REG__ Register to be read
226 * @retval Register value
227 */
228 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
229 /**
230 * @}
231 */
232
233 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
234 * @{
235 */
236
237 /**
238 * @brief Helper macro to select the COMP common instance
239 * to which is belonging the selected COMP instance.
240 * @note COMP common register instance can be used to
241 * set parameters common to several COMP instances.
242 * Refer to functions having argument "COMPxy_COMMON" as parameter.
243 * @param __COMPx__ COMP instance
244 * @retval COMP common instance or value "0" if there is no COMP common instance.
245 */
246 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
247 (COMP12_COMMON)
248
249 /**
250 * @}
251 */
252
253 /**
254 * @}
255 */
256
257 /* Exported functions --------------------------------------------------------*/
258 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
259 * @{
260 */
261
262 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
263 * @{
264 */
265
266 /**
267 * @brief Set window mode of a pair of comparators instances
268 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
269 * @rmtoll COMP1_CSR COMP1WM LL_COMP_SetCommonWindowMode
270 * @param COMPxy_COMMON Comparator common instance
271 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
272 * @param WindowMode This parameter can be one of the following values:
273 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
274 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
275 * @retval None
276 */
LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowMode)277 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
278 {
279 MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_COMP1WM, WindowMode);
280 }
281
282 /**
283 * @brief Get window mode of a pair of comparators instances
284 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
285 * @rmtoll COMP1_CSR COMP1WM LL_COMP_GetCommonWindowMode
286 * @param COMPxy_COMMON Comparator common instance
287 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
288 * @retval Returned value can be one of the following values:
289 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
290 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
291 */
LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON)292 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
293 {
294 return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_COMP1WM));
295 }
296
297 /**
298 * @}
299 */
300
301 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
302 * @{
303 */
304
305 /**
306 * @brief Set comparator instance operating mode to adjust power and speed.
307 * @rmtoll COMP2_CSR COMP2SPEED LL_COMP_SetPowerMode
308 * @param COMPx Comparator instance
309 * @param PowerMode This parameter can be one of the following values:
310 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
311 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
312 *
313 * (1) Available only on COMP instance: COMP2.
314 * @retval None
315 */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)316 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
317 {
318 MODIFY_REG(COMPx->CSR, COMP_CSR_COMP2SPEED, PowerMode);
319 }
320
321 /**
322 * @brief Get comparator instance operating mode to adjust power and speed.
323 * @note Available only on COMP instance: COMP2.
324 * @rmtoll COMP2_CSR COMP2SPEED LL_COMP_GetPowerMode\n
325 * @param COMPx Comparator instance
326 * @retval Returned value can be one of the following values:
327 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
328 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
329 *
330 * (1) Available only on COMP instance: COMP2.
331 */
LL_COMP_GetPowerMode(COMP_TypeDef * COMPx)332 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
333 {
334 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP2SPEED));
335 }
336
337 /**
338 * @}
339 */
340
341 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
342 * @{
343 */
344
345 /**
346 * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
347 * @note This function shall only be used for COMP2.
348 * For setting COMP1 input it is recommended to use LL_COMP_SetInputMinus()
349 * Plus (non-inverting) input is not configurable on COMP1.
350 * Using this function for COMP1 will corrupt COMP1WM register
351 * @note On this STM32 series, specificity if using COMP instance COMP2
352 * with COMP input based on VrefInt (VrefInt or subdivision
353 * of VrefInt): scaler bridge is based on VrefInt and requires
354 * to enable path from VrefInt (refer to literal
355 * SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP).
356 * @rmtoll COMP2_CSR COMP2INNSEL LL_COMP_ConfigInputs\n
357 * COMP2_CSR COMP2INPSEL LL_COMP_ConfigInputs
358 * @param COMPx Comparator instance
359 * @param InputMinus This parameter can be one of the following values:
360 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
361 * @arg @ref LL_COMP_INPUT_MINUS_IO1
362 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
363 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
364 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
365 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
366 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
367 * @arg @ref LL_COMP_INPUT_MINUS_IO2
368 * @param InputPlus This parameter can be one of the following values:
369 * @arg @ref LL_COMP_INPUT_PLUS_IO1 (1)
370 * @arg @ref LL_COMP_INPUT_PLUS_IO2 (1)
371 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (1)
372 * @arg @ref LL_COMP_INPUT_PLUS_IO4 (1)
373 * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
374 * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)(2)
375 *
376 * (1) Available only on COMP instance: COMP2.
377 * (2) Available only on devices STM32L0 category 1.
378 * @retval None
379 */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)380 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
381 {
382 MODIFY_REG(COMPx->CSR,
383 COMP_CSR_COMP2INNSEL | COMP_CSR_COMP2INPSEL,
384 InputMinus | InputPlus);
385 }
386
387 /**
388 * @brief Set comparator input plus (non-inverting).
389 * @note Only COMP2 allows to set the input plus (non-inverting).
390 * For COMP1 it is always PA1 IO, except when Windows Mode is selected.
391 * @rmtoll COMP2_CSR COMP2INPSEL LL_COMP_SetInputPlus
392 * @param COMPx Comparator instance
393 * @param InputPlus This parameter can be one of the following values:
394 * @arg @ref LL_COMP_INPUT_PLUS_IO1 (1)
395 * @arg @ref LL_COMP_INPUT_PLUS_IO2 (1)
396 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (1)
397 * @arg @ref LL_COMP_INPUT_PLUS_IO4 (1)
398 * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
399 * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)(2)
400 *
401 * (1) Available only on COMP instance: COMP2.
402 * (2) Available only on devices STM32L0 category 1.
403 * @retval None
404 */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)405 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
406 {
407 MODIFY_REG(COMPx->CSR, COMP_CSR_COMP2INPSEL, InputPlus);
408 }
409
410 /**
411 * @brief Get comparator input plus (non-inverting).
412 * @note Only COMP2 allows to set the input plus (non-inverting).
413 * For COMP1 it is always PA1 IO, except when Windows Mode is selected.
414 * @rmtoll COMP2_CSR COMP2INPSEL LL_COMP_GetInputPlus
415 * @param COMPx Comparator instance
416 * @retval Returned value can be one of the following values:
417 * @arg @ref LL_COMP_INPUT_PLUS_IO1 (1)
418 * @arg @ref LL_COMP_INPUT_PLUS_IO2 (1)
419 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (1)
420 * @arg @ref LL_COMP_INPUT_PLUS_IO4 (1)
421 * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
422 * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)(2)
423 *
424 * (1) Available only on COMP instance: COMP2.
425 * (2) Available only on devices STM32L0 category 1.
426 */
LL_COMP_GetInputPlus(COMP_TypeDef * COMPx)427 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
428 {
429 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP2INPSEL));
430 }
431
432 /**
433 * @brief Set comparator input minus (inverting).
434 * @note In case of comparator input selected to be connected to IO:
435 * GPIO pins are specific to each comparator instance.
436 * Refer to description of parameters or to reference manual.
437 * @note On this STM32 series, specificity if using COMP instance COMP2
438 * with COMP input based on VrefInt (VrefInt or subdivision
439 * of VrefInt): scaler bridge is based on VrefInt and requires
440 * to enable path from VrefInt (refer to literal
441 * SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP).
442 * @rmtoll COMP1_CSR COMP1INNSEL LL_COMP_SetInputMinus\n
443 * COMP2_CSR COMP2INNSEL LL_COMP_SetInputMinus
444 * @param COMPx Comparator instance
445 * @param InputMinus This parameter can be one of the following values:
446 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
447 * @arg @ref LL_COMP_INPUT_MINUS_IO1
448 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
449 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
450 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (*)
451 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (*)
452 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (*)
453 * @arg @ref LL_COMP_INPUT_MINUS_IO2 (*)
454 *
455 * (*) Available only on COMP instance: COMP2.
456 * @retval None
457 */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)458 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
459 {
460 MODIFY_REG(COMPx->CSR, COMP_CSR_COMP2INNSEL, InputMinus);
461 }
462
463 /**
464 * @brief Get comparator input minus (inverting).
465 * @note In case of comparator input selected to be connected to IO:
466 * GPIO pins are specific to each comparator instance.
467 * Refer to description of parameters or to reference manual.
468 * @rmtoll COMP1_CSR COMP1INNSEL LL_COMP_GetInputMinus\n
469 * COMP2_CSR COMP2INNSEL LL_COMP_GetInputMinus
470 * @param COMPx Comparator instance
471 * @retval Returned value can be one of the following values:
472 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
473 * @arg @ref LL_COMP_INPUT_MINUS_IO1
474 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
475 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
476 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (*)
477 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (*)
478 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (*)
479 * @arg @ref LL_COMP_INPUT_MINUS_IO2 (*)
480 *
481 * (*) Available only on COMP instance: COMP2.
482 */
LL_COMP_GetInputMinus(COMP_TypeDef * COMPx)483 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
484 {
485 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP2INNSEL));
486 }
487
488 /**
489 * @}
490 */
491
492 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
493 * @{
494 */
495
496 /**
497 * @brief Set comparator output LPTIM.
498 * @rmtoll COMP1_CSR COMP1LPTIMIN1 LL_COMP_SetOutputLPTIM\n
499 * COMP2_CSR COMP2LPTIMIN1 LL_COMP_SetOutputLPTIM\n
500 * COMP2_CSR COMP2LPTIMIN2 LL_COMP_SetOutputLPTIM
501 * @param COMPx Comparator instance
502 * @param OutputLptim This parameter can be one of the following values:
503 * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP1 (*)
504 * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP2 (**)
505 * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN2_COMP2 (**)
506 *
507 * (*) Available only on COMP instance: COMP1.\n
508 * (**) Available only on COMP instance: COMP2.
509 * @retval None
510 */
LL_COMP_SetOutputLPTIM(COMP_TypeDef * COMPx,uint32_t OutputLptim)511 __STATIC_INLINE void LL_COMP_SetOutputLPTIM(COMP_TypeDef *COMPx, uint32_t OutputLptim)
512 {
513 MODIFY_REG(COMPx->CSR, (COMP_CSR_COMP1LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN2), OutputLptim);
514 }
515
516 /**
517 * @brief Get comparator output LPTIM.
518 * @rmtoll COMP1_CSR COMP1LPTIMIN1 LL_COMP_GetOutputLPTIM\n
519 * COMP2_CSR COMP2LPTIMIN1 LL_COMP_GetOutputLPTIM\n
520 * COMP2_CSR COMP2LPTIMIN2 LL_COMP_GetOutputLPTIM
521 * @param COMPx Comparator instance
522 * @retval Returned value can be one of the following values:
523 * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP1 (*)
524 * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP2 (**)
525 * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN2_COMP2 (**)
526 *
527 * (*) Available only on COMP instance: COMP1.\n
528 * (**) Available only on COMP instance: COMP2.
529 */
LL_COMP_GetOutputLPTIM(COMP_TypeDef * COMPx)530 __STATIC_INLINE uint32_t LL_COMP_GetOutputLPTIM(COMP_TypeDef *COMPx)
531 {
532 return (uint32_t)(READ_BIT(COMPx->CSR, (COMP_CSR_COMP1LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN2)));
533 }
534
535 /**
536 * @brief Set comparator instance output polarity.
537 * @rmtoll COMP COMP1POLARITY LL_COMP_SetOutputPolarity
538 * @param COMPx Comparator instance
539 * @param OutputPolarity This parameter can be one of the following values:
540 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
541 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
542 * @retval None
543 */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)544 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
545 {
546 MODIFY_REG(COMPx->CSR, COMP_CSR_COMPxPOLARITY, OutputPolarity);
547 }
548
549 /**
550 * @brief Get comparator instance output polarity.
551 * @rmtoll COMP COMP1POLARITY LL_COMP_GetOutputPolarity
552 * @param COMPx Comparator instance
553 * @retval Returned value can be one of the following values:
554 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
555 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
556 */
LL_COMP_GetOutputPolarity(COMP_TypeDef * COMPx)557 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
558 {
559 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMPxPOLARITY));
560 }
561
562 /**
563 * @}
564 */
565
566 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
567 * @{
568 */
569
570 /**
571 * @brief Enable comparator instance.
572 * @note After enable from off state, comparator requires a delay
573 * to reach reach propagation delay specification.
574 * Refer to device datasheet, parameter "tSTART".
575 * @rmtoll COMP1_CSR COMP1EN LL_COMP_Enable\n
576 * COMP2_CSR COMP2EN LL_COMP_Enable
577 * @param COMPx Comparator instance
578 * @retval None
579 */
LL_COMP_Enable(COMP_TypeDef * COMPx)580 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
581 {
582 SET_BIT(COMPx->CSR, COMP_CSR_COMPxEN);
583 }
584
585 /**
586 * @brief Disable comparator instance.
587 * @rmtoll COMP1_CSR COMP1EN LL_COMP_Disable\n
588 * COMP2_CSR COMP2EN LL_COMP_Disable
589 * @param COMPx Comparator instance
590 * @retval None
591 */
LL_COMP_Disable(COMP_TypeDef * COMPx)592 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
593 {
594 CLEAR_BIT(COMPx->CSR, COMP_CSR_COMPxEN);
595 }
596
597 /**
598 * @brief Get comparator enable state
599 * (0: COMP is disabled, 1: COMP is enabled)
600 * @rmtoll COMP1_CSR COMP1EN LL_COMP_IsEnabled\n
601 * COMP2_CSR COMP2EN LL_COMP_IsEnabled
602 * @param COMPx Comparator instance
603 * @retval State of bit (1 or 0).
604 */
LL_COMP_IsEnabled(COMP_TypeDef * COMPx)605 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
606 {
607 return (READ_BIT(COMPx->CSR, COMP_CSR_COMPxEN) == (COMP_CSR_COMPxEN));
608 }
609
610 /**
611 * @brief Lock comparator instance.
612 * @note Once locked, comparator configuration can be accessed in read-only.
613 * @note The only way to unlock the comparator is a device hardware reset.
614 * @rmtoll COMP1_CSR COMP1LOCK LL_COMP_Lock\n
615 * COMP2_CSR COMP2LOCK LL_COMP_Lock
616 * @param COMPx Comparator instance
617 * @retval None
618 */
LL_COMP_Lock(COMP_TypeDef * COMPx)619 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
620 {
621 SET_BIT(COMPx->CSR, COMP_CSR_COMPxLOCK);
622 }
623
624 /**
625 * @brief Get comparator lock state
626 * (0: COMP is unlocked, 1: COMP is locked).
627 * @note Once locked, comparator configuration can be accessed in read-only.
628 * @note The only way to unlock the comparator is a device hardware reset.
629 * @rmtoll COMP1_CSR COMP1LOCK LL_COMP_IsLocked\n
630 * COMP2_CSR COMP2LOCK LL_COMP_IsLocked
631 * @param COMPx Comparator instance
632 * @retval State of bit (1 or 0).
633 */
LL_COMP_IsLocked(COMP_TypeDef * COMPx)634 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
635 {
636 return (READ_BIT(COMPx->CSR, COMP_CSR_COMPxLOCK) == (COMP_CSR_COMPxLOCK));
637 }
638
639 /**
640 * @brief Read comparator instance output level.
641 * @note The comparator output level depends on the selected polarity
642 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
643 * If the comparator polarity is not inverted:
644 * - Comparator output is low when the input plus
645 * is at a lower voltage than the input minus
646 * - Comparator output is high when the input plus
647 * is at a higher voltage than the input minus
648 * If the comparator polarity is inverted:
649 * - Comparator output is high when the input plus
650 * is at a lower voltage than the input minus
651 * - Comparator output is low when the input plus
652 * is at a higher voltage than the input minus
653 * @rmtoll COMP1_CSR COMP1VALUE LL_COMP_ReadOutputLevel\n
654 * COMP2_CSR COMP2VALUE LL_COMP_ReadOutputLevel
655 * @param COMPx Comparator instance
656 * @retval Returned value can be one of the following values:
657 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
658 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
659 */
LL_COMP_ReadOutputLevel(COMP_TypeDef * COMPx)660 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
661 {
662 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMPxOUTVALUE)
663 >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
664 }
665
666 /**
667 * @}
668 */
669
670 #if defined(USE_FULL_LL_DRIVER)
671 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
672 * @{
673 */
674
675 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
676 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
677 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
678
679 /**
680 * @}
681 */
682 #endif /* USE_FULL_LL_DRIVER */
683
684 /**
685 * @}
686 */
687
688 /**
689 * @}
690 */
691
692 #endif /* COMP1 || COMP2 */
693
694 /**
695 * @}
696 */
697
698 #ifdef __cplusplus
699 }
700 #endif
701
702 #endif /* __STM32L0xx_LL_COMP_H */
703
704