2 ******************************************************************************
3 * @file stm32h7xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef __STM32H7xx_LL_COMP_H
22 #define __STM32H7xx_LL_COMP_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx.h"
31 /** @addtogroup STM32H7xx_LL_Driver
35 #if defined (COMP1) || defined (COMP2)
37 /** @defgroup COMP_LL COMP
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup COMP_LL_Private_Constants COMP Private Constants
48 /* COMP registers bits positions */
49 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
55 /* Private macros ------------------------------------------------------------*/
56 /* Exported types ------------------------------------------------------------*/
57 #if defined(USE_FULL_LL_DRIVER)
58 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
63 * @brief Structure definition of some features of COMP instance.
67 uint32_t PowerMode
; /*!< Set comparator operating mode to adjust power and speed.
68 This parameter can be a value of @ref COMP_LL_EC_POWERMODE
70 This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
72 uint32_t InputPlus
; /*!< Set comparator input plus (non-inverting input).
73 This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
75 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
77 uint32_t InputMinus
; /*!< Set comparator input minus (inverting input).
78 This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
80 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
82 uint32_t InputHysteresis
; /*!< Set comparator hysteresis mode of the input minus.
83 This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
85 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
87 uint32_t OutputPolarity
; /*!< Set comparator output polarity.
88 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
90 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
92 uint32_t OutputBlankingSource
; /*!< Set comparator blanking source.
93 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
95 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */
97 } LL_COMP_InitTypeDef
;
102 #endif /* USE_FULL_LL_DRIVER */
104 /* Exported constants --------------------------------------------------------*/
105 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
109 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
112 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
113 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CFGRx_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). */
118 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
121 #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
122 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CFGRx_PWRMODE_0) /*!< COMP power mode to medium speed */
123 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CFGRx_PWRMODE_1 | COMP_CFGRx_PWRMODE_0) /*!< COMP power mode to ultra-low power */
128 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
131 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PB0 for COMP1, pin PE9 for COMP2) */
132 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CFGRx_INPSEL) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PE11 for COMP2) */
133 #if defined (COMP_CFGRx_INP2SEL)
134 #define LL_COMP_INPUT_PLUS_DAC2_CH1 (COMP_CFGRx_INP2SEL) /*!< Comparator input plus 2 connected to (DAC2_CH1 for COMP1) */
140 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
143 #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
144 #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
145 #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
146 #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN ) /*!< Comparator input minus connected to VrefInt */
147 #define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CFGRx_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
148 #define LL_COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
149 #define LL_COMP_INPUT_MINUS_IO1 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PE10 for COMP2) */
150 #define LL_COMP_INPUT_MINUS_IO2 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PE7 for COMP2) */
151 #if defined (COMP_CFGRx_INMSEL_3)
152 #define LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1 (COMP_CFGRx_INMSEL_3 ) /*!< Comparator input minus connected to (temp sensor which is exist in ADC for COMP1, DAC2_CH1 for COMP2) */
153 #define LL_COMP_INPUT_MINUS_VBAT_VDDAP (COMP_CFGRx_INMSEL_3 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to (VBAT/4 for COMP1, VDDAP for COMP2) */
159 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
162 #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
163 #define LL_COMP_HYSTERESIS_LOW ( COMP_CFGRx_HYST_0) /*!< Hysteresis level low */
164 #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CFGRx_HYST_1 ) /*!< Hysteresis level medium */
165 #define LL_COMP_HYSTERESIS_HIGH (COMP_CFGRx_HYST_1 | COMP_CFGRx_HYST_0) /*!< Hysteresis level high */
170 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
173 #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 */
174 #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CFGRx_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 */
179 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
182 #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
183 #define LL_COMP_BLANKINGSRC_TIM1_OC5 (COMP_CFGRx_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2) */
184 #define LL_COMP_BLANKINGSRC_TIM2_OC3 (COMP_CFGRx_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2) */
185 #define LL_COMP_BLANKINGSRC_TIM3_OC3 (COMP_CFGRx_BLANKING_0 |COMP_CFGRx_BLANKING_1) /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2) */
186 #define LL_COMP_BLANKINGSRC_TIM3_OC4 (COMP_CFGRx_BLANKING_2) /*!< Comparator output blanking source TIM3 OC4 (common to all COMP instances: COMP1, COMP2) */
187 #define LL_COMP_BLANKINGSRC_TIM8_OC5 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_0) /*!< Comparator output blanking source TIM8 OC5 (common to all COMP instances: COMP1, COMP2) */
188 #define LL_COMP_BLANKINGSRC_TIM15_OC1 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_1) /*!< Comparator output blanking source TIM15 OC1 (common to all COMP instances: COMP1, COMP2) */
193 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
196 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
197 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
201 /** @defgroup COMP_LL_EC_OUTPUT_BKIN_TIMER Comparator output - Output to BKIN timer
204 #define LL_COMP_AF_PA6 COMP_OR_AFOPA6 /*!< Comparator Alternate Function PA6 source selected to timer BKIN input */
205 #define LL_COMP_AF_PA8 COMP_OR_AFOPA8 /*!< Comparator Alternate Function PA8 source selected to timer BKIN input */
206 #define LL_COMP_AF_PB12 COMP_OR_AFOPB12 /*!< Comparator Alternate Function PB12 source selected to timer BKIN input */
207 #define LL_COMP_AF_PE6 COMP_OR_AFOPE6 /*!< Comparator Alternate Function PE6 source selected to timer BKIN input */
208 #define LL_COMP_AF_PE15 COMP_OR_AFOPE15 /*!< Comparator Alternate Function PE15 source selected to timer BKIN input */
209 #define LL_COMP_AF_PG2 COMP_OR_AFOPG2 /*!< Comparator Alternate Function PG2 source selected to timer BKIN input */
210 #define LL_COMP_AF_PG3 COMP_OR_AFOPG3 /*!< Comparator Alternate Function PG3 source selected to timer BKIN input */
211 #define LL_COMP_AF_PG4 COMP_OR_AFOPG4 /*!< Comparator Alternate Function PG4 source selected to timer BKIN input */
212 #define LL_COMP_AF_PI1 COMP_OR_AFOPI1 /*!< Comparator Alternate Function PI1 source selected to timer BKIN input */
213 #define LL_COMP_AF_PI4 COMP_OR_AFOPI4 /*!< Comparator Alternate Function PI4 source selected to timer BKIN input */
214 #define LL_COMP_AF_PK2 COMP_OR_AFOPK2 /*!< Comparator Alternate Function PK2 source selected to timer BKIN input */
219 /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
220 * @note Only COMP IP HW delays are defined in COMP LL driver driver,
221 * not timeout values.
222 * For details on delays values, refer to descriptions in source code
223 * above each literal definition.
227 /* Delay for comparator startup time. */
228 /* Note: Delay required to reach propagation delay specification. */
229 /* Literal set to maximum value (refer to device datasheet, */
230 /* parameter "tSTART"). */
232 #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
234 /* Delay for comparator voltage scaler stabilization time. */
235 /* Note: Voltage scaler is used when selecting comparator input */
236 /* based on VrefInt: VrefInt or subdivision of VrefInt. */
237 /* Literal set to maximum value (refer to device datasheet, */
238 /* parameter "tSTART_SCALER"). */
240 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
250 /* Exported macro ------------------------------------------------------------*/
251 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
254 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
259 * @brief Write a value in COMP register
260 * @param __INSTANCE__ comparator instance
261 * @param __REG__ Register to be written
262 * @param __VALUE__ Value to be written in the register
265 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
268 * @brief Read a value in COMP register
269 * @param __INSTANCE__ comparator instance
270 * @param __REG__ Register to be read
271 * @retval Register value
273 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
278 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
283 * @brief Helper macro to select the COMP common instance
284 * to which is belonging the selected COMP instance.
285 * @note COMP common register instance can be used to
286 * set parameters common to several COMP instances.
287 * Refer to functions having argument "COMPxy_COMMON" as parameter.
288 * @param __COMPx__ COMP instance
289 * @retval COMP common instance or value "0" if there is no COMP common instance.
291 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
302 /* Exported functions --------------------------------------------------------*/
303 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
307 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
312 * @brief Set window mode of a pair of comparators instances
313 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
314 * @rmtoll CFGRx WINMODE LL_COMP_SetCommonWindowMode
315 * @param COMPxy_COMMON Comparator common instance
316 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
317 * @param WindowMode This parameter can be one of the following values:
318 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
319 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
322 __STATIC_INLINE
void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef
*COMPxy_COMMON
, uint32_t WindowMode
)
324 /* Note: On this STM32 serie, window mode can be set only */
325 /* from COMP instance: COMP2. */
326 MODIFY_REG(COMPxy_COMMON
->CFGR
, COMP_CFGRx_WINMODE
, WindowMode
);
330 * @brief Get window mode of a pair of comparators instances
331 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
332 * @rmtoll CFGRx WINMODE LL_COMP_GetCommonWindowMode
333 * @param COMPxy_COMMON Comparator common instance
334 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
335 * @retval Returned value can be one of the following values:
336 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
337 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
339 __STATIC_INLINE
uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef
*COMPxy_COMMON
)
341 return (uint32_t)(READ_BIT(COMPxy_COMMON
->CFGR
, COMP_CFGRx_WINMODE
));
348 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
353 * @brief Set comparator instance operating mode to adjust power and speed.
354 * @rmtoll CFGRx PWRMODE LL_COMP_SetPowerMode
355 * @param COMPx Comparator instance
356 * @param PowerMode This parameter can be one of the following values:
357 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
358 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
359 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
362 __STATIC_INLINE
void LL_COMP_SetPowerMode(COMP_TypeDef
*COMPx
, uint32_t PowerMode
)
364 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_PWRMODE
, PowerMode
);
368 * @brief Get comparator instance operating mode to adjust power and speed.
369 * @rmtoll CFGRx PWRMODE LL_COMP_GetPowerMode
370 * @param COMPx Comparator instance
371 * @retval Returned value can be one of the following values:
372 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
373 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
374 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
376 __STATIC_INLINE
uint32_t LL_COMP_GetPowerMode(COMP_TypeDef
*COMPx
)
378 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_PWRMODE
));
385 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
390 * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
391 * @note In case of comparator input selected to be connected to IO:
392 * GPIO pins are specific to each comparator instance.
393 * Refer to description of parameters or to reference manual.
394 * @note On this STM32 serie, scaler bridge is configurable:
395 * to optimize power consumption, this function enables the
396 * voltage scaler bridge only when required
397 * (when selecting comparator input based on VrefInt: VrefInt or
398 * subdivision of VrefInt).
399 * - For scaler bridge power consumption values,
400 * refer to device datasheet, parameter "IDDA(SCALER)".
401 * - Voltage scaler requires a delay for voltage stabilization.
402 * Refer to device datasheet, parameter "tSTART_SCALER".
403 * - Scaler bridge is common for all comparator instances,
404 * therefore if at least one of the comparator instance
405 * is requiring the scaler bridge, it remains enabled.
406 * @rmtoll CFGRx INMSEL LL_COMP_ConfigInputs\n
407 * CFGRx INPSEL LL_COMP_ConfigInputs\n
408 * CFGRx BRGEN LL_COMP_ConfigInputs\n
409 * CFGRx SCALEN LL_COMP_ConfigInputs
410 * @param COMPx Comparator instance
411 * @param InputMinus This parameter can be one of the following values:
412 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
413 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
414 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
415 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
416 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
417 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
418 * @arg @ref LL_COMP_INPUT_MINUS_IO1
419 * @arg @ref LL_COMP_INPUT_MINUS_IO2
420 * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
421 * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
422 * @param InputPlus This parameter can be one of the following values:
423 * @arg @ref LL_COMP_INPUT_PLUS_IO1
424 * @arg @ref LL_COMP_INPUT_PLUS_IO2
425 * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
428 __STATIC_INLINE
void LL_COMP_ConfigInputs(COMP_TypeDef
*COMPx
, uint32_t InputMinus
, uint32_t InputPlus
)
430 #if defined (COMP_CFGRx_INP2SEL)
431 MODIFY_REG(COMPx
->CFGR
,
432 COMP_CFGRx_INMSEL
| COMP_CFGRx_INPSEL
|
434 COMP_CFGRx_SCALEN
| COMP_CFGRx_BRGEN
,
435 InputMinus
| InputPlus
);
437 MODIFY_REG(COMPx
->CFGR
,
438 COMP_CFGRx_INMSEL
| COMP_CFGRx_INPSEL
|
439 COMP_CFGRx_SCALEN
| COMP_CFGRx_BRGEN
,
440 InputMinus
| InputPlus
);
445 * @brief Set comparator input plus (non-inverting).
446 * @note In case of comparator input selected to be connected to IO:
447 * GPIO pins are specific to each comparator instance.
448 * Refer to description of parameters or to reference manual.
449 * @rmtoll CFGRx INPSEL LL_COMP_SetInputPlus
450 * @param COMPx Comparator instance
451 * @param InputPlus This parameter can be one of the following values:
452 * @arg @ref LL_COMP_INPUT_PLUS_IO1
453 * @arg @ref LL_COMP_INPUT_PLUS_IO2
454 * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
457 __STATIC_INLINE
void LL_COMP_SetInputPlus(COMP_TypeDef
*COMPx
, uint32_t InputPlus
)
459 #if defined (COMP_CFGRx_INP2SEL)
460 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_INPSEL
| COMP_CFGRx_INP2SEL
, InputPlus
);
462 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_INPSEL
, InputPlus
);
467 * @brief Get comparator input plus (non-inverting).
468 * @note In case of comparator input selected to be connected to IO:
469 * GPIO pins are specific to each comparator instance.
470 * Refer to description of parameters or to reference manual.
471 * @rmtoll CFGRx INPSEL LL_COMP_GetInputPlus
472 * @param COMPx Comparator instance
473 * @retval Returned value can be one of the following values:
474 * @arg @ref LL_COMP_INPUT_PLUS_IO1
475 * @arg @ref LL_COMP_INPUT_PLUS_IO2
476 * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
478 __STATIC_INLINE
uint32_t LL_COMP_GetInputPlus(COMP_TypeDef
*COMPx
)
480 #if defined (COMP_CFGRx_INP2SEL)
481 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_INPSEL
| COMP_CFGRx_INP2SEL
));
483 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_INPSEL
));
488 * @brief Set comparator input minus (inverting).
489 * @note In case of comparator input selected to be connected to IO:
490 * GPIO pins are specific to each comparator instance.
491 * Refer to description of parameters or to reference manual.
492 * @note On this STM32 serie, scaler bridge is configurable:
493 * to optimize power consumption, this function enables the
494 * voltage scaler bridge only when required
495 * (when selecting comparator input based on VrefInt: VrefInt or
496 * subdivision of VrefInt).
497 * - For scaler bridge power consumption values,
498 * refer to device datasheet, parameter "IDDA(SCALER)".
499 * - Voltage scaler requires a delay for voltage stabilization.
500 * Refer to device datasheet, parameter "tSTART_SCALER".
501 * - Scaler bridge is common for all comparator instances,
502 * therefore if at least one of the comparator instance
503 * is requiring the scaler bridge, it remains enabled.
504 * @rmtoll CFGRx INMSEL LL_COMP_SetInputMinus\n
505 * CFGRx BRGEN LL_COMP_SetInputMinus\n
506 * CFGRx SCALEN LL_COMP_SetInputMinus
507 * @param COMPx Comparator instance
508 * @param InputMinus This parameter can be one of the following values:
509 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
510 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
511 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
512 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
513 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
514 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
515 * @arg @ref LL_COMP_INPUT_MINUS_IO1
516 * @arg @ref LL_COMP_INPUT_MINUS_IO2
517 * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
518 * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
521 __STATIC_INLINE
void LL_COMP_SetInputMinus(COMP_TypeDef
*COMPx
, uint32_t InputMinus
)
523 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_INMSEL
| COMP_CFGRx_SCALEN
| COMP_CFGRx_BRGEN
, InputMinus
);
527 * @brief Get comparator input minus (inverting).
528 * @note In case of comparator input selected to be connected to IO:
529 * GPIO pins are specific to each comparator instance.
530 * Refer to description of parameters or to reference manual.
531 * @rmtoll CFGRx INMSEL LL_COMP_GetInputMinus\n
532 * CFGRx BRGEN LL_COMP_GetInputMinus\n
533 * CFGRx SCALEN LL_COMP_GetInputMinus
534 * @param COMPx Comparator instance
535 * @retval Returned value can be one of the following values:
536 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
537 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
538 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
539 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
540 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
541 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
542 * @arg @ref LL_COMP_INPUT_MINUS_IO1
543 * @arg @ref LL_COMP_INPUT_MINUS_IO2
544 * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
545 * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
547 __STATIC_INLINE
uint32_t LL_COMP_GetInputMinus(COMP_TypeDef
*COMPx
)
549 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_INMSEL
| COMP_CFGRx_SCALEN
| COMP_CFGRx_BRGEN
));
553 * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
554 * @rmtoll CFGRx HYST LL_COMP_SetInputHysteresis
555 * @param COMPx Comparator instance
556 * @param InputHysteresis This parameter can be one of the following values:
557 * @arg @ref LL_COMP_HYSTERESIS_NONE
558 * @arg @ref LL_COMP_HYSTERESIS_LOW
559 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
560 * @arg @ref LL_COMP_HYSTERESIS_HIGH
563 __STATIC_INLINE
void LL_COMP_SetInputHysteresis(COMP_TypeDef
*COMPx
, uint32_t InputHysteresis
)
565 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_HYST
, InputHysteresis
);
569 * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
570 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
571 * @param COMPx Comparator instance
572 * @retval Returned value can be one of the following values:
573 * @arg @ref LL_COMP_HYSTERESIS_NONE
574 * @arg @ref LL_COMP_HYSTERESIS_LOW
575 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
576 * @arg @ref LL_COMP_HYSTERESIS_HIGH
578 __STATIC_INLINE
uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef
*COMPx
)
580 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_HYST
));
587 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
592 * @brief Set comparator instance output polarity.
593 * @rmtoll CFGRx POLARITY LL_COMP_SetOutputPolarity
594 * @param COMPx Comparator instance
595 * @param OutputPolarity This parameter can be one of the following values:
596 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
597 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
600 __STATIC_INLINE
void LL_COMP_SetOutputPolarity(COMP_TypeDef
*COMPx
, uint32_t OutputPolarity
)
602 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_POLARITY
, OutputPolarity
);
606 * @brief Get comparator instance output polarity.
607 * @rmtoll CFGRx POLARITY LL_COMP_GetOutputPolarity
608 * @param COMPx Comparator instance
609 * @retval Returned value can be one of the following values:
610 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
611 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
613 __STATIC_INLINE
uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef
*COMPx
)
615 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_POLARITY
));
619 * @brief Set comparator instance blanking source.
620 * @note Blanking source may be specific to each comparator instance.
621 * Refer to description of parameters or to reference manual.
622 * @note Availability of parameters of blanking source from timer
623 * depends on timers availability on the selected device.
624 * @rmtoll CFGR BLANKING LL_COMP_SetOutputBlankingSource
625 * @param COMPx Comparator instance
626 * @param BlankingSource This parameter can be one of the following values:
627 * @arg @ref LL_COMP_BLANKINGSRC_NONE
628 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
629 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
630 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
631 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
632 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
633 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
636 __STATIC_INLINE
void LL_COMP_SetOutputBlankingSource(COMP_TypeDef
*COMPx
, uint32_t BlankingSource
)
638 MODIFY_REG(COMPx
->CFGR
, COMP_CFGRx_BLANKING
, BlankingSource
);
642 * @brief Get comparator instance blanking source.
643 * @note Availability of parameters of blanking source from timer
644 * depends on timers availability on the selected device.
645 * @note Blanking source may be specific to each comparator instance.
646 * Refer to description of parameters or to reference manual.
647 * @rmtoll CFGR BLANKING LL_COMP_GetOutputBlankingSource
648 * @param COMPx Comparator instance
649 * @retval Returned value can be one of the following values:
650 * @arg @ref LL_COMP_BLANKINGSRC_NONE
651 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
652 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
653 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
654 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
655 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
656 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
658 __STATIC_INLINE
uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef
*COMPx
)
660 return (uint32_t)(READ_BIT(COMPx
->CFGR
, COMP_CFGRx_BLANKING
));
663 /** @brief Set the output alternate function in the Option register
664 * in order to be used with the alternate function
665 * of the timer break input.
666 * @rmtoll OR AFOP COMP_LL_EC_OUTPUT_BKIN_TIMER
667 * @param COMPx specifies the instance.
668 * @param CompAFx specifies the Alternate Function source selection.
669 * This parameter can be one of the following values:
670 * @arg @ref LL_COMP_AF_PA6
671 * @arg @ref LL_COMP_AF_PA8
672 * @arg @ref LL_COMP_AF_PB12
673 * @arg @ref LL_COMP_AF_PE6
674 * @arg @ref LL_COMP_AF_PE15
675 * @arg @ref LL_COMP_AF_PG2
676 * @arg @ref LL_COMP_AF_PG3
677 * @arg @ref LL_COMP_AF_PG4
678 * @arg @ref LL_COMP_AF_PI1
679 * @arg @ref LL_COMP_AF_PI4
680 * @arg @ref LL_COMP_AF_PK2
683 __STATIC_INLINE
void LL_COMP_SetOutputAlternateFunction(COMP_TypeDef
*COMPx
, uint32_t CompAFx
)
685 MODIFY_REG(COMP12
->OR
, 0x7FFUL
, (COMPx
== COMP1
) ? ((~CompAFx
) & 0x7FFUL
) : CompAFx
);
688 /** @brief Get the output alternate function from the Option register.
689 * @rmtoll OR AFOP COMP_LL_EC_OUTPUT_BKIN_TIMER
690 * @param COMPx specifies the Comparator instance.
691 * @retval Returned value can be one of the following values:
692 * @arg @ref LL_COMP_AF_PA6
693 * @arg @ref LL_COMP_AF_PA8
694 * @arg @ref LL_COMP_AF_PB12
695 * @arg @ref LL_COMP_AF_PE6
696 * @arg @ref LL_COMP_AF_PE15
697 * @arg @ref LL_COMP_AF_PG2
698 * @arg @ref LL_COMP_AF_PG3
699 * @arg @ref LL_COMP_AF_PG4
700 * @arg @ref LL_COMP_AF_PI1
701 * @arg @ref LL_COMP_AF_PI4
702 * @arg @ref LL_COMP_AF_PK2
704 __STATIC_INLINE
uint32_t LL_COMP_GetOutputAlternateFunction(COMP_TypeDef
*COMPx
)
706 return (uint32_t) ((COMPx
== COMP1
) ? ((~COMP12
->OR
) & 0x7FFUL
) : (COMP12
->OR
& 0x7FFUL
));
713 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
718 * @brief Enable comparator instance.
719 * @note After enable from off state, comparator requires a delay
720 * to reach reach propagation delay specification.
721 * Refer to device datasheet, parameter "tSTART".
722 * @rmtoll CFGR EN LL_COMP_Enable
723 * @param COMPx Comparator instance
726 __STATIC_INLINE
void LL_COMP_Enable(COMP_TypeDef
*COMPx
)
728 SET_BIT(COMPx
->CFGR
, COMP_CFGRx_EN
);
732 * @brief Disable comparator instance.
733 * @rmtoll CFGR EN LL_COMP_Disable
734 * @param COMPx Comparator instance
737 __STATIC_INLINE
void LL_COMP_Disable(COMP_TypeDef
*COMPx
)
739 CLEAR_BIT(COMPx
->CFGR
, COMP_CFGRx_EN
);
743 * @brief Get comparator enable state
744 * (0: COMP is disabled, 1: COMP is enabled)
745 * @rmtoll CFGR EN LL_COMP_IsEnabled
746 * @param COMPx Comparator instance
747 * @retval State of bit (1 or 0).
749 __STATIC_INLINE
uint32_t LL_COMP_IsEnabled(COMP_TypeDef
*COMPx
)
751 return ((READ_BIT(COMPx
->CFGR
, COMP_CFGRx_EN
) == (COMP_CFGRx_EN
)) ? 1UL : 0UL);
755 * @brief Lock comparator instance.
756 * @note Once locked, comparator configuration can be accessed in read-only.
757 * @note The only way to unlock the comparator is a device hardware reset.
758 * @rmtoll CFGR LOCK LL_COMP_Lock
759 * @param COMPx Comparator instance
762 __STATIC_INLINE
void LL_COMP_Lock(COMP_TypeDef
*COMPx
)
764 SET_BIT(COMPx
->CFGR
, COMP_CFGRx_LOCK
);
768 * @brief Get comparator lock state
769 * (0: COMP is unlocked, 1: COMP is locked).
770 * @note Once locked, comparator configuration can be accessed in read-only.
771 * @note The only way to unlock the comparator is a device hardware reset.
772 * @rmtoll CFGR LOCK LL_COMP_IsLocked
773 * @param COMPx Comparator instance
774 * @retval State of bit (1 or 0).
776 __STATIC_INLINE
uint32_t LL_COMP_IsLocked(COMP_TypeDef
*COMPx
)
778 return ((READ_BIT(COMPx
->CFGR
, COMP_CFGRx_LOCK
) == (COMP_CFGRx_LOCK
)) ? 1UL : 0UL);
782 * @brief Read comparator instance output level.
783 * @note The comparator output level depends on the selected polarity
784 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
785 * If the comparator polarity is not inverted:
786 * - Comparator output is low when the input plus
787 * is at a lower voltage than the input minus
788 * - Comparator output is high when the input plus
789 * is at a higher voltage than the input minus
790 * If the comparator polarity is inverted:
791 * - Comparator output is high when the input plus
792 * is at a lower voltage than the input minus
793 * - Comparator output is low when the input plus
794 * is at a higher voltage than the input minus
795 * @rmtoll CFGR VALUE LL_COMP_ReadOutputLevel
796 * @param COMPx Comparator instance
797 * @retval Returned value can be one of the following values:
798 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
799 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
801 __STATIC_INLINE
uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef
*COMPx
)
805 return (uint32_t)(READ_BIT(COMP12
->SR
, COMP_SR_C1VAL
));
809 return (uint32_t)((READ_BIT(COMP12
->SR
, COMP_SR_C2VAL
))>> 1);
817 #if defined(USE_FULL_LL_DRIVER)
818 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
822 ErrorStatus
LL_COMP_DeInit(COMP_TypeDef
*COMPx
);
823 ErrorStatus
LL_COMP_Init(COMP_TypeDef
*COMPx
, LL_COMP_InitTypeDef
*COMP_InitStruct
);
824 void LL_COMP_StructInit(LL_COMP_InitTypeDef
*COMP_InitStruct
);
829 #endif /* USE_FULL_LL_DRIVER */
839 #endif /* COMP1 || COMP2 */
849 #endif /* __STM32H7xx_LL_COMP_H */
851 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/