refactor(behaviors): Make label property optional

Changed all code (except for layer names) which used the label property
to use DEVICE_DT_NAME() instead, which uses the label if set or falls
back to the full node name. This matches how Zephyr determines the node
names used with device_get_binding() and allows us to start removing the
deprecated label property from things.
This commit is contained in:
Joel Spadin 2023-09-05 11:35:51 -05:00
parent dbe5dfb1d8
commit 179bdbc41a
15 changed files with 71 additions and 63 deletions

View file

@ -4,7 +4,8 @@
properties:
label:
type: string
required: true
required: false
deprecated: true
"#binding-cells":
type: int
required: true

View file

@ -4,7 +4,8 @@
properties:
label:
type: string
required: true
required: false
deprecated: true
"#binding-cells":
type: int
required: true

View file

@ -4,7 +4,8 @@
properties:
label:
type: string
required: true
required: false
deprecated: true
"#binding-cells":
type: int
required: true

View file

@ -8,7 +8,8 @@ compatible: "zmk,behavior-sensor-rotate-var"
properties:
label:
type: string
required: true
required: false
deprecated: true
"#sensor-binding-cells":
type: int
required: true

View file

@ -8,7 +8,8 @@ compatible: "zmk,behavior-sensor-rotate"
properties:
label:
type: string
required: true
required: false
deprecated: true
"#sensor-binding-cells":
type: int
required: true

View file

@ -6,6 +6,8 @@ compatible: "zmk,kscan-composite"
properties:
label:
type: string
required: false
deprecated: true
rows:
type: int
columns:
@ -17,6 +19,8 @@ child-binding:
properties:
label:
type: string
required: false
deprecated: true
kscan:
type: phandle
row-offset:

View file

@ -6,6 +6,8 @@ compatible: "zmk,kscan-mock"
properties:
label:
type: string
required: false
deprecated: true
event-period:
type: int
description: Milliseconds between each generated event

View file

@ -29,7 +29,7 @@ int zmk_keymap_position_state_changed(uint8_t source, uint32_t position, bool pr
#define ZMK_KEYMAP_EXTRACT_BINDING(idx, drv_inst) \
{ \
.behavior_dev = DT_PROP(DT_PHANDLE_BY_IDX(drv_inst, bindings, idx), label), \
.behavior_dev = DEVICE_DT_NAME(DT_PHANDLE_BY_IDX(drv_inst, bindings, idx)), \
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(drv_inst, bindings, idx, param1), (0), \
(DT_PHA_BY_IDX(drv_inst, bindings, idx, param1))), \
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(drv_inst, bindings, idx, param2), (0), \

View file

@ -703,8 +703,8 @@ static int behavior_hold_tap_init(const struct device *dev) {
#define KP_INST(n) \
static 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), \
.hold_behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(n, bindings, 0)), \
.tap_behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(n, bindings, 1)), \
.quick_tap_ms = DT_INST_PROP(n, quick_tap_ms), \
.require_prior_idle_ms = DT_INST_PROP(n, global_quick_tap) \
? DT_INST_PROP(n, quick_tap_ms) \

View file

