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