You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.7 KiB
73 lines
1.7 KiB
6 years ago
|
#include "eeprom.h"
|
||
|
|
||
|
#define ITYPE_IIC (0x01)
|
||
|
#define ITYPE_I2C (0x02)
|
||
|
|
||
|
static int rdwr_type;
|
||
|
|
||
|
int at24_i2c_init(uint32_t scl, uint32_t sda, uint8_t addr, int bits);
|
||
|
int at24_i2c_init_ex(i2c_t i2c, uint8_t addr, int bits);
|
||
|
|
||
|
void at24_i2c_close(void);
|
||
|
int at24_i2c_write(uint16_t addr, uint8_t data);
|
||
|
uint8_t at24_i2c_read(uint16_t addr);
|
||
|
|
||
|
int at24_iic_init(struct iic_descr *i2c, uint8_t addr, int bits);
|
||
|
void at24_iic_close(void);
|
||
|
uint8_t at24_iic_read(uint16_t addr);
|
||
|
int at24_iic_write(uint16_t addr, uint8_t data);
|
||
|
|
||
|
int eeprom_init(iic_t _i2c, uint8_t addr, int is_16bits_address)
|
||
|
{
|
||
|
rdwr_type = ITYPE_IIC;
|
||
|
return at24_iic_init(_i2c, addr, is_16bits_address);
|
||
|
}
|
||
|
|
||
|
int eeprom_init_with_io(uint32_t scl, uint32_t sda, uint8_t addr, int is_16bits_address)
|
||
|
{
|
||
|
rdwr_type = ITYPE_I2C;
|
||
|
return at24_i2c_init(scl, sda, addr, is_16bits_address);
|
||
|
}
|
||
|
|
||
|
int eeprom_init_with_i2c(i2c_t i2c, uint8_t addr, int is_16bits_address)
|
||
|
{
|
||
|
rdwr_type = ITYPE_I2C;
|
||
|
return at24_i2c_init_ex(i2c, addr, is_16bits_address);
|
||
|
}
|
||
|
|
||
|
void eeprom_close(void)
|
||
|
{
|
||
|
switch (rdwr_type) {
|
||
|
case ITYPE_IIC:
|
||
|
at24_iic_close();
|
||
|
break;
|
||
|
case ITYPE_I2C:
|
||
|
at24_i2c_close();
|
||
|
break;
|
||
|
}
|
||
|
rdwr_type = 0;
|
||
|
}
|
||
|
|
||
|
int eeprom_write(uint16_t addr, uint8_t data)
|
||
|
{
|
||
|
switch (rdwr_type) {
|
||
|
case ITYPE_IIC:
|
||
|
return at24_iic_write(addr, data);
|
||
|
case ITYPE_I2C:
|
||
|
return at24_i2c_write(addr, data);
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
uint8_t eeprom_read(uint16_t addr)
|
||
|
{
|
||
|
switch (rdwr_type) {
|
||
|
case ITYPE_IIC:
|
||
|
return at24_iic_read(addr);
|
||
|
case ITYPE_I2C:
|
||
|
return at24_i2c_read(addr);
|
||
|
}
|
||
|
return 0xff;
|
||
|
}
|
||
|
|