AceUtils
0.5.0
Useful Arduino utilties which are too small as separate libraries, but complex enough to be shared among multiple projects, and often have external dependencies to other libraries.
|
6 #ifndef ACE_UTILS_CRC_EEPROM_H
7 #define ACE_UTILS_CRC_EEPROM_H
12 namespace crc_eeprom {
30 virtual void begin(
size_t size) = 0;
33 virtual void write(
size_t address, uint8_t val) = 0;
36 virtual uint8_t
read(
size_t address)
const = 0;
54 virtual void begin(
size_t size) {
58 virtual void write(
size_t address, uint8_t val) {
59 mEeprom.update(address, val);
62 virtual uint8_t
read(
size_t address)
const {
63 return mEeprom.read(address);
86 virtual void begin(
size_t size) {
90 virtual uint8_t
read(
size_t address)
const {
91 return mEeprom.read(address);
94 virtual void write(
size_t address, uint8_t val) {
95 mEeprom.write(address, val);
99 return mEeprom.commit();
145 static constexpr uint32_t
toContextId(
char a,
char b,
char c,
char d) {
146 return ((uint32_t) d << 24)
147 | ((uint32_t) c << 16)
148 | ((uint32_t) b << 8)
186 uint32_t contextId = 0,
193 mEepromAdapter(eepromAdapter),
194 mContextId(contextId),
195 mCrc32Calculator(crcCalc)
204 mEepromAdapter.
begin(size);
242 bool readDataWithCrc(
size_t address,
void* data,
size_t dataSize)
const;
245 void write(
size_t address, uint8_t val) {
246 mEepromAdapter.
write(address, val);
249 uint8_t read(
size_t address)
const {
return mEepromAdapter.
read(address); }
251 bool commit() {
return mEepromAdapter.
commit(); }
253 void writeData(
size_t address,
const uint8_t* data,
size_t size) {
255 write(address++, *data++);
259 void readData(
size_t address, uint8_t* data,
size_t size)
const {
261 *data++ = read(address++);
266 IEepromAdapter& mEepromAdapter;
267 uint32_t
const mContextId;
274 #endif // defined(ACE_UTILS_CRC_EEPROM_H)
size_t writeWithCrc(size_t address, const T &data)
Convenience method that writes the given data of type T at given address.
void begin(size_t size)
Initialize the underlying eepromAdapter with the given size.
AvrEepromAdapter(E &eeprom)
Wrap around an AVR-flavored EEPROM object.
virtual void write(size_t address, uint8_t val)
Write thte byte at address, potentially buffered.
virtual void begin(size_t size)=0
Initialize the size of the EEPROM space.
size_t writeDataWithCrc(size_t address, const void *data, size_t dataSize)
Write the data with its CRC and its contextId.
static constexpr size_t toSavedSize(size_t dataSize)
Return the actual number of bytes saved to EEPROM for the given dataSize.
static constexpr uint32_t toContextId(char a, char b, char c, char d)
Convert 4 characters into a uint32_t contextId Example ‘toContextId('d’, 'e', 'm',...
CrcEeprom(IEepromAdapter &eepromAdapter, uint32_t contextId=0, Crc32Calculator crcCalc=ace_crc::crc32_nibblem::crc_calculate)
Constructor with an optional contextId identifier and an optional Crc32Calculator crcCalc function po...
uint32_t(* Crc32Calculator)(const void *data, size_t dataSize)
Function pointer to the CRC32 calculator.
A wrapper class around an EEPROM class that follows the AVR-style API.
EspEepromAdapter(E &eeprom)
Wrap around an ESP-flavored EEPROM object.
virtual bool commit()
Flush the buffer if it is used.
A wrapper class around an EEPROM class that follows the ESP-style API.
virtual void write(size_t address, uint8_t val)
Write thte byte at address, potentially buffered.
virtual uint8_t read(size_t address) const =0
Return the byte at address.
virtual uint8_t read(size_t address) const
Return the byte at address.
virtual void write(size_t address, uint8_t val)=0
Write thte byte at address, potentially buffered.
bool readDataWithCrc(size_t address, void *data, size_t dataSize) const
Read the data from EEPROM along with its CRC and contextId.
The base EEPROM API used by CrcEeprom class.
Thin wrapper around the EEPROM object (from the the built-in EEPROM library) to read and write a give...
bool readWithCrc(size_t address, T &data) const
Convenience function that reads the given data of type T at given address.
virtual bool commit()=0
Flush the buffer if it is used.
virtual uint8_t read(size_t address) const
Return the byte at address.
virtual void begin(size_t size)
Initialize the size of the EEPROM space.
virtual bool commit()
Flush the buffer if it is used.
virtual void begin(size_t size)
Initialize the size of the EEPROM space.