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