From 4227796c88d46eb3b12cba2f0b2c7a85550660c3 Mon Sep 17 00:00:00 2001 From: fabian18 Date: Mon, 12 Aug 2019 13:52:44 +0200 Subject: [PATCH] drivers/at24cxxx: eeprom api wrapper for eepreg --- drivers/Makefile.dep | 4 + drivers/Makefile.include | 4 + drivers/at24cxxx/Makefile | 5 ++ drivers/at24cxxx/eeprom_wrapper.c | 139 ++++++++++++++++++++++++++++++ makefiles/pseudomodules.inc.mk | 1 + sys/Makefile.dep | 4 - 6 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 drivers/at24cxxx/eeprom_wrapper.c diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index d35524c37e795..b3ea69b06ad9a 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -49,6 +49,10 @@ ifneq (,$(filter at24cxxx,$(USEMODULE))) USEMODULE += xtimer endif +ifneq (,$(filter at24cxxx_eeprom_wrapper,$(USEMODULE))) + USEMODULE += at24cxxx +endif + ifneq (,$(filter at30tse75x,$(USEMODULE))) USEMODULE += xtimer FEATURES_REQUIRED += periph_i2c diff --git a/drivers/Makefile.include b/drivers/Makefile.include index 2db218b9d27d7..7d8fa8c358c13 100644 --- a/drivers/Makefile.include +++ b/drivers/Makefile.include @@ -22,6 +22,10 @@ ifneq (,$(filter at24cxxx,$(USEMODULE))) USEMODULE_INCLUDE += $(RIOTBASE)/drivers/at24cxxx/include endif +ifneq (,$(filter at24cxxx_eeprom_wrapper,$(USEMODULE))) + CFLAGS += -DEEPROM_SIZE=0x8000 +endif + ifneq (,$(filter at86rf2xx,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/drivers/at86rf2xx/include endif diff --git a/drivers/at24cxxx/Makefile b/drivers/at24cxxx/Makefile index 9c9ae9884ad6d..63d3d191adb8b 100644 --- a/drivers/at24cxxx/Makefile +++ b/drivers/at24cxxx/Makefile @@ -1 +1,6 @@ +SRC := $(filter-out eeprom_wrapper.c,$(wildcard *.c)) + +# enable submodules +SUBMODULES := 1 + include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/drivers/at24cxxx/eeprom_wrapper.c b/drivers/at24cxxx/eeprom_wrapper.c new file mode 100644 index 0000000000000..a0270378b33d6 --- /dev/null +++ b/drivers/at24cxxx/eeprom_wrapper.c @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_at24cxxx + * @{ + * + * @file + * @brief Implementation of expected EEPROM interface, expected by EEPROM registry + * + * @author Fabian Hüßler + * @} + */ + +#include "at24cxxx.h" + +/** + * @brief Wrapper around @see at24cxxx_read_byte that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @param[in] pos position in EEPROM memory + * + * @return Read byte + */ +uint8_t eeprom_read_byte(uint32_t pos) +{ + return at24cxxx_read_byte( + at24cxxx_get_default_dev(), pos); +} + +/** + * @brief Wrapper around @see at24cxxx_read that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @param[in] pos position in EEPROM memory + * @param[out] data read buffer + * @param[in] len requested length to be read + * + * @return @p len on success + * @return 0 on failure + */ +size_t eeprom_read(uint32_t pos, void *data, size_t len) +{ + return at24cxxx_read( + at24cxxx_get_default_dev(), pos, data, len); +} + +/** + * @brief Wrapper around @see at24cxxx_write_byte that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @param[in] pos position in EEPROM memory + * @param[in] data value to be written + */ +void eeprom_write_byte(uint32_t pos, uint8_t data) +{ + at24cxxx_write_byte( + at24cxxx_get_default_dev(), pos, data); +} + +/** + * @brief Wrapper around @see at24cxxx_write that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @param[in] pos position in EEPROM memory + * @param[in] data write buffer + * @param[in] len requested length to be written + * + * @return number of bytes that have been written + * @return 0 on failure + */ +size_t eeprom_write(uint32_t pos, const void *data, size_t len) +{ + return at24cxxx_write( + at24cxxx_get_default_dev(), pos, data, len); +} + +/** + * @brief Wrapper around @see at24cxxx_set that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @param[in] pos position in EEPROM memory + * @param[in] val value to be set + * @param[in] len requested length to be written + * + * @return number of bytes that have been written + * @return 0 on failure + */ +size_t eeprom_set(uint32_t pos, uint8_t val, size_t len) +{ + return at24cxxx_set( + at24cxxx_get_default_dev(), pos, val, len); +} + +/** + * @brief Wrapper around @see at24cxxx_clear that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @param[in] pos position in EEPROM memory + * @param[in] len requested length to be written + * + * @return number of bytes that have been cleared + */ +size_t eeprom_clear(uint32_t pos, size_t len) +{ + return at24cxxx_clear( + at24cxxx_get_default_dev(), pos, len); +} + +/** + * @brief Wrapper around @see at24cxxx_erase that uses + * the first parameters in the at24cxxx_params array + * + * This allows the use of EEPROM registry. + * + * @return number of bytes that have been cleared + */ +size_t eeprom_erase(void) +{ + return at24cxxx_erase( + at24cxxx_get_default_dev()); +} diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 8b6d6eb8f1d10..765ba4dc8275b 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -1,6 +1,7 @@ PSEUDOMODULES += at_urc PSEUDOMODULES += at24c128 PSEUDOMODULES += at24c256% +PSEUDOMODULES += at24cxxx_eeprom_wrapper PSEUDOMODULES += auto_init_gnrc_rpl PSEUDOMODULES += can_mbox PSEUDOMODULES += can_pm diff --git a/sys/Makefile.dep b/sys/Makefile.dep index f9afc587e3bd3..1940414872375 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -1,7 +1,3 @@ -ifneq (,$(filter eepreg,$(USEMODULE))) - FEATURES_REQUIRED += periph_eeprom -endif - ifneq (,$(filter i2c_scan,$(USEMODULE))) FEATURES_REQUIRED += periph_i2c endif