/**
  ******************************************************************************
  * @file    ys32f030_comp.h
  * @author  YSPRING Application Team
  * @version V1.0.1
  * @date    2023.6.28
  * @brief   This file contains all the functions prototypes for the COMP firmware 
  *          library.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __YS32F030_COMP_H
#define __YS32F030_COMP_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "ys32f030.h"
#include "system_ys32f030.h"

/** @addtogroup YS32F030_StdPeriph_Driver
  * @{
  */

/** @addtogroup COMP
  * @{
  */

/* Exported types ------------------------------------------------------------*/
typedef struct{
    uint32_t COMP_PowerMode;
    uint32_t COMP_Polarity;
    uint32_t COMP_FilterCount;
}COMP_InitTypeDef;

/* Exported constants --------------------------------------------------------*/

#define IS_COMP_ALL_PERIPH(PERIPH)       (((PERIPH) == COMP1) || \
                                          ((PERIPH) == COMP2) || \
                                          ((PERIPH) == COMP3) || \
                                          ((PERIPH) == COMP4))

/** @defgroup COMP_PowerMode_define 
  * @{
  */ 
#define  COMP_PowerMode_High     0
#define  COMP_PowerMode_Low      COMP_CSR_PWRMODE_01

#define  IS_COMP_POWER_MODE(MODE)      (((MODE) == COMP_PowerMode_High)  || \
                                        ((MODE) == COMP_PowerMode_Low))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP_Polarity_define 
  * @{
  */ 
#define  COMP_Polarity_NotReversed      0
#define  COMP_Polarity_Reverse          COMP_CSR_POLARITY


#define  IS_COMP_POLARITY(POLARITY)      (((POLARITY) == COMP_Polarity_NotReversed)  || \
                                          ((POLARITY) == COMP_Polarity_Reverse))                                 
/**
  * @}
  */ 

/** @defgroup COMP_Filter_Count_define 
 * @{
 */ 
#define  IS_COMP_FILTER_COUNT(COUNT)  (((COUNT) <= 0xFFFF))                                 
/**
  * @}
  */ 

/** @defgroup COMP1_WindowMode_define 
  * @{
  */ 
#define  COMP1_WindowMode_INPSEL         0                 //The signal is selected by INPSEL [1:0].
#define  COMP1_WindowMode_COMP2_INP      COMP_CSR_WINMODE

#define  IS_COMP1_WINDOW_MODE(MODE)      (((MODE) == COMP1_WindowMode_INPSEL)  || \
                                          ((MODE) == COMP1_WindowMode_COMP2_INP))                                 
/**
  * @}
  */ 

/** @defgroup COMP2_WindowMode_define 
  * @{
  */ 
#define  COMP2_WindowMode_INPSEL         0                 //The signal is selected by INPSEL [1:0].
#define  COMP2_WindowMode_COMP1_INP      COMP_CSR_WINMODE

#define  IS_COMP2_WINDOW_MODE(MODE)      (((MODE) == COMP2_WindowMode_INPSEL)  || \
                                          ((MODE) == COMP2_WindowMode_COMP1_INP))                                 
/**
  * @}
  */ 

/** @defgroup COMP3_WindowMode_define 
  * @{
  */ 
#define  COMP3_WindowMode_INPSEL         0                 //The signal is selected by INPSEL [1:0].
#define  COMP3_WindowMode_COMP4_INP      COMP_CSR_WINMODE

#define  IS_COMP3_WINDOW_MODE(MODE)      (((MODE) == COMP3_WindowMode_INPSEL)  || \
                                          ((MODE) == COMP3_WindowMode_COMP4_INP))                                 
/**
  * @}
  */ 

/** @defgroup COMP4_WindowMode_define 
  * @{
  */ 
#define  COMP4_WindowMode_INPSEL         0                 //The signal is selected by INPSEL [1:0].
#define  COMP4_WindowMode_COMP3_INP      COMP_CSR_WINMODE

#define  IS_COMP4_WINDOW_MODE(MODE)      (((MODE) == COMP4_WindowMode_INPSEL)  || \
                                          ((MODE) == COMP4_WindowMode_COMP3_INP))                                 
/**
  * @}
  */ 

/** @defgroup COMP1_InputPlus_define 
  * @{
  */ 
#define  COMP1_InputPlus_PF4     (0UL<<COMP_CSR_INPSEL_Pos)
#define  COMP1_InputPlus_PB2     (5UL<<COMP_CSR_INPSEL_Pos)
#define  COMP1_InputPlus_PA3     (7UL<<COMP_CSR_INPSEL_Pos)

