From 657d33450c69b0b45a63ef3ba52fba0388fb4bbb Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 6 Jun 2022 12:09:25 +0200 Subject: [PATCH] driver::storage: Fix isSliceUninitialized() for AVREEPROM `kaleidoscope::driver::storage::AVREEPROM` wasn't implementing its own `isSliceUninitialized()` method, and relied on the Base class to do so. However, since we're not using `virtual` methods, the base class was using `Base::read()` (which always returns 0) rather than `AVREEPROM::read()`, so `isSliceUninitialized()` always returned false. To fix this, we implement the function in `AVREEPROM`, and let the default implementation in Base always return false. Signed-off-by: Gergely Nagy --- src/kaleidoscope/driver/storage/AVREEPROM.h | 8 ++++++++ src/kaleidoscope/driver/storage/Base.h | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kaleidoscope/driver/storage/AVREEPROM.h b/src/kaleidoscope/driver/storage/AVREEPROM.h index 88585ef8..a91d1d04 100644 --- a/src/kaleidoscope/driver/storage/AVREEPROM.h +++ b/src/kaleidoscope/driver/storage/AVREEPROM.h @@ -56,6 +56,14 @@ class AVREEPROM : public kaleidoscope::driver::storage::Base<_StorageProps> { void update(int idx, uint8_t val) { EEPROM.update(idx, val); } + + bool isSliceUninitialized(uint16_t offset, uint16_t size) { + for (uint16_t o = offset; o < offset + size; o++) { + if (this->read(o) != _StorageProps::uninitialized_byte) + return false; + } + return true; + } }; } // namespace storage diff --git a/src/kaleidoscope/driver/storage/Base.h b/src/kaleidoscope/driver/storage/Base.h index ccf99a33..5f7c76d9 100644 --- a/src/kaleidoscope/driver/storage/Base.h +++ b/src/kaleidoscope/driver/storage/Base.h @@ -50,11 +50,7 @@ class Base { void update(int idx, uint8_t val) {} bool isSliceUninitialized(uint16_t offset, uint16_t size) { - for (uint16_t o = offset; o < offset + size; o++) { - if (read(o) != _StorageProps::uninitialized_byte) - return false; - } - return true; + return false; } const uint16_t length() {