File tree 2 files changed +12
-2
lines changed
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -56,16 +56,21 @@ void EEPROMClass::begin(size_t size) {
56
56
57
57
size = (size + 3 ) & (~3 );
58
58
59
- if (_data) {
59
+ // In case begin() is called a 2nd+ time, don't reallocate if size is the same
60
+ if (_data && size != _size) {
60
61
delete[] _data;
62
+ _data = new uint8_t [size];
63
+ } else if (!_data) {
64
+ _data = new uint8_t [size];
61
65
}
62
66
63
- _data = new uint8_t [size];
64
67
_size = size;
65
68
66
69
noInterrupts ();
67
70
spi_flash_read (_sector * SPI_FLASH_SEC_SIZE, reinterpret_cast <uint32_t *>(_data), _size);
68
71
interrupts ();
72
+
73
+ _dirty = false ; // make sure dirty is cleared in case begin() is called 2nd+ time
69
74
}
70
75
71
76
void EEPROMClass::end () {
@@ -131,6 +136,10 @@ uint8_t * EEPROMClass::getDataPtr() {
131
136
return &_data[0 ];
132
137
}
133
138
139
+ uint8_t const * EEPROMClass::getConstDataPtr () {
140
+ return &_data[0 ];
141
+ }
142
+
134
143
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
135
144
EEPROMClass EEPROM;
136
145
#endif
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ class EEPROMClass {
38
38
void end ();
39
39
40
40
uint8_t * getDataPtr ();
41
+ uint8_t const * getConstDataPtr ();
41
42
42
43
template <typename T>
43
44
T &get (int address, T &t) {
You can’t perform that action at this time.
0 commit comments