From 9406d39d14e5b808ed3d6f428bcb53a3a2579c8d Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Wed, 26 Feb 2025 15:01:04 -0700 Subject: [PATCH] refactor(behaviors): Small caps word RAM reduction. (#2842) Don't use lazy initialized in-memory array of devices. --- app/src/behaviors/behavior_caps_word.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/app/src/behaviors/behavior_caps_word.c b/app/src/behaviors/behavior_caps_word.c index 59dd29a7b..52eaaa02e 100644 --- a/app/src/behaviors/behavior_caps_word.c +++ b/app/src/behaviors/behavior_caps_word.c @@ -32,7 +32,6 @@ struct caps_word_continue_item { struct behavior_caps_word_config { zmk_mod_flags_t mods; - uint8_t index; uint8_t continuations_count; struct caps_word_continue_item continuations[]; }; @@ -85,7 +84,7 @@ static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh); ZMK_LISTENER(behavior_caps_word, caps_word_keycode_state_changed_listener); ZMK_SUBSCRIPTION(behavior_caps_word, zmk_keycode_state_changed); -static const struct device *devs[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)]; +static const struct device *devs[] = {DT_INST_FOREACH_STATUS_OKAY(DEVICE_DT_INST_GET)}; static bool caps_word_is_caps_includelist(const struct behavior_caps_word_config *config, uint16_t usage_page, uint8_t usage_id, @@ -133,11 +132,8 @@ static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh) { return ZMK_EV_EVENT_BUBBLE; } - for (int i = 0; i < DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT); i++) { + for (int i = 0; i < ARRAY_SIZE(devs); i++) { const struct device *dev = devs[i]; - if (dev == NULL) { - continue; - } struct behavior_caps_word_data *data = dev->data; if (!data->active) { @@ -160,12 +156,6 @@ static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh) { return ZMK_EV_EVENT_BUBBLE; } -static int behavior_caps_word_init(const struct device *dev) { - const struct behavior_caps_word_config *config = dev->config; - devs[config->index] = dev; - return 0; -} - #define CAPS_WORD_LABEL(i, _n) DT_INST_LABEL(i) #define PARSE_BREAK(i) \ @@ -176,12 +166,11 @@ static int behavior_caps_word_init(const struct device *dev) { #define KP_INST(n) \ static struct behavior_caps_word_data behavior_caps_word_data_##n = {.active = false}; \ static const struct behavior_caps_word_config behavior_caps_word_config_##n = { \ - .index = n, \ .mods = DT_INST_PROP_OR(n, mods, MOD_LSFT), \ .continuations = {LISTIFY(DT_INST_PROP_LEN(n, continue_list), BREAK_ITEM, (, ), n)}, \ .continuations_count = DT_INST_PROP_LEN(n, continue_list), \ }; \ - BEHAVIOR_DT_INST_DEFINE(n, behavior_caps_word_init, NULL, &behavior_caps_word_data_##n, \ + BEHAVIOR_DT_INST_DEFINE(n, NULL, NULL, &behavior_caps_word_data_##n, \ &behavior_caps_word_config_##n, POST_KERNEL, \ CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_caps_word_driver_api);