Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_ll_comp.h
blob243c89ded388c8b21645d35a5fdc0c37c5278d66
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; 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
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx.h"
31 /** @addtogroup STM32H7xx_LL_Driver
32 * @{
35 #if defined (COMP1) || defined (COMP2)
37 /** @defgroup COMP_LL COMP
38 * @{
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup COMP_LL_Private_Constants COMP Private Constants
45 * @{
48 /* COMP registers bits positions */
49 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
51 /**
52 * @}
55 /* Private macros ------------------------------------------------------------*/
56 /* Exported types ------------------------------------------------------------*/
57 #if defined(USE_FULL_LL_DRIVER)
58 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
59 * @{
62 /**
63 * @brief Structure definition of some features of COMP instance.
65 typedef struct
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;
99 /**
100 * @}
102 #endif /* USE_FULL_LL_DRIVER */
104 /* Exported constants --------------------------------------------------------*/
105 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
106 * @{
109 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
110 * @{
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). */
115 * @}
118 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
119 * @{
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 */
125 * @}
128 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
129 * @{
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) */
135 #endif
137 * @}
140 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
141 * @{
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) */
154 #endif
156 * @}
159 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
160 * @{
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 */
167 * @}
170 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
171 * @{
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 */
176 * @}
179 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
180 * @{
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) */
190 * @}
193 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
194 * @{
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) */
199 * @}
201 /** @defgroup COMP_LL_EC_OUTPUT_BKIN_TIMER Comparator output - Output to BKIN timer
202 * @{
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 */
216 * @}
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.
224 * @{
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"). */
231 /* Unit: us */
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"). */
239 /* Unit: us */
240 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
243 * @}
247 * @}
250 /* Exported macro ------------------------------------------------------------*/
251 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
252 * @{
254 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
255 * @{
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
263 * @retval None
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__)
275 * @}
278 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
279 * @{
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__) \
292 (COMP12_COMMON)
295 * @}
299 * @}
302 /* Exported functions --------------------------------------------------------*/
303 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
304 * @{
307 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
308 * @{
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
320 * @retval None
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));
345 * @}
348 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
349 * @{
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
360 * @retval None
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));
382 * @}
385 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
386 * @{
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 #if defined (COMP_CFGRx_INMSEL_3)
421 * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
422 * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
423 #endif
424 * @param InputPlus This parameter can be one of the following values:
425 * @arg @ref LL_COMP_INPUT_PLUS_IO1
426 * @arg @ref LL_COMP_INPUT_PLUS_IO2
427 #if defined (COMP_CFGRx_INP2SEL)
428 * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
429 #endif
430 * @retval None
432 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
434 #if defined (COMP_CFGRx_INP2SEL)
435 MODIFY_REG(COMPx->CFGR,
436 COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL |
437 COMP_CFGRx_INP2SEL |
438 COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN,
439 InputMinus | InputPlus);
440 #else
441 MODIFY_REG(COMPx->CFGR,
442 COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL |
443 COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN,
444 InputMinus | InputPlus);
445 #endif
449 * @brief Set comparator input plus (non-inverting).
450 * @note In case of comparator input selected to be connected to IO:
451 * GPIO pins are specific to each comparator instance.
452 * Refer to description of parameters or to reference manual.
453 * @rmtoll CFGRx INPSEL LL_COMP_SetInputPlus
454 * @param COMPx Comparator instance
455 * @param InputPlus This parameter can be one of the following values:
456 * @arg @ref LL_COMP_INPUT_PLUS_IO1
457 * @arg @ref LL_COMP_INPUT_PLUS_IO2
458 #if defined (COMP_CFGRx_INP2SEL)
459 * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
460 #endif
461 * @retval None
463 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
465 #if defined (COMP_CFGRx_INP2SEL)
466 MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INPSEL | COMP_CFGRx_INP2SEL , InputPlus);
467 #else
468 MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INPSEL , InputPlus);
469 #endif
473 * @brief Get comparator input plus (non-inverting).
474 * @note In case of comparator input selected to be connected to IO:
475 * GPIO pins are specific to each comparator instance.
476 * Refer to description of parameters or to reference manual.
477 * @rmtoll CFGRx INPSEL LL_COMP_GetInputPlus
478 * @param COMPx Comparator instance
479 * @retval Returned value can be one of the following values:
480 * @arg @ref LL_COMP_INPUT_PLUS_IO1
481 * @arg @ref LL_COMP_INPUT_PLUS_IO2
482 #if defined (COMP_CFGRx_INP2SEL)
483 * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
484 #endif
486 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
488 #if defined (COMP_CFGRx_INP2SEL)
489 return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INPSEL | COMP_CFGRx_INP2SEL));
490 #else
491 return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INPSEL));
492 #endif
496 * @brief Set comparator input minus (inverting).
497 * @note In case of comparator input selected to be connected to IO:
498 * GPIO pins are specific to each comparator instance.
499 * Refer to description of parameters or to reference manual.
500 * @note On this STM32 serie, scaler bridge is configurable:
501 * to optimize power consumption, this function enables the
502 * voltage scaler bridge only when required
503 * (when selecting comparator input based on VrefInt: VrefInt or
504 * subdivision of VrefInt).
505 * - For scaler bridge power consumption values,
506 * refer to device datasheet, parameter "IDDA(SCALER)".
507 * - Voltage scaler requires a delay for voltage stabilization.
508 * Refer to device datasheet, parameter "tSTART_SCALER".
509 * - Scaler bridge is common for all comparator instances,
510 * therefore if at least one of the comparator instance
511 * is requiring the scaler bridge, it remains enabled.
512 * @rmtoll CFGRx INMSEL LL_COMP_SetInputMinus\n
513 * CFGRx BRGEN LL_COMP_SetInputMinus\n
514 * CFGRx SCALEN LL_COMP_SetInputMinus
515 * @param COMPx Comparator instance
516 * @param InputMinus This parameter can be one of the following values:
517 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
518 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
519 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
520 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
521 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
522 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
523 * @arg @ref LL_COMP_INPUT_MINUS_IO1
524 * @arg @ref LL_COMP_INPUT_MINUS_IO2
525 #if defined (COMP_CFGRx_INMSEL_3)
526 * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
527 * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
528 #endif
529 * @retval None
531 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
533 MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INMSEL | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN, InputMinus);
537 * @brief Get comparator input minus (inverting).
538 * @note In case of comparator input selected to be connected to IO:
539 * GPIO pins are specific to each comparator instance.
540 * Refer to description of parameters or to reference manual.
541 * @rmtoll CFGRx INMSEL LL_COMP_GetInputMinus\n
542 * CFGRx BRGEN LL_COMP_GetInputMinus\n
543 * CFGRx SCALEN LL_COMP_GetInputMinus
544 * @param COMPx Comparator instance
545 * @retval Returned value can be one of the following values:
546 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
547 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
548 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
549 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
550 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
551 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
552 * @arg @ref LL_COMP_INPUT_MINUS_IO1
553 * @arg @ref LL_COMP_INPUT_MINUS_IO2
554 #if defined (COMP_CFGRx_INMSEL_3)
555 * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
556 * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
557 #endif
559 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
561 return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INMSEL | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN));
565 * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
566 * @rmtoll CFGRx HYST LL_COMP_SetInputHysteresis
567 * @param COMPx Comparator instance
568 * @param InputHysteresis This parameter can be one of the following values:
569 * @arg @ref LL_COMP_HYSTERESIS_NONE
570 * @arg @ref LL_COMP_HYSTERESIS_LOW
571 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
572 * @arg @ref LL_COMP_HYSTERESIS_HIGH
573 * @retval None
575 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
577 MODIFY_REG(COMPx->CFGR, COMP_CFGRx_HYST, InputHysteresis);
581 * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
582 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
583 * @param COMPx Comparator instance
584 * @retval Returned value can be one of the following values:
585 * @arg @ref LL_COMP_HYSTERESIS_NONE
586 * @arg @ref LL_COMP_HYSTERESIS_LOW
587 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
588 * @arg @ref LL_COMP_HYSTERESIS_HIGH
590 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
592 return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_HYST));
596 * @}
599 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
600 * @{
604 * @brief Set comparator instance output polarity.
605 * @rmtoll CFGRx POLARITY LL_COMP_SetOutputPolarity
606 * @param COMPx Comparator instance
607 * @param OutputPolarity This parameter can be one of the following values:
608 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
609 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
610 * @retval None
612 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
614 MODIFY_REG(COMPx->CFGR, COMP_CFGRx_POLARITY, OutputPolarity);
618 * @brief Get comparator instance output polarity.
619 * @rmtoll CFGRx POLARITY LL_COMP_GetOutputPolarity
620 * @param COMPx Comparator instance
621 * @retval Returned value can be one of the following values:
622 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
623 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
625 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
627 return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_POLARITY));
631 * @brief Set comparator instance blanking source.
632 * @note Blanking source may be specific to each comparator instance.
633 * Refer to description of parameters or to reference manual.
634 * @note Availability of parameters of blanking source from timer
635 * depends on timers availability on the selected device.
636 * @rmtoll CFGR BLANKING LL_COMP_SetOutputBlankingSource
637 * @param COMPx Comparator instance
638 * @param BlankingSource This parameter can be one of the following values:
639 * @arg @ref LL_COMP_BLANKINGSRC_NONE
640 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
641 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
642 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
643 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
644 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
645 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
646 * @retval None
648 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
650 MODIFY_REG(COMPx->CFGR, COMP_CFGRx_BLANKING, BlankingSource);
654 * @brief Get comparator instance blanking source.
655 * @note Availability of parameters of blanking source from timer
656 * depends on timers availability on the selected device.
657 * @note Blanking source may be specific to each comparator instance.
658 * Refer to description of parameters or to reference manual.
659 * @rmtoll CFGR BLANKING LL_COMP_GetOutputBlankingSource
660 * @param COMPx Comparator instance
661 * @retval Returned value can be one of the following values:
662 * @arg @ref LL_COMP_BLANKINGSRC_NONE
663 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
664 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
665 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
666 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
667 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
668 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
670 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
672 return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_BLANKING));
675 /** @brief Set the output alternate function in the Option register
676 * in order to be used with the alternate function
677 * of the timer break input.
678 * @rmtoll OR AFOP COMP_LL_EC_OUTPUT_BKIN_TIMER
679 * @param COMPx specifies the instance.
680 * @param CompAFx specifies the Alternate Function source selection.
681 * This parameter can be one of the following values:
682 * @arg @ref LL_COMP_AF_PA6
683 * @arg @ref LL_COMP_AF_PA8
684 * @arg @ref LL_COMP_AF_PB12
685 * @arg @ref LL_COMP_AF_PE6
686 * @arg @ref LL_COMP_AF_PE15
687 * @arg @ref LL_COMP_AF_PG2
688 * @arg @ref LL_COMP_AF_PG3
689 * @arg @ref LL_COMP_AF_PG4
690 * @arg @ref LL_COMP_AF_PI1
691 * @arg @ref LL_COMP_AF_PI4
692 * @arg @ref LL_COMP_AF_PK2
693 * @retval None
695 __STATIC_INLINE void LL_COMP_SetOutputAlternateFunction(COMP_TypeDef *COMPx, uint32_t CompAFx)
697 MODIFY_REG(COMP12->OR, 0x7FFUL, (COMPx == COMP1) ? ((~CompAFx) & 0x7FFUL) : CompAFx);
700 /** @brief Get the output alternate function from the Option register.
701 * @rmtoll OR AFOP COMP_LL_EC_OUTPUT_BKIN_TIMER
702 * @param COMPx specifies the Comparator instance.
703 * @retval Returned value can be one of the following values:
704 * @arg @ref LL_COMP_AF_PA6
705 * @arg @ref LL_COMP_AF_PA8
706 * @arg @ref LL_COMP_AF_PB12
707 * @arg @ref LL_COMP_AF_PE6
708 * @arg @ref LL_COMP_AF_PE15
709 * @arg @ref LL_COMP_AF_PG2
710 * @arg @ref LL_COMP_AF_PG3
711 * @arg @ref LL_COMP_AF_PG4
712 * @arg @ref LL_COMP_AF_PI1
713 * @arg @ref LL_COMP_AF_PI4
714 * @arg @ref LL_COMP_AF_PK2
716 __STATIC_INLINE uint32_t LL_COMP_GetOutputAlternateFunction(COMP_TypeDef *COMPx )
718 return (uint32_t) ((COMPx == COMP1) ? ((~COMP12->OR) & 0x7FFUL) : (COMP12->OR & 0x7FFUL));
722 * @}
725 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
726 * @{
730 * @brief Enable comparator instance.
731 * @note After enable from off state, comparator requires a delay
732 * to reach reach propagation delay specification.
733 * Refer to device datasheet, parameter "tSTART".
734 * @rmtoll CFGR EN LL_COMP_Enable
735 * @param COMPx Comparator instance
736 * @retval None
738 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
740 SET_BIT(COMPx->CFGR, COMP_CFGRx_EN);
744 * @brief Disable comparator instance.
745 * @rmtoll CFGR EN LL_COMP_Disable
746 * @param COMPx Comparator instance
747 * @retval None
749 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
751 CLEAR_BIT(COMPx->CFGR, COMP_CFGRx_EN);
755 * @brief Get comparator enable state
756 * (0: COMP is disabled, 1: COMP is enabled)
757 * @rmtoll CFGR EN LL_COMP_IsEnabled
758 * @param COMPx Comparator instance
759 * @retval State of bit (1 or 0).
761 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
763 return ((READ_BIT(COMPx->CFGR, COMP_CFGRx_EN) == (COMP_CFGRx_EN)) ? 1UL : 0UL);
767 * @brief Lock comparator instance.
768 * @note Once locked, comparator configuration can be accessed in read-only.
769 * @note The only way to unlock the comparator is a device hardware reset.
770 * @rmtoll CFGR LOCK LL_COMP_Lock
771 * @param COMPx Comparator instance
772 * @retval None
774 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
776 SET_BIT(COMPx->CFGR, COMP_CFGRx_LOCK);
780 * @brief Get comparator lock state
781 * (0: COMP is unlocked, 1: COMP is locked).
782 * @note Once locked, comparator configuration can be accessed in read-only.
783 * @note The only way to unlock the comparator is a device hardware reset.
784 * @rmtoll CFGR LOCK LL_COMP_IsLocked
785 * @param COMPx Comparator instance
786 * @retval State of bit (1 or 0).
788 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
790 return ((READ_BIT(COMPx->CFGR, COMP_CFGRx_LOCK) == (COMP_CFGRx_LOCK)) ? 1UL : 0UL);
794 * @brief Read comparator instance output level.
795 * @note The comparator output level depends on the selected polarity
796 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
797 * If the comparator polarity is not inverted:
798 * - Comparator output is low when the input plus
799 * is at a lower voltage than the input minus
800 * - Comparator output is high when the input plus
801 * is at a higher voltage than the input minus
802 * If the comparator polarity is inverted:
803 * - Comparator output is high when the input plus
804 * is at a lower voltage than the input minus
805 * - Comparator output is low when the input plus
806 * is at a higher voltage than the input minus
807 * @rmtoll CFGR VALUE LL_COMP_ReadOutputLevel
808 * @param COMPx Comparator instance
809 * @retval Returned value can be one of the following values:
810 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
811 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
813 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
815 if (COMPx == COMP1)
817 return (uint32_t)(READ_BIT(COMP12->SR, COMP_SR_C1VAL));
819 else
821 return (uint32_t)((READ_BIT(COMP12->SR, COMP_SR_C2VAL))>> 1);
826 * @}
829 #if defined(USE_FULL_LL_DRIVER)
830 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
831 * @{
834 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
835 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
836 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
839 * @}
841 #endif /* USE_FULL_LL_DRIVER */
844 * @}
848 * @}
851 #endif /* COMP1 || COMP2 */
854 * @}
857 #ifdef __cplusplus
859 #endif
861 #endif /* __STM32H7xx_LL_COMP_H */
863 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/