@ -44,18 +44,18 @@ struct behavior_macro_config {
struct zmk_behavior_binding bindings[];
};
#define TAP_MODE DT_PROP(DT_INST(0, zmk_macro_control_mode_tap), label)
#define PRESS_MODE DT_PROP(DT_INST(0, zmk_macro_control_mode_press), label)
#define REL_MODE DT_PROP(DT_INST(0, zmk_macro_control_mode_release), label)
#define TAP_MODE DEVICE_DT_NAME(DT_INST(0, zmk_macro_control_mode_tap))
#define PRESS_MODE DEVICE_DT_NAME(DT_INST(0, zmk_macro_control_mode_press))
#define REL_MODE DEVICE_DT_NAME(DT_INST(0, zmk_macro_control_mode_release))
#define TAP_TIME DT_PROP(DT_INST(0, zmk_macro_control_tap_time), label)
#define WAIT_TIME DT_PROP(DT_INST(0, zmk_macro_control_wait_time), label)
#define WAIT_REL DT_PROP(DT_INST(0, zmk_macro_pause_for_release), label)
#define TAP_TIME DEVICE_DT_NAME(DT_INST(0, zmk_macro_control_tap_time))
#define WAIT_TIME DEVICE_DT_NAME(DT_INST(0, zmk_macro_control_wait_time))
#define WAIT_REL DEVICE_DT_NAME(DT_INST(0, zmk_macro_pause_for_release))
#define P1TO1 DT_PROP(DT_INST(0, zmk_macro_param_1to1), label)
#define P1TO2 DT_PROP(DT_INST(0, zmk_macro_param_1to2), label)
#define P2TO1 DT_PROP(DT_INST(0, zmk_macro_param_2to1), label)
#define P2TO2 DT_PROP(DT_INST(0, zmk_macro_param_2to2), label)
#define P1TO1 DEVICE_DT_NAME(DT_INST(0, zmk_macro_param_1to1))
#define P1TO2 DEVICE_DT_NAME(DT_INST(0, zmk_macro_param_1to2))
#define P2TO1 DEVICE_DT_NAME(DT_INST(0, zmk_macro_param_2to1))
#define P2TO2 DEVICE_DT_NAME(DT_INST(0, zmk_macro_param_2to2))
#define ZM_IS_NODE_MATCH(a, b) (strcmp(a, b) == 0)
#define IS_TAP_MODE(dev) ZM_IS_NODE_MATCH(dev, TAP_MODE)

View file

@ -81,7 +81,7 @@ static int behavior_mod_morph_init(const struct device *dev) { return 0; }
#define _TRANSFORM_ENTRY(idx, node) \
{ \
.behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(node, bindings, idx), label), \
.behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \
.param1 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param1), (0), \
(DT_INST_PHA_BY_IDX(node, bindings, idx, param1))), \
.param2 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param2), (0), \

View file

@ -20,7 +20,7 @@ static int behavior_sensor_rotate_init(const struct device *dev) { return 0; };
#define _TRANSFORM_ENTRY(idx, node) \
{ \
.behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(node, bindings, idx), label), \
.behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \
.param1 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param1), (0), \
(DT_INST_PHA_BY_IDX(node, bindings, idx, param1))), \
.param2 = COND_CODE_0(DT_INST_PHA_HAS_CELL_AT_IDX(node, bindings, idx, param2), (0), \

View file

@ -20,8 +20,8 @@ static int behavior_sensor_rotate_var_init(const struct device *dev) { return 0;
#define SENSOR_ROTATE_VAR_INST(n) \
static struct behavior_sensor_rotate_config behavior_sensor_rotate_var_config_##n = { \
.cw_binding = {.behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 0), label)}, \
.ccw_binding = {.behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 1), label)}, \
.cw_binding = {.behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(n, bindings, 0))}, \
.ccw_binding = {.behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(n, bindings, 1))}, \
.tap_ms = DT_INST_PROP(n, tap_ms), \
.override_params = true, \
}; \

View file

