-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
6,240 additions
and
2,291 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
EEPROM.h -ported by Paolo Becchi to Esp32 from esp8266 EEPROM | ||
-Modified by Elochukwu Ifediora <[email protected]> | ||
-Converted to nvs [email protected] | ||
Uses a nvs byte array to emulate EEPROM | ||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. | ||
This file is part of the esp8266 core for Arduino environment. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef EEPROMESP_h | ||
#define EEPROMESP_h | ||
#ifndef EEPROM_FLASH_PARTITION_NAME | ||
#define EEPROM_FLASH_PARTITION_NAME "eeprom" | ||
#endif | ||
#include <Arduino.h> | ||
|
||
typedef uint32_t nvs_handle; | ||
|
||
class EEPROMClassESP | ||
{ | ||
public: | ||
EEPROMClassESP(uint32_t sector); | ||
EEPROMClassESP(const char *name, uint32_t user_defined_size); | ||
EEPROMClassESP(void); | ||
~EEPROMClassESP(void); | ||
|
||
bool begin(size_t size); | ||
uint8_t read(int address); | ||
void write(int address, uint8_t val); | ||
uint16_t length(); | ||
bool commit(); | ||
void end(); | ||
|
||
uint8_t *getDataPtr(); | ||
|
||
template <typename T> | ||
T &get(int address, T &t) | ||
{ | ||
if (address < 0 || address + sizeof(T) > _size) | ||
return t; | ||
|
||
memcpy((uint8_t *)&t, _data + address, sizeof(T)); | ||
return t; | ||
} | ||
|
||
template <typename T> | ||
const T &put(int address, const T &t) | ||
{ | ||
if (address < 0 || address + sizeof(T) > _size) | ||
return t; | ||
|
||
memcpy(_data + address, (const uint8_t *)&t, sizeof(T)); | ||
_dirty = true; | ||
return t; | ||
} | ||
|
||
uint8_t readByte(int address); | ||
int8_t readChar(int address); | ||
uint8_t readUChar(int address); | ||
int16_t readShort(int address); | ||
uint16_t readUShort(int address); | ||
int32_t readInt(int address); | ||
uint32_t readUInt(int address); | ||
int32_t readLong(int address); | ||
uint32_t readULong(int address); | ||
int64_t readLong64(int address); | ||
uint64_t readULong64(int address); | ||
float_t readFloat(int address); | ||
double_t readDouble(int address); | ||
bool readBool(int address); | ||
size_t readString(int address, char *value, size_t maxLen); | ||
String readString(int address); | ||
size_t readBytes(int address, void *value, size_t maxLen); | ||
template <class T> | ||
T readAll(int address, T &); | ||
|
||
size_t writeByte(int address, uint8_t value); | ||
size_t writeChar(int address, int8_t value); | ||
size_t writeUChar(int address, uint8_t value); | ||
size_t writeShort(int address, int16_t value); | ||
size_t writeUShort(int address, uint16_t value); | ||
size_t writeInt(int address, int32_t value); | ||
size_t writeUInt(int address, uint32_t value); | ||
size_t writeLong(int address, int32_t value); | ||
size_t writeULong(int address, uint32_t value); | ||
size_t writeLong64(int address, int64_t value); | ||
size_t writeULong64(int address, uint64_t value); | ||
size_t writeFloat(int address, float_t value); | ||
size_t writeDouble(int address, double_t value); | ||
size_t writeBool(int address, bool value); | ||
size_t writeString(int address, const char *value); | ||
size_t writeString(int address, String value); | ||
size_t writeBytes(int address, const void *value, size_t len); | ||
template <class T> | ||
T writeAll(int address, const T &); | ||
|
||
protected: | ||
nvs_handle _handle; | ||
uint8_t *_data; | ||
size_t _size; | ||
bool _dirty; | ||
const char *_name; | ||
uint32_t _user_defined_size; | ||
}; | ||
|
||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM) | ||
extern EEPROMClassESP EEPROM_ESP; | ||
#endif | ||
|
||
#endif |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.