Skip to content

Commit

Permalink
A first pass at removing mixed progmem and EEPROM Keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Feb 29, 2024
1 parent 3d8e759 commit 99ca12e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ EventHandlerResult EEPROMKeymap::onNameQuery() {

void EEPROMKeymap::setup(uint8_t max) {
layer_count = max;
if (::EEPROMSettings.ignoreHardcodedLayers()) {
Layer.getKey = getKey;
} else {
layer_count += progmem_layers_;
Layer.getKey = getKeyExtended;
}
max_layers(max);
}

Expand All @@ -71,17 +66,6 @@ Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) {
Runtime.storage().read(keymap_base_ + pos)); // flags
}

Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) {

// If the layer is within PROGMEM bounds, look it up from there
if (layer < progmem_layers_) {
return Layer.getKeyFromPROGMEM(layer, key_addr);
}

// If the layer is outside of PROGMEM, look up from EEPROM
return getKey(layer - progmem_layers_, key_addr);
}

uint16_t EEPROMKeymap::keymap_base() {
return keymap_base_;
}
Expand All @@ -104,30 +88,9 @@ void EEPROMKeymap::dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr)) {
EventHandlerResult EEPROMKeymap::onFocusEvent(const char *input) {
const char *cmd_custom = PSTR("keymap.custom");
const char *cmd_default = PSTR("keymap.default");
const char *cmd_onlyCustom = PSTR("keymap.onlyCustom");

if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd_custom, cmd_default, cmd_onlyCustom);

if (::Focus.inputMatchesCommand(input, cmd_onlyCustom)) {
if (::Focus.isEOL()) {
::Focus.send((uint8_t)::EEPROMSettings.ignoreHardcodedLayers());
} else {
bool v;

::Focus.read((uint8_t &)v);
::EEPROMSettings.ignoreHardcodedLayers(v);

layer_count = max_layers_;
if (v) {
Layer.getKey = getKey;
} else {
layer_count += progmem_layers_;
Layer.getKey = getKeyExtended;
}
}
return EventHandlerResult::EVENT_CONSUMED;
}
return ::Focus.printHelp(cmd_custom, cmd_default);

if (::Focus.inputMatchesCommand(input, cmd_default)) {
// By using a cast to the appropriate function type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
static uint16_t keymap_base();

static Key getKey(uint8_t layer, KeyAddr key_addr);
static Key getKeyExtended(uint8_t layer, KeyAddr key_addr);

static void updateKey(uint16_t base_pos, Key key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ EventHandlerResult EEPROMSettings::onSetup() {

/* If the version is undefined, set up sensible defaults. */
if (settings_.version == VERSION_UNDEFINED) {
if (settings_.default_layer == 127 &&
settings_.ignore_hardcoded_layers) {
if (settings_.default_layer == 127 ) {
/* If both of these are set, that means that the EEPROM is uninitialized,
and setting sensible defaults is safe. If either of them is not at it's
uninitialized state, we do not override them, to avoid overwriting user
settings. */
settings_.ignore_hardcoded_layers = false;
settings_.default_layer = 0;
}

Expand Down Expand Up @@ -81,24 +79,10 @@ uint8_t EEPROMSettings::default_layer(uint8_t layer) {
settings_.default_layer = layer;
}

/*
* We set default_layer to IGNORE_HARDCODED_LAYER (instead of `value`) because
* due to compatibility reasons, we might get passed 0xff, yet, we want to set
* a different value to signal an explicit "no default".
*/
if (layer >= IGNORE_HARDCODED_LAYER) {
settings_.default_layer = IGNORE_HARDCODED_LAYER;
}
update();
return settings_.default_layer;
}

void EEPROMSettings::ignoreHardcodedLayers(bool value) {
settings_.ignore_hardcoded_layers = value;
if (settings_.default_layer > IGNORE_HARDCODED_LAYER)
settings_.default_layer = IGNORE_HARDCODED_LAYER;
update();
}

void EEPROMSettings::seal() {
sealed_ = true;
Expand All @@ -119,6 +103,7 @@ void EEPROMSettings::seal() {

is_valid_ = true;

<<<<<<< Updated upstream
/* If we have a default layer set, switch to it.
*
* We check if the layer is smaller than IGNORE_HARDCODED_LAYER (0x7e),
Expand All @@ -130,6 +115,20 @@ void EEPROMSettings::seal() {
if (settings_.default_layer < IGNORE_HARDCODED_LAYER && settings_.default_layer < layer_count) {
Layer.move(settings_.default_layer);
}
||||||| Stash base
/* If we have a default layer set, switch to it.
*
* We check if the layer is smaller than IGNORE_HARDCODED_LAYER (0x7e),
* because we want to avoid setting a default layer in two cases:
*
* - When the EEPROM is uninitialized (0x7f)
* - When such layer switching is explicitly turned off (0x7e)
*/
if (settings_.default_layer < IGNORE_HARDCODED_LAYER)
Layer.move(settings_.default_layer);
=======
Layer.move(settings_.default_layer);
>>>>>>> Stashed changes
}

uint16_t EEPROMSettings::requestSlice(uint16_t size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EEPROMSettings : public kaleidoscope::Plugin {
private:
struct Settings {
uint8_t default_layer : 7;
bool ignore_hardcoded_layers : 1;
bool _unused : 1;
uint8_t version;
uint16_t crc;
};
Expand Down Expand Up @@ -69,10 +69,6 @@ class EEPROMSettings : public kaleidoscope::Plugin {
uint8_t default_layer() {
return settings_.default_layer;
}
void ignoreHardcodedLayers(bool value);
bool ignoreHardcodedLayers() {
return settings_.ignore_hardcoded_layers;
}

private:
static constexpr uint8_t IGNORE_HARDCODED_LAYER = 0x7e;
Expand Down

0 comments on commit 99ca12e

Please sign in to comment.