|
|
@ -42,25 +42,22 @@ bool PersistentStore::access_start() { eeprom_init(); return true; } |
|
|
|
bool PersistentStore::access_finish() { return true; } |
|
|
|
|
|
|
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { |
|
|
|
uint16_t written = 0; |
|
|
|
while (size--) { |
|
|
|
uint8_t v = *value; |
|
|
|
|
|
|
|
// EEPROM has only ~100,000 write cycles,
|
|
|
|
// so only write bytes that have changed!
|
|
|
|
uint8_t * const p = (uint8_t * const)pos; |
|
|
|
if (v != eeprom_read_byte(p)) { |
|
|
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
|
|
|
eeprom_write_byte(p, v); |
|
|
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
|
|
|
if (eeprom_read_byte(p) != v) { |
|
|
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
crc16(crc, &v, 1); |
|
|
|
pos++; |
|
|
|
value++; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@ -68,7 +65,6 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t |
|
|
|
do { |
|
|
|
// Read from external EEPROM
|
|
|
|
const uint8_t c = eeprom_read_byte((uint8_t*)pos); |
|
|
|
|
|
|
|
if (writing) *value = c; |
|
|
|
crc16(crc, &c, 1); |
|
|
|
pos++; |
|
|
|