3.3.1. eeprom_i2c — I2C EEPROM

Below is a list of I2C EEPROMs that are known to work with this driver. Other I2C EEPROMs may work as well, as they often implement the same interface.

  • AT24C32 from Atmel.
  • AT24C256 from Atmel.

Known limitations:

  • Only supports 16 bits addressing. 8 bits addressing can easily be added.

Source code: src/drivers/storage/eeprom_i2c.h, src/drivers/storage/eeprom_i2c.c

Test code: tst/drivers/hardware/storage/eeprom_i2c/main.c


Functions

int eeprom_i2c_module_init(void)

Initialize EEPROM I2C module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int eeprom_i2c_init(struct eeprom_i2c_driver_t *self_p, struct i2c_driver_t *i2c_p, int i2c_address, uint32_t size)

Initialize given driver object.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to initialize.
  • i2c_p: Initialized and started I2C driver object.
  • i2c_address: The I2C address of the EEPROM.
  • size: Size of the EEPROM in bytes.

ssize_t eeprom_i2c_read(struct eeprom_i2c_driver_t *self_p, void *dst_p, uint32_t src, size_t size)

Read into given buffer from given EEPROM address.

Return
Number of bytes read or negative error code.
Parameters
  • self_p: Initialized driver object.
  • dst_p: Buffer to read into.
  • src: EEPROM address to read from.
  • size: Number of bytes to read.

ssize_t eeprom_i2c_write(struct eeprom_i2c_driver_t *self_p, uint32_t dst, const void *src_p, size_t size)

Write given buffer to given EEPROM address.

Return
Number of bytes written or negative error code.
Parameters
  • self_p: Initialized driver object.
  • dst: EEPROM address to write to.
  • src_p: Buffer to write.
  • size: Number of bytes to write.

struct eeprom_i2c_driver_t

Public Members

struct i2c_driver_t *i2c_p
int i2c_address
uint32_t size