mirror of https://github.com/zmkfirmware/zmk.git
refactor(behaviors): Minor RAM usage tweaks (#2839)
Follow up cleanup of some config structs not marked as const.
This commit is contained in:
parent
d2eb6de7ad
commit
2fe55c4c41
|
|
@ -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)}, \
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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_<behavior_name>_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_<behavior_name>_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.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue