1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Clear dirty flag in begin and reallocate only if necessary, add getConstDataPtr method (#2217) (#3849)

This commit is contained in:
Develo 2017-11-20 14:39:27 -03:00 committed by GitHub
parent 117bc875ff
commit 1b76e9bf72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -56,16 +56,21 @@ void EEPROMClass::begin(size_t size) {
size = (size + 3) & (~3); 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; delete[] _data;
_data = new uint8_t[size];
} else if(!_data) {
_data = new uint8_t[size];
} }
_data = new uint8_t[size];
_size = size; _size = size;
noInterrupts(); noInterrupts();
spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size); spi_flash_read(_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast<uint32_t*>(_data), _size);
interrupts(); interrupts();
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
} }
void EEPROMClass::end() { void EEPROMClass::end() {
@ -131,6 +136,10 @@ uint8_t * EEPROMClass::getDataPtr() {
return &_data[0]; return &_data[0];
} }
uint8_t const * EEPROMClass::getConstDataPtr() {
return &_data[0];
}
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM) #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
EEPROMClass EEPROM; EEPROMClass EEPROM;
#endif #endif

View File

@ -38,6 +38,7 @@ public:
void end(); void end();
uint8_t * getDataPtr(); uint8_t * getDataPtr();
uint8_t const * getConstDataPtr();
template<typename T> template<typename T>
T &get(int address, T &t) { T &get(int address, T &t) {