1 /**
2 ******************************************************************************
3 * @file stm32g0xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2018 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 STM32G0xx_LL_COMP_H
21 #define STM32G0xx_LL_COMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g0xx.h"
29
30 /** @addtogroup STM32G0xx_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 /* Internal mask for pair of comparators instances window mode: */
48 /* To select into literals LL_COMP_WINDOWMODE_COMPx_INPUT_PLUS_COMMON */
49 /* the relevant bits for: */
50 /* (concatenation of multiple bits used in different registers) */
51 /* - Comparator instance selected as master for window mode : register offset */
52 /* - Window mode enable or disable: bit value */
53 #define LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK (0x00000000UL) /* Register of COMP instance odd (COMP1_CSR, ...) defined as reference register */
54 #define LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK (0x00000001UL) /* Register of COMP instance even (COMP2_CSR, ...) offset vs register of COMP instance odd */
55 #define LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK (LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
56 #define LL_COMP_WINDOWMODE_COMPX_SETTING_MASK (COMP_CSR_WINMODE)
57 #define LL_COMP_WINDOWOUTPUT_COMPX_SETTING_MASK (COMP_CSR_WINOUT)
58 #define LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK (COMP_CSR_WINOUT << 1UL)
59 #define LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW (1UL)
60
61 /* COMP registers bits positions */
62 #define LL_COMP_WINDOWMODE_BITOFFSET_POS (11UL) /* Value equivalent to POSITION_VAL(COMP_CSR_WINMODE) */
63 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
64
65 /**
66 * @}
67 */
68
69 /* Private macros ------------------------------------------------------------*/
70 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
71 * @{
72 */
73
74 /**
75 * @brief Driver macro reserved for internal use: set a pointer to
76 * a register from a register basis from which an offset
77 * is applied.
78 * @param __REG__ Register basis from which the offset is applied.
79 * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
80 * @retval Pointer to register address
81 */
82 #define __COMP_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
83 ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
84
85 /**
86 * @}
87 */
88
89 /* Exported types ------------------------------------------------------------*/
90 #if defined(USE_FULL_LL_DRIVER)
91 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
92 * @{
93 */
94
95 /**
96 * @brief Structure definition of some features of COMP instance.
97 */
98 typedef struct
99 {
100 uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
101 This parameter can be a value of @ref COMP_LL_EC_POWERMODE
102
103 This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
104
105 uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
106 This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
107
108 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
109
110 uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
111 This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
112
113 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
114
115 uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
116 This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
117
118 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
119
120 uint32_t OutputPolarity; /*!< Set comparator output polarity.
121 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
122
123 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
124
125 uint32_t OutputBlankingSource; /*!< Set comparator blanking source.
126 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
127
128 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */
129
130 } LL_COMP_InitTypeDef;
131
132 /**
133 * @}
134 */
135 #endif /* USE_FULL_LL_DRIVER */
136
137 /* Exported constants --------------------------------------------------------*/
138 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
139 * @{
140 */
141
142 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
143 * @{
144 */
145 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
146 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< 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). */
147 #define LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window mode enable: if used from COMP1 or COMP2 instance, comparators instances pair COMP1 and COMP2 have their input plus connected together, the common input is COMP2 input plus (COMP1 input plus is no more accessible). If used from COMP3 instance (when available), comparators instances pair COMP2 and COMP3 have their input plus connected together, the common input is COMP2 input plus (COMP3 input plus is no more accessible). */
148 /**
149 * @}
150 */
151
152 /** @defgroup COMP_LL_EC_COMMON_WINDOWOUTPUT Comparator common modes - Window output
153 * @{
154 */
155 #define LL_COMP_WINDOWOUTPUT_EACH_COMP (0x00000000UL) /*!< Window output default mode: Comparators output are indicating each their own state. To know window mode state: each comparator output must be read, if "((COMPx exclusive or COMPy) == 1)" then monitored signal is within comparators window. The same way, if both comparators output are high, then monitored signal is below window. */
156 #define LL_COMP_WINDOWOUTPUT_COMP1 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window output synthetized on COMP1 output: COMP1 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). Note: impacts only comparator output signal level (COMPx_OUT propagated to GPIO, EXTI lines, timers, ...), does not impact output digital state of comparator (COMPx_VALUE) always reflecting each comparator output state.*/
157 #define LL_COMP_WINDOWOUTPUT_COMP2 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< Window output synthetized on COMP2 output: COMP2 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). Note: impacts only comparator output signal level (COMPx_OUT propagated to GPIO, EXTI lines, timers, ...), does not impact output digital state of comparator (COMPx_VALUE) always reflecting each comparator output state.*/
158 #if defined(COMP3)
159 #define LL_COMP_WINDOWOUTPUT_COMP3 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window output synthetized on COMP3 output: COMP3 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). Available only on devices featuring COMP3 instance. */
160 #endif /* COMP3 */
161 #define LL_COMP_WINDOWOUTPUT_BOTH (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK | LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK) /*!< Window output synthetized on both comparators output of pair of comparator selected (COMP1 and COMP2, or COMP2 and COMP3 for devices featuring COMP3 instance): both comparators outputs are no more indicating their own state, but global window mode state (logical high means monitored signal is within comparators window). This is a specific configuration (technically possible but not relevant from application point of view: 2 comparators output used for the same signal level), standard configuration for window mode is one of the settings above. */
162 /**
163 * @}
164 */
165
166 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
167 * @{
168 */
169 #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
170 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */
171 /**
172 * @}
173 */
174
175 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
176 * @{
177 */
178 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2, pin PB0 for COMP3 (for devices featuring COMP3 instance)) */
179 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2, pin PC1 for COMP3 (for devices featuring COMP3 instance)) */
180 #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2, pin PE7 for COMP3 (for devices featuring COMP3 instance)) */
181 /**
182 * @}
183 */
184
185 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
186 * @{
187 */
188 #define LL_COMP_INPUT_MINUS_1_4VREFINT (0x00000000UL) /*!< Comparator input minus connected to 1/4 VrefInt */
189 #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */
190 #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */
191 #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
192 #define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
193 #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) */
194 #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, pin PB2 for COMP3 (for devices featuring COMP3 instance)) */
195 #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, pin PC0 for COMP3 (for devices featuring COMP3 instance)) */
196 #define LL_COMP_INPUT_MINUS_IO3 (COMP_CSR_INMSEL_3 ) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2, pin PE8 for COMP3 (for devices featuring COMP3 instance)) */
197 /**
198 * @}
199 */
200
201 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
202 * @{
203 */
204 #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
205 #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
206 #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
207 #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
208 /**
209 * @}
210 */
211
212 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
213 * @{
214 */
215 #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 */
216 #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 */
217 /**
218 * @}
219 */
220
221 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
222 * @{
223 */
224 #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
225 /* Note: Output blanking source common to all COMP instances */
226 #define LL_COMP_BLANKINGSRC_TIM1_OC4 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC4 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
227 #define LL_COMP_BLANKINGSRC_TIM1_OC5 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
228 #define LL_COMP_BLANKINGSRC_TIM2_OC3 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
229 #define LL_COMP_BLANKINGSRC_TIM3_OC3 (COMP_CSR_BLANKING_3) /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
230 #define LL_COMP_BLANKINGSRC_TIM15_OC2 (COMP_CSR_BLANKING_4) /*!< Comparator output blanking source TIM15 OC2 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
231 /**
232 * @}
233 */
234
235 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
236 * @{
237 */
238 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
239 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
240 /**
241 * @}
242 */
243
244 /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
245 * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
246 * not timeout values.
247 * For details on delays values, refer to descriptions in source code
248 * above each literal definition.
249 * @{
250 */
251
252 /* Delay for comparator startup time. */
253 /* Note: Delay required to reach propagation delay specification. */
254 /* Literal set to maximum value (refer to device datasheet, */
255 /* parameter "tSTART"). */
256 /* Unit: us */
257 #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
258
259 /* Delay for comparator voltage scaler stabilization time. */
260 /* Note: Voltage scaler is used when selecting comparator input */
261 /* based on VrefInt: VrefInt or subdivision of VrefInt. */
262 /* Literal set to maximum value (refer to device datasheet, */
263 /* parameter "tSTART_SCALER"). */
264 /* Unit: us */
265 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
266
267 /**
268 * @}
269 */
270
271 /**
272 * @}
273 */
274
275 /* Exported macro ------------------------------------------------------------*/
276 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
277 * @{
278 */
279 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
280 * @{
281 */
282
283 /**
284 * @brief Write a value in COMP register
285 * @param __INSTANCE__ comparator instance
286 * @param __REG__ Register to be written
287 * @param __VALUE__ Value to be written in the register
288 * @retval None
289 */
290 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
291
292 /**
293 * @brief Read a value in COMP register
294 * @param __INSTANCE__ comparator instance
295 * @param __REG__ Register to be read
296 * @retval Register value
297 */
298 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
299 /**
300 * @}
301 */
302
303 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
304 * @{
305 */
306
307 /**
308 * @brief Helper macro to select the COMP common instance
309 * to which is belonging the selected COMP instance.
310 * @note COMP common register instance can be used to
311 * set parameters common to several COMP instances.
312 * Refer to functions having argument "COMPxy_COMMON" as parameter.
313 * @param __COMPx__ COMP instance
314 * @retval COMP common instance or value "0" if there is no COMP common instance.
315 */
316 #if defined(COMP3)
317 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
318 ((((__COMPx__) == COMP3)) \
319 ? ( \
320 (COMP23_COMMON) \
321 ) \
322 : \
323 ( \
324 (COMP12_COMMON) \
325 ) \
326 )
327 #else
328 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
329 (COMP12_COMMON)
330 #endif /* COMP3 */
331
332 /**
333 * @}
334 */
335
336 /**
337 * @}
338 */
339
340 /* Exported functions --------------------------------------------------------*/
341 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
342 * @{
343 */
344
345 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
346 * @{
347 */
348
349 /**
350 * @brief Set window mode of a pair of comparators instances
351 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
352 * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
353 * @param COMPxy_COMMON Comparator common instance
354 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
355 * @param WindowMode This parameter can be one of the following values:
356 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
357 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (1)
358 * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (1)(2)
359 *
360 * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
361 * (2) Parameter specificity on devices STM32G0B1xx and STM32G0C1xx: only parameter that can be used only with comparator common instance COMP23_COMMON
362 * @retval None
363 */
LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowMode)364 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
365 {
366 uint32_t window_mode_tmp = WindowMode;
367
368 /* Note: On this STM32 series, window mode can be set from any instance */
369 /* of the pair of comparator instances. */
370 #if defined(COMP3)
371 /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
372 /* group of COMP2 and COMP3, instances odd and even are inverted. */
373 /* Perform switch of parameter selected. */
374 if(COMPxy_COMMON == COMP23_COMMON)
375 {
376 if(WindowMode == LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON)
377 {
378 window_mode_tmp = LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON;
379 }
380 }
381 #endif /* COMP3 */
382
383 __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
384
385 /* Clear the potential previous setting of window mode */
386 __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (~(window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & 0x1UL));
387 CLEAR_BIT(*preg_clear,
388 COMP_CSR_WINMODE
389 );
390
391 /* Set window mode */
392 MODIFY_REG(*preg,
393 COMP_CSR_WINMODE,
394 (window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_SETTING_MASK)
395 );
396 }
397
398 /**
399 * @brief Get window mode of a pair of comparators instances
400 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
401 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
402 * @param COMPxy_COMMON Comparator common instance
403 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
404 * @retval Returned value can be one of the following values:
405 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
406 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (1)
407 * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (1)(2)
408 *
409 * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
410 * (2) Parameter specificity on devices STM32G0B1xx and STM32G0C1xx: only parameter that can be used only with comparator common instance COMP23_COMMON
411 */
LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON)412 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
413 {
414 /* Note: On this STM32 series, window mode can be set from any instance */
415 /* of the pair of comparator instances. */
416 #if defined(COMP3)
417 uint32_t window_mode_comp_odd;
418 uint32_t window_mode_comp_even;
419
420 /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
421 /* group of COMP2 and COMP3, instances odd and even are inverted. */
422 /* Perform switch of parameter selected. */
423 if(COMPxy_COMMON == COMP23_COMMON)
424 {
425 window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
426 window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
427 }
428 else
429 {
430 window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
431 window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
432 }
433 #else
434 const uint32_t window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
435 const uint32_t window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
436 #endif /* COMP3 */
437
438 return (uint32_t)(window_mode_comp_odd
439 | window_mode_comp_even
440 | ((window_mode_comp_even >> LL_COMP_WINDOWMODE_BITOFFSET_POS) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK));
441 }
442
443 /**
444 * @brief Set window output of a pair of comparators instances
445 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
446 * @rmtoll CSR WINOUT LL_COMP_SetCommonWindowOutput
447 * @param COMPxy_COMMON Comparator common instance
448 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
449 * @param WindowOutput This parameter can be one of the following values:
450 * @arg @ref LL_COMP_WINDOWOUTPUT_EACH_COMP
451 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP1 (1)
452 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP2 (1)
453 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP3 (2)
454 * @arg @ref LL_COMP_WINDOWOUTPUT_BOTH
455 *
456 * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
457 * (2) Parameter available only on devices STM32G0B1xx and STM32G0C1xx, must be used with comparator common instance COMP23_COMMON
458 * @retval None
459 */
LL_COMP_SetCommonWindowOutput(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowOutput)460 __STATIC_INLINE void LL_COMP_SetCommonWindowOutput(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowOutput)
461 {
462 uint32_t window_output_tmp = WindowOutput;
463
464 #if defined(COMP3)
465 /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
466 /* group of COMP2 and COMP3, instances odd and even are inverted. */
467 /* Perform switch of parameter selected. */
468 if(COMPxy_COMMON == COMP23_COMMON)
469 {
470 if(WindowOutput == LL_COMP_WINDOWOUTPUT_COMP2)
471 {
472 window_output_tmp = LL_COMP_WINDOWOUTPUT_COMP3;
473 }
474 else if(WindowOutput == LL_COMP_WINDOWOUTPUT_COMP3)
475 {
476 window_output_tmp = LL_COMP_WINDOWOUTPUT_COMP2;
477 }
478 else
479 {
480 /* No modification of other parameters */
481 }
482 }
483 #endif /* COMP3 */
484
485 __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (window_output_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
486
487 /* Clear the potential previous setting of window output on the relevant comparator instance */
488 /* (clear bit of window output unless specific case of setting of comparator both output selected) */
489 __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (~(window_output_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & 0x1UL));
490 MODIFY_REG(*preg_clear,
491 COMP_CSR_WINOUT,
492 ((window_output_tmp & LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK) >> LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW)
493 );
494
495 /* Set window output */
496 MODIFY_REG(*preg,
497 COMP_CSR_WINOUT,
498 (window_output_tmp & LL_COMP_WINDOWOUTPUT_COMPX_SETTING_MASK)
499 );
500 }
501
502 /**
503 * @brief Get window output of a pair of comparators instances
504 * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
505 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowOutput
506 * @param COMPxy_COMMON Comparator common instance
507 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
508 * @retval Returned value can be one of the following values:
509 * @arg @ref LL_COMP_WINDOWOUTPUT_EACH_COMP
510 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP1 (1)
511 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP2 (1)
512 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP3 (2)
513 * @arg @ref LL_COMP_WINDOWOUTPUT_BOTH
514 *
515 * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
516 * (2) Parameter available only on devices STM32G0B1xx and STM32G0C1xx, must be used with comparator common instance COMP23_COMMON
517 */
LL_COMP_GetCommonWindowOutput(COMP_Common_TypeDef * COMPxy_COMMON)518 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowOutput(COMP_Common_TypeDef *COMPxy_COMMON)
519 {
520 #if defined(COMP3)
521 uint32_t window_output_comp_odd;
522 uint32_t window_output_comp_even;
523
524 /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
525 /* group of COMP2 and COMP3, instances odd and even are inverted. */
526 /* Perform switch of parameter selected. */
527 if(COMPxy_COMMON == COMP23_COMMON)
528 {
529 window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
530 window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
531 }
532 else
533 {
534 window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
535 window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
536 }
537 #else
538 const uint32_t window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
539 const uint32_t window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
540 #endif /* COMP3 */
541
542 /* Construct value corresponding to LL_COMP_WINDOWOUTPUT_xxx */
543 return (uint32_t)(window_output_comp_odd
544 | window_output_comp_even
545 | ((window_output_comp_even >> COMP_CSR_WINOUT_Pos) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
546 | (window_output_comp_odd + window_output_comp_even));
547 }
548
549 /**
550 * @}
551 */
552
553 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
554 * @{
555 */
556
557 /**
558 * @brief Set comparator instance operating mode to adjust power and speed.
559 * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode
560 * @param COMPx Comparator instance
561 * @param PowerMode This parameter can be one of the following values:
562 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
563 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
564 * @retval None
565 */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)566 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
567 {
568 MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
569 }
570
571 /**
572 * @brief Get comparator instance operating mode to adjust power and speed.
573 * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode
574 * @param COMPx Comparator instance
575 * @retval Returned value can be one of the following values:
576 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
577 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
578 */
LL_COMP_GetPowerMode(COMP_TypeDef * COMPx)579 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
580 {
581 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
582 }
583
584 /**
585 * @}
586 */
587
588 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
589 * @{
590 */
591
592 /**
593 * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
594 * @note In case of comparator input selected to be connected to IO:
595 * GPIO pins are specific to each comparator instance.
596 * Refer to description of parameters or to reference manual.
597 * @note On this STM32 series, a voltage scaler is used
598 * when COMP input is based on VrefInt (VrefInt or subdivision
599 * of VrefInt):
600 * Voltage scaler requires a delay for voltage stabilization.
601 * Refer to device datasheet, parameter "tSTART_SCALER".
602 * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
603 * CSR INPSEL LL_COMP_ConfigInputs\n
604 * @param COMPx Comparator instance
605 * @param InputMinus This parameter can be one of the following values:
606 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
607 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
608 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
609 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
610 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
611 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
612 * @arg @ref LL_COMP_INPUT_MINUS_IO1
613 * @arg @ref LL_COMP_INPUT_MINUS_IO2
614 * @arg @ref LL_COMP_INPUT_MINUS_IO3
615 * @param InputPlus This parameter can be one of the following values:
616 * @arg @ref LL_COMP_INPUT_PLUS_IO1
617 * @arg @ref LL_COMP_INPUT_PLUS_IO2
618 * @arg @ref LL_COMP_INPUT_PLUS_IO3
619 * @retval None
620 */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)621 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
622 {
623 MODIFY_REG(COMPx->CSR,
624 COMP_CSR_INMSEL | COMP_CSR_INPSEL,
625 InputMinus | InputPlus);
626 }
627
628 /**
629 * @brief Set comparator input plus (non-inverting).
630 * @note In case of comparator input selected to be connected to IO:
631 * GPIO pins are specific to each comparator instance.
632 * Refer to description of parameters or to reference manual.
633 * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
634 * @param COMPx Comparator instance
635 * @param InputPlus This parameter can be one of the following values:
636 * @arg @ref LL_COMP_INPUT_PLUS_IO1
637 * @arg @ref LL_COMP_INPUT_PLUS_IO2
638 * @arg @ref LL_COMP_INPUT_PLUS_IO3
639 * @retval None
640 */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)641 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
642 {
643 MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
644 }
645
646 /**
647 * @brief Get comparator input plus (non-inverting).
648 * @note In case of comparator input selected to be connected to IO:
649 * GPIO pins are specific to each comparator instance.
650 * Refer to description of parameters or to reference manual.
651 * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
652 * @param COMPx Comparator instance
653 * @retval Returned value can be one of the following values:
654 * @arg @ref LL_COMP_INPUT_PLUS_IO1
655 * @arg @ref LL_COMP_INPUT_PLUS_IO2
656 * @arg @ref LL_COMP_INPUT_PLUS_IO3
657 */
LL_COMP_GetInputPlus(COMP_TypeDef * COMPx)658 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
659 {
660 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
661 }
662
663 /**
664 * @brief Set comparator input minus (inverting).
665 * @note In case of comparator input selected to be connected to IO:
666 * GPIO pins are specific to each comparator instance.
667 * Refer to description of parameters or to reference manual.
668 * @note On this STM32 series, a voltage scaler is used
669 * when COMP input is based on VrefInt (VrefInt or subdivision
670 * of VrefInt):
671 * Voltage scaler requires a delay for voltage stabilization.
672 * Refer to device datasheet, parameter "tSTART_SCALER".
673 * @rmtoll CSR INMSEL LL_COMP_SetInputMinus
674 * @param COMPx Comparator instance
675 * @param InputMinus This parameter can be one of the following values:
676 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
677 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
678 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
679 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
680 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
681 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
682 * @arg @ref LL_COMP_INPUT_MINUS_IO1
683 * @arg @ref LL_COMP_INPUT_MINUS_IO2
684 * @arg @ref LL_COMP_INPUT_MINUS_IO3
685 * @retval None
686 */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)687 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
688 {
689 MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL, InputMinus);
690 }
691
692 /**
693 * @brief Get comparator input minus (inverting).
694 * @note In case of comparator input selected to be connected to IO:
695 * GPIO pins are specific to each comparator instance.
696 * Refer to description of parameters or to reference manual.
697 * @rmtoll CSR INMSEL LL_COMP_GetInputMinus
698 * @param COMPx Comparator instance
699 * @retval Returned value can be one of the following values:
700 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
701 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
702 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
703 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
704 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
705 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
706 * @arg @ref LL_COMP_INPUT_MINUS_IO1
707 * @arg @ref LL_COMP_INPUT_MINUS_IO2
708 * @arg @ref LL_COMP_INPUT_MINUS_IO3
709 */
LL_COMP_GetInputMinus(COMP_TypeDef * COMPx)710 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
711 {
712 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL));
713 }
714
715 /**
716 * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
717 * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
718 * @param COMPx Comparator instance
719 * @param InputHysteresis This parameter can be one of the following values:
720 * @arg @ref LL_COMP_HYSTERESIS_NONE
721 * @arg @ref LL_COMP_HYSTERESIS_LOW
722 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
723 * @arg @ref LL_COMP_HYSTERESIS_HIGH
724 * @retval None
725 */
LL_COMP_SetInputHysteresis(COMP_TypeDef * COMPx,uint32_t InputHysteresis)726 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
727 {
728 MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
729 }
730
731 /**
732 * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
733 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
734 * @param COMPx Comparator instance
735 * @retval Returned value can be one of the following values:
736 * @arg @ref LL_COMP_HYSTERESIS_NONE
737 * @arg @ref LL_COMP_HYSTERESIS_LOW
738 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
739 * @arg @ref LL_COMP_HYSTERESIS_HIGH
740 */
LL_COMP_GetInputHysteresis(COMP_TypeDef * COMPx)741 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
742 {
743 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
744 }
745
746 /**
747 * @}
748 */
749
750 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
751 * @{
752 */
753
754 /**
755 * @brief Set comparator instance output polarity.
756 * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
757 * @param COMPx Comparator instance
758 * @param OutputPolarity This parameter can be one of the following values:
759 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
760 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
761 * @retval None
762 */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)763 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
764 {
765 MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
766 }
767
768 /**
769 * @brief Get comparator instance output polarity.
770 * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
771 * @param COMPx Comparator instance
772 * @retval Returned value can be one of the following values:
773 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
774 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
775 */
LL_COMP_GetOutputPolarity(COMP_TypeDef * COMPx)776 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
777 {
778 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
779 }
780
781 /**
782 * @brief Set comparator instance blanking source.
783 * @note Blanking source may be specific to each comparator instance.
784 * Refer to description of parameters or to reference manual.
785 * @note Availability of parameters of blanking source from timer
786 * depends on timers availability on the selected device.
787 * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource
788 * @param COMPx Comparator instance
789 * @param BlankingSource This parameter can be one of the following values:
790 * @arg @ref LL_COMP_BLANKINGSRC_NONE
791 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC4 (1)
792 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 (1)
793 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 (1)
794 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3 (1)
795 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2 (1)
796 *
797 * (1) Parameter availability depending on timer availability
798 * on the selected device.
799 * @retval None
800 */
LL_COMP_SetOutputBlankingSource(COMP_TypeDef * COMPx,uint32_t BlankingSource)801 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
802 {
803 MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
804 }
805
806 /**
807 * @brief Get comparator instance blanking source.
808 * @note Availability of parameters of blanking source from timer
809 * depends on timers availability on the selected device.
810 * @note Blanking source may be specific to each comparator instance.
811 * Refer to description of parameters or to reference manual.
812 * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource
813 * @param COMPx Comparator instance
814 * @retval Returned value can be one of the following values:
815 * @arg @ref LL_COMP_BLANKINGSRC_NONE
816 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC4 (1)
817 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 (1)
818 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 (1)
819 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3 (1)
820 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2 (1)
821 *
822 * (1) Parameter availability depending on timer availability
823 * on the selected device.
824 */
LL_COMP_GetOutputBlankingSource(COMP_TypeDef * COMPx)825 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
826 {
827 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
828 }
829
830 /**
831 * @}
832 */
833
834 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
835 * @{
836 */
837
838 /**
839 * @brief Enable comparator instance.
840 * @note After enable from off state, comparator requires a delay
841 * to reach reach propagation delay specification.
842 * Refer to device datasheet, parameter "tSTART".
843 * @rmtoll CSR EN LL_COMP_Enable
844 * @param COMPx Comparator instance
845 * @retval None
846 */
LL_COMP_Enable(COMP_TypeDef * COMPx)847 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
848 {
849 SET_BIT(COMPx->CSR, COMP_CSR_EN);
850 }
851
852 /**
853 * @brief Disable comparator instance.
854 * @rmtoll CSR EN LL_COMP_Disable
855 * @param COMPx Comparator instance
856 * @retval None
857 */
LL_COMP_Disable(COMP_TypeDef * COMPx)858 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
859 {
860 CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
861 }
862
863 /**
864 * @brief Get comparator enable state
865 * (0: COMP is disabled, 1: COMP is enabled)
866 * @rmtoll CSR EN LL_COMP_IsEnabled
867 * @param COMPx Comparator instance
868 * @retval State of bit (1 or 0).
869 */
LL_COMP_IsEnabled(COMP_TypeDef * COMPx)870 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
871 {
872 return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
873 }
874
875 /**
876 * @brief Lock comparator instance.
877 * @note Once locked, comparator configuration can be accessed in read-only.
878 * @note The only way to unlock the comparator is a device hardware reset.
879 * @rmtoll CSR LOCK LL_COMP_Lock
880 * @param COMPx Comparator instance
881 * @retval None
882 */
LL_COMP_Lock(COMP_TypeDef * COMPx)883 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
884 {
885 SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
886 }
887
888 /**
889 * @brief Get comparator lock state
890 * (0: COMP is unlocked, 1: COMP is locked).
891 * @note Once locked, comparator configuration can be accessed in read-only.
892 * @note The only way to unlock the comparator is a device hardware reset.
893 * @rmtoll CSR LOCK LL_COMP_IsLocked
894 * @param COMPx Comparator instance
895 * @retval State of bit (1 or 0).
896 */
LL_COMP_IsLocked(COMP_TypeDef * COMPx)897 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
898 {
899 return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
900 }
901
902 /**
903 * @brief Read comparator instance output level.
904 * @note The comparator output level depends on the selected polarity
905 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
906 * If the comparator polarity is not inverted:
907 * - Comparator output is low when the input plus
908 * is at a lower voltage than the input minus
909 * - Comparator output is high when the input plus
910 * is at a higher voltage than the input minus
911 * If the comparator polarity is inverted:
912 * - Comparator output is high when the input plus
913 * is at a lower voltage than the input minus
914 * - Comparator output is low when the input plus
915 * is at a higher voltage than the input minus
916 * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
917 * @param COMPx Comparator instance
918 * @retval Returned value can be one of the following values:
919 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
920 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
921 */
LL_COMP_ReadOutputLevel(COMP_TypeDef * COMPx)922 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
923 {
924 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
925 >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
926 }
927
928 /**
929 * @}
930 */
931
932 #if defined(USE_FULL_LL_DRIVER)
933 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
934 * @{
935 */
936
937 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
938 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
939 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
940
941 /**
942 * @}
943 */
944 #endif /* USE_FULL_LL_DRIVER */
945
946 /**
947 * @}
948 */
949
950 /**
951 * @}
952 */
953
954 /**
955 * @}
956 */
957
958 #endif /* COMP1 || COMP2 */
959
960 /**
961 * @}
962 */
963
964 #ifdef __cplusplus
965 }
966 #endif
967
968 #endif /* STM32G0xx_LL_COMP_H */
969