@ -39,7 +39,7 @@ static void ext_power_save_state_work(struct k_work *work) {
const struct device *ext_power = DEVICE_DT_GET(DT_DRV_INST(0));
struct ext_power_generic_data *data = ext_power->data;
snprintf(setting_path, 40, "ext_power/state/%s", DT_INST_PROP(0, label));
snprintf(setting_path, sizeof(setting_path), "ext_power/state/%s", ext_power->name);
settings_save_one(setting_path, &data->status, sizeof(data->status));
}
@ -86,38 +86,38 @@ static int ext_power_generic_get(const struct device *dev) {
}
#if IS_ENABLED(CONFIG_SETTINGS)
static int ext_power_settings_set_status(const struct device *dev, size_t len,
settings_read_cb read_cb, void *cb_arg) {
struct ext_power_generic_data *data = dev->data;
if (len != sizeof(data->status)) {
return -EINVAL;
}
int rc = read_cb(cb_arg, &data->status, sizeof(data->status));
if (rc >= 0) {
data->settings_init = true;
if (data->status) {
ext_power_generic_enable(dev);
} else {
ext_power_generic_disable(dev);
}
return 0;
}
return rc;
}
static int ext_power_settings_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg) {
const struct device *ext_power = DEVICE_DT_GET(DT_DRV_INST(0));
const char *next;
int rc;
if (settings_name_steq(name, DT_INST_PROP(0, label), &next) && !next) {
const struct device *ext_power = DEVICE_DT_GET(DT_DRV_INST(0));
struct ext_power_generic_data *data = ext_power->data;
if (len != sizeof(data->status)) {
return -EINVAL;
}
rc = read_cb(cb_arg, &data->status, sizeof(data->status));
if (rc >= 0) {
data->settings_init = true;
if (ext_power == NULL) {
LOG_ERR("Unable to retrieve ext_power device: %s", DT_INST_PROP(0, label));
return -EIO;
}
if (data->status) {
ext_power_generic_enable(ext_power);
} else {
ext_power_generic_disable(ext_power);
}
return 0;
}
return rc;
if (settings_name_steq(name, ext_power->name, &next) && !next) {
return ext_power_settings_set_status(ext_power, len, read_cb, cb_arg);
}
return -ENOENT;
}

View file

@ -31,15 +31,13 @@ static uint8_t _zmk_keymap_layer_default = 0;
#define DT_DRV_COMPAT zmk_keymap
#define BINDING_WITH_COMMA(idx, drv_inst) ZMK_KEYMAP_EXTRACT_BINDING(idx, drv_inst)
#define TRANSFORMED_LAYER(node) \
{LISTIFY(DT_PROP_LEN(node, bindings), BINDING_WITH_COMMA, (, ), node)},
{ LISTIFY(DT_PROP_LEN(node, bindings), ZMK_KEYMAP_EXTRACT_BINDING, (, ), node) }
#if ZMK_KEYMAP_HAS_SENSORS
#define _TRANSFORM_SENSOR_ENTRY(idx, layer) \
{ \
.behavior_dev = DT_PROP(DT_PHANDLE_BY_IDX(layer, sensor_bindings, idx), label), \
.behavior_dev = DEVICE_DT_NAME(DT_PHANDLE_BY_IDX(layer, sensor_bindings, idx)), \
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, sensor_bindings, idx, param1), (0), \
(DT_PHA_BY_IDX(layer, sensor_bindings, idx, param1))), \
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, sensor_bindings, idx, param2), (0), \
@ -50,12 +48,11 @@ static uint8_t _zmk_keymap_layer_default = 0;
COND_CODE_1( \
DT_NODE_HAS_PROP(node, sensor_bindings), \
({LISTIFY(DT_PROP_LEN(node, sensor_bindings), _TRANSFORM_SENSOR_ENTRY, (, ), node)}), \
({})),
({}))
#endif /* ZMK_KEYMAP_HAS_SENSORS */
#define LAYER_LABEL(node) \
COND_CODE_0(DT_NODE_HAS_PROP(node, label), (NULL), (DT_PROP(node, label))),
#define LAYER_LABEL(node) DT_PROP_OR(node, label, NULL)
// State
@ -65,16 +62,16 @@ static uint8_t _zmk_keymap_layer_default = 0;
static uint32_t zmk_keymap_active_behavior_layer[ZMK_KEYMAP_LEN];
static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = {
DT_INST_FOREACH_CHILD(0, TRANSFORMED_LAYER)};
DT_INST_FOREACH_CHILD_SEP(0, TRANSFORMED_LAYER, (, ))};
static const char *zmk_keymap_layer_names[ZMK_KEYMAP_LAYERS_LEN] = {
DT_INST_FOREACH_CHILD(0, LAYER_LABEL)};
DT_INST_FOREACH_CHILD_SEP(0, LAYER_LABEL, (, ))};
#if ZMK_KEYMAP_HAS_SENSORS
static struct zmk_behavior_binding zmk_sensor_keymap[ZMK_KEYMAP_LAYERS_LEN]
[ZMK_KEYMAP_SENSORS_LEN] = {
DT_INST_FOREACH_CHILD(0, SENSOR_LAYER)};
static struct zmk_behavior_binding
zmk_sensor_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_SENSORS_LEN] = {
DT_INST_FOREACH_CHILD_SEP(0, SENSOR_LAYER, (, ))};
#endif /* ZMK_KEYMAP_HAS_SENSORS */