forked from kofal.net/zmk
feat(behaviors): Support parameterized macros.
* Add two new compatibles for macros that take one or two parameters when bound in a keymap. * Use `¯o_param_1to1`, `¯o_param_1to2`, `¯o_param_2to1`, and `¯o_param_2to2` control entries in the bindings for the macro to have the next binding entry have it's values substituted. Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
This commit is contained in:
committed by
Pete Johanson
parent
e686fce4d9
commit
805dd4a53b
@@ -4,16 +4,33 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define MACRO_PLACEHOLDER 0
|
||||
#define ZMK_MACRO_STRINGIFY(x) #x
|
||||
#define ZMK_MACRO(name,...) \
|
||||
name: name { \
|
||||
label = ZMK_MACRO_STRINGIFY(ZM_ ## name); \
|
||||
compatible = "zmk,behavior-macro"; \
|
||||
#binding-cells = <0>; \
|
||||
__VA_ARGS__ \
|
||||
};
|
||||
name: name { \
|
||||
label = ZMK_MACRO_STRINGIFY(ZM_ ## name); \
|
||||
compatible = "zmk,behavior-macro"; \
|
||||
#binding-cells = <0>; \
|
||||
__VA_ARGS__ \
|
||||
};
|
||||
|
||||
/ {
|
||||
#define ZMK_MACRO1(name,...) \
|
||||
name: name { \
|
||||
label = ZMK_MACRO_STRINGIFY(ZM_ ## name); \
|
||||
compatible = "zmk,behavior-macro-one-param"; \
|
||||
#binding-cells = <1>; \
|
||||
__VA_ARGS__ \
|
||||
};
|
||||
|
||||
#define ZMK_MACRO2(name,...) \
|
||||
name: name { \
|
||||
label = ZMK_MACRO_STRINGIFY(ZM_ ## name); \
|
||||
compatible = "zmk,behavior-macro-two-param"; \
|
||||
#binding-cells = <2>; \
|
||||
__VA_ARGS__ \
|
||||
};
|
||||
|
||||
/ {
|
||||
behaviors {
|
||||
macro_tap: macro_control_mode_tap {
|
||||
compatible = "zmk,macro-control-mode-tap";
|
||||
@@ -50,5 +67,29 @@
|
||||
label = "MAC_WAIT_REL";
|
||||
#binding-cells = <0>;
|
||||
};
|
||||
|
||||
macro_param_1to1: macro_param_1to1 {
|
||||
compatible = "zmk,macro-param-1to1";
|
||||
label = "MAC_PARAM_1TO1";
|
||||
#binding-cells = <0>;
|
||||
};
|
||||
|
||||
macro_param_1to2: macro_param_1to2 {
|
||||
compatible = "zmk,macro-param-1to2";
|
||||
label = "MAC_PARAM_1TO2";
|
||||
#binding-cells = <0>;
|
||||
};
|
||||
|
||||
macro_param_2to1: macro_param_2to1 {
|
||||
compatible = "zmk,macro-param-2to1";
|
||||
label = "MAC_PARAM_2TO1";
|
||||
#binding-cells = <0>;
|
||||
};
|
||||
|
||||
macro_param_2to2: macro_param_2to2 {
|
||||
compatible = "zmk,macro-param-2to2";
|
||||
label = "MAC_PARAM_2TO2";
|
||||
#binding-cells = <0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
13
app/dts/bindings/behaviors/macro_base.yaml
Normal file
13
app/dts/bindings/behaviors/macro_base.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2022 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
properties:
|
||||
bindings:
|
||||
type: phandle-array
|
||||
required: true
|
||||
wait-ms:
|
||||
type: int
|
||||
description: The default time to wait (in milliseconds) before triggering the next behavior in the macro bindings list.
|
||||
tap-ms:
|
||||
type: int
|
||||
description: The default time to wait (in milliseconds) between the press and release events on a tapped macro behavior binding
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2022 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Macro Behavior
|
||||
|
||||
compatible: "zmk,behavior-macro-one-param"
|
||||
|
||||
include: [one_param.yaml, macro_base.yaml]
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2022 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Macro Behavior
|
||||
|
||||
compatible: "zmk,behavior-macro-two-param"
|
||||
|
||||
include: [two_param.yaml, macro_base.yaml]
|
||||
@@ -5,15 +5,4 @@ description: Macro Behavior
|
||||
|
||||
compatible: "zmk,behavior-macro"
|
||||
|
||||
include: zero_param.yaml
|
||||
|
||||
properties:
|
||||
bindings:
|
||||
type: phandle-array
|
||||
required: true
|
||||
wait-ms:
|
||||
type: int
|
||||
description: The default time to wait (in milliseconds) before triggering the next behavior in the macro bindings list.
|
||||
tap-ms:
|
||||
type: int
|
||||
description: The default time to wait (in milliseconds) between the press and release events on a tapped macro behavior binding
|
||||
include: [zero_param.yaml, macro_base.yaml]
|
||||
|
||||
8
app/dts/bindings/macros/zmk,macro-param-1to1.yaml
Normal file
8
app/dts/bindings/macros/zmk,macro-param-1to1.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2023 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Macro Parameter One Substituted Into Next Binding's First Parameter
|
||||
|
||||
compatible: "zmk,macro-param-1to1"
|
||||
|
||||
include: zero_param.yaml
|
||||
8
app/dts/bindings/macros/zmk,macro-param-1to2.yaml
Normal file
8
app/dts/bindings/macros/zmk,macro-param-1to2.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2023 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Macro Parameter One Substituted Into Next Binding's Second Parameter
|
||||
|
||||
compatible: "zmk,macro-param-1to2"
|
||||
|
||||
include: zero_param.yaml
|
||||
8
app/dts/bindings/macros/zmk,macro-param-2to1.yaml
Normal file
8
app/dts/bindings/macros/zmk,macro-param-2to1.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2023 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Macro Parameter Two Substituted Into Next Binding's First Parameter
|
||||
|
||||
compatible: "zmk,macro-param-2to1"
|
||||
|
||||
include: zero_param.yaml
|
||||
8
app/dts/bindings/macros/zmk,macro-param-2to2.yaml
Normal file
8
app/dts/bindings/macros/zmk,macro-param-2to2.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2023 The ZMK Contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
description: Macro Parameter Two Substituted Into Next Binding's Second Parameter
|
||||
|
||||
compatible: "zmk,macro-param-2to2"
|
||||
|
||||
include: zero_param.yaml
|
||||
Reference in New Issue
Block a user