-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Converted EEPROM library to use nvs instead of partition. #2678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+189
−127
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20f9f83
Converted EEPROM library to use nvs instead of partition. Removed ee…
lbernstone 6a4b337
Changed variable names, added some comments, formatting as per me-no-…
lbernstone d3b9524
Checks for memory on malloc
lbernstone e262520
Moved include nvs.h from header to code
lbernstone 1c13541
Reworked the extra example to make it more clear how to actually use …
lbernstone ea34660
No good deed goes unpunished
lbernstone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,68 +20,117 @@ void setup() { | |
ESP.restart(); | ||
} | ||
|
||
int address = 0; // Same address is used through the example | ||
int address = 0; | ||
|
||
EEPROM.writeByte(address, -128); // -2^7 | ||
Serial.println(EEPROM.readByte(address)); | ||
address += sizeof(byte); | ||
|
||
EEPROM.writeChar(address, 'A'); // Same as writyByte and readByte | ||
Serial.println(char(EEPROM.readChar(address))); | ||
address += sizeof(char); | ||
|
||
EEPROM.writeUChar(address, 255); // 2^8 - 1 | ||
Serial.println(EEPROM.readUChar(address)); | ||
address += sizeof(unsigned char); | ||
|
||
EEPROM.writeShort(address, -32768); // -2^15 | ||
Serial.println(EEPROM.readShort(address)); | ||
address += sizeof(short); | ||
|
||
EEPROM.writeUShort(address, 65535); // 2^16 - 1 | ||
Serial.println(EEPROM.readUShort(address)); | ||
address += sizeof(unsigned short); | ||
|
||
EEPROM.writeInt(address, -2147483648); // -2^31 | ||
Serial.println(EEPROM.readInt(address)); | ||
address += sizeof(int); | ||
|
||
EEPROM.writeUInt(address, 4294967295); // 2^32 - 1 | ||
Serial.println(EEPROM.readUInt(address)); | ||
address += sizeof(unsigned int); | ||
|
||
EEPROM.writeLong(address, -2147483648); // Same as writeInt and readInt | ||
Serial.println(EEPROM.readLong(address)); | ||
address += sizeof(long); | ||
|
||
EEPROM.writeULong(address, 4294967295); // Same as writeUInt and readUInt | ||
Serial.println(EEPROM.readULong(address)); | ||
address += sizeof(unsigned long); | ||
|
||
int64_t value = -9223372036854775808; // -2^63 | ||
EEPROM.writeLong64(address, value); | ||
value = 0; // Clear value | ||
address += sizeof(int64_t); | ||
|
||
uint64_t Value = 18446744073709551615; // 2^64 - 1 | ||
EEPROM.writeULong64(address, Value); | ||
address += sizeof(uint64_t); | ||
|
||
EEPROM.writeFloat(address, 1234.1234); | ||
address += sizeof(float); | ||
|
||
EEPROM.writeDouble(address, 123456789.123456789); | ||
address += sizeof(double); | ||
|
||
EEPROM.writeBool(address, true); | ||
address += sizeof(bool); | ||
|
||
String sentence = "I love ESP32."; | ||
EEPROM.writeString(address, sentence); | ||
address += sentence.length(); | ||
|
||
char gratitude[21] = "Thank You Espressif!"; | ||
EEPROM.writeString(address, gratitude); | ||
address += 21; | ||
|
||
// See also the general purpose writeBytes() and readBytes() for BLOB in EEPROM library | ||
EEPROM.commit(); | ||
address = 0; | ||
|
||
Serial.println(EEPROM.readByte(address)); | ||
address += sizeof(byte); | ||
|
||
Serial.println(char(EEPROM.readChar(address))); | ||
address += sizeof(char); | ||
|
||
Serial.println(EEPROM.readUChar(address)); | ||
address += sizeof(unsigned char); | ||
|
||
Serial.println(EEPROM.readShort(address)); | ||
address += sizeof(short); | ||
|
||
Serial.println(EEPROM.readUShort(address)); | ||
address += sizeof(unsigned short); | ||
|
||
Serial.println(EEPROM.readInt(address)); | ||
address += sizeof(int); | ||
|
||
Serial.println(EEPROM.readUInt(address)); | ||
address += sizeof(unsigned int); | ||
|
||
Serial.println(EEPROM.readLong(address)); | ||
address += sizeof(long); | ||
|
||
Serial.println(EEPROM.readULong(address)); | ||
address += sizeof(unsigned long); | ||
|
||
value = 0; | ||
value = EEPROM.readLong64(value); | ||
Serial.printf("0x%08X", (uint32_t)(value >> 32)); // Print High 4 bytes in HEX | ||
Serial.printf("%08X\n", (uint32_t)value); // Print Low 4 bytes in HEX | ||
address += sizeof(int64_t); | ||
|
||
uint64_t Value = 18446744073709551615; // 2^64 - 1 | ||
EEPROM.writeULong64(address, Value); | ||
Value = 0; // Clear Value | ||
Value = EEPROM.readULong64(Value); | ||
Serial.printf("0x%08X", (uint32_t)(Value >> 32)); // Print High 4 bytes in HEX | ||
Serial.printf("%08X\n", (uint32_t)Value); // Print Low 4 bytes in HEX | ||
address += sizeof(uint64_t); | ||
|
||
EEPROM.writeFloat(address, 1234.1234); | ||
Serial.println(EEPROM.readFloat(address), 4); | ||
address += sizeof(float); | ||
|
||
EEPROM.writeDouble(address, 123456789.123456789); | ||
Serial.println(EEPROM.readDouble(address), 8); | ||
address += sizeof(double); | ||
|
||
EEPROM.writeBool(address, true); | ||
Serial.println(EEPROM.readBool(address)); | ||
address += sizeof(bool); | ||
|
||
String sentence = "I love ESP32."; | ||
EEPROM.writeString(address, sentence); | ||
Serial.println(EEPROM.readString(address)); | ||
address += sentence.length(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Length +1? |
||
|
||
char gratitude[] = "Thank You Espressif!"; | ||
EEPROM.writeString(address, gratitude); | ||
Serial.println(EEPROM.readString(address)); | ||
|
||
// See also the general purpose writeBytes() and readBytes() for BLOB in EEPROM library | ||
// To avoid data overwrite, next address should be chosen/offset by using "address =+ sizeof(previousData)" | ||
address += 21; | ||
} | ||
|
||
void loop() { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
*/ | ||
|
||
#include "EEPROM.h" | ||
|
||
#include <nvs.h> | ||
#include <esp_log.h> | ||
|
||
EEPROMClass::EEPROMClass(void) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
EEPROM.h -ported by Paolo Becchi to Esp32 from esp8266 EEPROM | ||
-Modified by Elochukwu Ifediora <[email protected]> | ||
-Converted to nvs [email protected] | ||
-Converted to nvs [email protected] | ||
|
||
Uses a nvs byte array to emulate EEPROM | ||
|
||
|
@@ -29,7 +29,8 @@ | |
#define EEPROM_FLASH_PARTITION_NAME "eeprom" | ||
#endif | ||
#include <Arduino.h> | ||
#include <nvs.h> | ||
|
||
typedef uint32_t nvs_handle; | ||
|
||
class EEPROMClass { | ||
public: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually compile? Shouldn't it be
println((char)EEPROM.readChar(address));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
travis would have complained :) not sure how Make will like it though