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

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

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "ys32md211.h"
#include "system_ys32md211.h"

/** @addtogroup YS32MD211_StdPeriph_Driver
  * @{
  */

/** @addtogroup COMP
  * @{
  */

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

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

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

/** @defgroup COMP_PowerMode_define 
  * @{
  */ 
#define  COMP_PowerMode_Medium           ((uint32_t)0x40000UL)
#define  COMP_PowerMode_High             ((uint32_t)COMP1_CSR_PWRMODE)

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


#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         ((uint32_t)0x0UL)            //The signal is selected by INPSEL [1:0].
#define  COMP1_WindowMode_COMP2_INP      ((uint32_t)0x800UL)

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

/** @defgroup COMP2_WindowMode_define 
  * @{
  */ 
#define  COMP2_WindowMode_INPSEL         ((uint32_t)0x0UL)            //The signal is selected by INPSEL [1:0].
#define  COMP2_WindowMode_COMP1_INP      ((uint32_t)0x800UL)

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

/** @defgroup COMP1_InputPlus_define 
  * @{
  */ 
#define  COMP1_InputPlus_PF4     (uint32_t)(0UL<<COMP1_CSR_INPSEL_Pos)
#define  COMP1_InputPlus_PA3     (uint32_t)(1UL<<COMP1_CSR_INPSEL_Pos)
#define  COMP1_InputPlus_PB4     (uint32_t)(2UL<<COMP1_CSR_INPSEL_Pos)
#define  COMP1_InputPlus_OPA1    (uint32_t)(3UL<<COMP1_CSR_INPSEL_Pos)

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

/** @defgroup COMP2_InputPlus_define 
  * @{
  */ 
#define  COMP2_InputPlus_PF4     (uint32_t)(0UL<<COMP2_CSR_INPSEL_Pos)
#define  COMP2_InputPlus_PA1     (uint32_t)(1UL<<COMP2_CSR_INPSEL_Pos)
#define  COMP2_InputPlus_PA3     (uint32_t)(2UL<<COMP2_CSR_INPSEL_Pos)
#define  COMP2_InputPlus_OPA2    (uint32_t)(3UL<<COMP2_CSR_INPSEL_Pos)

#define  IS_COMP2_INP_SIGNAL(SIGNAL)      (((SIGNAL) == COMP1_InputPlus_PF4)  || \
                                           ((SIGNAL) == COMP2_InputPlus_PA1)  || \
                                           ((SIGNAL) == COMP2_InputPlus_PA3)  || \
                                           ((SIGNAL) == COMP1_InputPlus_OPA1))                                  
/**
  * @}
  */ 
  
/** @defgroup COMP1_InputMinus_define 
  * @{
  */ 
#define  COMP1_InputMinus_PA0           (uint32_t)(0x0UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PB1           (uint32_t)(0x1UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PB3           (uint32_t)(0x2UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_PB7           (uint32_t)(0x3UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_1_8_VBG1P2    (uint32_t)(0x4UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_2_8_VBG1P2    (uint32_t)(0x5UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_3_8_VBG1P2    (uint32_t)(0x6UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_4_8_VBG1P2    (uint32_t)(0x7UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_5_8_VBG1P2    (uint32_t)(0x8UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_6_8_VBG1P2    (uint32_t)(0x9UL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_7_8_VBG1P2    (uint32_t)(0xAUL<<COMP1_CSR_INMSEL_Pos)
#define  COMP1_InputMinus_VBG1P2        (uint32_t)(0xBUL<<COMP1_CSR_INMSEL_Pos)



#define  IS_COMP1_INM_SIGNAL(SIGNAL)      (((SIGNAL) == COMP1_InputMinus_PA0)        || \
                                           ((SIGNAL) == COMP1_InputMinus_PB1)        || \
                                           ((SIGNAL) == COMP1_InputMinus_PB3)        || \
                                           ((SIGNAL) == COMP1_InputMinus_PB7)        || \
                                           ((SIGNAL) == COMP1_InputMinus_1_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_2_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_3_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_4_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_5_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_6_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_7_8_VBG1P2) || \
                                           ((SIGNAL) == COMP1_InputMinus_VBG1P2))                                 
/**
  * @}
  */ 
  
/** @defgroup COMP2_InputMinus_define 
  * @{
  */ 
#define  COMP2_InputMinus_PA2           (uint32_t)(0x0UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PA4           (uint32_t)(0x1UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PA5           (uint32_t)(0x2UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_PB7           (uint32_t)(0x3UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_1_8_VBG1P2    (uint32_t)(0x4UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_2_8_VBG1P2    (uint32_t)(0x5UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_3_8_VBG1P2    (uint32_t)(0x6UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_4_8_VBG1P2    (uint32_t)(0x7UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_5_8_VBG1P2    (uint32_t)(0x8UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_6_8_VBG1P2    (uint32_t)(0x9UL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_7_8_VBG1P2    (uint32_t)(0xAUL<<COMP2_CSR_INMSEL_Pos)
#define  COMP2_InputMinus_VBG1P2        (uint32_t)(0xBUL<<COMP2_CSR_INMSEL_Pos)



#define  IS_COMP2_INM_SIGNAL(SIGNAL)      (((SIGNAL) == COMP2_InputMinus_PA2)        || \
                                           ((SIGNAL) == COMP2_InputMinus_PA4)        || \
                                           ((SIGNAL) == COMP2_InputMinus_PA5)        || \
                                           ((SIGNAL) == COMP2_InputMinus_PB7)        || \
                                           ((SIGNAL) == COMP2_InputMinus_1_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_2_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_3_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_4_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_5_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_6_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_7_8_VBG1P2) || \
                                           ((SIGNAL) == COMP2_InputMinus_VBG1P2))                                  
/**
  * @}
  */ 
  
/** @defgroup COMP_Anolog_Filter_define 
  * @{
  */ 
#define  COMP_AnologFilter_Disable         ((uint32_t)COMP1_FR_DEG_CTRL1_00)
#define  COMP_AnologFilter_Low             ((uint32_t)COMP1_FR_DEG_CTRL1_Low)
#define  COMP_AnologFilter_Medium          ((uint32_t)COMP1_FR_DEG_CTRL1_Medium)
#define  COMP_AnologFilter_High            ((uint32_t)COMP1_FR_DEG_CTRL1_High)

#define  IS_COMP_AnologFilter(INTENSITY)   (((INTENSITY) == COMP_AnologFilter_Disable)  || \
                                            ((INTENSITY) == COMP_AnologFilter_Low)      || \
                                            ((INTENSITY) == COMP_AnologFilter_Medium)   || \
                                            ((INTENSITY) == COMP_AnologFilter_High))                                 
/**
  * @}
  */ 

/**
  * @}
  */ 


/* 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(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 COMP_AnologFilterSelect(COMP_TypeDef *COMPx, uint32_t intensity);

void COMP1_WindowModeConfig(uint32_t Mode);
void COMP2_WindowModeConfig(uint32_t Mode);

void COMP1_InputPlusConfig(uint32_t INPSignal);
void COMP2_InputPlusConfig(uint32_t INPSignal);

void COMP1_InputMinusConfig(uint32_t INMSignal);
void COMP2_InputMinusConfig(uint32_t INMSignal);
  
#ifdef __cplusplus
}
#endif

#endif /* __YS32MD211_COMP_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

