#ifndef __POWER_H__
#define __POWER_H__
#include "base/define.h"
#include "dac_cfg.h"
#include "adc_cfg.h"
#include "gpio_cfg.h"

#define R10_ON_Out						PBout(R10_ON_Pin_Nu)
#define R10_SW_ON   					R10_ON_Out=1
#define R10_SW_OFF  					R10_ON_Out=0
#define R510_ON_Out 					PBout(R510_ON_Pin_Nu)
#define R510_SW_ON   					R510_ON_Out=1
#define R510_SW_OFF  					R510_ON_Out=0
#define R100_ON_Out 					PCout(R100_ON_Pin_Nu)
#define R100_SW_ON   					R100_ON_Out=1
#define R100_SW_OFF  					R100_ON_Out=0



#define POWER_DEF_V    60


typedef enum{
R510_0uA_32uA_UC 		= (uint8_t)0,//x201
	R510_0uA_580uA_MC 	= (uint8_t)1,//x11
	R100_0uA_160uA_UC   = (uint8_t)2,//x201
	R100_0p2mA_3mA_MC		= (uint8_t)3,//x11
	R10_0p1mA_1p6mA_UC	= (uint8_t)4,//x201
	R10_2mA_30mA_MC			= (uint8_t)5,//x11
	Current_Max 				= (uint8_t)6,
	Current_SampleR_OFF = (uint8_t)9,
} CurrentSample_Range_eu;

typedef struct {
uint16_t V_LAH;
uint16_t V_LAM;
uint16_t V_LAH_DAC;
uint16_t V_LAM_DAC;
}PowerInfo_st;




 /*
@brief 采样总线输出电压
*/
uint32_t Power_GetBousV(void);
/*
@brief 采样高电平电压
*/
uint32_t Power_GetHPowerV(void);
/*
@brief 采样中电平电压
*/
uint32_t Power_GetMPowerV(void);
/*
@brief 获取内部基准1.2V电压对应的AD
*/
uint32_t Power_GetBaseVAD(void);
//获取总线电流
uint32_t Power_GetCurrent(void);
//根据电流大小的范围，设置采样电阻
CurrentSample_Range_eu  Power_SetSampleCurrentRange(CurrentSample_Range_eu range)	;
#define CurrentSampleR_Def  Power_SetSampleCurrentRange(Current_Max);
/*
@brief 设置电阻采样通道和AD采样配置
*/
CurrentSample_Range_eu Power_SetSampleRange_Seep(CurrentSample_Range_eu range , uint32_t speed);
//检测方案，上电充能采样电阻
#define Checker_PowerOn_Sample_R   		R100_0p2mA_3mA_MC
#define Checker_OnLine_Sample_R       R100_0uA_160uA_UC
#define Checker_MonitorBuf_Sample_R   R100_0p2mA_3mA_MC

#define JQChecker_ChgEnger_Sample_R   R100_0p2mA_3mA_MC
#define XTChecker_ChgEnger_Sample_R   R10_2mA_30mA_MC
#define EWChecker_ChgEnger_Sample_R   R100_0p2mA_3mA_MC
//模块通信采样电阻
#define XTDriver_Sample_R          R10_2mA_30mA_MC
#define JQDriver_Sample_R          R10_2mA_30mA_MC
#define EWDriver_Sample_R          R10_2mA_30mA_MC


//电压调节的关系为线性函数
void PowerCalibration(PowerInfo_st* info_st);
//设置总线电压
void PowerSetVoltage(PowerInfo_st* info_st);
//获取当前电压配置值
void PowerGetSet(PowerInfo_st* info_st);
/*
@brief 设置总线电压
@param h_v/10 设置高电平电压
@param m_v/10 设置中电平电压
@rtv  0 执行成功 1 执行失败
*/
	
uint8_t  PowerCalibration_set(uint16_t h_v,uint16_t m_v);
/*
@brief 将获取的ADC值转换为电压值
@param1 ul_adv 采样AD原始值
@rtv    返回AD采集到的电压值 扩大1000000倍
*/
uint32_t Power_ADVGetCalVal_106(uint16_t ul_adv);

/*
@brief 电源调压准备，计数频率和电压的线性关系
@rtv 返回值：0 成功 其他失败
*/

uint8_t PowerCalPrapare(void);
/*
@brief 通过采样adc，换算电流
@param adv adc 采样值
@param rang 采样电阻
@rtv uint32_t 电流值 0.1uA
*/
uint32_t Power_ConvCur(uint16_t adv,CurrentSample_Range_eu range);
#endif
