/*
 * spv40xx_pmu.h
 *
 *  Created on: 2023年5月10日
 *      Author: mglsq
 */

#ifndef _HAL_PMU_H_
#define _HAL_PMU_H_

#include "platform.h"

typedef enum
{
    PMU_POWER_DETECT_CPP = AON_PMU_PWR_CTL_CPP_DET_EN,
    PMU_POWER_DETECT_AVCC = AON_PMU_PWR_CTL_AVCC_DET_EN,
    PMU_POWER_DETECT_DVDD = AON_PMU_PWR_CTL_DVDD_DET_EN,
    PMU_POWER_DETECT_IOVCC = AON_PMU_PWR_CTL_IOVCC_DET_EN
} pmu_power_detect_en_t;

typedef enum
{
    PMU_POWER_FORCE_ON_CPP = AON_PMU_PWR_CTL_CPP_FORCE_EN,
    PMU_POWER_FORCE_ON_AVCC = AON_PMU_PWR_CTL_AVCC_FORCE_EN,
    PMU_POWER_FORCE_ON_VDDQ = AON_PMU_PWR_CTL_VDDQ_FORCE_EN,
    PMU_POWER_FORCE_ON_DVDD = AON_PMU_PWR_CTL_DVDD_FORCE_EN,
    PMU_POWER_FORCE_ON_IOVCC = AON_PMU_PWR_CTL_IOVCC_FORCE_EN,
    PMU_POWER_FORCE_ON_BIAS = AON_PMU_PWR_CTL_BIAS_FORCE_EN
} pmu_power_force_en_t;

typedef enum
{
    PMU_POWER_NORMAL_ON_CPP = AON_PMU_PWR_CTL_CPP_NORM_EN,
    PMU_POWER_NORMAL_ON_AVCC = AON_PMU_PWR_CTL_AVCC_NORM_EN,
    PMU_POWER_NORMAL_ON_VDDQ = AON_PMU_PWR_CTL_VDDQ_NORM_EN,
    PMU_POWER_NORMAL_ON_DVDD = AON_PMU_PWR_CTL_DVDD_NORM_EN,
    PMU_POWER_NORMAL_ON_IOVCC = AON_PMU_PWR_CTL_IOVCC_NORM_EN,
    PMU_POWER_NORMAL_ON_BIAS = AON_PMU_PWR_CTL_BIAS_NORM_EN
} pmu_power_normal_en_t;

typedef enum
{
    PMU_RESTART_TIME_100MS = AON_PMU_PWR_CTL_RESTART_TIME_100MS,
    PMU_RESTART_TIME_250MS = AON_PMU_PWR_CTL_RESTART_TIME_250MS,
    PMU_RESTART_TIME_500MS = AON_PMU_PWR_CTL_RESTART_TIME_500MS,
    PMU_RESTART_TIME_1S = AON_PMU_PWR_CTL_RESTART_TIME_1S
} pmu_restart_time_t;

typedef enum
{
    PMU_STATE_ACTIVE = AON_PMU_PWR_CTL_STATE_ACTIVE,
    PMU_STATE_STANDBY = AON_PMU_PWR_CTL_STATE_STANDBY,
    PMU_STATE_HIBERNATE = AON_PMU_PWR_CTL_STATE_HIBERNATE,
    PMU_STATE_RESTART = AON_PMU_PWR_CTL_STATE_RESTART
} pmu_state_set_t;

typedef enum
{
    PMU_AVDD_VOL_1_05V = AON_PMU_VOL_CTL_AVDD_VOL_1_05V,
    PMU_AVDD_VOL_1_10V = AON_PMU_VOL_CTL_AVDD_VOL_1_10V,
    PMU_AVDD_VOL_1_15V = AON_PMU_VOL_CTL_AVDD_VOL_1_15V,
    PMU_AVDD_VOL_1_20V = AON_PMU_VOL_CTL_AVDD_VOL_1_20V
} pmu_avdd_vol_t;

