Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:06

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_comp.c
0004   * @author  MCD Application Team
0005   * @brief   COMP HAL module driver. 
0006   *          This file provides firmware functions to manage the following 
0007   *          functionalities of the COMP peripheral:
0008   *           + Initialization and de-initialization functions
0009   *           + Peripheral control functions
0010   *           + Peripheral state functions
0011   ******************************************************************************
0012   * @attention
0013   *
0014   * Copyright (c) 2017 STMicroelectronics.
0015   * All rights reserved.
0016   *
0017   * This software is licensed under terms that can be found in the LICENSE file
0018   * in the root directory of this software component.
0019   * If no LICENSE file comes with this software, it is provided AS-IS.
0020   *
0021   ******************************************************************************
0022   @verbatim
0023   ================================================================================
0024                    ##### COMP Peripheral features #####
0025   ================================================================================
0026            
0027   [..]       
0028       The STM32H7xx device family integrates two analog comparators instances
0029       COMP1 and COMP2:
0030       (#) The COMP input minus (inverting input) and input plus (non inverting input)
0031           can be set to internal references or to GPIO pins
0032           (refer to GPIO list in reference manual).
0033   
0034       (#) The COMP output level is available using HAL_COMP_GetOutputLevel()
0035           and can be redirected to other peripherals: GPIO pins (in mode
0036           alternate functions for comparator), timers.
0037           (refer to GPIO list in reference manual).
0038   
0039       (#) Pairs of comparators instances can be combined in window mode
0040           (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
0041   
0042       (#) The comparators have interrupt capability through the EXTI controller
0043           with wake-up from sleep and stop modes:
0044           (++) COMP1 is internally connected to EXTI Line 20
0045           (++) COMP2 is internally connected to EXTI Line 21
0046   
0047   [..] 
0048           From the corresponding IRQ handler, the right interrupt source can be retrieved
0049           using macro __HAL_COMP_COMP1_EXTI_GET_FLAG() and __HAL_COMP_COMP2_EXTI_GET_FLAG().
0050 
0051 
0052     
0053             ##### How to use this driver #####
0054   ================================================================================
0055   [..]
0056       This driver provides functions to configure and program the comparator instances of 
0057       STM32H7xx devices.
0058 
0059       To use the comparator, perform the following steps:
0060   
0061       (#)  Initialize the COMP low level resources by implementing the HAL_COMP_MspInit():
0062       (++) Configure the GPIO connected to comparator inputs plus and minus in analog mode
0063            using HAL_GPIO_Init().
0064       (++) If needed, configure the GPIO connected to comparator output in alternate function mode
0065            using HAL_GPIO_Init().
0066       (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and 
0067            selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
0068            interrupt vector using HAL_NVIC_EnableIRQ() function.
0069   
0070       (#) Configure the comparator using HAL_COMP_Init() function:
0071       (++) Select the input minus (inverting input)
0072       (++) Select the input plus (non-inverting input)
0073       (++) Select the hysteresis
0074       (++) Select the blanking source
0075       (++) Select the output polarity  
0076       (++) Select the power mode
0077       (++) Select the window mode
0078       -@@- HAL_COMP_Init() calls internally __HAL_RCC_SYSCFG_CLK_ENABLE()
0079           to enable internal control clock of the comparators.
0080           However, this is a legacy strategy. 
0081           Therefore, for compatibility anticipation, it is recommended to 
0082           implement __HAL_RCC_SYSCFG_CLK_ENABLE() in "HAL_COMP_MspInit()".
0083           In STM32H7,COMP clock enable  __HAL_RCC_COMP12_CLK_ENABLE() must 
0084           be implemented by user in "HAL_COMP_MspInit()".
0085       (#) Reconfiguration on-the-fly of comparator can be done by calling again
0086           function HAL_COMP_Init() with new input structure parameters values.
0087   
0088       (#) Enable the comparator using HAL_COMP_Start() or HAL_COMP_Start_IT()to be enabled 
0089           with the interrupt through NVIC of the CPU. 
0090       Note: HAL_COMP_Start_IT() must be called after each interrupt otherwise the interrupt
0091       mode will stay disabled.
0092       
0093       (#) Use HAL_COMP_GetOutputLevel() or HAL_COMP_TriggerCallback()
0094           functions to manage comparator outputs(output level or events)
0095 
0096       (#) Disable the comparator using HAL_COMP_Stop() or HAL_COMP_Stop_IT() 
0097           to disable the interrupt too.
0098 
0099       (#) De-initialize the comparator using HAL_COMP_DeInit() function.
0100 
0101       (#) For safety purpose, comparator configuration can be locked using HAL_COMP_Lock() function.
0102           The only way to unlock the comparator is a device hardware reset.
0103    
0104     *** Callback registration ***
0105     =============================================
0106     [..]
0107 
0108      The compilation flag USE_HAL_COMP_REGISTER_CALLBACKS, when set to 1,
0109      allows the user to configure dynamically the driver callbacks.
0110      Use Functions HAL_COMP_RegisterCallback()
0111      to register an interrupt callback.
0112     [..]
0113 
0114      Function HAL_COMP_RegisterCallback() allows to register following callbacks:
0115        (+) TriggerCallback       : callback for COMP trigger.
0116        (+) MspInitCallback       : callback for Msp Init.
0117        (+) MspDeInitCallback     : callback for Msp DeInit.
0118      This function takes as parameters the HAL peripheral handle, the Callback ID
0119      and a pointer to the user callback function.
0120     [..]
0121 
0122      Use function HAL_COMP_UnRegisterCallback to reset a callback to the default
0123      weak function.
0124     [..]
0125 
0126      HAL_COMP_UnRegisterCallback takes as parameters the HAL peripheral handle,
0127      and the Callback ID.
0128      This function allows to reset following callbacks:
0129        (+) TriggerCallback       : callback for COMP trigger.
0130        (+) MspInitCallback       : callback for Msp Init.
0131        (+) MspDeInitCallback     : callback for Msp DeInit.
0132      [..]
0133 
0134      By default, after the HAL_COMP_Init() and when the state is HAL_COMP_STATE_RESET
0135      all callbacks are set to the corresponding weak functions:
0136      example HAL_COMP_TriggerCallback().
0137      Exception done for MspInit and MspDeInit functions that are
0138      reset to the legacy weak functions in the HAL_COMP_Init()/ HAL_COMP_DeInit() only when
0139      these callbacks are null (not registered beforehand).
0140     [..]
0141 
0142      If MspInit or MspDeInit are not null, the HAL_COMP_Init()/ HAL_COMP_DeInit()
0143      keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
0144      [..]
0145 
0146      Callbacks can be registered/unregistered in HAL_COMP_STATE_READY state only.
0147      Exception done MspInit/MspDeInit functions that can be registered/unregistered
0148      in HAL_COMP_STATE_READY or HAL_COMP_STATE_RESET state,
0149      thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
0150     [..]
0151 
0152      Then, the user first registers the MspInit/MspDeInit user callbacks
0153      using HAL_COMP_RegisterCallback() before calling HAL_COMP_DeInit()
0154      or HAL_COMP_Init() function.
0155      [..]
0156 
0157      When the compilation flag USE_HAL_COMP_REGISTER_CALLBACKS is set to 0 or
0158      not defined, the callback registration feature is not available and all callbacks
0159      are set to the corresponding weak functions.
0160 
0161   @endverbatim
0162   ******************************************************************************
0163 
0164   Table 1. COMP inputs and output for STM32H7xx devices
0165   +---------------------------------------------------------+
0166   |                |                |   COMP1   |   COMP2   |
0167   |----------------|----------------|-----------|-----------|
0168   |                | IO1            |    PB0    |    PE9    |
0169   | Input plus     | IO2            |    PB2    |    PE11   |
0170   |                |                |           |           |
0171   |----------------|----------------|-----------------------|
0172   |                | 1/4 VrefInt    | Available | Available |
0173   |                | 1/2 VrefInt    | Available | Available |
0174   |                | 3/4 VrefInt    | Available | Available |
0175   | Input minus    | VrefInt        | Available | Available |
0176   |                | DAC1 channel 1 | Available | Available |
0177   |                | DAC1 channel 2 | Available | Available |
0178   |                | IO1            |    PB1    |    PE10   |
0179   |                | IO2            |    PC4    |    PE7    |
0180   |                |                |           |           |
0181   |                |                |           |           |
0182   |                |                |           |           |
0183   +---------------------------------------------------------+
0184   | Output         |                |  PC5  (1) |  PE8  (1) |
0185   |                |                |  PE12 (1) |  PE13 (1) |
0186   |                |                |  TIM  (2) |  TIM  (2) |
0187   +---------------------------------------------------------+
0188   (1) GPIO must be set to alternate function for comparator
0189   (2) Comparators output to timers is set in timers instances.
0190 
0191   ******************************************************************************
0192   */
0193 
0194 /* Includes ------------------------------------------------------------------*/
0195 #include "stm32h7xx_hal.h"
0196 
0197 /** @addtogroup STM32H7xx_HAL_Driver
0198   * @{
0199   */
0200 
0201 /** @defgroup COMP COMP
0202   * @ingroup RTEMSBSPsARMSTM32H7
0203   * @brief COMP HAL module driver
0204   * @{
0205   */
0206 
0207 #ifdef HAL_COMP_MODULE_ENABLED
0208 
0209 /* Private typedef -----------------------------------------------------------*/
0210 /* Private define ------------------------------------------------------------*/
0211 /** @addtogroup COMP_Private_Constants
0212   * @{
0213   */
0214 
0215 /* Delay for COMP startup time.                                               */
0216 /* Note: Delay required to reach propagation delay specification.             */
0217 /* Literal set to maximum value (refer to device datasheet,                   */
0218 /* parameter "tSTART").                                                       */
0219 /* Unit: us                                                                   */
0220 #define COMP_DELAY_STARTUP_US             (80UL)  /*!< Delay for COMP startup time */
0221 
0222 /* Delay for COMP voltage scaler stabilization time.                          */
0223 /* Literal set to maximum value (refer to device datasheet,                   */
0224 /* parameter "tSTART_SCALER").                                                */
0225 /* Unit: us                                                                   */
0226 #define COMP_DELAY_VOLTAGE_SCALER_STAB_US (200UL)  /*!< Delay for COMP voltage scaler stabilization time */
0227 
0228 
0229 /**
0230   * @}
0231   */
0232 
0233 /* Private macro -------------------------------------------------------------*/
0234 /* Private variables ---------------------------------------------------------*/
0235 /* Private function prototypes -----------------------------------------------*/
0236 /* Exported functions --------------------------------------------------------*/
0237 
0238 /** @defgroup COMP_Exported_Functions COMP Exported Functions
0239   * @ingroup RTEMSBSPsARMSTM32H7
0240   * @{
0241   */
0242 
0243 /** @defgroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions 
0244   * @ingroup RTEMSBSPsARMSTM32H7
0245  *  @brief    Initialization and de-initialization functions. 
0246  *
0247 @verbatim    
0248  ===============================================================================
0249               ##### Initialization and de-initialization functions #####
0250  ===============================================================================
0251     [..]  This section provides functions to initialize and de-initialize comparators 
0252 
0253 @endverbatim
0254   * @{
0255   */
0256 
0257 /**
0258   * @brief  Initialize the COMP according to the specified
0259   *         parameters in the COMP_InitTypeDef and initialize the associated handle.
0260   * @note   If the selected comparator is locked, initialization can't be performed.
0261   *         To unlock the configuration, perform a system reset.
0262   * @param  hcomp COMP handle
0263   * @retval HAL status
0264   */
0265 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
0266 {
0267   uint32_t tmp_csr ;
0268   uint32_t exti_line ;
0269   uint32_t comp_voltage_scaler_initialized; /* Value "0" is comparator voltage scaler is not initialized */
0270   __IO uint32_t wait_loop_index = 0UL;
0271 
0272   HAL_StatusTypeDef status = HAL_OK;
0273   
0274   /* Check the COMP handle allocation and lock status */
0275   if(hcomp == NULL)
0276   {
0277     status = HAL_ERROR;
0278   }
0279   else if(__HAL_COMP_IS_LOCKED(hcomp))
0280   {
0281     status = HAL_ERROR;
0282   }
0283   else
0284   {
0285     /* Check the parameters */
0286     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
0287     assert_param(IS_COMP_INPUT_PLUS(hcomp->Instance, hcomp->Init.NonInvertingInput));
0288     assert_param(IS_COMP_INPUT_MINUS(hcomp->Instance, hcomp->Init.InvertingInput));
0289     assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol));
0290     assert_param(IS_COMP_POWERMODE(hcomp->Init.Mode));
0291     assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
0292     assert_param(IS_COMP_BLANKINGSRCE(hcomp->Init.BlankingSrce)); 
0293     assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
0294     assert_param(IS_COMP_WINDOWMODE(hcomp->Init.WindowMode));
0295 
0296     if(hcomp->State == HAL_COMP_STATE_RESET)
0297     {
0298       /* Allocate lock resource and initialize it */
0299       hcomp->Lock = HAL_UNLOCKED;
0300       
0301       /* Set COMP error code to none */
0302       COMP_CLEAR_ERRORCODE(hcomp);
0303       
0304 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
0305      /* Init the COMP Callback settings */
0306       hcomp->TriggerCallback = HAL_COMP_TriggerCallback; /* Legacy weak callback */
0307 
0308       if (hcomp->MspInitCallback == NULL)
0309       {
0310         hcomp->MspInitCallback = HAL_COMP_MspInit; /* Legacy weak MspInit  */
0311       }
0312       
0313       /* Init the low level hardware */
0314       hcomp->MspInitCallback(hcomp);
0315 #else
0316      /* Init the low level hardware */
0317       HAL_COMP_MspInit(hcomp);
0318 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
0319     }
0320     /* Memorize voltage scaler state before initialization */
0321     comp_voltage_scaler_initialized = READ_BIT(hcomp->Instance->CFGR, COMP_CFGRx_SCALEN);
0322 
0323     /* Set COMP parameters */
0324     /*     Set INMSEL bits according to hcomp->Init.InvertingInput value       */
0325     /*     Set INPSEL bits according to hcomp->Init.NonInvertingInput value    */
0326     /*     Set BLANKING bits according to hcomp->Init.BlankingSrce value       */
0327     /*     Set HYST bits according to hcomp->Init.Hysteresis value             */
0328     /*     Set POLARITY bit according to hcomp->Init.OutputPol value           */
0329     /*     Set POWERMODE bits according to hcomp->Init.Mode value              */
0330    
0331     tmp_csr = (hcomp->Init.InvertingInput    |  \
0332               hcomp->Init.NonInvertingInput  |  \
0333               hcomp->Init.BlankingSrce       |  \
0334               hcomp->Init.Hysteresis         |  \
0335               hcomp->Init.OutputPol          |  \
0336               hcomp->Init.Mode                );
0337     
0338     /* Set parameters in COMP register */
0339     /* Note: Update all bits except read-only, lock and enable bits */
0340 #if defined (COMP_CFGRx_INP2SEL)
0341     MODIFY_REG(hcomp->Instance->CFGR,
0342                COMP_CFGRx_PWRMODE  | COMP_CFGRx_INMSEL   | COMP_CFGRx_INPSEL  | 
0343                COMP_CFGRx_INP2SEL  | COMP_CFGRx_WINMODE  | COMP_CFGRx_POLARITY | COMP_CFGRx_HYST    |
0344                COMP_CFGRx_BLANKING | COMP_CFGRx_BRGEN    | COMP_CFGRx_SCALEN,
0345                tmp_csr
0346               );
0347 #else
0348     MODIFY_REG(hcomp->Instance->CFGR,
0349                COMP_CFGRx_PWRMODE  | COMP_CFGRx_INMSEL   | COMP_CFGRx_INPSEL  | 
0350                COMP_CFGRx_WINMODE  | COMP_CFGRx_POLARITY | COMP_CFGRx_HYST    |
0351                COMP_CFGRx_BLANKING | COMP_CFGRx_BRGEN    | COMP_CFGRx_SCALEN,
0352                tmp_csr
0353               );
0354 #endif
0355     /* Set window mode */
0356     /* Note: Window mode bit is located into 1 out of the 2 pairs of COMP     */
0357     /*       instances. Therefore, this function can update another COMP      */
0358     /*       instance that the one currently selected.                        */
0359     if(hcomp->Init.WindowMode == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)
0360     {
0361       SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_WINMODE);
0362     }
0363     else
0364     {
0365       CLEAR_BIT(hcomp->Instance->CFGR, COMP_CFGRx_WINMODE);
0366     }
0367     /* Delay for COMP scaler bridge voltage stabilization */
0368     /* Apply the delay if voltage scaler bridge is enabled for the first time */
0369     if ((READ_BIT(hcomp->Instance->CFGR, COMP_CFGRx_SCALEN) != 0UL) &&
0370         (comp_voltage_scaler_initialized != 0UL)               )
0371     {
0372       /* Wait loop initialization and execution */
0373       /* Note: Variable divided by 2 to compensate partially                  */
0374       /*       CPU processing cycles.*/
0375 
0376      wait_loop_index = ((COMP_DELAY_VOLTAGE_SCALER_STAB_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
0377 
0378      while(wait_loop_index != 0UL)
0379      {
0380        wait_loop_index --;
0381      }
0382     }
0383 
0384     /* Get the EXTI line corresponding to the selected COMP instance */
0385     exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
0386     
0387     /* Manage EXTI settings */
0388     if((hcomp->Init.TriggerMode & (COMP_EXTI_IT | COMP_EXTI_EVENT)) != 0UL) 
0389     {
0390       /* Configure EXTI rising edge */
0391       if((hcomp->Init.TriggerMode & COMP_EXTI_RISING) != 0UL)
0392       {
0393         SET_BIT(EXTI->RTSR1, exti_line);
0394       }
0395       else
0396       {
0397         CLEAR_BIT(EXTI->RTSR1, exti_line);
0398       }
0399       
0400       /* Configure EXTI falling edge */
0401       if((hcomp->Init.TriggerMode & COMP_EXTI_FALLING) != 0UL)
0402       {
0403         SET_BIT(EXTI->FTSR1, exti_line);
0404       }
0405       else
0406       {
0407         CLEAR_BIT(EXTI->FTSR1, exti_line);
0408       }
0409      
0410 #if !defined (CORE_CM4)
0411       /* Clear COMP EXTI pending bit (if any) */
0412       WRITE_REG(EXTI->PR1, exti_line);
0413 
0414       /* Configure EXTI event mode */
0415       if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != 0UL)
0416       {
0417         SET_BIT(EXTI->EMR1, exti_line);
0418       }
0419       else
0420       {
0421         CLEAR_BIT(EXTI->EMR1, exti_line);
0422       }
0423       
0424        /* Configure EXTI interrupt mode */
0425       if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != 0UL)
0426       {
0427         SET_BIT(EXTI->IMR1, exti_line);
0428       }
0429       else
0430       {
0431         CLEAR_BIT(EXTI->IMR1, exti_line);
0432       }
0433     }
0434     else
0435     {
0436       /* Disable EXTI event mode */
0437       CLEAR_BIT(EXTI->EMR1, exti_line);
0438       
0439       /* Disable EXTI interrupt mode */
0440       CLEAR_BIT(EXTI->IMR1, exti_line);
0441     }
0442 #else
0443       /* Clear COMP EXTI pending bit (if any) */
0444       WRITE_REG(EXTI->C2PR1, exti_line);
0445 
0446       /* Configure EXTI event mode */
0447       if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != 0UL)
0448       {
0449         SET_BIT(EXTI->C2EMR1, exti_line);
0450       }
0451       else
0452       {
0453         CLEAR_BIT(EXTI->C2EMR1, exti_line);
0454       }
0455 
0456        /* Configure EXTI interrupt mode */
0457       if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != 0UL)
0458       {
0459         SET_BIT(EXTI->C2IMR1, exti_line);
0460       }
0461       else
0462       {
0463         CLEAR_BIT(EXTI->C2IMR1, exti_line);
0464       }
0465     }
0466     else
0467     {
0468       /* Disable EXTI event mode */
0469       CLEAR_BIT(EXTI->C2EMR1, exti_line);
0470 
0471       /* Disable EXTI interrupt mode */
0472       CLEAR_BIT(EXTI->C2IMR1, exti_line);
0473     }
0474 #endif
0475     /* Set HAL COMP handle state */
0476     /* Note: Transition from state reset to state ready,                      */
0477     /*       otherwise (coming from state ready or busy) no state update.     */
0478     if (hcomp->State == HAL_COMP_STATE_RESET)
0479     {
0480      
0481       hcomp->State = HAL_COMP_STATE_READY;
0482     }
0483    
0484   }
0485   
0486   return status;
0487 }
0488 
0489 /**
0490   * @brief  DeInitialize the COMP peripheral. 
0491   * @note   Deinitialization cannot be performed if the COMP configuration is locked.
0492   *         To unlock the configuration, perform a system reset.
0493   * @param  hcomp  COMP handle
0494   * @retval HAL status
0495   */
0496 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
0497 {
0498   HAL_StatusTypeDef status = HAL_OK;
0499 
0500   /* Check the COMP handle allocation and lock status */
0501   if(hcomp == NULL)
0502   {
0503     status = HAL_ERROR;
0504   }
0505   else if(__HAL_COMP_IS_LOCKED(hcomp))
0506   {
0507     status = HAL_ERROR;
0508   }
0509   else
0510   {
0511     /* Check the parameter */
0512     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
0513 
0514     /* Set COMP_CFGR register to reset value */
0515     WRITE_REG(hcomp->Instance->CFGR, 0x00000000UL);
0516 
0517 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
0518     if (hcomp->MspDeInitCallback == NULL)
0519     {
0520       hcomp->MspDeInitCallback = HAL_COMP_MspDeInit; /* Legacy weak MspDeInit  */
0521     }
0522     
0523     /* DeInit the low level hardware */
0524     hcomp->MspDeInitCallback(hcomp);
0525 #else
0526     /* DeInit the low level hardware */
0527     HAL_COMP_MspDeInit(hcomp);
0528 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
0529 
0530     /* Set HAL COMP handle state */
0531     hcomp->State = HAL_COMP_STATE_RESET;
0532     
0533     /* Release Lock */
0534     __HAL_UNLOCK(hcomp);
0535   }
0536   
0537   return status;
0538 }
0539 
0540 /**
0541   * @brief  Initialize the COMP MSP.
0542   * @param  hcomp COMP handle
0543   * @retval None
0544   */
0545 __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
0546 {
0547   /* Prevent unused argument(s) compilation warning */
0548   UNUSED(hcomp);
0549   /* NOTE : This function should not be modified, when the callback is needed,
0550             the HAL_COMP_MspInit could be implemented in the user file
0551    */
0552 }
0553 
0554 /**
0555   * @brief  DeInitialize the COMP MSP.
0556   * @param  hcomp COMP handle
0557   * @retval None
0558   */
0559 __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
0560 {
0561   /* Prevent unused argument(s) compilation warning */
0562    UNUSED(hcomp);
0563   /* NOTE : This function should not be modified, when the callback is needed,
0564             the HAL_COMP_MspDeInit could be implemented in the user file
0565    */
0566 }
0567 
0568 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
0569 /**
0570   * @brief  Register a User COMP Callback
0571   *         To be used instead of the weak predefined callback
0572   * @param  hcomp Pointer to a COMP_HandleTypeDef structure that contains
0573   *                the configuration information for the specified COMP.
0574   * @param  CallbackID ID of the callback to be registered
0575   *         This parameter can be one of the following values:
0576   *          @arg @ref HAL_COMP_TRIGGER_CB_ID Trigger callback ID
0577   *          @arg @ref HAL_COMP_MSPINIT_CB_ID MspInit callback ID
0578   *          @arg @ref HAL_COMP_MSPDEINIT_CB_ID MspDeInit callback ID
0579   * @param  pCallback pointer to the Callback function
0580   * @retval HAL status
0581   */
0582 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback)
0583 {
0584   HAL_StatusTypeDef status = HAL_OK;
0585   
0586   if (pCallback == NULL)
0587   {
0588     /* Update the error code */
0589     hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0590 
0591     return HAL_ERROR;
0592   }
0593   
0594   if (HAL_COMP_STATE_READY == hcomp->State)
0595   {
0596     switch (CallbackID)
0597     {
0598       case HAL_COMP_TRIGGER_CB_ID :
0599         hcomp->TriggerCallback = pCallback;
0600         break;
0601       
0602       case HAL_COMP_MSPINIT_CB_ID :
0603         hcomp->MspInitCallback = pCallback;
0604         break;
0605       
0606       case HAL_COMP_MSPDEINIT_CB_ID :
0607         hcomp->MspDeInitCallback = pCallback;
0608         break;
0609       
0610       default :
0611         /* Update the error code */
0612         hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0613         
0614         /* Return error status */
0615         status = HAL_ERROR;
0616         break;
0617     }
0618   }
0619   else if (HAL_COMP_STATE_RESET == hcomp->State)
0620   {
0621     switch (CallbackID)
0622     {
0623       case HAL_COMP_MSPINIT_CB_ID :
0624         hcomp->MspInitCallback = pCallback;
0625         break;
0626       
0627       case HAL_COMP_MSPDEINIT_CB_ID :
0628         hcomp->MspDeInitCallback = pCallback;
0629         break;
0630       
0631       default :
0632         /* Update the error code */
0633         hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0634         
0635         /* Return error status */
0636         status = HAL_ERROR;
0637         break;
0638     }
0639   }
0640   else
0641   {
0642     /* Update the error code */
0643     hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0644     
0645     /* Return error status */
0646     status =  HAL_ERROR;
0647   }
0648   
0649   return status;
0650 }
0651 
0652 /**
0653   * @brief  Unregister a COMP Callback
0654   *         COMP callback is redirected to the weak predefined callback
0655   * @param  hcomp Pointer to a COMP_HandleTypeDef structure that contains
0656   *                the configuration information for the specified COMP.
0657   * @param  CallbackID ID of the callback to be unregistered
0658   *         This parameter can be one of the following values:
0659   *          @arg @ref HAL_COMP_TRIGGER_CB_ID Trigger callback ID
0660   *          @arg @ref HAL_COMP_MSPINIT_CB_ID MspInit callback ID
0661   *          @arg @ref HAL_COMP_MSPDEINIT_CB_ID MspDeInit callback ID
0662   * @retval HAL status
0663   */
0664 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID)
0665 {
0666   HAL_StatusTypeDef status = HAL_OK;
0667 
0668   if (HAL_COMP_STATE_READY == hcomp->State)
0669   {
0670     switch (CallbackID)
0671     {
0672       case HAL_COMP_TRIGGER_CB_ID :
0673         hcomp->TriggerCallback = HAL_COMP_TriggerCallback;         /* Legacy weak callback */
0674         break;
0675       
0676       case HAL_COMP_MSPINIT_CB_ID :
0677         hcomp->MspInitCallback = HAL_COMP_MspInit;                 /* Legacy weak MspInit */
0678         break;
0679 
0680       case HAL_COMP_MSPDEINIT_CB_ID :
0681         hcomp->MspDeInitCallback = HAL_COMP_MspDeInit;             /* Legacy weak MspDeInit */
0682         break;
0683 
0684       default :
0685         /* Update the error code */
0686         hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0687 
0688         /* Return error status */
0689         status =  HAL_ERROR;
0690         break;
0691     }
0692   }
0693   else if (HAL_COMP_STATE_RESET == hcomp->State)
0694   {
0695     switch (CallbackID)
0696     {
0697       case HAL_COMP_MSPINIT_CB_ID :
0698         hcomp->MspInitCallback = HAL_COMP_MspInit;                 /* Legacy weak MspInit */
0699         break;
0700 
0701       case HAL_COMP_MSPDEINIT_CB_ID :
0702         hcomp->MspDeInitCallback = HAL_COMP_MspDeInit;             /* Legacy weak MspDeInit */
0703         break;
0704 
0705       default :
0706         /* Update the error code */
0707         hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0708 
0709         /* Return error status */
0710         status =  HAL_ERROR;
0711         break;
0712     }
0713   }
0714   else
0715   {
0716     /* Update the error code */
0717     hcomp->ErrorCode |= HAL_COMP_ERROR_INVALID_CALLBACK;
0718 
0719     /* Return error status */
0720     status =  HAL_ERROR;
0721   }
0722 
0723   return status;
0724 }
0725 
0726 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
0727 /**
0728   * @}
0729   */
0730 
0731 /** @defgroup COMP_Exported_Functions_Group2 Start-Stop operation functions 
0732   * @ingroup RTEMSBSPsARMSTM32H7
0733  *  @brief   Start-Stop operation functions. 
0734  *
0735 @verbatim   
0736  ===============================================================================
0737                       ##### IO operation functions #####
0738  ===============================================================================  
0739     [..]  This section provides functions allowing to:
0740       (+) Start a Comparator instance without interrupt.
0741       (+) Stop a Comparator instance without interrupt.
0742       (+) Start a Comparator instance with interrupt generation.
0743       (+) Stop a Comparator instance with interrupt generation.
0744 
0745 @endverbatim
0746   * @{
0747   */
0748 
0749 /**
0750   * @brief  Start the comparator. 
0751   * @param  hcomp COMP handle
0752   * @retval HAL status
0753   */
0754 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
0755 { 
0756   __IO uint32_t wait_loop_index = 0UL;
0757 
0758   HAL_StatusTypeDef status = HAL_OK;
0759   
0760   /* Check the COMP handle allocation and lock status */
0761   if(hcomp == NULL)
0762   {
0763     status = HAL_ERROR;
0764   }
0765   else if(__HAL_COMP_IS_LOCKED(hcomp))
0766   {
0767     status = HAL_ERROR;
0768   }
0769   else
0770   {
0771     /* Check the parameter */
0772     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
0773 
0774     if(hcomp->State == HAL_COMP_STATE_READY)
0775     {
0776       /* Enable the selected comparator */
0777       SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_EN);
0778 
0779       /* Set HAL COMP handle state */
0780       hcomp->State = HAL_COMP_STATE_BUSY;
0781 
0782      /* Delay for COMP startup time */
0783      /* Wait loop initialization and execution */
0784      /* Note: Variable divided by 2 to compensate partially    */
0785      /*       CPU processing cycles.                           */
0786     
0787      wait_loop_index = ((COMP_DELAY_STARTUP_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
0788      while(wait_loop_index != 0UL)
0789      {
0790        wait_loop_index--;
0791      }      
0792     }
0793     else
0794     {
0795       status = HAL_ERROR;
0796     }
0797   }
0798 
0799   return status;
0800 }
0801 
0802 /**
0803   * @brief  Stop the comparator. 
0804   * @param  hcomp COMP handle
0805   * @retval HAL status
0806   */
0807 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
0808 { 
0809   HAL_StatusTypeDef status = HAL_OK;
0810   
0811   /* Check the COMP handle allocation and lock status */
0812   if(hcomp == NULL)
0813   {
0814     status = HAL_ERROR;
0815   }
0816   else if(__HAL_COMP_IS_LOCKED(hcomp))
0817   {
0818     status = HAL_ERROR;
0819   }
0820   else
0821   {
0822     /* Check the parameter */
0823     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
0824 
0825     /* Check compliant states: HAL_COMP_STATE_READY or HAL_COMP_STATE_BUSY    */
0826     /* (all states except HAL_COMP_STATE_RESET and except locked status.      */
0827     if(hcomp->State != HAL_COMP_STATE_RESET)
0828     {
0829 
0830       /* Disable the selected comparator */
0831       CLEAR_BIT(hcomp->Instance->CFGR, COMP_CFGRx_EN);
0832 
0833       /* Set HAL COMP handle state */
0834       hcomp->State = HAL_COMP_STATE_READY;
0835     }
0836     else
0837     {
0838       status = HAL_ERROR;
0839     }
0840   }
0841   
0842   return status;
0843 }
0844 
0845 /**
0846   * @brief  Enable the interrupt and start the comparator.
0847   * @param  hcomp COMP handle
0848   * @retval HAL status
0849   */
0850 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp)
0851 { 
0852   
0853  __IO uint32_t wait_loop_index = 0UL;
0854  HAL_StatusTypeDef status = HAL_OK;
0855   
0856   /* Check the COMP handle allocation and lock status */
0857   if(hcomp == NULL)
0858   {
0859     status = HAL_ERROR;
0860   }
0861   else if(__HAL_COMP_IS_LOCKED(hcomp))
0862   {
0863     status = HAL_ERROR;
0864   }
0865   else
0866   {
0867     /* Check the parameter */
0868     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
0869     /* Set HAL COMP handle state */
0870     if(hcomp->State == HAL_COMP_STATE_READY)
0871     {
0872 
0873     /* Enable the selected comparator */
0874     SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_EN);
0875     /* Enable the Interrupt comparator */
0876     SET_BIT(hcomp->Instance->CFGR, COMP_CFGRx_ITEN);
0877 
0878     hcomp->State = HAL_COMP_STATE_BUSY; 
0879       /* Delay for COMP startup time */
0880       /* Wait loop initialization and execution */
0881       /* Note: Variable divided by 2 to compensate partially                  */
0882       /*       CPU processing cycles.                                         */
0883 
0884      wait_loop_index = ((COMP_DELAY_STARTUP_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
0885      while(wait_loop_index != 0UL)
0886      {
0887        wait_loop_index--;
0888      }
0889 
0890     }
0891     else
0892     {
0893        status = HAL_ERROR;
0894     }
0895    }
0896 
0897   return status;
0898 }
0899 
0900 /**
0901   * @brief  Disable the interrupt and Stop the comparator. 
0902   * @param  hcomp COMP handle
0903   * @retval HAL status
0904   */
0905 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp)
0906 {  
0907   HAL_StatusTypeDef status;
0908   /* Disable the EXTI Line interrupt mode */
0909 #if !defined (CORE_CM4)
0910    CLEAR_BIT(EXTI->IMR1, COMP_GET_EXTI_LINE(hcomp->Instance));
0911 #else
0912    CLEAR_BIT(EXTI->C2IMR1, COMP_GET_EXTI_LINE(hcomp->Instance));
0913 #endif   
0914   /* Disable the Interrupt comparator */
0915    CLEAR_BIT(hcomp->Instance->CFGR, COMP_CFGRx_ITEN);
0916 
0917   status = HAL_COMP_Stop(hcomp);
0918   
0919   return status;
0920   
0921 }
0922 
0923 /**
0924   * @brief  Comparator IRQ Handler. 
0925   * @param  hcomp COMP handle
0926   * @retval HAL status
0927   */
0928 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
0929 {
0930   /* Get the EXTI line corresponding to the selected COMP instance */
0931   uint32_t exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
0932   
0933 
0934 #if defined(DUAL_CORE)
0935   /* EXTI line interrupt detected */
0936  if (HAL_GetCurrentCPUID() == CM7_CPUID)
0937  {
0938     /* Check COMP EXTI flag */
0939     if(READ_BIT(EXTI->PR1, exti_line) != 0UL)
0940     {    
0941        /* Check whether comparator is in independent or window mode */
0942         if(READ_BIT(COMP12_COMMON->CFGR, COMP_CFGRx_WINMODE) != 0UL)
0943         {
0944           /* Clear COMP EXTI line pending bit of the pair of comparators          */
0945           /* in window mode.                                                      */
0946           /* Note: Pair of comparators in window mode can both trig IRQ when      */
0947           /*       input voltage is changing from "out of window" area            */
0948           /*       (low or high ) to the other "out of window" area (high or low).*/
0949           /*       Both flags must be cleared to call comparator trigger          */
0950           /*       callback is called once.                                       */
0951           WRITE_REG(EXTI->PR1, (COMP_EXTI_LINE_COMP1 | COMP_EXTI_LINE_COMP2));
0952         }
0953         else
0954         {
0955           /* Clear COMP EXTI line pending bit */
0956           WRITE_REG(EXTI->PR1, exti_line);
0957         }
0958 
0959     /* COMP trigger user callback */
0960 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
0961     hcomp->TriggerCallback(hcomp);
0962 #else
0963     HAL_COMP_TriggerCallback(hcomp);
0964 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
0965     }
0966 
0967 
0968  }
0969  else
0970  {
0971     /* Check COMP EXTI flag */
0972     if(READ_BIT(EXTI->C2PR1, exti_line) != 0UL)
0973     {    
0974        /* Check whether comparator is in independent or window mode */
0975         if(READ_BIT(COMP12_COMMON->CFGR, COMP_CFGRx_WINMODE) != 0UL)
0976         {
0977           /* Clear COMP EXTI line pending bit of the pair of comparators          */
0978           /* in window mode.                                                      */
0979           /* Note: Pair of comparators in window mode can both trig IRQ when      */
0980           /*       input voltage is changing from "out of window" area            */
0981           /*       (low or high ) to the other "out of window" area (high or low).*/
0982           /*       Both flags must be cleared to call comparator trigger          */
0983           /*       callback is called once.                                       */
0984           WRITE_REG(EXTI->C2PR1, (COMP_EXTI_LINE_COMP1 | COMP_EXTI_LINE_COMP2));
0985         }
0986         else
0987         {
0988           /* Clear COMP EXTI line pending bit */
0989           WRITE_REG(EXTI->C2PR1, exti_line);
0990         }
0991 
0992     /* COMP trigger user callback */
0993 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
0994     hcomp->TriggerCallback(hcomp);
0995 #else
0996     HAL_COMP_TriggerCallback(hcomp);
0997 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
0998     } 
0999 
1000  
1001  } 
1002 #else
1003     /* Check COMP EXTI flag */
1004     if(READ_BIT(EXTI->PR1, exti_line) != 0UL)
1005     {    
1006        /* Check whether comparator is in independent or window mode */
1007         if(READ_BIT(COMP12_COMMON->CFGR, COMP_CFGRx_WINMODE) != 0UL)
1008         {
1009           /* Clear COMP EXTI line pending bit of the pair of comparators          */
1010           /* in window mode.                                                      */
1011           /* Note: Pair of comparators in window mode can both trig IRQ when      */
1012           /*       input voltage is changing from "out of window" area            */
1013           /*       (low or high ) to the other "out of window" area (high or low).*/
1014           /*       Both flags must be cleared to call comparator trigger          */
1015           /*       callback is called once.                                       */
1016           WRITE_REG(EXTI->PR1, (COMP_EXTI_LINE_COMP1 | COMP_EXTI_LINE_COMP2));
1017         }
1018         else
1019         {
1020           /* Clear COMP EXTI line pending bit */
1021           WRITE_REG(EXTI->PR1, exti_line);
1022         }
1023 
1024     /* COMP trigger user callback */
1025 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
1026     hcomp->TriggerCallback(hcomp);
1027 #else
1028     HAL_COMP_TriggerCallback(hcomp);
1029 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
1030     }
1031 #endif /*DUAL_CORE*/
1032 
1033    /* Get COMP interrupt source */
1034   if (__HAL_COMP_GET_IT_SOURCE(hcomp, COMP_IT_EN) != RESET)
1035   {
1036 
1037     if((__HAL_COMP_GET_FLAG( COMP_FLAG_C1I)) != 0UL)
1038     {
1039       /* Clear the COMP channel 1 interrupt flag */
1040          __HAL_COMP_CLEAR_C1IFLAG();
1041    
1042       /* Disable COMP interrupt */
1043        __HAL_COMP_DISABLE_IT(hcomp,COMP_IT_EN);
1044    
1045     }
1046     if((__HAL_COMP_GET_FLAG( COMP_FLAG_C2I)) != 0UL)
1047     {
1048      /* Clear the COMP channel 2 interrupt flag */
1049        __HAL_COMP_CLEAR_C2IFLAG();
1050    
1051      /* Disable COMP interrupt */
1052      __HAL_COMP_DISABLE_IT(hcomp,COMP_IT_EN);
1053        
1054     }
1055 
1056     /* Change COMP state */
1057     hcomp->State = HAL_COMP_STATE_READY;
1058 
1059     /* COMP trigger user callback */
1060 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
1061     hcomp->TriggerCallback(hcomp);
1062 #else
1063     HAL_COMP_TriggerCallback(hcomp);
1064 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
1065   }    
1066  
1067 
1068 }
1069 
1070 /**
1071   * @}
1072   */
1073 
1074 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions 
1075   * @ingroup RTEMSBSPsARMSTM32H7
1076  *  @brief   Management functions.
1077  *
1078 @verbatim   
1079  ===============================================================================
1080                       ##### Peripheral Control functions #####
1081  ===============================================================================  
1082     [..]
1083     This subsection provides a set of functions allowing to control the comparators.
1084 
1085 @endverbatim
1086   * @{
1087   */
1088 
1089 /**
1090   * @brief  Lock the selected comparator configuration.
1091   * @note   A system reset is required to unlock the comparator configuration. 
1092   * @param  hcomp COMP handle
1093   * @retval HAL status
1094   */
1095 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
1096 {
1097  HAL_StatusTypeDef status = HAL_OK;
1098 
1099   /* Check the COMP handle allocation and lock status */
1100   if(hcomp == NULL)
1101   {
1102     status = HAL_ERROR;
1103   }
1104   else if(__HAL_COMP_IS_LOCKED(hcomp))
1105   {
1106     status = HAL_ERROR;
1107   }
1108   else
1109   {
1110     /* Check the parameter */
1111     assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
1112     
1113     /* Set HAL COMP handle state */
1114     switch(hcomp->State)
1115     {
1116       case HAL_COMP_STATE_RESET:
1117         hcomp->State = HAL_COMP_STATE_RESET_LOCKED;
1118         break;
1119       case HAL_COMP_STATE_READY:
1120         hcomp->State = HAL_COMP_STATE_READY_LOCKED;
1121         break;
1122       default: /* HAL_COMP_STATE_BUSY */
1123         hcomp->State = HAL_COMP_STATE_BUSY_LOCKED;
1124         break;
1125     }
1126   }
1127   
1128   if(status == HAL_OK)
1129   {
1130     /* Set the lock bit corresponding to selected comparator */
1131     __HAL_COMP_LOCK(hcomp);
1132   }
1133   
1134   return status; 
1135 }
1136 
1137 /**
1138   * @brief  Return the output level (high or low) of the selected comparator. 
1139   * @note   The output level depends on the selected polarity.
1140   *         If the polarity is not inverted:
1141   *           - Comparator output is low when the input plus is at a lower
1142   *             voltage than the input minus
1143   *           - Comparator output is high when the input plus is at a higher
1144   *             voltage than the input minus
1145   *         If the polarity is inverted:
1146   *           - Comparator output is high when the input plus is at a lower
1147   *             voltage than the input minus
1148   *           - Comparator output is low when the input plus is at a higher
1149   *             voltage than the input minus
1150   * @param  hcomp  COMP handle
1151   * @retval Returns the selected comparator output level: 
1152   *         @arg @ref COMP_OUTPUT_LEVEL_LOW
1153   *         @arg @ref COMP_OUTPUT_LEVEL_HIGH
1154   *       
1155   */
1156 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
1157 {
1158   /* Check the parameter */
1159   assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
1160  
1161   if (hcomp->Instance == COMP1)
1162   {
1163     return (uint32_t)(READ_BIT(COMP12->SR, COMP_SR_C1VAL));                 
1164   }
1165   else
1166   {
1167     return (uint32_t)((READ_BIT(COMP12->SR, COMP_SR_C2VAL))>> 1UL);
1168   }
1169 }
1170 
1171 /**
1172   * @brief  Comparator trigger callback.
1173   * @param  hcomp COMP handle
1174   * @retval None
1175   */
1176 __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
1177 {
1178    /* Prevent unused argument(s) compilation warning */
1179    UNUSED(hcomp);
1180   /* NOTE : This function should not be modified, when the callback is needed,
1181             the HAL_COMP_TriggerCallback should be implemented in the user file
1182    */
1183 }
1184 
1185 
1186 /**
1187   * @}
1188   */
1189 
1190 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions 
1191   * @ingroup RTEMSBSPsARMSTM32H7
1192  *  @brief   Peripheral State functions. 
1193  *
1194 @verbatim   
1195  ===============================================================================
1196                       ##### Peripheral State functions #####
1197  ===============================================================================  
1198     [..]
1199     This subsection permit to get in run-time the status of the peripheral.
1200 
1201 @endverbatim
1202   * @{
1203   */
1204 
1205 /**
1206   * @brief  Return the COMP handle state.
1207   * @param  hcomp  COMP handle
1208   * @retval HAL state
1209   */
1210 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
1211 {
1212   /* Check the COMP handle allocation */
1213   if(hcomp == NULL)
1214   {
1215     return HAL_COMP_STATE_RESET;
1216   }
1217 
1218   /* Check the parameter */
1219   assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
1220 
1221   /* Return HAL COMP handle state */
1222   return hcomp->State;
1223 }
1224 
1225 /**
1226   * @brief  Return the COMP error code.
1227   * @param hcomp COMP handle
1228   * @retval COMP error code
1229   */
1230 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp)
1231 {
1232   /* Check the parameters */
1233   assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
1234   
1235   return hcomp->ErrorCode;
1236 }
1237 /**
1238   * @}
1239   */
1240 
1241 /**
1242   * @}
1243   */
1244 
1245 #endif /* HAL_COMP_MODULE_ENABLED */
1246 /**
1247   * @}
1248   */
1249 
1250 /**
1251   * @}
1252   */
1253