#ifndef _24CXX_H_
#define _24CXX_H_
#include "i2c-dev.h"

#define EEPROM_TYPE_UNKNOWN     0
#define EEPROM_TYPE_8BIT_ADDR   1
#define EEPROM_TYPE_16BIT_ADDR  2

struct eeprom
{
	char *dev;      // device file i.e. /dev/i2c-N
	int addr;       // i2c address
	int fd;         // file descriptor
	int type;       // eeprom type
	int write_cycle_time;
};


void pabort(const char *s);
int spinor_init(int fd, uint8_t spimode, uint8_t spibits, uint32_t spispeed, uint16_t spidelay);
int spinor_wake(int iFd);
int spinor_wren(int iFd);
int spinor_rdsr(int iFd, char *cBuf);
int spinor_write(int iFd, int iAddr, char *cBuf, int iLen);
int spinor_read(int iFd, int iAddr, char *cBuf, int iLen);


/*
 * opens the eeprom device at [dev_fqn] (i.e. /dev/i2c-N) whose address is
 * [addr] and set the eeprom_24c32 [e]
 */
int eeprom_open(char *dev_fqn, int addr, int type, int delay, struct eeprom*);
/*
 * closees the eeprom device [e]
 */
int eeprom_close(struct eeprom *e);
/*
 * read and returns the eeprom byte at memory address [mem_addr]
 * Note: eeprom must have been selected by ioctl(fd,I2C_SLAVE,address)
 */
int eeprom_read_byte(struct eeprom* e, __u16 mem_addr);
/*
 * read the current byte
 * Note: eeprom must have been selected by ioctl(fd,I2C_SLAVE,address)
 */
int eeprom_read_current_byte(struct eeprom *e);
/*
 * writes [data] at memory address [mem_addr]
 * Note: eeprom must have been selected by ioctl(fd,I2C_SLAVE,address)
 */
int eeprom_write_byte(struct eeprom *e, __u16 mem_addr, __u8 data);

void eeprom_enable_wp();        //enable LX-2031 eeprom write protect
void eeprom_disable_wp();       //disable LX-2031 eeprom write protect
#endif

