Skip to content

Commit

Permalink
feat(behaviors): Add behavior metadata information.
Browse files Browse the repository at this point in the history
* For upcoming ZMK studio work, make a set of rich metadata available
  to provide a friendly name for a behavior, and allow super flexible
  descriptions of the parameters the behaviors take.
* Add ability to validate a zmk_behavior_binding against
  the behavior metadata available.
  • Loading branch information
petejohanson committed Jun 21, 2024
1 parent 7be955f commit 3949f90
Show file tree
Hide file tree
Showing 42 changed files with 952 additions and 14 deletions.
8 changes: 7 additions & 1 deletion app/Kconfig.behaviors
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Copyright (c) 2023 The ZMK Contributors
# SPDX-License-Identifier: MIT

config ZMK_BEHAVIOR_METADATA
bool "Metadata"
help
Enabling this option adds APIs for documenting and fetching
metadata describing a behaviors name, and supported parameters.

config ZMK_BEHAVIOR_KEY_TOGGLE
bool
default y
Expand Down Expand Up @@ -35,4 +41,4 @@ config ZMK_BEHAVIOR_SENSOR_ROTATE_VAR
config ZMK_BEHAVIOR_MACRO
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_MACRO_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_ONE_PARAM_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_TWO_PARAM_ENABLED
depends on DT_HAS_ZMK_BEHAVIOR_MACRO_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_ONE_PARAM_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_TWO_PARAM_ENABLED
1 change: 1 addition & 0 deletions app/dts/behaviors/backlight.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/omit-if-no-ref/ bl: bcklight {
compatible = "zmk,behavior-backlight";
#binding-cells = <2>;
display-name = "Backlight";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/bluetooth.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ bt: bluetooth {
compatible = "zmk,behavior-bluetooth";
#binding-cells = <2>;
display-name = "Bluetooth";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/caps_word.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
compatible = "zmk,behavior-caps-word";
#binding-cells = <0>;
continue-list = <UNDERSCORE BACKSPACE DELETE>;
display-name = "Caps Word";
};
};
};
Expand Down
1 change: 1 addition & 0 deletions app/dts/behaviors/ext_power.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ext_power: extpower {
compatible = "zmk,behavior-ext-power";
#binding-cells = <1>;
display-name = "External Power";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/gresc.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#binding-cells = <0>;
bindings = <&kp ESC>, <&kp GRAVE>;
mods = <(MOD_LGUI|MOD_LSFT|MOD_RGUI|MOD_RSFT)>;
display-name = "Grave/Escape";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/key_press.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/omit-if-no-ref/ cp: kp: key_press {
compatible = "zmk,behavior-key-press";
#binding-cells = <1>;
display-name = "Key Press";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/key_repeat.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
compatible = "zmk,behavior-key-repeat";
#binding-cells = <0>;
usage-pages = <HID_USAGE_KEY>;
display-name = "Key Repeat";
};
};
};
Expand Down
1 change: 1 addition & 0 deletions app/dts/behaviors/key_toggle.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ kt: key_toggle {
compatible = "zmk,behavior-key-toggle";
#binding-cells = <1>;
display-name = "Key Toggle";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/layer_tap.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
flavor = "tap-preferred";
tapping-term-ms = <200>;
bindings = <&mo>, <&kp>;
display-name = "Layer-Tap";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/mod_tap.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
flavor = "hold-preferred";
tapping-term-ms = <200>;
bindings = <&kp>, <&kp>;
display-name = "Mod-Tap";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/momentary_layer.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ mo: momentary_layer {
compatible = "zmk,behavior-momentary-layer";
#binding-cells = <1>;
display-name = "Momentary Layer";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/none.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ none: none {
compatible = "zmk,behavior-none";
#binding-cells = <0>;
display-name = "None";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/outputs.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ out: outputs {
compatible = "zmk,behavior-outputs";
#binding-cells = <1>;
display-name = "Output Selection";
};
};
};
2 changes: 2 additions & 0 deletions app/dts/behaviors/reset.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
sys_reset: sysreset {
compatible = "zmk,behavior-reset";
#binding-cells = <0>;
display-name = "Reset";
};

// Behavior can be invoked on peripherals, so name must be <= 8 characters.
bootloader: bootload {
compatible = "zmk,behavior-reset";
type = <RST_UF2>;
#binding-cells = <0>;
display-name = "Bootloader";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/rgb_underglow.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
rgb_ug: rgb_ug {
compatible = "zmk,behavior-rgb-underglow";
#binding-cells = <2>;
display-name = "Underglow";
};
};
};
2 changes: 2 additions & 0 deletions app/dts/behaviors/sticky_key.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
release-after-ms = <1000>;
bindings = <&kp>;
ignore-modifiers;
display-name = "Sticky Key";
};
/omit-if-no-ref/ sl: sticky_layer {
compatible = "zmk,behavior-sticky-key";
#binding-cells = <1>;
release-after-ms = <1000>;
bindings = <&mo>;
quick-release;
display-name = "Sticky Layer";
};
};

Expand Down
1 change: 1 addition & 0 deletions app/dts/behaviors/to_layer.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ to: to_layer {
compatible = "zmk,behavior-to-layer";
#binding-cells = <1>;
display-name = "To Layer";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/toggle_layer.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ tog: toggle_layer {
compatible = "zmk,behavior-toggle-layer";
#binding-cells = <1>;
display-name = "Toggle Layer";
};
};
};
1 change: 1 addition & 0 deletions app/dts/behaviors/transparent.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/omit-if-no-ref/ trans: transparent {
compatible = "zmk,behavior-transparent";
#binding-cells = <0>;
display-name = "Transparent";
};
};
};
6 changes: 6 additions & 0 deletions app/dts/bindings/behaviors/behavior-metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

properties:
display-name:
type: string
2 changes: 2 additions & 0 deletions app/dts/bindings/behaviors/one_param.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: behavior-metadata.yaml

properties:
label:
type: string
Expand Down
2 changes: 2 additions & 0 deletions app/dts/bindings/behaviors/two_param.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: behavior-metadata.yaml

properties:
label:
type: string
Expand Down
2 changes: 2 additions & 0 deletions app/dts/bindings/behaviors/zero_param.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: behavior-metadata.yaml

properties:
label:
type: string
Expand Down
Loading

0 comments on commit 3949f90

Please sign in to comment.