feat(behaviors): Add macro support.

* Fine grainted press/release/tap actions.
* TIming between actions can be controlled.
* Processed async, to avoid blocking.
This commit is contained in:
Peter Johanson
2022-03-12 15:15:39 +00:00
committed by Pete Johanson
parent 58c7c0ee0c
commit 3a6a249ad0
36 changed files with 732 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,18 @@
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 50ms
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 10ms
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 50ms
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 10ms
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 50ms
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 10ms

View File

@@ -0,0 +1,14 @@
/*
* 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>
#include "../behavior_keymap.dtsi"
&kscan {
events = <ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_RELEASE(0,0,1000)>;
};

View File

@@ -0,0 +1,68 @@
/*
* 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 {
ZMK_MACRO(abc_macro,
wait-ms = <10>;
tap-ms = <50>;
bindings = <&kp A &kp B &kp C>;
)
ZMK_MACRO(hold_shift_macro,
bindings
= <&macro_press &kp LSHFT>
, <&macro_tap>
, <&kp D &kp O &kp G>
, <&macro_release &kp LSHFT>
;
)
ZMK_MACRO(custom_timing,
bindings
= <&macro_wait_time 50>
, <&kp A>
, <&macro_tap_time 20>
, <&kp B &kp C>
;
)
ZMK_MACRO(dual_sequence_macro,
wait-ms = <10>;
tap-ms = <40>;
bindings
= <&macro_press &kp LALT>
, <&macro_tap>
, <&kp TAB>
, <&macro_pause_for_release>
, <&macro_release &kp LALT>
;
)
};
keymap {
compatible = "zmk,keymap";
label ="Default keymap";
default_layer {
bindings = <
&abc_macro &mo 1
&hold_shift_macro &custom_timing>;
};
extra_layer {
bindings = <
&dual_sequence_macro &trans
&kp TAB &none>;
};
};
};

View File

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

View File

@@ -0,0 +1,4 @@
kp_pressed: usage_page 0x07 keycode 0xe1 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_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00

View File

@@ -0,0 +1,57 @@
/*
* 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 {
ZMK_MACRO(
mo_mod_macro,
wait-ms = <0>;
tap-ms = <20>;
bindings
= <&macro_press &mo 1 &kp LSHFT>
, <&macro_pause_for_release>
, <&macro_release &mo 1 &kp LSHFT>;
)
};
behaviors {
mth: macro_tap_hold {
compatible = "zmk,behavior-hold-tap";
label = "MACRO_TAP_HOLD";
#binding-cells = <2>;
flavor = "tap-unless-interrupted";
tapping-term-ms = <200>;
bindings = <&mo_mod_macro>, <&kp>;
};
};
keymap {
compatible = "zmk,keymap";
label ="Default keymap";
default_layer {
bindings = <
&mth 0 TAB &kp A
&kp B &kp C>;
};
extra_layer {
bindings = <
&kp D &kp E
&kp F &kp G>;
};
};
};
&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,1000)>;
};

View File

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

View File

@@ -0,0 +1,4 @@
kp_pressed: usage_page 0x07 keycode 0xe1 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_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00

View File

@@ -0,0 +1,46 @@
/*
* 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 {
ZMK_MACRO(
mo_mod_macro,
wait-ms = <0>;
tap-ms = <20>;
bindings
= <&macro_press &mo 1 &kp LSHFT>
, <&macro_pause_for_release>
, <&macro_release &mo 1 &kp LSHFT>;
)
};
keymap {
compatible = "zmk,keymap";
label ="Default keymap";
default_layer {
bindings = <
&mo_mod_macro &kp A
&kp B &kp C>;
};
extra_layer {
bindings = <
&kp D &kp E
&kp F &kp G>;
};
};
};
&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,1000)>;
};

View File

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

View File

@@ -0,0 +1,10 @@
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro
pos_state: layer: 0 position: 1, binding name: MO
pos_state: layer: 0 position: 1, binding name: MO
kp_released: usage_page 0x07 keycode 0x04 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 0x06 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00

View File

@@ -0,0 +1,14 @@
/*
* 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>
#include "../behavior_keymap.dtsi"
&kscan {
events = <ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_RELEASE(0,0,1) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,1000)>;
};

View File

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

View File

@@ -0,0 +1,8 @@
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x07 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x07 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x12 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x12 implicit_mods 0x00 explicit_mods 0x00
kp_pressed: usage_page 0x07 keycode 0x0a implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x0a implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00

View File

@@ -0,0 +1,14 @@
/*
* 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>
#include "../behavior_keymap.dtsi"
&kscan {
events = <ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,1000)>;
};

View File

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

View File

@@ -0,0 +1,18 @@
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 100ms
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 50ms
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 20ms
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 50ms
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 20ms
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 50ms

View File

@@ -0,0 +1,14 @@
/*
* 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>
#include "../behavior_keymap.dtsi"
&kscan {
events = <ZMK_MOCK_PRESS(1,1,10) ZMK_MOCK_RELEASE(1,1,750)>;
};

View File

@@ -0,0 +1,3 @@
s/.*hid_listener_keycode/kp/p
s/.*behavior_queue_process_next/queue_process_next/p
s/.*queue_macro/qm/p

View File

@@ -0,0 +1,16 @@
qm: Iterating macro bindings - starting: 0, count: 4
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00
kp_pressed: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 10ms
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 40ms
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 10ms
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00
qm: Iterating macro bindings - starting: 5, count: 2
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00
kp_released: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00
queue_process_next: Processing next queued behavior in 0ms

View File

@@ -0,0 +1,14 @@
/*
* 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>
#include "../behavior_keymap.dtsi"
&kscan {
events = <ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_PRESS(1,0,400) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,1000) ZMK_MOCK_RELEASE(0,1,1000)>;
};