Added implementation of the standard NVM device API to AT24Cx driver.

pull/218/head
Silvano Seva 2023-11-18 13:16:19 +01:00
rodzic ab66054341
commit d20f0e2c8d
2 zmienionych plików z 58 dodań i 0 usunięć

Wyświetl plik

@ -23,12 +23,32 @@
#include <stdint.h>
#include <sys/types.h>
#include <interfaces/nvmem.h>
/**
* Driver for ATMEL AT24Cx family of I2C EEPROM devices, used as external non
* volatile memory on various radios to store global settings and contact data.
*/
/**
* Device driver API for AT24Cx EEPROM memory.
*/
extern const struct nvmApi AT24Cx_api;
/**
* Instantiate an AT24Cx nonvolatile memory device.
*
* @param name: instance name.
*/
#define AT24Cx_DEVICE_DEFINE(name) \
struct nvmDevice name = \
{ \
.config = NULL, \
.priv = NULL, \
.api = &AT24Cx_api \
};
/**
* Initialise driver for external EEPROM.
*/

Wyświetl plik

@ -96,3 +96,41 @@ int AT24Cx_writeData(uint32_t addr, const void *buf, size_t len)
return 0;
}
static const struct nvmParams AT24Cx_params =
{
.write_size = 1,
.erase_size = 1,
.erase_cycles = 1000000,
.type = NVM_EEPROM,
};
static int nvm_api_read(const struct nvmDevice *dev, uint32_t offset, void *data, size_t len)
{
(void) dev;
return AT24Cx_readData(offset, data, len);
}
static int nvm_api_write(const struct nvmDevice *dev, uint32_t offset, const void *data, size_t len)
{
(void) dev;
return AT24Cx_writeData(offset, data, len);
}
static const struct nvmParams *nvm_api_params(const struct nvmDevice *dev)
{
(void) dev;
return &AT24Cx_params;
}
const struct nvmApi AT24Cx_api =
{
.read = nvm_api_read,
.write = nvm_api_write,
.erase = NULL,
.sync = NULL,
.params = nvm_api_params
};