#define  IS_COMP1_INP_SIGNAL(SIGNAL)      (((SIGNAL) == COMP1_InputPlus_PF4)  || \
                                           ((SIGNAL) == COMP1_InputPlus_PB2)  || \
                                           ((SIGNAL) == COMP1_InputPlus_PA3))                                 
/**
  * @}
  */ 

/** @defgroup COMP2_InputPlus_define 
  * @{
  */ 
#define  COMP2_InputPlus_PF4     (0UL<<COMP_CSR_INPSEL_Pos)
#define  COMP2_InputPlus_PA3     (5UL<<COMP_CSR_INPSEL_Pos)
#define  COMP2_InputPlus_PA1     (7UL<<COMP_CSR_INPSEL_Pos)

#define  IS_COMP2_INP_SIGNAL(SIGNAL)      (((SIGNAL) == COMP2_InputPlus_PF4)  || \
                                           ((SIGNAL) == COMP2_InputPlus_PA3)  || \
                                           ((SIGNAL) == COMP2_InputPlus_PA1))                                 
/**
  * @}
  */ 

/** @defgroup COMP3_InputPlus_define 
  * @{
  */ 
#define  COMP3_InputPlus_PA1     (0UL<<COMP_CSR_INPSEL_Pos)
#define  COMP3_InputPlus_PB0     (5UL<<COMP_CSR_INPSEL_Pos)
#define  COMP3_InputPlus_PA5     (7UL<<COMP_CSR_INPSEL_Pos)

#define  IS_COMP3_INP_SIGNAL(SIGNAL)      (((SIGNAL) == COMP3_InputPlus_PA1 )  || \
                                           ((SIGNAL) == COMP3_InputPlus_PB0 )  || \
                                           ((SIGNAL) == COMP3_InputPlus_PA5 ))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP4_InputPlus_define 
  * @{
  */ 
#define  COMP4_InputPlus_PA0     (0UL<<COMP_CSR_INPSEL_Pos)
#define  COMP4_InputPlus_PB3     (5UL<<COMP_CSR_INPSEL_Pos)
#define  COMP4_InputPlus_PA5     (7UL<<COMP_CSR_INPSEL_Pos)

#define  IS_COMP4_INP_SIGNAL(SIGNAL)      (((SIGNAL) == COMP4_InputPlus_PA0 )  || \
                                           ((SIGNAL) == COMP4_InputPlus_PB3 )  || \
                                           ((SIGNAL) == COMP4_InputPlus_PA5 ))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP1_InputMinus_define 
  * @{
  */ 
#define  COMP1_InputMinus_1_4_VREF    ( 0UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_1_2_VREF    ( 1UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_3_4_VREF    ( 2UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_VREF        ( 3UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PB7         ( 4UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PA0         ( 8UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PB3         (13UL<<COMP_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PB1         (14UL<<COMP_CSR_INMSEL_Pos)

#define  IS_COMP1_INM_SIGNAL(SIGNAL)      (((SIGNAL) == COMP1_InputMinus_1_4_VREF)  || \
                                           ((SIGNAL) == COMP1_InputMinus_1_2_VREF)  || \
                                           ((SIGNAL) == COMP1_InputMinus_3_4_VREF)  || \
                                           ((SIGNAL) == COMP1_InputMinus_VREF    )  || \
                                           ((SIGNAL) == COMP1_InputMinus_PB7     )  || \
                                           ((SIGNAL) == COMP1_InputMinus_PA0     )  || \
                                           ((SIGNAL) == COMP1_InputMinus_PB3     )  || \
                                           ((SIGNAL) == COMP1_InputMinus_PB1     ))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP2_InputMinus_define 
  * @{
  */ 
#define  COMP2_InputMinus_1_4_VREF    ( 0UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_1_2_VREF    ( 1UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_3_4_VREF    ( 2UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_VREF        ( 3UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PA4         ( 4UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PA2         ( 8UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PB7         (13UL<<COMP_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PA5         (14UL<<COMP_CSR_INMSEL_Pos)

#define  IS_COMP2_INM_SIGNAL(SIGNAL)      (((SIGNAL) == COMP2_InputMinus_1_4_VREF)  || \
                                           ((SIGNAL) == COMP2_InputMinus_3_4_VREF)  || \
                                           ((SIGNAL) == COMP2_InputMinus_1_2_VREF)  || \
                                           ((SIGNAL) == COMP2_InputMinus_VREF    )  || \
                                           ((SIGNAL) == COMP2_InputMinus_PA4     )  || \
                                           ((SIGNAL) == COMP2_InputMinus_PA2     )  || \
                                           ((SIGNAL) == COMP2_InputMinus_PB7     )  || \
                                           ((SIGNAL) == COMP2_InputMinus_PA5     ))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP3_InputMinus_define 
  * @{
  */ 
#define  COMP3_InputMinus_1_4_VREF    ( 0UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_1_2_VREF    ( 1UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_3_4_VREF    ( 2UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_VREF        ( 3UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_PB2         ( 4UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_PA2         ( 8UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_PB13        (13UL<<COMP_CSR_INMSEL_Pos)
#define  COMP3_InputMinus_PB5         (14UL<<COMP_CSR_INMSEL_Pos)

#define  IS_COMP3_INM_SIGNAL(SIGNAL)      (((SIGNAL) == COMP3_InputMinus_1_4_VREF)  || \
                                           ((SIGNAL) == COMP3_InputMinus_3_4_VREF)  || \
                                           ((SIGNAL) == COMP3_InputMinus_1_2_VREF)  || \
                                           ((SIGNAL) == COMP3_InputMinus_VREF    )  || \
                                           ((SIGNAL) == COMP3_InputMinus_PB2     )  || \
                                           ((SIGNAL) == COMP3_InputMinus_PA2     )  || \
                                           ((SIGNAL) == COMP3_InputMinus_PB13    )  || \
                                           ((SIGNAL) == COMP3_InputMinus_PB5     ))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP4_InputMinus_define 
  * @{
  */ 
#define  COMP4_InputMinus_1_4_VREF    ( 0UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_1_2_VREF    ( 1UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_3_4_VREF    ( 2UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_VREF        ( 3UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_PA4         ( 4UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_PA1         ( 8UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_PB13        (13UL<<COMP_CSR_INMSEL_Pos)
#define  COMP4_InputMinus_PB1         (14UL<<COMP_CSR_INMSEL_Pos)

#define  IS_COMP4_INM_SIGNAL(SIGNAL)      (((SIGNAL) == COMP4_InputMinus_1_4_VREF)  || \
                                           ((SIGNAL) == COMP4_InputMinus_3_4_VREF)  || \
                                           ((SIGNAL) == COMP4_InputMinus_1_2_VREF)  || \
                                           ((SIGNAL) == COMP4_InputMinus_VREF    )  || \
                                           ((SIGNAL) == COMP4_InputMinus_PA4     )  || \
                                           ((SIGNAL) == COMP4_InputMinus_PA1     )  || \
                                           ((SIGNAL) == COMP4_InputMinus_PB13    )  || \
                                           ((SIGNAL) == COMP4_InputMinus_PB1     ))                                 
