diff --git a/platform/drivers/NVM/AT24Cx.h b/platform/drivers/NVM/AT24Cx.h index cb81df12..df9e78d3 100644 --- a/platform/drivers/NVM/AT24Cx.h +++ b/platform/drivers/NVM/AT24Cx.h @@ -23,12 +23,32 @@ #include #include +#include /** * 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. */ diff --git a/platform/drivers/NVM/AT24Cx_GDx.c b/platform/drivers/NVM/AT24Cx_GDx.c index 70228b5d..5ad61bef 100644 --- a/platform/drivers/NVM/AT24Cx_GDx.c +++ b/platform/drivers/NVM/AT24Cx_GDx.c @@ -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 +};