feat(behaviors): Support parameterized macros.

* Add two new compatibles for macros that
  take one or two parameters when bound in
  a keymap.
* Use `&macro_param_1to1`, `&macro_param_1to2`, `&macro_param_2to1`,
  and `&macro_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:
Peter Johanson
2022-04-08 15:38:46 +00:00
committed by Pete Johanson
parent e686fce4d9
commit 805dd4a53b
16 changed files with 310 additions and 48 deletions

View File

@@ -0,0 +1 @@
s/.*hid_listener_keycode/kp/p

View File

@@ -0,0 +1,16 @@
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x38 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x38 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x34 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x34 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x34 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x34 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x09 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x09 implicit_mods 0x00 explicit_mods 0x00

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
/ {
macros {
slash_macro: slash_macro {
#binding-cells = <2>;
label = "ZM_SLASH";
compatible = "zmk,behavior-macro-two-param";
wait-ms = <40>;
tap-ms = <40>;
bindings = <
&macro_param_1to1 &kp MACRO_PLACEHOLDER
&kp SLASH
&macro_param_2to1 &kp MACRO_PLACEHOLDER>;
};
to_second_macro: to_second_macro {
#binding-cells = <2>;
label = "ZMK_TO_SECOND";
compatible = "zmk,behavior-macro-two-param";
wait-ms = <40>;
tap-ms = <40>;
bindings = <
&macro_param_1to2 &mt LSHIFT MACRO_PLACEHOLDER
&macro_param_2to2 &mt RSHIFT MACRO_PLACEHOLDER>;
};
quote_letter_macro: quote_letter_macro {
#binding-cells = <1>;
label = "ZMK_QLET";
compatible = "zmk,behavior-macro-one-param";
wait-ms = <40>;
tap-ms = <40>;
bindings = <
&kp QUOT
&macro_param_1to1 &kp MACRO_PLACEHOLDER
&kp QUOT>;
};
};
keymap {
compatible = "zmk,keymap";
label = "Default keymap";
default_layer {
bindings = <
&slash_macro A B &quote_letter_macro B
&to_second_macro E F &kp C>;
};
};
};
&kscan {
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,10) ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,1000)>;
};