Device driver interface for the AT24CXXX EEPROM units.
More...
Device driver interface for the AT24CXXX EEPROM units.
Overview
Various manufacturers such as Atmel/Microchip or ST offer small I2C EEPROMs which usually come in 8-pin packages and are used for persistent data storage of settings, counters, etc. This driver adds support for these devices with direct read and write functions.
The high level wrapper for RIOTs MTD interface to utilize the I2C EEPROMs as MTD storage is described in drivers_mtd_at24cxxx.
A list of supported devices can be found in the at24cxxx_defines.h file.
Usage
The preconfigured devices in the at24cxxx_defines.h file devices are easily accessible as pseudomodules and can be added to the Makefile of your project:
USEMODULE += at24c02
When using one of the pseudomodules, the configuration of the device is already predefined in the AT24CXXX_PARAMS macro and can be used for the initialization:
at24cxxx_t eeprom_dev;
at24cxxx_params_t eeprom_params = AT24CXXX_PARAMS;
at24cxxx_init(&eeprom_dev, &eeprom_params);
For other devices that are not yet part of the library, the generic module has to be added:
USEMODULE += at24cxxx
The predefined macro can not be used in this case, so the parameters of the device have to be added to the at24cxxx_params_t structure manually with the values from the corresponding datasheet:
at24cxxx_t eeprom_dev;
at24cxxx_params_t eeprom_params = {
.i2c = I2C_DEV(0), \
...
};
at24cxxx_init(&eeprom_dev, &eeprom_params);
|
typedef struct at24cxxx_params | at24cxxx_params_t |
| Struct that holds initialization parameters.
|
|
|
enum | { AT24CXXX_OK
, AT24CXXX_I2C_ERROR
} |
| Return values. More...
|
|
|
int | at24cxxx_init (at24cxxx_t *dev, const at24cxxx_params_t *params) |
| Initialize an AT24CXXX device handle with AT24CXXX parameters.
|
|
int | at24cxxx_read_byte (const at24cxxx_t *dev, uint32_t pos, void *dest) |
| Read a byte at a given position pos .
|
|
int | at24cxxx_read (const at24cxxx_t *dev, uint32_t pos, void *data, size_t len) |
| Sequentially read len bytes from a given position pos .
|
|
int | at24cxxx_write_byte (const at24cxxx_t *dev, uint32_t pos, uint8_t data) |
| Write a byte at a given position pos .
|
|
int | at24cxxx_write (const at24cxxx_t *dev, uint32_t pos, const void *data, size_t len) |
| Sequentially write len bytes from a given position pos .
|
|
int | at24cxxx_set (const at24cxxx_t *dev, uint32_t pos, uint8_t val, size_t len) |
| Set len bytes from a given position pos to the value val .
|
|
int | at24cxxx_clear (const at24cxxx_t *dev, uint32_t pos, size_t len) |
| Set len bytes from position pos to AT24CXXX_CLEAR_BYTE.
|
|
int | at24cxxx_erase (const at24cxxx_t *dev) |
| Set the entire EEPROM memory to AT24CXXX_CLEAR_BYTE.
|
|
int | at24cxxx_enable_write_protect (const at24cxxx_t *dev) |
| Enable write protection.
|
|
int | at24cxxx_disable_write_protect (const at24cxxx_t *dev) |
| Disable write protection.
|
|
◆ anonymous enum
◆ at24cxxx_clear()
int at24cxxx_clear |
( |
const at24cxxx_t * |
dev, |
|
|
uint32_t |
pos, |
|
|
size_t |
len |
|
) |
| |
Set len
bytes from position pos
to AT24CXXX_CLEAR_BYTE.
This is a wrapper around
- See also
- at24cxxx_set.
- Parameters
-
[in] | dev | AT24CXXX device handle |
[in] | pos | Position in EEPROM memory |
[in] | len | Requested length to be written |
- Returns
- See also
- at24cxxx_set
◆ at24cxxx_disable_write_protect()
int at24cxxx_disable_write_protect |
( |
const at24cxxx_t * |
dev | ) |
|
Disable write protection.
- Parameters
-
[in] | dev | AT24CXXX device handle |
- Returns
- AT24CXXX_OK on success
-
-ENOTSUP if pin_wp was initialized with GPIO_UNDEF
◆ at24cxxx_enable_write_protect()
int at24cxxx_enable_write_protect |
( |
const at24cxxx_t * |
dev | ) |
|
Enable write protection.
- Parameters
-
[in] | dev | AT24CXXX device handle |
- Returns
- AT24CXXX_OK on success
-
-ENOTSUP if pin_wp was initialized with GPIO_UNDEF
◆ at24cxxx_erase()
Set the entire EEPROM memory to AT24CXXX_CLEAR_BYTE.
This is a wrapper around
- See also
- at24cxxx_clear.
- Parameters
-
[in] | dev | AT24CXXX device handle |
- Returns
- See also
- at24cxxx_set
◆ at24cxxx_init()
Initialize an AT24CXXX device handle with AT24CXXX parameters.
- Parameters
-
[in,out] | dev | AT24CXXX device handle |
[in] | params | AT24CXXX parameters |
- Returns
- AT24CXXX_OK on success
-
-AT24CXXX_I2C_ERROR if i2c could not be acquired
-
-EINVAL if input parameters are NULL
◆ at24cxxx_read()
int at24cxxx_read |
( |
const at24cxxx_t * |
dev, |
|
|
uint32_t |
pos, |
|
|
void * |
data, |
|
|
size_t |
len |
|
) |
| |
Sequentially read len
bytes from a given position pos
.
- Parameters
-
[in] | dev | AT24CXXX device handle |
[in] | pos | Position in EEPROM memory |
[out] | data | Read buffer |
[in] | len | Requested length to be read |
- Returns
- AT24CXXX_OK on success
-
-ERANGE if
pos
+ len
is out of bounds
-
- See also
- i2c_read_regs
◆ at24cxxx_read_byte()
int at24cxxx_read_byte |
( |
const at24cxxx_t * |
dev, |
|
|
uint32_t |
pos, |
|
|
void * |
dest |
|
) |
| |
Read a byte at a given position pos
.
- Parameters
-
[in] | dev | AT24CXXX device handle |
[in] | pos | Position in EEPROM memory |
[out] | dest | Read byte |
- Returns
- AT24CXXX_OK on success
-
-ERANGE if
pos
is out of bounds
-
- See also
- i2c_read_regs
◆ at24cxxx_set()
int at24cxxx_set |
( |
const at24cxxx_t * |
dev, |
|
|
uint32_t |
pos, |
|
|
uint8_t |
val, |
|
|
size_t |
len |
|
) |
| |
Set len
bytes from a given position pos
to the value val
.
Writing is performed in chunks of size AT24CXXX_SET_BUFFER_SIZE.
- Parameters
-
[in] | dev | AT24CXXX device handle |
[in] | pos | Position in EEPROM memory |
[in] | val | Value to be set |
[in] | len | Requested length to be written |
- Returns
- AT24CXXX_OK on success
-
-ERANGE if
pos
+ len
is out of bounds
-
- See also
- i2c_write_byte
◆ at24cxxx_write()
int at24cxxx_write |
( |
const at24cxxx_t * |
dev, |
|
|
uint32_t |
pos, |
|
|
const void * |
data, |
|
|
size_t |
len |
|
) |
| |
Sequentially write len
bytes from a given position pos
.
Writing is performed in chunks of size AT24CXXX_PAGE_SIZE.
- Parameters
-
[in] | dev | AT24CXXX device handle |
[in] | pos | Position in EEPROM memory |
[in] | data | Write buffer |
[in] | len | Requested length to be written |
- Returns
- AT24CXXX_OK on success
-
-ERANGE if
pos
+ len
is out of bounds
-
- See also
- i2c_write_regs
◆ at24cxxx_write_byte()
int at24cxxx_write_byte |
( |
const at24cxxx_t * |
dev, |
|
|
uint32_t |
pos, |
|
|
uint8_t |
data |
|
) |
| |
Write a byte at a given position pos
.
- Parameters
-
[in] | dev | AT24CXXX device handle |
[in] | pos | Position in EEPROM memory |
[in] | data | Value to be written |
- Returns
- AT24CXXX_OK on success
-
-ERANGE if
pos
is out of bounds
-
- See also
- i2c_write_regs