typedef enum
{
    PMU_CPP_VOL_1_70V = AON_PMU_VOL_CTL_CPP_VOL_1_70V,
    PMU_CPP_VOL_1_75V = AON_PMU_VOL_CTL_CPP_VOL_1_75V,
    PMU_CPP_VOL_1_80V = AON_PMU_VOL_CTL_CPP_VOL_1_80V,
    PMU_CPP_VOL_1_85V = AON_PMU_VOL_CTL_CPP_VOL_1_85V
} pmu_cpp_vol_t;

typedef enum
{
    PMU_IOVCC_VOL_1_8V = AON_PMU_VOL_CTL_IOVCC_VOL_1_8V,
    PMU_IOVCC_VOL_1_9V = AON_PMU_VOL_CTL_IOVCC_VOL_1_9V,
    PMU_IOVCC_VOL_2_0V = AON_PMU_VOL_CTL_IOVCC_VOL_2_0V,
    PMU_IOVCC_VOL_2_1V = AON_PMU_VOL_CTL_IOVCC_VOL_2_1V,
    PMU_IOVCC_VOL_2_2V = AON_PMU_VOL_CTL_IOVCC_VOL_2_2V,
    PMU_IOVCC_VOL_2_3V = AON_PMU_VOL_CTL_IOVCC_VOL_2_3V,
    PMU_IOVCC_VOL_2_4V = AON_PMU_VOL_CTL_IOVCC_VOL_2_4V,
    PMU_IOVCC_VOL_2_5V = AON_PMU_VOL_CTL_IOVCC_VOL_2_5V,
    PMU_IOVCC_VOL_2_6V = AON_PMU_VOL_CTL_IOVCC_VOL_2_6V,
    PMU_IOVCC_VOL_2_7V = AON_PMU_VOL_CTL_IOVCC_VOL_2_7V,
    PMU_IOVCC_VOL_2_8V = AON_PMU_VOL_CTL_IOVCC_VOL_2_8V,
    PMU_IOVCC_VOL_2_9V = AON_PMU_VOL_CTL_IOVCC_VOL_2_9V,
    PMU_IOVCC_VOL_3_0V = AON_PMU_VOL_CTL_IOVCC_VOL_3_0V,
    PMU_IOVCC_VOL_3_1V = AON_PMU_VOL_CTL_IOVCC_VOL_3_1V,
    PMU_IOVCC_VOL_3_2V = AON_PMU_VOL_CTL_IOVCC_VOL_3_2V,
    PMU_IOVCC_VOL_3_3V = AON_PMU_VOL_CTL_IOVCC_VOL_3_3V
} pmu_iovcc_vol_t;

typedef enum
{
    PMU_AVCC_VOL_2_7V = AON_PMU_VOL_CTL_AVCC_VOL_2_7V,
    PMU_AVCC_VOL_2_8V = AON_PMU_VOL_CTL_AVCC_VOL_2_8V,
    PMU_AVCC_VOL_2_9V = AON_PMU_VOL_CTL_AVCC_VOL_2_9V,
    PMU_AVCC_VOL_3_0V = AON_PMU_VOL_CTL_AVCC_VOL_3_0V,
    PMU_AVCC_VOL_3_1V = AON_PMU_VOL_CTL_AVCC_VOL_3_1V,
    PMU_AVCC_VOL_3_2V = AON_PMU_VOL_CTL_AVCC_VOL_3_2V,
    PMU_AVCC_VOL_3_3V = AON_PMU_VOL_CTL_AVCC_VOL_3_3V,
    PMU_AVCC_VOL_3_4V = AON_PMU_VOL_CTL_AVCC_VOL_3_4V
} pmu_avcc_vol_t;

