/*
*********************************************************************************************************
*
* 模块名称 : ds2782驱动
* 文件名称 : DS2782.h
* 版 本 : V1.0
* 说 明 :
*
* 修改记录 :
* 版本号 日期 作者 说明
* V1.0 2019-02-022 Baiyang 正式发布
*
* Copyright (C), 本宝宝不高兴
*
*********************************************************************************************************
*/
#ifndef __BSP_DS2782_H
#define __BSP_DS2782_H
/* Function Commands */
/* 详细 Memory Map 见数据手册P27 [Table 5. Function Commands] */
#define Copy_data_back_0 0x42
#define Copy_data_back_1 0x44
#define recall_data_back_0 0xB2
#define recall_data_back_1 0xB4
#define lock_data_back_0 0x63
#define lock_data_back_1 0x66
/* Memory Map */
/* 详细 Memory Map 见数据手册P23 */
#define STATUS 0x01
#define RAACMSB 0x02
#define RAACLSB 0x03
#define RSACMSB 0x04
#define RSACLSB 0x05
#define RARC 0x06
#define RSRC 0x07
#define IAVGMSB 0x08
#define IAVGLSB 0x09
#define TEMPMSB 0x0A
#define TEMPLSB 0x0B
#define VOLTMSB 0x0C
#define VOLTLSB 0x0D
#define CURRENTMSB 0x0E
#define CURRENTLSB 0x0F
#define ACRMSB 0x10 //. 累计电流
#define ACRLSB 0x11
#define ACRLMSB 0x12
#define ACRLLSB 0x13
#define AS 0x14
#define SFR 0x15
#define FULLMSB 0x16
#define FULLLSB 0x17
#define AEMSB 0x18
#define AELSB 0x19
#define SEMSB 0x1A
#define SELSB 0x1B
#define CONTROL 0x60 //控制寄存器
#define AB 0x61 //累计偏置
#define ACMSB 0x62 //老化容量
#define ACLSB 0x63
#define VCHG 0x64 //充电电压
#define IMIN 0x65 //最小充电电流
#define VAE 0x66 //有效空电压
#define IAE 0x67 //有效空电9999流
#define RSNSP 0x69 //采样电阻
#define FULLSMSB 0x6A //+40°C温度时的满电量值
#define FULLSLSB 0x6B
#define FULL3040 0x6C
#define FULL2030 0x6D
#define FULL1020 0x6E
#define FULL0010 0x6F
#define AE3040 0x70
#define AE2030 0x71
#define AE1020 0x72
#define AE0010 0x73
#define SE3040 0x74
#define SE2030 0x75
#define SE1020 0x76
#define SE0010 0x77
#define RSGAINMSB 0X78
#define RSGAINLSB 0X79
#define RSTC 0X7A
#define FCR 0XFE
#define I2C_WR 0X00
#define I2C_RD 0X01
/*
*Slave Address
* 7bit 0110100
*/
#define DS2782_8bit_Slave_Address 0x34
#define Capacity 4900 //电池容量 mAH
#define RSNSP_mOhm 10 //采样电阻 毫欧
#define Charge_Voltage 3600 //充电电压 mV
#define Minimum_Charge_Current 20 //最小充电电流 mA
#define Empty_Voltage 2800 //有效空电电压 mV
#define Empty_Current 300 //有效空电电流 mA
typedef struct
{
uint8_t _STATUS ; //0x01
uint8_t _RAACMSB ; //0x02
uint8_t _RAACLSB ; //0x03
uint8_t _RSACMSB ; //0x04
uint8_t _RSACLSB ; //0x05
uint8_t _RARC ; //0x06
uint8_t _RSRC ; //0x07
uint8_t _IAVGMSB ; //0x08
uint8_t _IAVGLSB ; //0x09
uint8_t _TEMPMSB ; //0x0A
uint8_t _TEMPLSB ; //0x0B
uint8_t _VOLTMSB ; //0x0C
uint8_t _VOLTLSB ; //0x0D
uint8_t _CURRENTMSB ; //0x0E
uint8_t _CURRENTLSB ; //0x0F
uint8_t _ACRMSB ; //0x10 //. 累计电流
uint8_t _ACRLSB ; //0x11
uint8_t _ACRLMSB ; //0x12
uint8_t _ACRLLSB ; //0x13
uint8_t _AS ; //0x14
uint8_t _SFR ; //0x15
uint8_t _FULLMSB ; //0x16
uint8_t _FULLLSB ; //0x17
uint8_t _AEMSB ; //0x18
uint8_t _AELSB ; //0x19
uint8_t _SEMSB ; //0x1A
uint8_t _SELSB ; //0x1B
}Ds278x;
typedef struct
{
uint8_t _STATUS;
uint16_t _RAAC; //剩余绝对有效电量 (RAAC) [mAh]
uint16_t _RSAC;
uint8_t _RARC; //剩余相对有效电量 (RARC) [%]
uint8_t _RSRC;
uint16_t _IAVG;
uint16_t _TEMP;
uint16_t _VOLT;
int16_t Current;
uint16_t Voltage;
uint16_t _ARC;
uint8_t Connect; //芯片连接状态 连接上写入1 连接失败写入 0
}Ds2782_Typedef;
extern Ds2782_Typedef Ds2782;
extern Ds278x Ds2782_RAM;
uint8_t Get_DS2782_STATUS();
uint16_t Get_DS2782_Temperature();
uint16_t Get_DS2782_Voltage();
int16_t Get_DS2782_Current();
uint16_t Get_DS2782_RAAC();
uint16_t Get_DS2782_RSAC();
uint8_t Get_DS2782_RARC();
uint8_t Get_DS2782_RSRC();
uint16_t Get_DS2782_ACR();
uint16_t Get_DS2782_FULL();
uint16_t Get_DS2782_AE();
uint16_t Get_DS2782_SE();
void Write_DS2782_Shadow_RAM(uint8_t reg_Addres,uint8_t data);
void Copy_Data_For_Shadow_RAM_To_EEPROM(uint8_t EEPROM_BLOCK);
void bsp_Init_DS2782();
void Module_DS2781_Set_Register(void);
#endif