8 #ifndef BUFFERED_EEPROM_CLASS_H
9 #define BUFFERED_EEPROM_CLASS_H
11 #if defined(ARDUINO_ARCH_STM32)
43 class BufferedEEPROMClass {
45 BufferedEEPROMClass() =
default;
47 void begin(
size_t size) {
52 uint8_t read(
int const address) {
53 return eeprom_buffered_read_byte(address);
56 void write(
int const address, uint8_t
const val) {
57 eeprom_buffered_write_byte(address, val);
60 bool commit() { eeprom_buffer_flush();
return true; }
62 void end() { commit(); }
65 T &get(
int address, T &t) {
66 size_t dataSize =
sizeof(T);
67 uint8_t* data = (uint8_t*) &t;
69 *data++ = read(address++);
75 const T &put(
int address,
const T &t) {
76 size_t dataSize =
sizeof(T);
77 uint8_t* data = (uint8_t*) &t;
79 write(address++, *data++);
84 size_t length() {
return FLASH_PAGE_SIZE; }
89 uint8_t * getDataPtr();
90 uint8_t
const * getConstDataPtr()
const;
92 uint8_t& operator[](
int const address) {
93 return getDataPtr()[address];
95 uint8_t
const & operator[](
int const address)
const {
96 return getConstDataPtr()[address];
101 #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
102 extern BufferedEEPROMClass BufferedEEPROM;
105 #endif // defined(ARDUINO_ARCH_STM32)
106 #endif // BUFFERED_EEPROM_CLASS_H