typedef enum
{
    PMU_DVDD_VOL_0_7V = AON_PMU_VOL_CTL_DVDD_VOL_0_7V,
    PMU_DVDD_VOL_0_8V = AON_PMU_VOL_CTL_DVDD_VOL_0_8V,
    PMU_DVDD_VOL_0_9V = AON_PMU_VOL_CTL_DVDD_VOL_0_9V,
    PMU_DVDD_VOL_1_0V = AON_PMU_VOL_CTL_DVDD_VOL_1_0V,
    PMU_DVDD_VOL_1_1V = AON_PMU_VOL_CTL_DVDD_VOL_1_1V,
    PMU_DVDD_VOL_1_2V = AON_PMU_VOL_CTL_DVDD_VOL_1_2V,
    PMU_DVDD_VOL_1_3V = AON_PMU_VOL_CTL_DVDD_VOL_1_3V,
    PMU_DVDD_VOL_1_4V = AON_PMU_VOL_CTL_DVDD_VOL_1_4V
} pmu_dvdd_vol_t;

typedef enum
{
    PMU_SVDD_VOL_1_05V = AON_PMU_VOL_CTL_SVDD_VOL_1_05V,
    PMU_SVDD_VOL_1_10V = AON_PMU_VOL_CTL_SVDD_VOL_1_10V,
    PMU_SVDD_VOL_1_15V = AON_PMU_VOL_CTL_SVDD_VOL_1_15V,
    PMU_SVDD_VOL_1_20V = AON_PMU_VOL_CTL_SVDD_VOL_1_20V
} pmu_svdd_vol_t;

typedef enum
{
    PMU_SVCC_VOL_2_7V = AON_PMU_VOL_CTL_SVCC_VOL_2_7V,
    PMU_SVCC_VOL_2_8V = AON_PMU_VOL_CTL_SVCC_VOL_2_8V,
    PMU_SVCC_VOL_2_9V = AON_PMU_VOL_CTL_SVCC_VOL_2_9V,
    PMU_SVCC_VOL_3_0V = AON_PMU_VOL_CTL_SVCC_VOL_3_0V,
    PMU_SVCC_VOL_3_1V = AON_PMU_VOL_CTL_SVCC_VOL_3_1V,
    PMU_SVCC_VOL_3_2V = AON_PMU_VOL_CTL_SVCC_VOL_3_2V,
    PMU_SVCC_VOL_3_3V = AON_PMU_VOL_CTL_SVCC_VOL_3_3V,
    PMU_SVCC_VOL_3_4V = AON_PMU_VOL_CTL_SVCC_VOL_3_4V
} pmu_svcc_vol_t;

typedef enum
{
    PMU_CLK_KEEP_PLL_AUDIO = AON_PMU_CLK_CTL_PLL_AUDIO_KEEP,
    PMU_CLK_KEEP_PLL_CORE = AON_PMU_CLK_CTL_PLL_CORE_KEEP,
    PMU_CLK_KEEP_OSC_XTAL = AON_PMU_CLK_CTL_OSC_XTAL_KEEP,
    PMU_CLK_KEEP_OSC_DEV = AON_PMU_CLK_CTL_OSC_DEV_KEEP
} pmu_clk_keep_t;

typedef enum
{
    PMU_ONOFF_EDGE_NONE = AON_PMU_ONOFF_ONOFF_EDGE_NONE,
    PMU_ONOFF_EDGE_RISE = AON_PMU_ONOFF_ONOFF_EDGE_RISE,
    PMU_ONOFF_EDGE_FALL = AON_PMU_ONOFF_ONOFF_EDGE_FALL,
    PMU_ONOFF_EDGE_BOTH = AON_PMU_ONOFF_ONOFF_EDGE_BOTHEDGE,
    PMU_ONOFF_EDGE_HIGH = AON_PMU_ONOFF_ONOFF_EDGE_HIGH,
    PMU_ONOFF_EDGE_LOW = AON_PMU_ONOFF_ONOFF_EDGE_LOW
} pmu_onoff_edge_t;

typedef enum
{
    PMU_ONOFF_LONG_TIME_4S = AON_PMU_ONOFF_ONOFF_LONG_TIME_4S,
    PMU_ONOFF_LONG_TIME_8S = AON_PMU_ONOFF_ONOFF_LONG_TIME_8S,
    PMU_ONOFF_LONG_TIME_12S = AON_PMU_ONOFF_ONOFF_LONG_TIME_12S,
    PMU_ONOFF_LONG_TIME_16S = AON_PMU_ONOFF_ONOFF_LONG_TIME_16S
} pmu_onoff_long_time_t;

