Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libraries/EEPROM/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,21 @@ void EEPROMClass::begin(size_t size) {

size = (size + 3) & (~3);

if (_data) {
//In case begin() is called a 2nd+ time, don't reallocate if size is the same
if(_data && size != _size) {
delete[] _data;
_data = new uint8_t[size];
} else if(!_data) {
_data = new uint8_t[size];
}

_data = new uint8_t[size];
_size = size;

noInterrupts();
spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
interrupts();

_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
}

void EEPROMClass::end() {
Expand Down Expand Up @@ -131,6 +136,10 @@ uint8_t * EEPROMClass::getDataPtr() {
return &_data[0];
}

uint8_t const * EEPROMClass::getConstDataPtr() {
return &_data[0];
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
EEPROMClass EEPROM;
#endif
1 change: 1 addition & 0 deletions libraries/EEPROM/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class EEPROMClass {
void end();

uint8_t * getDataPtr();
uint8_t const * getConstDataPtr();

template<typename T>
T &get(int address, T &t) {
Expand Down