#ifndef _FRAM_I2C_H_
#define _FRAM_I2C_H_

#include "apt32f102.h"
#include "apt32f102_gpio.h"

#define FRAM_IIC_SCL	13	//PA13
#define FRAM_IIC_SDA	0	//PB0


#define SDA_ON		GPIO_Write_High(GPIOB0,FRAM_IIC_SDA)
#define SCL_ON		GPIO_Write_High(GPIOA0,FRAM_IIC_SCL)

#define SDA_OFF		GPIO_Write_Low(GPIOB0,FRAM_IIC_SDA)
#define SCL_OFF		GPIO_Write_Low(GPIOA0,FRAM_IIC_SCL)

#define SDA_READ	GPIO_Read_Status(GPIOB0,FRAM_IIC_SDA)


#define FRAM_ENERGY_SAVE_ADDR		0x0010		//存储地址
#define FRAM_ENERGY_SAVE_FLAG		0xA6		//电能检测参数保存标志
#define FRAM_ENERGY_SIZE			50			//存储最大长度
#define PRAM_Offset_Data			0x04		//读取地址偏移




typedef struct{
	
	U32_T total_A_eng;		//A通道总能耗，单位：w/h
	U32_T total_B_eng;		//B通道总能耗，单位：w/h
	U32_T Eng_A_RegData;	//A通道有功电能寄存器累计值
	U32_T Eng_B_RegData;	//B通道有功电能寄存器累计值
	
}FRAM_ENG_t;



extern FRAM_ENG_t g_engfram;

void Bsp_I2C_Fram_Init(void);
U8_T Fram_I2C_WriteByte(U16_T addr, U8_T data);
U8_T Fram_I2C_ReadByte(U16_T addr, U8_T *data);
U8_T Fram_I2C_WriteBytes(U16_T addr, U8_T *data, U16_T len);
U8_T Fram_I2C_ReadBytes(U16_T addr, U8_T *buf, U16_T len);
U8_T FRAM_WriteTotalEng(FRAM_ENG_t *info);
U8_T FRAM_ReadTotalEng(FRAM_ENG_t *info);


#endif


