STM32L4xx_HAL_Driver  1.14.0
Start-Stop operation functions

Start-Stop operation functions. More...

Functions

HAL_StatusTypeDef HAL_COMP_Start (COMP_HandleTypeDef *hcomp)
 Start the comparator. More...
 
HAL_StatusTypeDef HAL_COMP_Stop (COMP_HandleTypeDef *hcomp)
 Stop the comparator. More...
 
void HAL_COMP_IRQHandler (COMP_HandleTypeDef *hcomp)
 Comparator IRQ handler. More...
 

Detailed Description

Start-Stop operation functions.

 ===============================================================================
                      ##### IO operation functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Start a comparator instance.
      (+) Stop a comparator instance.

Function Documentation

◆ HAL_COMP_IRQHandler()

void HAL_COMP_IRQHandler ( COMP_HandleTypeDef hcomp)

Comparator IRQ handler.

Parameters
hcompCOMP handle
Return values
None

Definition at line 832 of file stm32l4xx_hal_comp.c.

833 {
834  /* Get the EXTI line corresponding to the selected COMP instance */
835  uint32_t exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
836 
837  /* Check COMP EXTI flag */
838  if(LL_EXTI_IsActiveFlag_0_31(exti_line) != 0UL)
839  {
840 #if defined(COMP2)
841  /* Check whether comparator is in independent or window mode */
842  if(READ_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE) != RESET)
843  {
844  /* Clear COMP EXTI line pending bit of the pair of comparators */
845  /* in window mode. */
846  /* Note: Pair of comparators in window mode can both trig IRQ when */
847  /* input voltage is changing from "out of window" area */
848  /* (low or high ) to the other "out of window" area (high or low).*/
849  /* Both flags must be cleared to call comparator trigger */
850  /* callback is called once. */
851  LL_EXTI_ClearFlag_0_31((COMP_EXTI_LINE_COMP1 | COMP_EXTI_LINE_COMP2));
852  }
853  else
854 #endif /* COMP2 */
855  {
856  /* Clear COMP EXTI line pending bit */
857  LL_EXTI_ClearFlag_0_31(exti_line);
858  }
859 
860  /* COMP trigger user callback */
861 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
862  hcomp->TriggerCallback(hcomp);
863 #else
865 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
866  }
867 }
__STATIC_INLINE void LL_EXTI_ClearFlag_0_31(uint32_t ExtiLine)
Clear ExtLine Flags for Lines in range 0 to 31.
__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.
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
Comparator trigger callback.

◆ HAL_COMP_Start()

HAL_StatusTypeDef HAL_COMP_Start ( COMP_HandleTypeDef hcomp)

Start the comparator.

Parameters
hcompCOMP handle
Return values
HALstatus

Definition at line 738 of file stm32l4xx_hal_comp.c.

739 {
740  __IO uint32_t wait_loop_index = 0UL;
741  HAL_StatusTypeDef status = HAL_OK;
742 
743  /* Check the COMP handle allocation and lock status */
744  if(hcomp == NULL)
745  {
746  status = HAL_ERROR;
747  }
748  else if(__HAL_COMP_IS_LOCKED(hcomp))
749  {
750  status = HAL_ERROR;
751  }
752  else
753  {
754  /* Check the parameter */
755  assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
756 
757  if(hcomp->State == HAL_COMP_STATE_READY)
758  {
759  /* Enable the selected comparator */
760  SET_BIT(hcomp->Instance->CSR, COMP_CSR_EN);
761 
762  /* Set HAL COMP handle state */
763  hcomp->State = HAL_COMP_STATE_BUSY;
764 
765  /* Delay for COMP startup time */
766  /* Wait loop initialization and execution */
767  /* Note: Variable divided by 2 to compensate partially */
768  /* CPU processing cycles, scaling in us split to not */
769  /* exceed 32 bits register capacity and handle low frequency. */
770  wait_loop_index = ((COMP_DELAY_STARTUP_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
771  while(wait_loop_index != 0UL)
772  {
773  wait_loop_index--;
774  }
775  }
776  else
777  {
778  status = HAL_ERROR;
779  }
780  }
781 
782  return status;
783 }
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_COMP_Stop()

HAL_StatusTypeDef HAL_COMP_Stop ( COMP_HandleTypeDef hcomp)

Stop the comparator.

Parameters
hcompCOMP handle
Return values
HALstatus

Definition at line 790 of file stm32l4xx_hal_comp.c.

791 {
792  HAL_StatusTypeDef status = HAL_OK;
793 
794  /* Check the COMP handle allocation and lock status */
795  if(hcomp == NULL)
796  {
797  status = HAL_ERROR;
798  }
799  else if(__HAL_COMP_IS_LOCKED(hcomp))
800  {
801  status = HAL_ERROR;
802  }
803  else
804  {
805  /* Check the parameter */
806  assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
807 
808  /* Check compliant states: HAL_COMP_STATE_READY or HAL_COMP_STATE_BUSY */
809  /* (all states except HAL_COMP_STATE_RESET and except locked status. */
810  if(hcomp->State != HAL_COMP_STATE_RESET)
811  {
812  /* Disable the selected comparator */
813  CLEAR_BIT(hcomp->Instance->CSR, COMP_CSR_EN);
814 
815  /* Set HAL COMP handle state */
816  hcomp->State = HAL_COMP_STATE_READY;
817  }
818  else
819  {
820  status = HAL_ERROR;
821  }
822  }
823 
824  return status;
825 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))