Skip to content

Commit

Permalink
fix default layer persistence to support up to 32 single layer or 8 b…
Browse files Browse the repository at this point in the history
…itmasked layers
  • Loading branch information
infinityis committed Apr 8, 2024
1 parent ad8d934 commit f3f1748
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/feature_layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Layers stack on top of each other in numerical order. When determining what a ke

Sometimes, you might want to switch between layers in a macro or as part of a tap dance routine. `layer_on` activates a layer, and `layer_off` deactivates it. More layer-related functions can be found in [action_layer.h](https://github.com/qmk/qmk_firmware/blob/master/quantum/action_layer.h).

If you want to save multiple persistent default layers, you will want to avoid using the `set_single_persistent_default_layer` function which only supports one default persistent layer at a time. Instead, you can `#define DEFAULT_LAYER_BITMASK_ENABLE` and call the `eeconfig_update_default_layer` function directly, passing it an 8-bit wide bitfield representing the least significant byte of a layer_state_t variable. Note that this approach is limited to storing persistent default layers only between layers 0 and 7.

## Functions :id=functions

There are a number of functions (and variables) related to how you can use or manipulate the layers.
Expand Down
6 changes: 5 additions & 1 deletion keyboards/satt/comet46/keymaps/default-rgbled/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ void matrix_init_user(void) {

void matrix_scan_user(void) {
uint8_t layer = get_highest_layer(layer_state);
uint8_t default_layer = biton32(eeconfig_read_default_layer());
#ifdef DEFAULT_LAYER_BITMASK_ENABLE
uint8_t default_layer = get_highest_layer(eeconfig_read_default_layer());
#else
uint8_t default_layer = eeconfig_read_default_layer();
#endif
switch (layer) {
case _LOWER:
set_led_red;
Expand Down
4 changes: 4 additions & 0 deletions keyboards/satt/comet46/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ bool oled_task_user(void) {
char layer_str[22];
oled_write_P(PSTR("Layer: "), false);
uint8_t layer = get_highest_layer(layer_state);
#ifdef DEFAULT_LAYER_BITMASK_ENABLE
uint8_t default_layer = get_highest_layer(eeconfig_read_default_layer());
#else
uint8_t default_layer = eeconfig_read_default_layer();
#endif
switch (layer) {
case _QWERTY:
switch (default_layer) {
Expand Down
4 changes: 4 additions & 0 deletions quantum/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ void eeconfig_init_quantum(void) {

eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
eeprom_update_byte(EECONFIG_DEBUG, 0);
#if defined(DEFAULT_LAYER_BITMASK_ENABLE)
default_layer_state = (layer_state_t)1 << 0;
#else
default_layer_state = 0;
#endif
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, default_layer_state);
// Enable oneshot and autocorrect by default: 0b0001 0100 0000 0000
eeprom_update_word(EECONFIG_KEYMAP, 0x1400);
Expand Down
4 changes: 4 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,11 @@ void set_single_persistent_default_layer(uint8_t default_layer) {
#if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
PLAY_SONG(default_layer_songs[default_layer]);
#endif
#if defined(DEFAULT_LAYER_BITMASK_ENABLE)
eeconfig_update_default_layer((layer_state_t)1 << default_layer);
#else
eeconfig_update_default_layer(default_layer);
#endif
default_layer_set((layer_state_t)1 << default_layer);
}

Expand Down

0 comments on commit f3f1748

Please sign in to comment.