/* * SPDX-FileCopyrightText: 2016 STMicroelectronics * SPDX-FileCopyrightText: 2019-2025 SiFli Technologies(Nanjing) Co., Ltd * * SPDX-License-Identifier: BSD-3-Clause AND Apache-2.0 */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef BF0_HAL_LPCOMP_H #define BF0_HAL_LPCOMP_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "bf0_hal_def.h" /** @addtogroup BF0_HAL_Driver * @{ */ /** @addtogroup COMP * @{ */ /* Exported types ------------------------------------------------------------*/ /** @defgroup COMP_Exported_Types COMP Exported Types * @{ */ /** * @brief COMP Init structure definition */ typedef struct { uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed. Note: For the characteristics of comparator power modes (propagation delay and power consumption), refer to device datasheet. This parameter can be a value of @ref COMP_PowerMode */ uint32_t NonInvertingInput; /*!< Set comparator input plus (non-inverting input). This parameter can be a value of @ref COMP_InputPlus */ uint32_t InvertingInput; /*!< Set comparator input minus (inverting input). This parameter can be a value of @ref COMP_InputMinus */ uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus. This parameter can be a value of @ref COMP_Hysteresis */ uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI). This parameter can be a value of @ref COMP_EXTI_TriggerMode */ uint32_t InternalVRef; /*!< Set the comparator internal voltage refrence. This parameter can be a value of @ref COMP_Internal_VRefMode */ uint32_t WorkingPin; /*!< There are 2 comparator, they can not work seperate, need use one instance. Use a flag to check whichi one used , bit 0 for comp0 ,bit 1 for comp1, 2 for composite*/ } COMP_InitTypeDef; typedef struct { uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed. Note: For the characteristics of comparator power modes (propagation delay and power consumption), refer to device datasheet. This parameter can be a value of @ref COMP_PowerMode */ uint32_t InvertingInput; /*!< Set comparator input minus (inverting input). This parameter can be a value of @ref COMP_InputMinus */ uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI). This parameter can be a value of @ref COMP_EXTI_TriggerMode */ uint32_t InternalVRef; /*!< Set the comparator internal voltage refrence. This parameter can be a value of @ref COMP_Internal_VRefMode */ uint32_t WorkingPin; /*!< There are 2 comparator, they can not work seperate, need use one instance. Use a flag to check whichi one used , bit 0 for comp0 ,bit 1 for comp1, 2 for composite*/ } COMP_ConfigTypeDef; /** * @brief HAL COMP state machine: HAL COMP states definition */ #define COMP_STATE_BITFIELD_LOCK (0x10U) typedef enum { HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */ HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */ HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */ HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */ HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */ HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */ } HAL_COMP_StateTypeDef; /** * @brief COMP Handle Structure definition */ typedef struct __COMP_HandleTypeDef { LPCOMP_TypeDef *Instance; /*!< Register base address */ COMP_InitTypeDef Init; /*!< COMP required parameters */ HAL_LockTypeDef Lock; /*!< Locking object */ __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */ __IO uint32_t ErrorCode; /*!< COMP error code */ #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ } COMP_HandleTypeDef; #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) /** * @brief HAL COMP Callback ID enumeration definition */ typedef enum { HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ } HAL_COMP_CallbackIDTypeDef; /** * @brief HAL COMP Callback pointer definition */ typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ /** * @} */ /* Exported constants --------------------------------------------------------*/ /** @defgroup COMP_Exported_Constants COMP Exported Constants * @{ */ /** @defgroup COMP_Error_Code COMP Error Code * @{ */ #define HAL_COMP_ERROR_NONE (0x00UL) /*!< No error */ #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL) /*!< Invalid Callback error */ #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ /** * @} */ /** @defgroup COMP_PowerMode COMP power mode * @{ */ /* Note: For the characteristics of comparator power modes */ /* (propagation delay and power consumption), */ /* refer to device datasheet. */ #define COMP_POWERMODE_HIGHSPEED (0x00000002UL<State = HAL_COMP_STATE_RESET; \ (__HANDLE__)->MspInitCallback = NULL; \ (__HANDLE__)->MspDeInitCallback = NULL; \ } while(0) #else #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET) #endif /** * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE"). * @param \__HANDLE__ COMP handle * @retval None */ #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) /** * @brief Enable the specified comparator. * @param \__HANDLE__ COMP handle * @retval None */ #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, LPCOMP_CR1_EN) /** * @brief Disable the specified comparator. * @param \__HANDLE__ COMP handle * @retval None */ #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, LPCOMP_CR1_EN) /** * @} */ /** * @} */ /* Private types -------------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /** @defgroup COMP_Private_Constants COMP Private Constants * @{ */ /** @defgroup COMP_ExtiLine COMP EXTI Lines * @{ */ #define COMP_EXTI_IT (LPCOMP_CR1_IE) /*!< EXTI line event with interruption */ #define COMP_EXTI_EVENT (0x00000000UL) /*!< EXTI line event only (without interruption) */ #define COMP_EXTI_HIGH (0x00000001UL<