aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/keymap.c
diff options
context:
space:
mode:
authorPeter Johanson <[email protected]>2024-09-16 22:59:47 -0600
committerPete Johanson <[email protected]>2024-09-16 23:20:14 -0600
commita9167b2275a17970169a84c5041441ef0b36d0f7 (patch)
tree248189fcd7ce7d2f32736bda5bdb89ad0878e876 /app/src/keymap.c
parent32d0a4bf4102148d394dc5a7acc962e71c5ed000 (diff)
downloadzmk-a9167b2275a17970169a84c5041441ef0b36d0f7.tar.gz
zmk-a9167b2275a17970169a84c5041441ef0b36d0f7.zip
fix: Reduce RAM usage in the keymap
* When not building with runtime keymap support, make the keymap const.
Diffstat (limited to 'app/src/keymap.c')
-rw-r--r--app/src/keymap.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/app/src/keymap.c b/app/src/keymap.c
index c9845479cb..041ee11311 100644
--- a/app/src/keymap.c
+++ b/app/src/keymap.c
@@ -83,7 +83,7 @@ static uint8_t keymap_layer_orders[ZMK_KEYMAP_LAYERS_LEN];
(DT_INST_FOREACH_CHILD_SEP(0, TRANSFORMED_LAYER, (, ))), \
(DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(0, TRANSFORMED_LAYER, (, ))))};
-KEYMAP_VAR(zmk_keymap, )
+KEYMAP_VAR(zmk_keymap, COND_CODE_1(IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE), (), (const)))
#if IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)
@@ -238,8 +238,6 @@ zmk_keymap_get_layer_binding_at_idx(zmk_keymap_layer_id_t layer_id, uint8_t bind
static uint8_t zmk_keymap_layer_pending_changes[ZMK_KEYMAP_LAYERS_LEN][PENDING_ARRAY_SIZE];
-#endif // IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)
-
int zmk_keymap_set_layer_binding_at_idx(zmk_keymap_layer_id_t layer_id, uint8_t binding_idx,
struct zmk_behavior_binding binding) {
if (binding_idx >= ZMK_KEYMAP_LEN) {
@@ -248,11 +246,9 @@ int zmk_keymap_set_layer_binding_at_idx(zmk_keymap_layer_id_t layer_id, uint8_t
ASSERT_LAYER_VAL(layer_id, -EINVAL)
-#if IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)
uint8_t *pending = zmk_keymap_layer_pending_changes[layer_id];
WRITE_BIT(pending[binding_idx / 8], binding_idx % 8, 1);
-#endif // IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)
// TODO: Need a mutex to protect access to the keymap data?
memcpy(&zmk_keymap[layer_id][binding_idx], &binding, sizeof(binding));
@@ -260,6 +256,14 @@ int zmk_keymap_set_layer_binding_at_idx(zmk_keymap_layer_id_t layer_id, uint8_t
return 0;
}
+#else
+
+int zmk_keymap_set_layer_binding_at_idx(zmk_keymap_layer_id_t layer_id, uint8_t binding_idx,
+ struct zmk_behavior_binding binding) {
+ return -ENOTSUP;
+}
+
+#endif // IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)
#if IS_ENABLED(CONFIG_ZMK_KEYMAP_LAYER_REORDERING)
#if IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)