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

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

#ifdef __cplusplus
 extern "C" {
#endif

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

/** @addtogroup YS32MD211_StdPeriph_Driver
  * @{
  */

/** @addtogroup PWR
  * @{
  */ 

 typedef struct
{
  uint8_t PWR_MR_SOFT_ADD;
  uint8_t PWR_CPU_Halt;
  uint8_t PWR_HSION_CFG;
  uint8_t PWR_FLS_Turbo;
  uint8_t PWR_VOS;
  uint8_t PWR_Bias_CR_Sel;
  uint8_t PWR_Bias_CR_MR;
}PWR_InitTypeDef;

/* Exported types ------------------------------------------------------------*/

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

/** @defgroup PWR_Exported_Constants
  * @{
  */ 

 /** @defgroup PWR_Init
  * @{
  */
#define PWR_MR_SOFT_ADD_DISABLE     ((uint32_t)0x00000000)
#define PWR_MR_SOFT_ADD_ENABLE      ((uint32_t)PWR_CR1_MR_SOFT_ADD)
#define IS_PWR_MR_SOFT_ADD(STATUS)  (((STATUS) == PWR_MR_SOFT_ADD_DISABLE) || \
                                     ((STATUS) == PWR_MR_SOFT_ADD_ENABLE))

#define PWR_CPU_Halt_OFF            ((uint32_t)0x00000000)
#define PWR_CPU_Halt_0N             ((uint32_t)PWR_CR1_CPU_HALT)
#define IS_PWR_CPU_HALT(STATUS) (((STATUS) == PWR_CPU_Halt_OFF) || \
                                 ((STATUS) == PWR_CPU_Halt_0N))

#define PWR_HSION_CFG_MR            ((uint32_t)0x00000000)
#define PWR_HSION_CFG_VR            ((uint32_t)PWR_CR1_HSION_CFG)
#define IS_PWR_HSION_CFG(STATUS) (((STATUS) == PWR_HSION_CFG_MR) || \
                                  ((STATUS) == PWR_HSION_CFG_VR))

#define PWR_FLS_Turbo_6US           ((uint32_t)0x00000000)
#define PWR_FLS_Turbo_3US           ((uint32_t)PWR_CR1_FLS_TURBO)
#define IS_PWR_FLS_TURBO(STATUS) (((STATUS) == PWR_FLS_Turbo_6US) || \
                                  ((STATUS) == PWR_FLS_Turbo_3US))

#define PWR_VOS_1_2V                ((uint32_t)0x00000000)
#define PWR_VOS_1_0V                ((uint32_t)PWR_CR1_VOS)
#define IS_PWR_VOS(STATUS) (((STATUS) == PWR_VOS_1_2V) || \
                            ((STATUS) == PWR_VOS_1_0V))

#define PWR_Bias_CR_Sel_Factory     ((uint32_t)0x00000000)
#define PWR_Bias_CR_Sel_CR          ((uint32_t)PWR_CR1_BIAS_CR_SEL)
#define IS_PWR_BIAS_CR_SEL(STATUS) (((STATUS) == PWR_Bias_CR_Sel_Factory) || \
                                    ((STATUS) == PWR_Bias_CR_Sel_CR))

#define PWR_Bias_CR_MR_0            ((uint32_t)0)
#define PWR_Bias_CR_MR_1            ((uint32_t)1)
#define PWR_Bias_CR_MR_2            ((uint32_t)2)
#define PWR_Bias_CR_MR_3            ((uint32_t)3)
#define PWR_Bias_CR_MR_4            ((uint32_t)4)
#define PWR_Bias_CR_MR_5            ((uint32_t)5)
#define PWR_Bias_CR_MR_6            ((uint32_t)6)
#define PWR_Bias_CR_MR_7            ((uint32_t)7)
#define PWR_Bias_CR_MR_8            ((uint32_t)8)
#define PWR_Bias_CR_MR_9            ((uint32_t)9)
#define PWR_Bias_CR_MR_10           ((uint32_t)10)
#define PWR_Bias_CR_MR_11           ((uint32_t)11)
#define PWR_Bias_CR_MR_12           ((uint32_t)12)
#define PWR_Bias_CR_MR_13           ((uint32_t)13)
#define PWR_Bias_CR_MR_14           ((uint32_t)14)
#define PWR_Bias_CR_MR_15           ((uint32_t)15)
#define IS_PWR_BIAS_CR_MR(STATUS) ((STATUS) <= PWR_Bias_CR_MR_15)

/**
  * @}
  */

/** @defgroup PWR_PVD_detection_level 
  * @brief    
  * @{
  */ 

#define PWR_PVDLevel_0                  PWR_CR2_PVDT_VPVD0
#define PWR_PVDLevel_1                  PWR_CR2_PVDT_VPVD1
#define PWR_PVDLevel_2                  PWR_CR2_PVDT_VPVD2
#define PWR_PVDLevel_3                  PWR_CR2_PVDT_VPVD3
#define PWR_PVDLevel_4                  PWR_CR2_PVDT_VPVD4
#define PWR_PVDLevel_5                  PWR_CR2_PVDT_VPVD5
#define PWR_PVDLevel_6                  PWR_CR2_PVDT_VPVD6
#define PWR_PVDLevel_7                  PWR_CR2_PVDT_VPVD7 

#define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \
                                 ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \
                                 ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \
                                 ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7))
/**
  * @}
  */

/** @defgroup PWR_Regulator_state_is_Sleep_STOP_mode 
  * @{
  */

#define PWR_Regulator_ON                ((uint32_t)0x00000000)
#define PWR_Regulator_LowPower          ((uint32_t)0x00000001)
#define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \
                                     ((REGULATOR) == PWR_Regulator_LowPower))
/**
  * @}
  */

/** @defgroup PWR_SLEEP_mode_entry 
  * @{
  */

#define PWR_SLEEPEntry_WFI              ((uint8_t)0x01)
#define PWR_SLEEPEntry_WFE              ((uint8_t)0x02)
#define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPEntry_WFI) || ((ENTRY) == PWR_SLEEPEntry_WFE))
 
/**
  * @}
  */

/** @defgroup PWR_STOP_mode_entry 
  * @{
  */

#define PWR_STOPEntry_WFI               ((uint8_t)0x01)
#define PWR_STOPEntry_WFE               ((uint8_t)0x02)
#define PWR_STOPEntry_SLEEPONEXIT       ((uint8_t)0x03)
#define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE) ||\
                                  ((ENTRY) == PWR_STOPEntry_SLEEPONEXIT))
 
/**
  * @}
  */

/** @defgroup PWR_Flag 
  * @{
  */

#define PWR_FLAG_PVDO                   PWR_SR_PVDO

#define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_PVDO))

/**
  * @}
  */

/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

/* Function used to set the PWR configuration to the default reset state ******/
void PWR_DeInit(void);
void PWR_Init(PWR_InitTypeDef * PWR_InitType);
void PWR_StructInit(PWR_InitTypeDef * PWR_InitType);
/* Backup Domain Access function **********************************************/
void PWR_BackupAccessCmd(FunctionalState NewState);

/* PVD configuration functions ************************************************/
void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 
void PWR_PVDCmd(FunctionalState NewState); 

/* Low Power modes configuration functions ************************************/
void PWR_EnterSleepMode(uint8_t PWR_SLEEPEntry);
void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);

/* Flags management functions *************************************************/
FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);

#ifdef __cplusplus
}
#endif

#endif /* __YS32MD211_PWR_H */

/**
  * @}
  */

/**
  * @}
  */

