Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update how default layers are stored/retrieved from EEPROM #22359

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 0 additions & 5 deletions keyboards/40percentclub/gherkin/keymaps/itsaferbie/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

void matrix_init_user(void) {
rgblight_enable();
}
Expand Down
11 changes: 3 additions & 8 deletions keyboards/40percentclub/gherkin/keymaps/mjt/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,14 @@ float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
#endif

void persistant_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
#ifdef AUDIO_ENABLE
PLAY_SONG(tone_qwerty);
#endif
persistant_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
Expand All @@ -98,7 +93,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
#ifdef AUDIO_ENABLE
PLAY_SONG(tone_dvorak);
#endif
persistant_default_layer_set(1UL<<_NUMBERS);
set_single_persistent_default_layer(_NUMBERS);
}
return false;
break;
Expand All @@ -107,7 +102,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
#ifdef AUDIO_ENABLE
PLAY_SONG(tone_colemak);
#endif
persistant_default_layer_set(1UL<<_SYMBOLS);
set_single_persistent_default_layer(_SYMBOLS);
}
return false;
break;
Expand Down
9 changes: 2 additions & 7 deletions keyboards/atreus/keymaps/henxing/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {

// The value to return
Expand All @@ -72,7 +67,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
break;

Expand All @@ -87,7 +82,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {

case RAISE:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_RAISE);
set_single_persistent_default_layer(_RAISE);
}
break;

Expand Down
7 changes: 1 addition & 6 deletions keyboards/biacco42/ergo42/keymaps/yshrsmz/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case BASE:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_BASE);
set_single_persistent_default_layer(_BASE);
}
return false;
break;
Expand Down
11 changes: 3 additions & 8 deletions keyboards/clueboard/66/keymaps/smt/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,23 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______, _______,_______, RGB_MOD,RGB_MOD, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_HUI),
};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
case COLEMAK:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_COLEMAK);
set_single_persistent_default_layer(_COLEMAK);
}
return false;
break;
case DVORAK:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_DVORAK);
set_single_persistent_default_layer(_DVORAK);
}
return false;
break;
Expand Down
13 changes: 4 additions & 9 deletions keyboards/converter/ibm_terminal/keymaps/priyadi/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,35 +246,30 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
*/
};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
/* layout switcher */
case LAY_QWE:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<QWE);
set_single_persistent_default_layer(QWE);
}
return false;
break;
case LAY_COL:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<COL);
set_single_persistent_default_layer(COL);
}
return false;
break;
case LAY_WOR:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<WOR);
set_single_persistent_default_layer(WOR);
}
return false;
break;
case LAY_DVO:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<DVO);
set_single_persistent_default_layer(DVO);
}
return false;
break;
Expand Down
7 changes: 1 addition & 6 deletions keyboards/crkbd/keymaps/thumb_ctrl/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

int RGB_current_mode;

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

// Setting ADJUST layer RGB back to default
void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
Expand Down Expand Up @@ -170,7 +165,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
Expand Down
7 changes: 1 addition & 6 deletions keyboards/crkbd/keymaps/vlukash_trackpad_left/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

int RGB_current_mode;

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

// Setting ADJUST layer RGB back to default
void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
Expand Down Expand Up @@ -154,7 +149,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
case LOWER:
Expand Down
7 changes: 1 addition & 6 deletions keyboards/crkbd/keymaps/vlukash_trackpad_right/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

int RGB_current_mode;

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

// Setting ADJUST layer RGB back to default
void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
Expand All @@ -126,7 +121,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
case LOWER:
Expand Down
3 changes: 2 additions & 1 deletion keyboards/custommk/ergostrafer/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
#define AUDIO_PWM_DRIVER PWMD4
#define AUDIO_PWM_CHANNEL 3
#define AUDIO_PWM_PAL_MODE 2
#define AUDIO_STATE_TIMER GPTD5
#define AUDIO_STATE_TIMER GPTD5
#define AUDIO_INIT_DELAY
5 changes: 0 additions & 5 deletions keyboards/dz60/keymaps/iso_split-spacebar/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
};


void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

// always enable num lock on layer NL and disable on other layers
// thanks to spidey3 & Erovia on discord
layer_state_t layer_state_set_user(layer_state_t state) {
Expand Down
7 changes: 1 addition & 6 deletions keyboards/eco/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

};

void persistant_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistant_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
Expand Down
7 changes: 1 addition & 6 deletions keyboards/eco/keymaps/that_canadian/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,14 @@ float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
#endif


void persistant_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
#ifdef AUDIO_ENABLE
PLAY_SONG(tone_qwerty);
#endif
persistant_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
Expand Down
2 changes: 1 addition & 1 deletion keyboards/evyd13/atom47/keymaps/junonum_a47/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
/* case MAIN:
if (record->event.pressed) {
persistant_default_layer_set(1UL<<_MAIN);
set_single_persistent_default_layer(_MAIN);
}
return false;
break; */
Expand Down
11 changes: 2 additions & 9 deletions keyboards/exclusive/e7v1/keymaps/masterzen/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ void matrix_init_user(void)
mode = rgblight_config.mode;
}


void persistent_default_layer_set(uint16_t default_layer)
{
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record)
{
switch (keycode)
Expand All @@ -85,14 +78,14 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record)
case LAY_LIN:
if (record->event.pressed)
{
persistent_default_layer_set(1UL << BASE);
set_single_persistent_default_layer(BASE);
}
return false;
break;
case LAY_OSX:
if (record->event.pressed)
{
persistent_default_layer_set(1UL << OSX);
set_single_persistent_default_layer(OSX);
}
return false;
break;
Expand Down
5 changes: 0 additions & 5 deletions keyboards/gh60/satan/keymaps/addcninblue/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
) ,
};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!process_record_dynamic_macro(keycode, record)) {
return false;
Expand Down
10 changes: 3 additions & 7 deletions keyboards/gh60/satan/keymaps/smt/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_QWERTY);
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
case COLEMAK:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_COLEMAK);
set_single_persistent_default_layer(_COLEMAK);
}
return false;
break;
case DVORAK:
if (record->event.pressed) {
persistent_default_layer_set(1UL<<_DVORAK);
set_single_persistent_default_layer(_DVORAK);
}
return false;
break;
Expand Down
Loading
Loading