diff --git a/doc/plugin/EEPROM-Settings.md b/doc/plugin/EEPROM-Settings.md index 840c0439..1969c30b 100644 --- a/doc/plugin/EEPROM-Settings.md +++ b/doc/plugin/EEPROM-Settings.md @@ -43,7 +43,7 @@ void setup () { return; } - EEPROM.get(settingsBase, testSettings); + KeyboardHardware.storage().get(settingsBase, testSettings); } ``` diff --git a/src/kaleidoscope/Hardware.h b/src/kaleidoscope/Hardware.h index 895cc2e8..4c507234 100644 --- a/src/kaleidoscope/Hardware.h +++ b/src/kaleidoscope/Hardware.h @@ -24,6 +24,8 @@ #include "kaleidoscope/MatrixAddr.h" #include "kaleidoscope_internal/deprecations.h" +#include "EEPROM.h" + #ifndef CRGB #error cRGB and CRGB *must* be defined before including this header! #endif @@ -385,6 +387,13 @@ class Hardware { */ void enableHardwareTestMode() {} + /** + * Method to return the object the hardware uses for storage. + */ + auto storage() -> decltype(EEPROM) & { + return EEPROM; + } + /** @} */ }; } diff --git a/src/kaleidoscope/plugin/DynamicMacros.cpp b/src/kaleidoscope/plugin/DynamicMacros.cpp index 41b7b268..565eb763 100644 --- a/src/kaleidoscope/plugin/DynamicMacros.cpp +++ b/src/kaleidoscope/plugin/DynamicMacros.cpp @@ -49,7 +49,7 @@ static void playKeyCode(Key key, uint8_t keyStates, bool explicit_report) { static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) { Key key; key.flags = flags; - key.keyCode = EEPROM.read(pos++); + key.keyCode = KeyboardHardware.storage().read(pos++); playKeyCode(key, keyStates, explicit_report); } @@ -63,7 +63,7 @@ void DynamicMacros::updateDynamicMacroCache(void) { map_[0] = 0; while (pos < storage_base_ + storage_size_) { - macro = EEPROM.read(pos++); + macro = KeyboardHardware.storage().read(pos++); switch (macro) { case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_IMPLICIT_REPORT: @@ -91,8 +91,8 @@ void DynamicMacros::updateDynamicMacroCache(void) { previous_macro_ended = false; uint8_t keyCode, flags; do { - flags = EEPROM.read(pos++); - keyCode = EEPROM.read(pos++); + flags = KeyboardHardware.storage().read(pos++); + keyCode = KeyboardHardware.storage().read(pos++); } while (!(flags == 0 && keyCode == 0)); break; } @@ -101,7 +101,7 @@ void DynamicMacros::updateDynamicMacroCache(void) { previous_macro_ended = false; uint8_t keyCode, flags; do { - keyCode = EEPROM.read(pos++); + keyCode = KeyboardHardware.storage().read(pos++); } while (keyCode != 0); break; } @@ -128,7 +128,7 @@ void DynamicMacros::play(uint8_t macro_id) { pos = storage_base_ + map_[macro_id]; while (true) { - switch (macro = EEPROM.read(pos++)) { + switch (macro = KeyboardHardware.storage().read(pos++)) { case MACRO_ACTION_STEP_EXPLICIT_REPORT: explicit_report = true; break; @@ -140,23 +140,23 @@ void DynamicMacros::play(uint8_t macro_id) { kaleidoscope::hid::sendMouseReport(); break; case MACRO_ACTION_STEP_INTERVAL: - interval = EEPROM.read(pos++); + interval = KeyboardHardware.storage().read(pos++); break; case MACRO_ACTION_STEP_WAIT: { - uint8_t wait = EEPROM.read(pos++); + uint8_t wait = KeyboardHardware.storage().read(pos++); delay(wait); break; } case MACRO_ACTION_STEP_KEYDOWN: - flags = EEPROM.read(pos++); + flags = KeyboardHardware.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report); break; case MACRO_ACTION_STEP_KEYUP: - flags = EEPROM.read(pos++); + flags = KeyboardHardware.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report); break; case MACRO_ACTION_STEP_TAP: - flags = EEPROM.read(pos++); + flags = KeyboardHardware.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false); break; @@ -173,8 +173,8 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_SEQUENCE: { uint8_t keyCode; do { - flags = EEPROM.read(pos++); - keyCode = EEPROM.read(pos++); + flags = KeyboardHardware.storage().read(pos++); + keyCode = KeyboardHardware.storage().read(pos++); playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false); delay(interval); } while (!(flags == 0 && keyCode == 0)); @@ -183,7 +183,7 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: { uint8_t keyCode; do { - keyCode = EEPROM.read(pos++); + keyCode = KeyboardHardware.storage().read(pos++); playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false); delay(interval); } while (keyCode != 0); @@ -221,7 +221,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) { if (::Focus.isEOL()) { for (uint16_t i = 0; i < storage_size_; i++) { uint8_t b; - b = EEPROM.read(storage_base_ + i); + b = KeyboardHardware.storage().read(storage_base_ + i); ::Focus.send(b); } } else { @@ -231,7 +231,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) { uint8_t b; ::Focus.read(b); - EEPROM.update(storage_base_ + pos++, b); + KeyboardHardware.storage().update(storage_base_ + pos++, b); } updateDynamicMacroCache(); } diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap.cpp b/src/kaleidoscope/plugin/EEPROM-Keymap.cpp index acc2d88d..f2e26faf 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Keymap.cpp @@ -55,8 +55,8 @@ Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) { uint16_t pos = ((layer * KeyboardHardware.numKeys()) + key_addr.toInt()) * 2; - key.flags = EEPROM.read(keymap_base_ + pos); - key.keyCode = EEPROM.read(keymap_base_ + pos + 1); + key.flags = KeyboardHardware.storage().read(keymap_base_ + pos); + key.keyCode = KeyboardHardware.storage().read(keymap_base_ + pos + 1); return key; } @@ -77,8 +77,8 @@ uint16_t EEPROMKeymap::keymap_base(void) { } void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) { - EEPROM.update(keymap_base_ + base_pos * 2, key.flags); - EEPROM.update(keymap_base_ + base_pos * 2 + 1, key.keyCode); + KeyboardHardware.storage().update(keymap_base_ + base_pos * 2, key.flags); + KeyboardHardware.storage().update(keymap_base_ + base_pos * 2 + 1, key.keyCode); } void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) { diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.cpp b/src/kaleidoscope/plugin/EEPROM-Settings.cpp index bf3df769..52a82b1d 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Settings.cpp @@ -28,7 +28,7 @@ bool EEPROMSettings::sealed_; uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings); EventHandlerResult EEPROMSettings::onSetup() { - EEPROM.get(0, settings_); + KeyboardHardware.storage().get(0, settings_); /* If the version is undefined, set up sensible defaults. */ if (settings_.version == VERSION_UNDEFINED) { @@ -49,7 +49,7 @@ EventHandlerResult EEPROMSettings::onSetup() { * not able to catch all writes yet. For the sake of consistency, if we * encounter a firmware with no version defined, we'll set sensible * defaults. */ - EEPROM.put(0, settings_); + KeyboardHardware.storage().put(0, settings_); } return EventHandlerResult::OK; } @@ -146,7 +146,7 @@ uint16_t EEPROMSettings::used(void) { } void EEPROMSettings::update(void) { - EEPROM.put(0, settings_); + KeyboardHardware.storage().put(0, settings_); is_valid_ = true; } @@ -220,22 +220,22 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) { switch (sub_command) { case CONTENTS: { if (::Focus.isEOL()) { - for (uint16_t i = 0; i < EEPROM.length(); i++) { - uint8_t d = EEPROM[i]; + for (uint16_t i = 0; i < KeyboardHardware.storage().length(); i++) { + uint8_t d = KeyboardHardware.storage().read(i); ::Focus.send(d); } } else { - for (uint16_t i = 0; i < EEPROM.length() && !::Focus.isEOL(); i++) { + for (uint16_t i = 0; i < KeyboardHardware.storage().length() && !::Focus.isEOL(); i++) { uint8_t d; ::Focus.read(d); - EEPROM.update(i, d); + KeyboardHardware.storage().update(i, d); } } break; } case FREE: - ::Focus.send(EEPROM.length() - ::EEPROMSettings.used()); + ::Focus.send(KeyboardHardware.storage().length() - ::EEPROMSettings.used()); break; } diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.h b/src/kaleidoscope/plugin/EEPROM-Settings.h index 307a5dd6..baaf91b8 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.h +++ b/src/kaleidoscope/plugin/EEPROM-Settings.h @@ -18,7 +18,6 @@ #pragma once #include -#include #define _DEPRECATED_MESSAGE_EEPROMSETTINGS_VERSION_SET \ "The EEPROMSettings.version(uint8_t version) method has been deprecated,\n" \ diff --git a/src/kaleidoscope/plugin/FingerPainter.cpp b/src/kaleidoscope/plugin/FingerPainter.cpp index 5d9f29df..e720ef58 100644 --- a/src/kaleidoscope/plugin/FingerPainter.cpp +++ b/src/kaleidoscope/plugin/FingerPainter.cpp @@ -101,7 +101,7 @@ EventHandlerResult FingerPainter::onFocusEvent(const char *command) { if (sub_command == CLEAR) { for (uint16_t i = 0; i < KeyboardHardware.numKeys() / 2; i++) { - EEPROM.update(color_base_ + i, 0); + KeyboardHardware.storage().update(color_base_ + i, 0); } return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/HostOS.cpp b/src/kaleidoscope/plugin/HostOS.cpp index d1d11206..4e8f75c1 100644 --- a/src/kaleidoscope/plugin/HostOS.cpp +++ b/src/kaleidoscope/plugin/HostOS.cpp @@ -18,8 +18,6 @@ #include #include -#include - namespace kaleidoscope { namespace plugin { @@ -35,14 +33,14 @@ EventHandlerResult HostOS::onSetup(void) { return EventHandlerResult::OK; } - os_ = (hostos::Type)EEPROM.read(eeprom_slice_); + os_ = (hostos::Type)KeyboardHardware.storage().read(eeprom_slice_); return EventHandlerResult::OK; } void HostOS::os(hostos::Type new_os) { os_ = new_os; - EEPROM.update(eeprom_slice_, os_); + KeyboardHardware.storage().update(eeprom_slice_, os_); } } diff --git a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index 42e9c8dd..2d546add 100644 --- a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -58,7 +58,7 @@ void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_ const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) { uint8_t color_index; - color_index = EEPROM.read(map_base + position / 2); + color_index = KeyboardHardware.storage().read(map_base + position / 2); if (position % 2) color_index &= ~0xf0; else @@ -76,7 +76,7 @@ const cRGB LEDPaletteTheme::lookupColorAtPosition(uint16_t map_base, uint16_t po const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { cRGB color; - EEPROM.get(palette_base_ + color_index * sizeof(cRGB), color); + KeyboardHardware.storage().get(palette_base_ + color_index * sizeof(cRGB), color); color.r ^= 0xff; color.g ^= 0xff; color.b ^= 0xff; @@ -87,7 +87,7 @@ const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) { uint8_t indexes; - indexes = EEPROM.read(map_base + position / 2); + indexes = KeyboardHardware.storage().read(map_base + position / 2); if (position % 2) { uint8_t other = indexes >> 4; indexes = (other << 4) + color_index; @@ -95,7 +95,7 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos uint8_t other = indexes & ~0xf0; indexes = (color_index << 4) + other; } - EEPROM.update(map_base + position / 2, indexes); + KeyboardHardware.storage().update(map_base + position / 2, indexes); } EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { @@ -129,7 +129,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { color.g ^= 0xff; color.b ^= 0xff; - EEPROM.put(palette_base_ + i * sizeof(color), color); + KeyboardHardware.storage().put(palette_base_ + i * sizeof(color), color); i++; } @@ -155,7 +155,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, if (::Focus.isEOL()) { for (uint16_t pos = 0; pos < max_index; pos++) { - uint8_t indexes = EEPROM.read(theme_base + pos); + uint8_t indexes = KeyboardHardware.storage().read(theme_base + pos); ::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0); } @@ -171,7 +171,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, uint8_t indexes = (idx1 << 4) + idx2; - EEPROM.update(theme_base + pos, indexes); + KeyboardHardware.storage().update(theme_base + pos, indexes); pos++; } diff --git a/src/kaleidoscope/plugin/TypingBreaks.cpp b/src/kaleidoscope/plugin/TypingBreaks.cpp index 38faeb58..e3692bdf 100644 --- a/src/kaleidoscope/plugin/TypingBreaks.cpp +++ b/src/kaleidoscope/plugin/TypingBreaks.cpp @@ -107,12 +107,12 @@ EventHandlerResult TypingBreaks::onSetup() { // If idleTime is max, assume that EEPROM is uninitialized, and store the // defaults. uint32_t idle_time; - EEPROM.get(settings_base_, idle_time); + KeyboardHardware.storage().get(settings_base_, idle_time); if (idle_time == 0xffffffff) { - EEPROM.put(settings_base_, settings); + KeyboardHardware.storage().put(settings_base_, settings); } - EEPROM.get(settings_base_, settings); + KeyboardHardware.storage().get(settings_base_, settings); return EventHandlerResult::OK; } @@ -192,7 +192,7 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *command) { break; } - EEPROM.put(settings_base_, settings); + KeyboardHardware.storage().put(settings_base_, settings); return EventHandlerResult::EVENT_CONSUMED; }