Commit 1c788487 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

dev/i2c_eeprom: support for 2-byte address devices

parent 9a6b3b5c
......@@ -11,6 +11,14 @@
#include "dev/bb_i2c.h"
#include "dev/i2c_eeprom.h"
int i2c_eeprom_create( struct i2c_eeprom_device *dev, struct i2c_bus *bus, uint8_t i2c_addr, int offset_bytes )
{
dev->bus = bus;
dev->offset_bytes = offset_bytes;
dev->addr = i2c_addr;
return 0;
}
int i2c_eeprom_read(struct i2c_eeprom_device *dev, int offset, void *buf, int count)
{
int i;
......@@ -21,7 +29,10 @@ int i2c_eeprom_read(struct i2c_eeprom_device *dev, int offset, void *buf, int co
bb_i2c_stop(dev->bus);
return -1;
}
bb_i2c_put_byte(dev->bus, (offset >> 8) & 0xff);
if(dev->offset_bytes == 2)
bb_i2c_put_byte(dev->bus, (offset >> 8) & 0xff);
bb_i2c_put_byte(dev->bus, offset & 0xff);
bb_i2c_repeat_start(dev->bus);
bb_i2c_put_byte(dev->bus, (dev->addr << 1) | 1);
......@@ -48,7 +59,10 @@ int i2c_eeprom_write(struct i2c_eeprom_device *dev, int offset, void *buf, int c
bb_i2c_stop(dev->bus);
return -1;
}
bb_i2c_put_byte(dev->bus, (offset >> 8) & 0xff);
if(dev->offset_bytes == 2)
bb_i2c_put_byte(dev->bus, (offset >> 8) & 0xff);
bb_i2c_put_byte(dev->bus, offset & 0xff);
bb_i2c_put_byte(dev->bus, *cb++);
offset++;
......@@ -75,7 +89,10 @@ int i2c_eeprom_erase(struct i2c_eeprom_device *dev, int offset, int count)
bb_i2c_stop(dev->bus);
return -1;
}
bb_i2c_put_byte(dev->bus, (offset >> 8) & 0xff);
if(dev->offset_bytes == 2)
bb_i2c_put_byte(dev->bus, (offset >> 8) & 0xff);
bb_i2c_put_byte(dev->bus, offset & 0xff);
bb_i2c_put_byte(dev->bus, 0xff);
offset++;
......
......@@ -15,8 +15,11 @@
struct i2c_eeprom_device {
struct i2c_bus *bus;
uint8_t addr;
int offset_bytes;
};
int i2c_eeprom_create( struct i2c_eeprom_device *dev, struct i2c_bus *bus, uint8_t i2c_addr, int offset_bytes );
int i2c_eeprom_read(struct i2c_eeprom_device *dev, int offset, void *buf, int count);
int i2c_eeprom_write(struct i2c_eeprom_device *dev, int offset, void *buf, int count);
int i2c_eeprom_erase(struct i2c_eeprom_device *dev, int offset, int count);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment