diff --git a/libraries/EEPROM/library.properties b/libraries/EEPROM/library.properties index bd32cb17..e6552058 100644 --- a/libraries/EEPROM/library.properties +++ b/libraries/EEPROM/library.properties @@ -1,9 +1,9 @@ name=EEPROM -version=1.0 +version=1.0.3 author=Ivan Grokhotkov maintainer=Paolo Becchi -sentence=Enables reading and writing data to the permanent FLASH storage, up to 4kb. +sentence=Enables reading and writing data a sequential, addressable FLASH storage paragraph= category=Data Storage url=http://arduino.cc/en/Reference/EEPROM -architectures=esp32 \ No newline at end of file +architectures=esp32 diff --git a/libraries/EEPROM/src/EEPROM.cpp b/libraries/EEPROM/src/EEPROM.cpp index 56282976..1bec6127 100644 --- a/libraries/EEPROM/src/EEPROM.cpp +++ b/libraries/EEPROM/src/EEPROM.cpp @@ -25,6 +25,7 @@ #include "EEPROM.h" #include +#include #include EEPROMClass::EEPROMClass(void) @@ -111,7 +112,7 @@ bool EEPROMClass::begin(size_t size) { log_e("Not enough memory to expand EEPROM!"); return false; } - memset(key_data, 0, size); + memset(key_data, 0xFF, size); if(key_size) { log_i("Expanding EEPROM from %d to %d", key_size, size); // hold data while key is deleted @@ -214,6 +215,67 @@ uint16_t EEPROMClass::length () return _user_defined_size; } +/* + Convert EEPROM partition into nvs blob + Call convert before you call begin +*/ +uint16_t EEPROMClass::convert (bool clear, const char* EEPROMname, const char* nvsname) +{ + uint16_t result = 0; + const esp_partition_t* mypart = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, EEPROMname); + if (mypart == NULL) { + log_i("EEPROM partition not found for conversion"); + return result; + } + + size_t size = mypart->size; + uint8_t* data = (uint8_t*) malloc(size); + if (!data) { + log_e("Not enough memory to convert EEPROM!"); + goto exit; + } + + if (esp_partition_read (mypart, 0, (void *) data, size) != ESP_OK) { + log_e("Unable to read EEPROM partition"); + goto exit; + } + + bool empty; + empty = true; + for (int x=0; x T &get(int address, T &t) {