Update PersistentStore api (#11538)

- Clean up the API to use a `static` class instance to adhere to Marlin convention
- Add `const` position data access for read/write
- Add Storage capacity to the interface
This commit is contained in:
Chris Pepper
2018-08-13 23:30:26 +01:00
committed by Scott Lahteine
parent 60f1376798
commit 66d2b48b59
13 changed files with 199 additions and 117 deletions

View File

@ -5,14 +5,12 @@
#if ENABLED(EEPROM_SETTINGS)
#include "../persistent_store_api.h"
#include <avr/eeprom.h>
namespace HAL {
namespace PersistentStore {
bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; }
bool access_start() { return true; }
bool access_finish() { return true; }
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value;
@ -33,7 +31,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return false;
}
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
uint8_t c = eeprom_read_byte((unsigned char*)pos);
if (writing) *value = c;
@ -44,8 +42,21 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
return false;
}
} // PersistentStore
} // HAL
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
int data_pos = pos;
uint16_t crc = 0;
return write_data(data_pos, value, size, &crc);
}
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
int data_pos = pos;
uint16_t crc = 0;
return read_data(data_pos, value, size, &crc);
}
const size_t PersistentStore::capacity() {
return E2END + 1;
}
#endif // EEPROM_SETTINGS
#endif // __MK64FX512__ || __MK66FX1M0__