/**
  * @}
  */ 


/* Exported functions ------------------------------------------------------- */
void COMP_DeInit(COMP_TypeDef *COMPx);
void COMP_Init(COMP_TypeDef *COMPx, COMP_InitTypeDef * COMP_InitStruct);
void COMP_StructInit(COMP_InitTypeDef *COMP_InitStruct);

void COMP_Cmd(COMP_TypeDef *COMPx, FunctionalState NewState);
void COMP12_InputHysteresisCmd(COMP_TypeDef *COMPx, FunctionalState NewState);
void COMP34_InputHysteresisCmd(COMP_TypeDef *COMPx, FunctionalState NewState);
void COMP_LockCmd(COMP_TypeDef *COMPx, FunctionalState NewState);

FlagStatus COMP_GetOutStatus(COMP_TypeDef *COMPx);

void COMP_DigitalFilterCmd(COMP_TypeDef *COMPx, FunctionalState NewState);
void COMP_DigitalFilterCountConfig(COMP_TypeDef *COMPx, uint32_t Count);

void COMP1_WindowModeConfig(COMP_TypeDef *COMPx, uint32_t Mode);
void COMP2_WindowModeConfig(COMP_TypeDef *COMPx, uint32_t Mode);
void COMP3_WindowModeConfig(COMP_TypeDef *COMPx, uint32_t Mode);
void COMP4_WindowModeConfig(COMP_TypeDef *COMPx, uint32_t Mode);

void COMP1_InputPlusConfig(COMP_TypeDef *COMPx, uint32_t INPSignal);
void COMP2_InputPlusConfig(COMP_TypeDef *COMPx, uint32_t INPSignal);
void COMP3_InputPlusConfig(COMP_TypeDef *COMPx, uint32_t INPSignal);
void COMP4_InputPlusConfig(COMP_TypeDef *COMPx, uint32_t INPSignal);

void COMP1_InputMinusConfig(COMP_TypeDef *COMPx, uint32_t INMSignal);
void COMP2_InputMinusConfig(COMP_TypeDef *COMPx, uint32_t INMSignal);
void COMP3_InputMinusConfig(COMP_TypeDef *COMPx, uint32_t INMSignal);
void COMP4_InputMinusConfig(COMP_TypeDef *COMPx, uint32_t INMSignal);
  
#ifdef __cplusplus
}
#endif

#endif /* __YS32F030_COMP_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

