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

refactor(keymap): Reduce flash usage for studio builds #2771

Merged
Merged
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
5 changes: 4 additions & 1 deletion app/include/zmk/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

#define ZMK_LAYER_CHILD_LEN_PLUS_ONE(node) 1 +
#define ZMK_KEYMAP_LAYERS_LEN \
(DT_FOREACH_CHILD(DT_INST(0, zmk_keymap), ZMK_LAYER_CHILD_LEN_PLUS_ONE) 0)
(COND_CODE_1( \
IS_ENABLED(CONFIG_ZMK_STUDIO), \
(DT_FOREACH_CHILD(DT_INST(0, zmk_keymap), ZMK_LAYER_CHILD_LEN_PLUS_ONE)), \
(DT_FOREACH_CHILD_STATUS_OKAY(DT_INST(0, zmk_keymap), ZMK_LAYER_CHILD_LEN_PLUS_ONE))) 0)

/**
* @brief A layer ID is a stable identifier to refer to a layer, regardless of ordering.
Expand Down
19 changes: 13 additions & 6 deletions app/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ static uint8_t keymap_layer_orders[ZMK_KEYMAP_LAYERS_LEN];

#endif // IS_ENABLED(CONFIG_ZMK_KEYMAP_LAYER_REORDERING)

#define KEYMAP_VAR(_name, _opts) \
#define KEYMAP_VAR(_name, _opts, no_init) \
static _opts struct zmk_behavior_binding _name[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = { \
COND_CODE_1(IS_ENABLED(CONFIG_ZMK_STUDIO), \
(DT_INST_FOREACH_CHILD_SEP(0, TRANSFORMED_LAYER, (, ))), \
(DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(0, TRANSFORMED_LAYER, (, ))))};
COND_CODE_0( \
no_init, \
(COND_CODE_1(IS_ENABLED(CONFIG_ZMK_STUDIO), \
(DT_INST_FOREACH_CHILD_SEP(0, TRANSFORMED_LAYER, (, ))), \
(DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(0, TRANSFORMED_LAYER, (, ))))), \
(0))};

KEYMAP_VAR(zmk_keymap, COND_CODE_1(IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE), (), (const)))
KEYMAP_VAR(zmk_keymap, COND_CODE_1(IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE), (), (const)),
IS_ENABLED(CONFIG_ZMK_STUDIO))

#if IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)

KEYMAP_VAR(zmk_stock_keymap, const)
KEYMAP_VAR(zmk_stock_keymap, const, 0)

static char zmk_keymap_layer_names[ZMK_KEYMAP_LAYERS_LEN][CONFIG_ZMK_KEYMAP_LAYER_NAME_MAX_LEN] = {
DT_INST_FOREACH_CHILD_SEP(0, LAYER_NAME, (, ))};
Expand Down Expand Up @@ -955,6 +959,9 @@ int keymap_init(void) {
#if IS_ENABLED(CONFIG_ZMK_KEYMAP_LAYER_REORDERING)
load_stock_keymap_layer_ordering();
#endif
#if IS_ENABLED(CONFIG_ZMK_STUDIO)
reload_from_stock_keymap();
#endif

return 0;
}
Expand Down
Loading