forked from kofal.net/zmk
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:
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user