typedef enum
{
    PMU_ONOFF_ULONG_TIME_12S = AON_PMU_ONOFF_ONOFF_ULONG_TIME_12S,
    PMU_ONOFF_ULONG_TIME_24S = AON_PMU_ONOFF_ONOFF_ULONG_TIME_24S
} pmu_onoff_ulong_time_t;

typedef enum
{
    PMU_ONOFF_SHORT_TIME_125MS = AON_PMU_ONOFF_ONOFF_SHORT_TIME_125MS,
    PMU_ONOFF_SHORT_TIME_250MS = AON_PMU_ONOFF_ONOFF_SHORT_TIME_250MS,
    PMU_ONOFF_SHORT_TIME_500MS = AON_PMU_ONOFF_ONOFF_SHORT_TIME_500MS,
    PMU_ONOFF_SHORT_TIME_1S = AON_PMU_ONOFF_ONOFF_SHORT_TIME_1S,
    PMU_ONOFF_SHORT_TIME_1_5S = AON_PMU_ONOFF_ONOFF_SHORT_TIME_1_5S,
    PMU_ONOFF_SHORT_TIME_2S = AON_PMU_ONOFF_ONOFF_SHORT_TIME_2S,
    PMU_ONOFF_SHORT_TIME_3S = AON_PMU_ONOFF_ONOFF_SHORT_TIME_3S,
    PMU_ONOFF_SHORT_TIME_4S = AON_PMU_ONOFF_ONOFF_SHORT_TIME_4S
} pmu_onoff_short_time_t;

typedef enum
{
    PMU_ONOFF_DEB_TIME_25MS = AON_PMU_ONOFF_ONOFF_DEB_TIME_25MS,
    PMU_ONOFF_DEB_TIME_50MS = AON_PMU_ONOFF_ONOFF_DEB_TIME_50MS,
    PMU_ONOFF_DEB_TIME_75MS = AON_PMU_ONOFF_ONOFF_DEB_TIME_75MS,
    PMU_ONOFF_DEB_TIME_100MS = AON_PMU_ONOFF_ONOFF_DEB_TIME_100MS
} pmu_onoff_deb_time_t;

typedef enum
{
    PMU_ONOFF_STATE_PRESS = 0ul,
    PMU_ONOFF_STATE_NO_PRESS = 1ul
} pmu_onoff_in_state_t;

typedef enum
{
    PMU_POWER_STATE_ONOFF_WAKEUP = 0ul,
    PMU_POWER_STATE_FISRT_POWERUP = 1ul
} pmu_power_on_status_t;

typedef enum
{
    PMU_POWER_OK_CPP = AON_PMU_PWR_STA_CPPOK,
    PMU_POWER_OK_IOVCC = AON_PMU_PWR_STA_IOVCCOK,
    PMU_POWER_OK_AVCC = AON_PMU_PWR_STA_AVCCOK,
    PMU_POWER_OK_DVDD = AON_PMU_PWR_STA_DVDDOK
} pmu_power_status_t;

typedef enum
{
    PMU_IT_SPIO_INT = AON_PMU_IE_SPIO_INT,
    PMU_IT_ONOFF_EDGE = AON_PMU_IE_ONOFF_EDGE,
    PMU_IT_ONOFF_XLONG = AON_PMU_IE_ONOFF_XLONG,
    PMU_IT_ONOFF_ULONG = AON_PMU_IE_ONOFF_ULONG,
    PMU_IT_ONOFF_LONG = AON_PMU_IE_ONOFF_LONG,
    PMU_IT_ONOFF_SHORT = AON_PMU_IE_ONOFF_SHORT
} pmu_interrupt_en_t;

