#ifndef AT24CXX_H__
#define AT24CXX_H__
#include "board.h"

#define IIC_WP_PORT     GPIO9
#define IIC_WP_PIN		GPIO_BIT2

#define IIC_SDA_PORT    GPIO9
#define IIC_SDA_PIN		GPIO_BIT1

#define IIC_SCL_PORT	GPIO9
#define IIC_SCL_PIN     GPIO_BIT0

#define SDA_IN()    GPIO_SetInput(IIC_SDA_PORT,IIC_SDA_PIN)
#define SDA_OUT()   {GPIO_SetOutput(IIC_SDA_PORT,IIC_SDA_PIN);}

#define IIC_SCL(n)  (n?GPIO_SetHigh(IIC_SCL_PORT,IIC_SCL_PIN) : GPIO_SetLow(IIC_SCL_PORT,IIC_SCL_PIN))
#define IIC_SDA(n)  (n?GPIO_SetHigh(IIC_SDA_PORT,IIC_SDA_PIN) : GPIO_SetLow(IIC_SDA_PORT,IIC_SDA_PIN))

#define READ_SDA GPIO_GetValue(IIC_SDA_PORT, IIC_SDA_PIN)

//写保护,低电平关闭，可以写入；高电平打开，不能写入
#define IIC_WRITE_PROTECT_ENABLE()   {GPIO_SetHigh(IIC_WP_PORT, IIC_WP_PIN);}
#define IIC_WRITE_PROTECT_DISABLE()  {GPIO_SetLow(IIC_WP_PORT, IIC_WP_PIN);}

void I2C_init(void);
void IIC_Start(void);
void IIC_Stop(void);
uint8_t IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
void IIC_Send_Byte(uint8_t txd);
uint8_t IIC_Read_Byte(uint8_t ack);

uint8_t AT24CXX_ReadOneByte(uint32_t ReadAddr);
void AT24CXX_WriteOneByte(uint32_t WriteAddr,uint8_t DataToWrite);
void AT24CXX_Read(uint32_t ReadAddr,uint8_t *pBuffer,uint16_t NumToRead);
void AT24CXX_Write(uint32_t WriteAddr,uint8_t *pBuffer,uint16_t NumToWrite);
void AT24CXX_clr(uint32_t WriteAddr,uint32_t NumToWrite);

uint8_t I2C_Test(void);

#define EEPROM_INFO(fmt,arg...)           printf("<<-EEPROM-INFO->> "fmt"\n",##arg)

#endif // !
