Skip to content

Commit

Permalink
drivers/at24cxxx: eeprom api wrapper for eepreg
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Aug 12, 2019
1 parent 5f6b423 commit 4227796
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 4 deletions.
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions drivers/at24cxxx/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
SRC := $(filter-out eeprom_wrapper.c,$(wildcard *.c))

# enable submodules
SUBMODULES := 1

include $(RIOTBASE)/Makefile.base
139 changes: 139 additions & 0 deletions drivers/at24cxxx/eeprom_wrapper.c
Original file line number Diff line number Diff line change
@@ -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 <fabian.huessler@ovgu.de>
* @}
*/

#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());
}
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
ifneq (,$(filter eepreg,$(USEMODULE)))
FEATURES_REQUIRED += periph_eeprom
endif

ifneq (,$(filter i2c_scan,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
endif
Expand Down

0 comments on commit 4227796

Please sign in to comment.