#ifndef SGM832_H
#define SGM832_H

#include "ch32v30x.h"
#include "IIC3_Software.h"
//#include "IIC2_Software.h"
#include "uart5.h"

//sgm832 I2C address
//7bit: 1 0 0 0 1 0 1 rw   [8A] ==> (A0->Vss, A1->Vss) for (system power detect)
#define SGM832_I2C_ADDR_SYS    0x8A

//7bit: 1 0 0 0 1 0 0 rw   [8A] ==> (A0->Gnd, A1->Vss) for (back light power detect)
#define SGM832_I2C_ADDR_BL     0x88

//sgm832 register address
#define CONFIGURATION_REGISTER    0x00
#define SHUNT_VOLTAGE_REGISTER    0x01
#define BUS_VOLTAGE_REGISTER      0x02
#define POWER_REGISTER            0x03
#define CURRENT_REGISTER          0x04
#define CALIBRATION_REGISTER      0x05
#define MASK_ENABLE_REGISTER      0x06
#define ALERT_LIMIT_REGISTER      0x07
#define MANUFACTURER_ID_REGISTER  0xFE
#define DIE_ID_REGISTER           0xFF

u8 SGM832_WriteData(u8 address, u8 reg, u8 *data, u8 num);
void Sgm832_Calibration(u8 address);
void sgm832_Power_detect_Proc_Bl(void);
void sgm832_Power_detect_Proc_Sys(void);

//定义全局变量供 IIC_Slave 调用
extern  u16 g_Power_bl;
extern  u16 g_Power_sys;
extern  u16 g_Bus_bl;
extern  u16 g_Bus_sys;


#endif // SGM832_H