typedef enum
{
    PMU_SPIO_PENDING = AON_PMU_PD_SPIO_INT,
    PMU_ONOFF_EDGE_PENDING = AON_PMU_PD_ONOFF_EDGE,
    PMU_ONOFF_XLONG_PENDING = AON_PMU_PD_ONOFF_XLONG,
    PMU_ONOFF_ULONG_PENDING = AON_PMU_PD_ONOFF_ULONG,
    PMU_ONOFF_LONG_PENDING = AON_PMU_PD_ONOFF_LONG,
    PMU_ONOFF_SHORT_PENDING = AON_PMU_PD_ONOFF_SHORT
} pmu_pending_flag_t;

typedef enum
{
    PMU_WAKEUP_SPIO_INT = AON_PMU_WKEN_SPIO_INT,
    PMU_WAKEUP_ONOFF_EDGE = AON_PMU_WKEN_ONOFF_EDGE,
    PMU_WAKEUP_ONOFF_XLONG = AON_PMU_WKEN_ONOFF_XLONG,
    PMU_WAKEUP_ONOFF_ULONG = AON_PMU_WKEN_ONOFF_ULONG,
    PMU_WAKEUP_ONOFF_LONG = AON_PMU_WKEN_ONOFF_LONG,
    PMU_WAKEUP_ONOFF_SHORT = AON_PMU_WKEN_ONOFF_SHORT
} pmu_wakeup_en_t;

typedef enum
{
    PMU_RESTART_SVDD = AON_PMU_RSTEN_RESTART_SVDD,
    PMU_RESTART_XLONG = AON_PMU_RSTEN_RESTART_XLONG,
    PMU_RESTART_ULONG = AON_PMU_RSTEN_RESTART_ULONG,
    PMU_RESTART_LONG = AON_PMU_RSTEN_RESTART_LONG,
    PMU_RESTART_SHORT = AON_PMU_RSTEN_RESTART_SHORT
} pmu_restart_en_t;

typedef enum
{
    PMU_RESET_SVDD = AON_PMU_RSTEN_RESET_SVDD,
    PMU_RESET_XLONG = AON_PMU_RSTEN_RESET_XLONG,
    PMU_RESET_ULONG = AON_PMU_RSTEN_RESET_ULONG,
    PMU_RESET_LONG = AON_PMU_RSTEN_RESET_LONG,
    PMU_RESET_SHORT = AON_PMU_RSTEN_RESET_SHORT
} pmu_reset_en_t;

//PMU电源检测
void pmu_power_detect_config(pmu_power_detect_en_t pwr_det, uint32_t en);
uint32_t pmu_get_power_detect_config(void);

//PMU电源强制开启功能
void pmu_power_force_on_config(pmu_power_force_en_t pwr_force, uint32_t en);
uint32_t pmu_get_power_force_on_config(void);

//PMU电源平常开启功能
void pmu_power_normal_on_config(pmu_power_normal_en_t pwr_normal, uint32_t en);
uint32_t pmu_get_power_normal_on_config(void);

//PMU状态配置
void pmu_state_config(pmu_state_set_t pwr_state);

//PMU RESTART功能
void pmu_state_restart(pmu_restart_time_t pwr_restart_time);

//PMU AVDD电压配置
void pmu_avdd_voltage_config(pmu_avdd_vol_t pwr_avdd_vol);
pmu_avdd_vol_t pmu_get_avdd_voltage_config(void);

//PMU CPP电压配置
void pmu_cpp_voltage_config(pmu_cpp_vol_t pwr_cpp_vol);
pmu_cpp_vol_t pmu_get_cpp_voltage_config(void);

//PMU IOVCC电压配置
void pmu_iovcc_voltage_config(pmu_iovcc_vol_t pwr_iovcc_vol);
pmu_iovcc_vol_t pmu_get_iovcc_voltage_config(void);

//PMU AVCC电压配置
void pmu_avcc_voltage_config(pmu_avcc_vol_t pwr_avcc_vol);
pmu_avcc_vol_t pmu_get_avcc_voltage_config(void);

