201 #ifdef HAL_COMP_MODULE_ENABLED 203 #if defined (COMP1) || defined (COMP2) 221 #define COMP_DELAY_STARTUP_US (80UL) 227 #define COMP_DELAY_VOLTAGE_SCALER_STAB_US (200UL) 229 #define COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) 269 uint32_t comp_voltage_scaler_initialized;
270 __IO uint32_t wait_loop_index = 0UL;
271 HAL_StatusTypeDef status =
HAL_OK;
278 else if(__HAL_COMP_IS_LOCKED(hcomp))
286 assert_param(IS_COMP_INPUT_PLUS(hcomp->Instance, hcomp->Init.NonInvertingInput));
287 assert_param(IS_COMP_INPUT_MINUS(hcomp->Instance, hcomp->Init.InvertingInput));
290 assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
291 assert_param(IS_COMP_BLANKINGSRC_INSTANCE(hcomp->Instance, hcomp->Init.BlankingSrce));
292 assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
294 assert_param(IS_COMP_WINDOWMODE(hcomp->Init.WindowMode));
303 COMP_CLEAR_ERRORCODE(hcomp);
314 __HAL_RCC_SYSCFG_CLK_ENABLE();
316 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 320 if (hcomp->MspInitCallback == NULL)
326 hcomp->MspInitCallback(hcomp);
334 comp_voltage_scaler_initialized = READ_BIT(hcomp->Instance->CSR, COMP_CSR_SCALEN);
337 tmp_csr = ( hcomp->Init.NonInvertingInput
338 | hcomp->Init.InvertingInput
339 | hcomp->Init.BlankingSrce
340 | hcomp->Init.Hysteresis
341 | hcomp->Init.OutputPol
347 #if defined (COMP_CSR_INMESEL) 348 #if defined (COMP_CSR_WINMODE) 350 COMP_CSR_PWRMODE | COMP_CSR_INMSEL | COMP_CSR_INPSEL |
351 COMP_CSR_WINMODE | COMP_CSR_POLARITY | COMP_CSR_HYST |
352 COMP_CSR_BLANKING | COMP_CSR_BRGEN | COMP_CSR_SCALEN | COMP_CSR_INMESEL,
357 COMP_CSR_PWRMODE | COMP_CSR_INMSEL | COMP_CSR_INPSEL |
358 COMP_CSR_POLARITY | COMP_CSR_HYST |
359 COMP_CSR_BLANKING | COMP_CSR_BRGEN | COMP_CSR_SCALEN | COMP_CSR_INMESEL,
365 COMP_CSR_PWRMODE | COMP_CSR_INMSEL | COMP_CSR_INPSEL |
366 COMP_CSR_WINMODE | COMP_CSR_POLARITY | COMP_CSR_HYST |
367 COMP_CSR_BLANKING | COMP_CSR_BRGEN | COMP_CSR_SCALEN,
377 if(hcomp->Init.WindowMode == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)
379 SET_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE);
383 CLEAR_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE);
389 if ((READ_BIT(hcomp->Instance->CSR, COMP_CSR_SCALEN) != 0UL) &&
390 (comp_voltage_scaler_initialized == 0UL) )
396 wait_loop_index = ((COMP_DELAY_VOLTAGE_SCALER_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
397 while(wait_loop_index != 0UL)
404 exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
407 if((hcomp->Init.TriggerMode & (COMP_EXTI_IT | COMP_EXTI_EVENT)) != 0UL)
410 if((hcomp->Init.TriggerMode & COMP_EXTI_RISING) != 0UL)
420 if((hcomp->Init.TriggerMode & COMP_EXTI_FALLING) != 0UL)
433 if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != 0UL)
443 if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != 0UL)
482 HAL_StatusTypeDef status =
HAL_OK;
489 else if(__HAL_COMP_IS_LOCKED(hcomp))
499 WRITE_REG(hcomp->Instance->CSR, 0x00000000UL);
501 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 502 if (hcomp->MspDeInitCallback == NULL)
508 hcomp->MspDeInitCallback(hcomp);
554 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 570 HAL_StatusTypeDef status =
HAL_OK;
572 if (pCallback == NULL)
575 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
585 hcomp->TriggerCallback = pCallback;
589 hcomp->MspInitCallback = pCallback;
593 hcomp->MspDeInitCallback = pCallback;
598 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
610 hcomp->MspInitCallback = pCallback;
614 hcomp->MspDeInitCallback = pCallback;
619 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
629 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
652 HAL_StatusTypeDef status =
HAL_OK;
672 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
693 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
703 hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
740 __IO uint32_t wait_loop_index = 0UL;
741 HAL_StatusTypeDef status =
HAL_OK;
748 else if(__HAL_COMP_IS_LOCKED(hcomp))
760 SET_BIT(hcomp->Instance->CSR, COMP_CSR_EN);
770 wait_loop_index = ((COMP_DELAY_STARTUP_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
771 while(wait_loop_index != 0UL)
792 HAL_StatusTypeDef status =
HAL_OK;
799 else if(__HAL_COMP_IS_LOCKED(hcomp))
813 CLEAR_BIT(hcomp->Instance->CSR, COMP_CSR_EN);
835 uint32_t exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
842 if(READ_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE) != RESET)
861 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 862 hcomp->TriggerCallback(hcomp);
897 HAL_StatusTypeDef status =
HAL_OK;
904 else if(__HAL_COMP_IS_LOCKED(hcomp))
931 __HAL_COMP_LOCK(hcomp);
961 return (uint32_t)(READ_BIT(hcomp->Instance->CSR, COMP_CSR_VALUE)
962 >> COMP_OUTPUT_LEVEL_BITOFFSET_POS);
1016 return hcomp->State;
1029 return hcomp->ErrorCode;
HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
Initialize the COMP according to the specified parameters in the COMP_InitTypeDef and initialize the ...
HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
DeInitialize the COMP peripheral.
__STATIC_INLINE void LL_EXTI_DisableEvent_0_31(uint32_t ExtiLine)
Disable ExtiLine Event request for Lines in range 0 to 31 EMR1 EMx LL_EXTI_DisableEvent_0_31.
__STATIC_INLINE void LL_EXTI_DisableFallingTrig_0_31(uint32_t ExtiLine)
Disable ExtiLine Falling Edge Trigger for Lines in range 0 to 31.
__STATIC_INLINE void LL_EXTI_EnableFallingTrig_0_31(uint32_t ExtiLine)
Enable ExtiLine Falling Edge Trigger for Lines in range 0 to 31.
HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback)
Register a User COMP Callback To be used instead of the weak predefined callback. ...
__STATIC_INLINE void LL_EXTI_EnableRisingTrig_0_31(uint32_t ExtiLine)
Enable ExtiLine Rising Edge Trigger for Lines in range 0 to 31.
HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
Return the COMP handle state.
HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
Start the comparator.
This file contains all the functions prototypes for the HAL module driver.
__STATIC_INLINE void LL_EXTI_ClearFlag_0_31(uint32_t ExtiLine)
Clear ExtLine Flags for Lines in range 0 to 31.
void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
DeInitialize the COMP MSP.
__STATIC_INLINE uint32_t LL_EXTI_IsActiveFlag_0_31(uint32_t ExtiLine)
Check if the ExtLine Flag is set or not for Lines in range 0 to 31.
HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID)
Unregister a COMP Callback COMP callback is redirected to the weak predefined callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void(* pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp)
HAL COMP Callback pointer definition.
__STATIC_INLINE void LL_EXTI_EnableEvent_0_31(uint32_t ExtiLine)
Enable ExtiLine Event request for Lines in range 0 to 31 EMR1 EMx LL_EXTI_EnableEvent_0_31.
__STATIC_INLINE void LL_EXTI_DisableRisingTrig_0_31(uint32_t ExtiLine)
Disable ExtiLine Rising Edge Trigger for Lines in range 0 to 31.
__STATIC_INLINE void LL_EXTI_DisableIT_0_31(uint32_t ExtiLine)
Disable ExtiLine Interrupt request for Lines in range 0 to 31.
struct __COMP_HandleTypeDef else typedef struct endif COMP_HandleTypeDef
COMP Handle Structure definition.
void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
Initialize the COMP MSP.
uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp)
Return the COMP error code.
__STATIC_INLINE void LL_EXTI_EnableIT_0_31(uint32_t ExtiLine)
Enable ExtiLine Interrupt request for Lines in range 0 to 31.
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
Comparator trigger callback.
HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
Lock the selected comparator configuration.
HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
Stop the comparator.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
HAL_COMP_CallbackIDTypeDef
HAL COMP Callback ID enumeration definition.
void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
Comparator IRQ handler.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
Return the output level (high or low) of the selected comparator. The output level depends on the sel...