STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_ll_comp.h
Go to the documentation of this file.
1 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32L4xx_LL_COMP_H
22 #define STM32L4xx_LL_COMP_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l4xx.h"
30 
35 #if defined (COMP1) || defined (COMP2)
36 
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
48 /* COMP registers bits positions */
49 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
50 
55 /* Private macros ------------------------------------------------------------*/
56 /* Exported types ------------------------------------------------------------*/
57 #if defined(USE_FULL_LL_DRIVER)
58 
65 typedef struct
66 {
67  uint32_t PowerMode;
72  uint32_t InputPlus;
77  uint32_t InputMinus;
82  uint32_t InputHysteresis;
87  uint32_t OutputPolarity;
98 
102 #endif /* USE_FULL_LL_DRIVER */
103 
104 /* Exported constants --------------------------------------------------------*/
112 #if defined(COMP2)
113 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL)
114 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE)
115 #endif /* COMP2 */
116 
123 #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL)
124 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0)
125 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0)
133 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL)
134 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0)
135 #if defined(COMP_CSR_INPSEL_1)
136 #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1)
137 #endif
138 
145 #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN)
146 #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN)
147 #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN)
148 #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN )
149 #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 )
150 #define LL_COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0)
151 #define LL_COMP_INPUT_MINUS_IO1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 )
152 #define LL_COMP_INPUT_MINUS_IO2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)
153 #if defined(COMP_CSR_INMESEL_1)
154 #define LL_COMP_INPUT_MINUS_IO3 ( COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)
155 #define LL_COMP_INPUT_MINUS_IO4 (COMP_CSR_INMESEL_1 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)
156 #define LL_COMP_INPUT_MINUS_IO5 (COMP_CSR_INMESEL_1 | COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)
157 #endif
158 
165 #define LL_COMP_WINDOWMODE_ENABLE LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
166 
167 #define LL_COMP_INVERTINGINPUT_1_4VREFINT LL_COMP_INPUT_MINUS_1_4VREFINT
168 #define LL_COMP_INVERTINGINPUT_1_2VREFINT LL_COMP_INPUT_MINUS_1_2VREFINT
169 #define LL_COMP_INVERTINGINPUT_3_4VREFINT LL_COMP_INPUT_MINUS_3_4VREFINT
170 #define LL_COMP_INVERTINGINPUT_VREFINT LL_COMP_INPUT_MINUS_VREFINT
171 #define LL_COMP_INVERTINGINPUT_DAC1 LL_COMP_INPUT_MINUS_DAC1_CH1
172 #define LL_COMP_INVERTINGINPUT_DAC2 LL_COMP_INPUT_MINUS_DAC1_CH2
173 #define LL_COMP_INVERTINGINPUT_IO1 LL_COMP_INPUT_MINUS_IO1
174 #define LL_COMP_INVERTINGINPUT_IO2 LL_COMP_INPUT_MINUS_IO2
175 #if defined(COMP_CSR_INMESEL_1)
176 #define LL_COMP_INVERTINGINPUT_IO3 LL_COMP_INPUT_MINUS_IO3
177 #define LL_COMP_INVERTINGINPUT_IO4 LL_COMP_INPUT_MINUS_IO4
178 #define LL_COMP_INVERTINGINPUT_IO5 LL_COMP_INPUT_MINUS_IO5
179 #endif
180 
181 #define LL_COMP_NONINVERTINGINPUT_IO1 LL_COMP_INPUT_PLUS_IO1
182 #define LL_COMP_NONINVERTINGINPUT_IO2 LL_COMP_INPUT_PLUS_IO2
183 #if defined(COMP_CSR_INPSEL_1)
184 #define LL_COMP_NONINVERTINGINPUT_IO3 LL_COMP_INPUT_PLUS_IO3
185 #endif
186 
193 #define LL_COMP_HYSTERESIS_NONE (0x00000000UL)
194 #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0)
195 #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 )
196 #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0)
204 #define LL_COMP_OUTPUTPOL_NONINVERTED (0x00000000UL)
205 #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY)
213 #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL)
214 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0)
215 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1)
216 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2)
217 #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0)
218 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1)
219 #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2)
227 #define LL_COMP_BLANKINGSRC_TIM1_OC5 (LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1)
228 #define LL_COMP_BLANKINGSRC_TIM2_OC3 (LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1)
229 #define LL_COMP_BLANKINGSRC_TIM3_OC3 (LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1)
230 
231 #define LL_COMP_BLANKINGSRC_TIM3_OC4 (LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2)
232 #define LL_COMP_BLANKINGSRC_TIM8_OC5 (LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2)
233 #define LL_COMP_BLANKINGSRC_TIM15_OC1 (LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2)
234 
241 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL)
242 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL)
255 /* Delay for comparator startup time. */
256 /* Note: Delay required to reach propagation delay specification. */
257 /* Literal set to maximum value (refer to device datasheet, */
258 /* parameter "tSTART"). */
259 /* Unit: us */
260 #define LL_COMP_DELAY_STARTUP_US ( 80UL)
262 /* Delay for comparator voltage scaler stabilization time. */
263 /* Note: Voltage scaler is used when selecting comparator input */
264 /* based on VrefInt: VrefInt or subdivision of VrefInt. */
265 /* Literal set to maximum value (refer to device datasheet, */
266 /* parameter "tSTART_SCALER"). */
267 /* Unit: us */
268 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL)
278 /* Exported macro ------------------------------------------------------------*/
279 
293 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
294 
301 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
302 
319 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
320  (COMP12_COMMON)
321 
330 /* Exported functions --------------------------------------------------------*/
335 #if defined(COMP2)
336 
351 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
352 {
353  /* Note: On this STM32 serie, window mode can be set only */
354  /* from COMP instance: COMP2. */
355  MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WINMODE, WindowMode);
356 }
357 
368 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
369 {
370  return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WINMODE));
371 }
372 
377 #endif /* COMP2 */
378 
392 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
393 {
394  MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
395 }
396 
406 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
407 {
408  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
409 }
410 
463 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
464 {
465 #if defined(COMP_CSR_INMESEL_1)
466  MODIFY_REG(COMPx->CSR,
467  COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
468  InputMinus | InputPlus);
469 #else
470  MODIFY_REG(COMPx->CSR,
471  COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
472  InputMinus | InputPlus);
473 #endif
474 }
475 
491 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
492 {
493  MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
494 }
495 
510 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
511 {
512  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
513 }
514 
552 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
553 {
554 #if defined(COMP_CSR_INMESEL_1)
555  MODIFY_REG(COMPx->CSR, COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
556 #else
557  MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
558 #endif
559 }
560 
585 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
586 {
587 #if defined(COMP_CSR_INMESEL_1)
588  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
589 #else
590  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
591 #endif
592 }
593 
605 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
606 {
607  MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
608 }
609 
620 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
621 {
622  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
623 }
624 
642 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
643 {
644  MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
645 }
646 
655 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
656 {
657  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
658 }
659 
683 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
684 {
685  MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
686 }
687 
710 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
711 {
712  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
713 }
714 
722 /* Old functions name kept for legacy purpose, to be replaced by the */
723 /* current functions name. */
724 __STATIC_INLINE void LL_COMP_SetInputNonInverting(COMP_TypeDef *COMPx, uint32_t InputNonInverting)
725 {
726  LL_COMP_SetInputPlus(COMPx, InputNonInverting);
727 }
728 __STATIC_INLINE uint32_t LL_COMP_GetInputNonInverting(COMP_TypeDef *COMPx)
729 {
730  return LL_COMP_GetInputPlus(COMPx);
731 }
732 
733 __STATIC_INLINE void LL_COMP_SetInputInverting(COMP_TypeDef *COMPx, uint32_t InputInverting)
734 {
735  LL_COMP_SetInputMinus(COMPx, InputInverting);
736 }
737 __STATIC_INLINE uint32_t LL_COMP_GetInputInverting(COMP_TypeDef *COMPx)
738 {
739  return LL_COMP_GetInputMinus(COMPx);
740 }
741 
759 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
760 {
761  SET_BIT(COMPx->CSR, COMP_CSR_EN);
762 }
763 
770 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
771 {
772  CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
773 }
774 
782 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
783 {
784  return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
785 }
786 
795 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
796 {
797  SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
798 }
799 
809 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
810 {
811  return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
812 }
813 
834 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
835 {
836  return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
837  >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
838 }
839 
844 #if defined(USE_FULL_LL_DRIVER)
845 
849 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
850 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
851 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
852 
856 #endif /* USE_FULL_LL_DRIVER */
857 
870 #endif /* COMP1 || COMP2 */
871 
876 #ifdef __cplusplus
877 }
878 #endif
879 
880 #endif /* STM32L4xx_LL_COMP_H */
881 
882 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
Set comparator inputs minus (inverting) and plus (non-inverting).
__STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
Disable comparator instance. CSR EN LL_COMP_Disable.
__STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
Set comparator instance blanking source.
__STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
Get window mode of a pair of comparators instances (2 consecutive COMP instances odd and even COMP<x>...
ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
Initialize some features of COMP instance.
__STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
Get comparator instance output polarity. CSR POLARITY LL_COMP_GetOutputPolarity. ...
__STATIC_INLINE uint32_t LL_COMP_GetInputNonInverting(COMP_TypeDef *COMPx)
__STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
Set comparator instance output polarity. CSR POLARITY LL_COMP_SetOutputPolarity. ...
__STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
Get comparator input plus (non-inverting).
Structure definition of some features of COMP instance.
__STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
Lock comparator instance.
__STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
Get comparator lock state (0: COMP is unlocked, 1: COMP is locked).
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
Get comparator instance blanking source.
__STATIC_INLINE void LL_COMP_SetInputNonInverting(COMP_TypeDef *COMPx, uint32_t InputNonInverting)
__STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
Get comparator instance operating mode to adjust power and speed. CSR PWRMODE LL_COMP_GetPowerMode.
__STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
Set comparator instance hysteresis mode of the input minus (inverting input). CSR HYST LL_COMP_SetIn...
__STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
Get comparator input minus (inverting).
__STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
Set window mode of a pair of comparators instances (2 consecutive COMP instances odd and even COMP<x>...
__STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
Set comparator instance operating mode to adjust power and speed. CSR PWRMODE LL_COMP_SetPowerMode.
__STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
Get comparator instance hysteresis mode of the minus (inverting) input. CSR HYST LL_COMP_GetInputHys...
__STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
Enable comparator instance.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
De-initialize registers of the selected COMP instance to their default reset values.
void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
Set each LL_COMP_InitTypeDef field to default value.
__STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
Set comparator input plus (non-inverting).
__STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
Read comparator instance output level.
__STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
Set comparator input minus (inverting).
__STATIC_INLINE uint32_t LL_COMP_GetInputInverting(COMP_TypeDef *COMPx)
__STATIC_INLINE void LL_COMP_SetInputInverting(COMP_TypeDef *COMPx, uint32_t InputInverting)
__STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
Get comparator enable state (0: COMP is disabled, 1: COMP is enabled) CSR EN LL_COMP_IsEnabled.