Skip to content

Commit

Permalink
Lift storage reset into the storage base class in preparation for bei…
Browse files Browse the repository at this point in the history
…ng able to do something smarter on platforms with a filesystem

Signed-off-by: Jesse Vincent <[email protected]>
  • Loading branch information
obra committed Dec 24, 2024
1 parent c003226 commit c7aace4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *input) {
} else if (::Focus.inputMatchesCommand(input, cmd_free)) {
::Focus.send(Runtime.storage().length() - ::EEPROMSettings.used());
} else if (::Focus.inputMatchesCommand(input, cmd_erase)) {
for (uint16_t i = 0; i < Runtime.storage().length(); i++) {
Runtime.storage().update(i, EEPROMSettings::EEPROM_UNINITIALIZED_BYTE);
}
Runtime.storage().commit();

Runtime.storage().erase();
Runtime.device().rebootBootloader();
} else {
return EventHandlerResult::OK;
Expand Down
7 changes: 7 additions & 0 deletions src/kaleidoscope/driver/storage/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class Base {

void setup() {}
void commit() {}

void erase() {
for (uint16_t i = 0; i < length(); i++) {
update(i, _StorageProps::uninitialized_byte);
}
commit();
}
};

} // namespace storage
Expand Down
6 changes: 6 additions & 0 deletions src/kaleidoscope/driver/storage/GD32Flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class GD32Flash : public EEPROMClass<_StorageProps::length> {
}
return true;
}
void erase() {
for (uint16_t i = 0; i < this->length(); i++) {
this->update(i, _StorageProps::uninitialized_byte);
}
this->commit();
}
};

} // namespace storage
Expand Down

0 comments on commit c7aace4

Please sign in to comment.