Skip to content

Commit

Permalink
remove _user_defined_size from EEPROM (espressif#5775)
Browse files Browse the repository at this point in the history
Summary

Related to the issue espressif#5773 and espressif#2280.

_user_defined_size is removed from EEPROMClass because it is redundant in the current code
EEPROMClass::length() returns _size that is the true available size of EEPROM
Impact

_user_defined_size is removed from EEPROMClass
EEPROMClass::length() returns _size that is the true available size of EEPROM
  • Loading branch information
hideakitai authored Oct 25, 2021
1 parent cb5a490 commit 02c3ec0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 6 additions & 6 deletions libraries/EEPROM/examples/eeprom_class/eeprom_class.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
#include "EEPROM.h"

// Instantiate eeprom objects with parameter/argument names and sizes
EEPROMClass NAMES("eeprom0", 0x500);
EEPROMClass HEIGHT("eeprom1", 0x200);
EEPROMClass AGE("eeprom2", 0x100);
EEPROMClass NAMES("eeprom0");
EEPROMClass HEIGHT("eeprom1");
EEPROMClass AGE("eeprom2");

void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Testing EEPROMClass\n");
if (!NAMES.begin(NAMES.length())) {
if (!NAMES.begin(0x500)) {
Serial.println("Failed to initialise NAMES");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
if (!HEIGHT.begin(HEIGHT.length())) {
if (!HEIGHT.begin(0x200)) {
Serial.println("Failed to initialise HEIGHT");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
if (!AGE.begin(AGE.length())) {
if (!AGE.begin(0x100)) {
Serial.println("Failed to initialise AGE");
Serial.println("Restarting...");
delay(1000);
Expand Down
7 changes: 2 additions & 5 deletions libraries/EEPROM/src/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ EEPROMClass::EEPROMClass(void)
, _size(0)
, _dirty(false)
, _name("eeprom")
, _user_defined_size(0)
{
}

Expand All @@ -45,17 +44,15 @@ EEPROMClass::EEPROMClass(uint32_t sector)
, _size(0)
, _dirty(false)
, _name("eeprom")
, _user_defined_size(0)
{
}

EEPROMClass::EEPROMClass(const char* name, uint32_t user_defined_size)
EEPROMClass::EEPROMClass(const char* name)
: _handle(0)
, _data(0)
, _size(0)
, _dirty(false)
, _name(name)
, _user_defined_size(user_defined_size)
{
}

Expand Down Expand Up @@ -215,7 +212,7 @@ uint8_t * EEPROMClass::getDataPtr() {
*/
uint16_t EEPROMClass::length ()
{
return _user_defined_size;
return _size;
}

/*
Expand Down
3 changes: 1 addition & 2 deletions libraries/EEPROM/src/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef uint32_t nvs_handle;
class EEPROMClass {
public:
EEPROMClass(uint32_t sector);
EEPROMClass(const char* name, uint32_t user_defined_size);
EEPROMClass(const char* name);
EEPROMClass(void);
~EEPROMClass(void);

Expand Down Expand Up @@ -112,7 +112,6 @@ class EEPROMClass {
size_t _size;
bool _dirty;
const char* _name;
uint32_t _user_defined_size;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
Expand Down

0 comments on commit 02c3ec0

Please sign in to comment.