EEPROM: Use constant instead of a hardcoded value for uninitialized bytes

Instead of hardcoding 255 in the `eeprom.erase` handler, use a constant instead,
to make it clear what the number is.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/1094/merge
Gergely Nagy 3 years ago
parent 9f69e430ea
commit eaca11af4a
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -246,7 +246,7 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
break; break;
case ERASE: { case ERASE: {
for (uint16_t i = 0; i < Runtime.storage().length(); i++) { for (uint16_t i = 0; i < Runtime.storage().length(); i++) {
Runtime.storage().update(i, 255); Runtime.storage().update(i, EEPROM_UNINITIALIZED_BYTE);
} }
Runtime.storage().commit(); Runtime.storage().commit();
Runtime.device().rebootBootloader(); Runtime.device().rebootBootloader();

@ -28,9 +28,12 @@ class EEPROMSettings : public kaleidoscope::Plugin {
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
/* EEPROM is filled with 0xff when uninitialized, and we use that in a few
* places. */
static constexpr uint8_t EEPROM_UNINITIALIZED_BYTE = 0xff;
/* EEPROM is filled with 0xff when uninitialized, so a version with that value /* EEPROM is filled with 0xff when uninitialized, so a version with that value
* means we do not have an EEPROM version defined yet. */ * means we do not have an EEPROM version defined yet. */
static constexpr uint8_t VERSION_UNDEFINED = 0xff; static constexpr uint8_t VERSION_UNDEFINED = EEPROM_UNINITIALIZED_BYTE;
/* A version set to zero is likely some kind of corruption, we do not normally /* A version set to zero is likely some kind of corruption, we do not normally
* clear the byte. */ * clear the byte. */
static constexpr uint8_t VERSION_IMPOSSIBLE_ZERO = 0x00; static constexpr uint8_t VERSION_IMPOSSIBLE_ZERO = 0x00;

Loading…
Cancel
Save