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;
case ERASE: {
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.device().rebootBootloader();

@ -28,9 +28,12 @@ class EEPROMSettings : public kaleidoscope::Plugin {
EventHandlerResult onSetup();
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
* 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
* clear the byte. */
static constexpr uint8_t VERSION_IMPOSSIBLE_ZERO = 0x00;

Loading…
Cancel
Save