diff --git a/app/src/behaviors/behavior_caps_word.c b/app/src/behaviors/behavior_caps_word.c index c3255f12c..59dd29a7b 100644 --- a/app/src/behaviors/behavior_caps_word.c +++ b/app/src/behaviors/behavior_caps_word.c @@ -175,7 +175,7 @@ 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 struct behavior_caps_word_config behavior_caps_word_config_##n = { \ + 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)}, \ diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 3faeec53a..380964b94 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -378,9 +378,6 @@ static int behavior_sticky_key_init(const struct device *dev) { return 0; } -struct behavior_sticky_key_data {}; -static struct behavior_sticky_key_data behavior_sticky_key_data; - #define KP_INST(n) \ static const struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \ .behavior = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ @@ -389,7 +386,7 @@ static struct behavior_sticky_key_data behavior_sticky_key_data; .lazy = DT_INST_PROP(n, lazy), \ .ignore_modifiers = DT_INST_PROP(n, ignore_modifiers), \ }; \ - BEHAVIOR_DT_INST_DEFINE(n, behavior_sticky_key_init, NULL, &behavior_sticky_key_data, \ + BEHAVIOR_DT_INST_DEFINE(n, behavior_sticky_key_init, NULL, NULL, \ &behavior_sticky_key_config_##n, POST_KERNEL, \ CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_sticky_key_driver_api); diff --git a/docs/docs/development/new-behavior.mdx b/docs/docs/development/new-behavior.mdx index 0e67a4494..3bdfebe8e 100644 --- a/docs/docs/development/new-behavior.mdx +++ b/docs/docs/development/new-behavior.mdx @@ -262,7 +262,7 @@ An example of this can be seen below, taking the `#define KP_INST(n)` from the h ```c #define KP_INST(n) \ - static struct behavior_hold_tap_config behavior_hold_tap_config_##n = { \ + static const struct behavior_hold_tap_config behavior_hold_tap_config_##n = { \ .tapping_term_ms = DT_INST_PROP(n, tapping_term_ms), \ .hold_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 0), label), \ .tap_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 1), label), \ @@ -423,7 +423,8 @@ The fourth cell of `BEHAVIOR_DT_INST_DEFINE` can be set to `NULL` instead if ins ##### Configuration pointers (optional) -The configuration `struct` stores the properties declared from the behavior's `.yaml` for **each new instance** of the behavior. As seen in the `#define KP_INST(n)` of the hold-tap example, the configuration `struct`, `behavior__config_##n`, for each instance number, `n`, can be initialized using the [Zephyr Devicetree Instance-based APIs](https://docs.zephyrproject.org/3.5.0/build/dts/api/api.html#instance-based-apis), which extract the values from the `properties` of each instance of the [devicetree binding](#creating-the-devicetree-binding-yaml) from a user's keymap or [predefined use-case `.dtsi` files](#defining-common-use-cases-for-the-behavior-dtsi-optional) stored in `app/dts/behaviors/`. We illustrate this further by comparing the [`#define KP_INST(n)` from the hold-tap driver](#behavior_dt_inst_define) and the [`properties` of the hold-tap devicetree binding.](#creating-the-devicetree-binding-yaml) +The configuration `struct` stores the properties declared from the behavior's `.yaml` for **each new instance** of the behavior. As seen in the `#define KP_INST(n)` of the hold-tap example, the configuration `struct`, `behavior__config_##n`, for each instance number, `n`, can be initialized using the [Zephyr Devicetree Instance-based APIs](https://docs.zephyrproject.org/3.5.0/build/dts/api/api.html#instance-based-apis), which extract the values from the `properties` of each instance of the [devicetree binding](#creating-the-devicetree-binding-yaml) from a user's keymap or [predefined use-case `.dtsi` files](#defining-common-use-cases-for-the-behavior-dtsi-optional) stored in `app/dts/behaviors/`. We illustrate this further by comparing the [`#define KP_INST(n)` from the hold-tap driver](#behavior_dt_inst_define) and the [`properties` of the hold-tap devicetree binding](#creating-the-devicetree-binding-yaml). The config structure instances should always be declared `const` +so they are placed into flash, not RAM, by the linker. The fifth cell of `BEHAVIOR_DT_INST_DEFINE` can be set to `NULL` instead if instance-specific configurations are not required.