//PMU DVDD电压配置
void pmu_dvdd_voltage_config(pmu_dvdd_vol_t pwr_dvdd_vol);
pmu_dvdd_vol_t pmu_get_dvdd_voltage_config(void);

//PMU SVDD电压配置
void pmu_svdd_voltage_config(pmu_svdd_vol_t pwr_svdd_vol);
pmu_svdd_vol_t pmu_get_svdd_voltage_config(void);

//PMU SVCC电压配置
void pmu_svcc_voltage_config(pmu_svcc_vol_t pwr_svcc_vol);
pmu_svcc_vol_t pmu_get_svcc_voltage_config(void);

//PMU时钟保持配置
void pmu_clk_keep_config(uint32_t pwr_clk_keep_s, uint32_t en);
uint32_t pmu_get_ckl_keep_config(void);

//PMU ONOFF边沿配置
void pmu_onoff_edge_config(pmu_onoff_edge_t pwr_onoff_edge);
pmu_onoff_edge_t pmu_get_onoff_edge_config(void);

//PMU GPIO作为ONOFF功能配置
void pmu_gpio_to_onoff_enable(uint32_t en);
uint32_t pmu_is_gpio_onoff_en(void);

//PMU ONOFF引脚的ONOFF功能配置
void pmu_onoff_pin_enable(uint32_t en);
uint32_t pmu_is_onoff_pin_en(void);

//PMU ONOFF长按时间配置
void pmu_onoff_long_time_config(pmu_onoff_long_time_t pwr_onoff_long_time);
pmu_onoff_long_time_t pmu_get_onoff_long_time_config(void);

//PMU ONOFF超长按时间配置
void pmu_onoff_ulong_time_config(pmu_onoff_ulong_time_t pwr_onoff_ulong_time);
pmu_onoff_ulong_time_t pmu_get_onoff_ulong_time_config(void);

//PMU ONOFF短按时间配置
void pmu_onoff_short_time_config(pmu_onoff_short_time_t pwr_onoff_short_time);
pmu_onoff_short_time_t pmu_get_onoff_short_time_config(void);

//PMU ONOFF防抖时间配置
void pmu_onoff_debounce_time_config(pmu_onoff_deb_time_t pwr_onoff_deb_time);
pmu_onoff_short_time_t pmu_get_onoff_debounce_time_config(void);

//PMU ONOFF的BOOT功能配置
void pmu_onoff_boot_cmd(uint32_t en);
uint32_t pmu_is_onoff_boot_en(void);

//获取PMU ONOFF防抖后的按下状态
pmu_onoff_in_state_t pmu_get_onoff_debounce_status(void);

//获取PMU 电源状态
pmu_power_on_status_t pmu_get_power_status(void);

//获取PMU 各路电源的状态
uint32_t pmu_get_power_ok_status(void);

//PMU 中断使能配置
void pmu_interrupt_enable_config(pmu_interrupt_en_t pwr_irq);

//获取PMU 中断Pending寄存器数据
uint32_t pmu_get_interrupt_pending(void);

//获取PMU 特定中断Pending位的状态
uint32_t pmu_is_interrupt_pending(pmu_pending_flag_t pwr_irq);

//获取PMU 特定中断是否有效
uint32_t pmu_is_interrupt_valid(pmu_pending_flag_t pwr_irq);

void pmu_restart_config(pmu_restart_en_t pwr_restart_s, uint32_t en);
uint32_t pmu_get_restart_config(void);

//清除PMU 中断Pending位
void pmu_clear_interrupt_pending(uint32_t pwr_it_s);

//PMU 唤醒功能
void pmu_wakeup_config(pmu_wakeup_en_t pwr_wakeup, uint32_t en);
uint32_t pmu_get_wakeup_config(void);

//PMU RESET功能
void pmu_reset_config(pmu_reset_en_t pwr_reset_s, uint32_t en);
uint32_t pmu_get_reset_config(void);

void pmu_onoff_boot_enable(uint32_t en);
#endif /* _HAL_PMU_H_ */
