diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index d853255c..0d547fbe 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -51,6 +51,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c) target_sources(app PRIVATE src/behaviors/behavior_caps_word.c) target_sources(app PRIVATE src/behaviors/behavior_key_repeat.c) + target_sources(app PRIVATE src/behaviors/behavior_macro.c) target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c) target_sources(app PRIVATE src/behaviors/behavior_mod_morph.c) target_sources(app PRIVATE src/behaviors/behavior_outputs.c) @@ -61,6 +62,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) target_sources(app PRIVATE src/behaviors/behavior_none.c) target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c) target_sources(app PRIVATE src/combo.c) + target_sources(app PRIVATE src/behavior_queue.c) target_sources(app PRIVATE src/conditional_layer.c) target_sources(app PRIVATE src/keymap.c) endif() diff --git a/app/Kconfig b/app/Kconfig index 1c9f929d..81637336 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -410,6 +410,14 @@ config ZMK_COMBO_MAX_KEYS_PER_COMBO #Combo options endmenu +menu "Behavior Options" + +config ZMK_BEHAVIORS_QUEUE_SIZE + int "Maximum number of behaviors to allow queueing from a macro or other complex behavior" + default 64 + +endmenu + menu "Advanced" menu "Initialization Priorities" diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 3e797cc9..c1dacbcd 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -17,3 +17,4 @@ #include #include #include +#include \ No newline at end of file diff --git a/app/dts/behaviors/macros.dtsi b/app/dts/behaviors/macros.dtsi new file mode 100644 index 00000000..76153291 --- /dev/null +++ b/app/dts/behaviors/macros.dtsi @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#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__ \ + }; + + / { + behaviors { + macro_tap: macro_control_mode_tap { + compatible = "zmk,macro-control-mode-tap"; + label = "MAC_TAP"; + #binding-cells = <0>; + }; + + macro_press: macro_control_mode_press { + compatible = "zmk,macro-control-mode-press"; + label = "MAC_PRESS"; + #binding-cells = <0>; + }; + + macro_release: macro_control_mode_release { + compatible = "zmk,macro-control-mode-release"; + label = "MAC_REL"; + #binding-cells = <0>; + }; + + macro_tap_time: macro_control_tap_time { + compatible = "zmk,macro-control-tap-time"; + label = "MAC_TAP_TIME"; + #binding-cells = <1>; + }; + + macro_wait_time: macro_control_wait_time { + compatible = "zmk,macro-control-wait-time"; + label = "MAC_WAIT_TIME"; + #binding-cells = <1>; + }; + + macro_pause_for_release: macro_pause_for_release { + compatible = "zmk,macro-pause-for-release"; + label = "MAC_WAIT_REL"; + #binding-cells = <0>; + }; + }; +}; diff --git a/app/dts/bindings/behaviors/zmk,behavior-macro.yaml b/app/dts/bindings/behaviors/zmk,behavior-macro.yaml new file mode 100644 index 00000000..ba5bcb07 --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-macro.yaml @@ -0,0 +1,21 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Macro Behavior + +compatible: "zmk,behavior-macro" + +include: zero_param.yaml + +properties: + bindings: + type: phandle-array + required: true + wait-ms: + type: int + default: 100 + description: The default time to wait (in milliseconds) before triggering the next behavior in the macro bindings list. + tap-ms: + type: int + default: 100 + description: The default time to wait (in milliseconds) between the press and release events on a tapped macro behavior binding \ No newline at end of file diff --git a/app/dts/bindings/macros/zmk,macro-control-mode-press.yaml b/app/dts/bindings/macros/zmk,macro-control-mode-press.yaml new file mode 100644 index 00000000..64b3939b --- /dev/null +++ b/app/dts/bindings/macros/zmk,macro-control-mode-press.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Set Macro To Press Mode + +compatible: "zmk,macro-control-mode-press" + +include: zero_param.yaml \ No newline at end of file diff --git a/app/dts/bindings/macros/zmk,macro-control-mode-release.yaml b/app/dts/bindings/macros/zmk,macro-control-mode-release.yaml new file mode 100644 index 00000000..c1c27882 --- /dev/null +++ b/app/dts/bindings/macros/zmk,macro-control-mode-release.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Set Macro To Release Mode + +compatible: "zmk,macro-control-mode-release" + +include: zero_param.yaml \ No newline at end of file diff --git a/app/dts/bindings/macros/zmk,macro-control-mode-tap.yaml b/app/dts/bindings/macros/zmk,macro-control-mode-tap.yaml new file mode 100644 index 00000000..dde32c91 --- /dev/null +++ b/app/dts/bindings/macros/zmk,macro-control-mode-tap.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Set Macro To Tap Mode + +compatible: "zmk,macro-control-mode-tap" + +include: zero_param.yaml diff --git a/app/dts/bindings/macros/zmk,macro-control-tap-time.yaml b/app/dts/bindings/macros/zmk,macro-control-tap-time.yaml new file mode 100644 index 00000000..8dacdc2a --- /dev/null +++ b/app/dts/bindings/macros/zmk,macro-control-tap-time.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Set Macro Tap Duration + +compatible: "zmk,macro-control-tap-time" + +include: one_param.yaml \ No newline at end of file diff --git a/app/dts/bindings/macros/zmk,macro-control-wait-time.yaml b/app/dts/bindings/macros/zmk,macro-control-wait-time.yaml new file mode 100644 index 00000000..9e9beac2 --- /dev/null +++ b/app/dts/bindings/macros/zmk,macro-control-wait-time.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Set Macro Wait Duration + +compatible: "zmk,macro-control-wait-time" + +include: one_param.yaml \ No newline at end of file diff --git a/app/dts/bindings/macros/zmk,macro-pause-for-release.yaml b/app/dts/bindings/macros/zmk,macro-pause-for-release.yaml new file mode 100644 index 00000000..e89d8b24 --- /dev/null +++ b/app/dts/bindings/macros/zmk,macro-pause-for-release.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Macro Pause Until Release Marker + +compatible: "zmk,macro-pause-for-release" + +include: zero_param.yaml \ No newline at end of file diff --git a/app/include/zmk/behavior_queue.h b/app/include/zmk/behavior_queue.h new file mode 100644 index 00000000..8a184e4a --- /dev/null +++ b/app/include/zmk/behavior_queue.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +int zmk_behavior_queue_add(uint32_t position, const struct zmk_behavior_binding behavior, + bool press, uint32_t wait); diff --git a/app/src/behavior_queue.c b/app/src/behavior_queue.c new file mode 100644 index 00000000..a3cd8d47 --- /dev/null +++ b/app/src/behavior_queue.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct q_item { + uint32_t position; + struct zmk_behavior_binding binding; + bool press : 1; + uint32_t wait : 31; +}; + +K_MSGQ_DEFINE(zmk_behavior_queue_msgq, sizeof(struct q_item), CONFIG_ZMK_BEHAVIORS_QUEUE_SIZE, 4); + +static void behavior_queue_process_next(struct k_work *work); +static K_DELAYED_WORK_DEFINE(queue_work, behavior_queue_process_next); + +static void behavior_queue_process_next(struct k_work *work) { + struct q_item item = {.wait = 0}; + + while (k_msgq_get(&zmk_behavior_queue_msgq, &item, K_NO_WAIT) == 0) { + LOG_DBG("Invoking %s: 0x%02x 0x%02x", log_strdup(item.binding.behavior_dev), + item.binding.param1, item.binding.param2); + + struct zmk_behavior_binding_event event = {.position = item.position, + .timestamp = k_uptime_get()}; + + if (item.press) { + behavior_keymap_binding_pressed(&item.binding, event); + } else { + behavior_keymap_binding_released(&item.binding, event); + } + + LOG_DBG("Processing next queued behavior in %dms", item.wait); + + if (item.wait > 0) { + k_delayed_work_submit(&queue_work, K_MSEC(item.wait)); + break; + } + } +} + +int zmk_behavior_queue_add(uint32_t position, const struct zmk_behavior_binding binding, bool press, + uint32_t wait) { + struct q_item item = {.press = press, .binding = binding, .wait = wait}; + + const int ret = k_msgq_put(&zmk_behavior_queue_msgq, &item, K_NO_WAIT); + if (ret < 0) { + return ret; + } + + if (!k_delayed_work_pending(&queue_work)) { + behavior_queue_process_next(&queue_work.work); + } + + return 0; +} diff --git a/app/src/behaviors/behavior_macro.c b/app/src/behaviors/behavior_macro.c new file mode 100644 index 00000000..92ee2c43 --- /dev/null +++ b/app/src/behaviors/behavior_macro.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_macro + +#include +#include +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) + +enum behavior_macro_mode { + MACRO_MODE_TAP, + MACRO_MODE_PRESS, + MACRO_MODE_RELEASE, +}; + +struct behavior_macro_trigger_state { + uint32_t wait_ms; + uint32_t tap_ms; + enum behavior_macro_mode mode; + uint16_t start_index; + uint16_t count; +}; + +struct behavior_macro_state { + struct behavior_macro_trigger_state release_state; + + uint32_t press_bindings_count; +}; + +struct behavior_macro_config { + uint32_t default_wait_ms; + uint32_t default_tap_ms; + uint32_t count; + struct zmk_behavior_binding bindings[]; +}; + +#define TAP_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_tap)) +#define PRESS_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_press)) +#define REL_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_release)) + +#define TAP_TIME DT_LABEL(DT_INST(0, zmk_macro_control_tap_time)) +#define WAIT_TIME DT_LABEL(DT_INST(0, zmk_macro_control_wait_time)) +#define WAIT_REL DT_LABEL(DT_INST(0, zmk_macro_pause_for_release)) + +#define ZM_IS_NODE_MATCH(a, b) (strcmp(a, b) == 0) +#define IS_TAP_MODE(dev) ZM_IS_NODE_MATCH(dev, TAP_MODE) +#define IS_PRESS_MODE(dev) ZM_IS_NODE_MATCH(dev, PRESS_MODE) +#define IS_RELEASE_MODE(dev) ZM_IS_NODE_MATCH(dev, REL_MODE) + +#define IS_TAP_TIME(dev) ZM_IS_NODE_MATCH(dev, TAP_TIME) +#define IS_WAIT_TIME(dev) ZM_IS_NODE_MATCH(dev, WAIT_TIME) +#define IS_PAUSE(dev) ZM_IS_NODE_MATCH(dev, WAIT_REL) + +static bool handle_control_binding(struct behavior_macro_trigger_state *state, + const struct zmk_behavior_binding *binding) { + if (IS_TAP_MODE(binding->behavior_dev)) { + state->mode = MACRO_MODE_TAP; + LOG_DBG("macro mode set: tap"); + } else if (IS_PRESS_MODE(binding->behavior_dev)) { + state->mode = MACRO_MODE_PRESS; + LOG_DBG("macro mode set: press"); + } else if (IS_RELEASE_MODE(binding->behavior_dev)) { + state->mode = MACRO_MODE_RELEASE; + LOG_DBG("macro mode set: release"); + } else if (IS_TAP_TIME(binding->behavior_dev)) { + state->tap_ms = binding->param1; + LOG_DBG("macro tap time set: %d", state->tap_ms); + } else if (IS_WAIT_TIME(binding->behavior_dev)) { + state->wait_ms = binding->param1; + LOG_DBG("macro wait time set: %d", state->wait_ms); + } else { + return false; + } + + return true; +} + +static int behavior_macro_init(const struct device *dev) { + const struct behavior_macro_config *cfg = dev->config; + struct behavior_macro_state *state = dev->data; + state->press_bindings_count = cfg->count; + state->release_state.start_index = cfg->count; + state->release_state.count = 0; + + LOG_DBG("Precalculate initial release state:"); + for (int i = 0; i < cfg->count; i++) { + if (handle_control_binding(&state->release_state, &cfg->bindings[i])) { + // Updated state used for initial state on release. + } else if (IS_PAUSE(cfg->bindings[i].behavior_dev)) { + state->release_state.start_index = i + 1; + state->release_state.count = cfg->count - state->release_state.start_index; + state->press_bindings_count = i; + LOG_DBG("Release will resume at %d", state->release_state.start_index); + break; + } else { + // Ignore regular invokable bindings + } + } + + return 0; +}; + +static void queue_macro(uint32_t position, const struct zmk_behavior_binding bindings[], + struct behavior_macro_trigger_state state) { + LOG_DBG("Iterating macro bindings - starting: %d, count: %d", state.start_index, state.count); + for (int i = state.start_index; i < state.start_index + state.count; i++) { + if (!handle_control_binding(&state, &bindings[i])) { + switch (state.mode) { + case MACRO_MODE_TAP: + zmk_behavior_queue_add(position, bindings[i], true, state.tap_ms); + zmk_behavior_queue_add(position, bindings[i], false, state.wait_ms); + break; + case MACRO_MODE_PRESS: + zmk_behavior_queue_add(position, bindings[i], true, state.wait_ms); + break; + case MACRO_MODE_RELEASE: + zmk_behavior_queue_add(position, bindings[i], false, state.wait_ms); + break; + default: + LOG_ERR("Unknown macro mode: %d", state.mode); + break; + } + } + } +} + +static int on_macro_binding_pressed(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = device_get_binding(binding->behavior_dev); + const struct behavior_macro_config *cfg = dev->config; + struct behavior_macro_state *state = dev->data; + struct behavior_macro_trigger_state trigger_state = {.mode = MACRO_MODE_TAP, + .tap_ms = cfg->default_tap_ms, + .wait_ms = cfg->default_wait_ms, + .start_index = 0, + .count = state->press_bindings_count}; + + queue_macro(event.position, cfg->bindings, trigger_state); + + return ZMK_BEHAVIOR_OPAQUE; +} + +static int on_macro_binding_released(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = device_get_binding(binding->behavior_dev); + const struct behavior_macro_config *cfg = dev->config; + struct behavior_macro_state *state = dev->data; + + queue_macro(event.position, cfg->bindings, state->release_state); + + return ZMK_BEHAVIOR_OPAQUE; +} + +static const struct behavior_driver_api behavior_macro_driver_api = { + .binding_pressed = on_macro_binding_pressed, + .binding_released = on_macro_binding_released, +}; + +#define BINDING_WITH_COMMA(idx, drv_inst) ZMK_KEYMAP_EXTRACT_BINDING(idx, DT_DRV_INST(drv_inst)), + +#define TRANSFORMED_BEHAVIORS(n) \ + {UTIL_LISTIFY(DT_PROP_LEN(DT_DRV_INST(n), bindings), BINDING_WITH_COMMA, n)}, + +#define MACRO_INST(n) \ + static struct behavior_macro_state behavior_macro_state_##n = {}; \ + static struct behavior_macro_config behavior_macro_config_##n = { \ + .default_wait_ms = DT_INST_PROP_OR(n, wait_ms, 100), \ + .default_tap_ms = DT_INST_PROP_OR(n, tap_ms, 100), \ + .count = DT_INST_PROP_LEN(n, bindings), \ + .bindings = TRANSFORMED_BEHAVIORS(n)}; \ + DEVICE_DT_INST_DEFINE(n, behavior_macro_init, device_pm_control_nop, \ + &behavior_macro_state_##n, &behavior_macro_config_##n, APPLICATION, \ + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_macro_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(MACRO_INST) + +#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ diff --git a/app/tests/macros/basic/events.patterns b/app/tests/macros/basic/events.patterns new file mode 100644 index 00000000..0a5f25ca --- /dev/null +++ b/app/tests/macros/basic/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*behavior_queue_process_next/queue_process_next/p \ No newline at end of file diff --git a/app/tests/macros/basic/keycode_events.snapshot b/app/tests/macros/basic/keycode_events.snapshot new file mode 100644 index 00000000..b238a2ff --- /dev/null +++ b/app/tests/macros/basic/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/basic/native_posix.keymap b/app/tests/macros/basic/native_posix.keymap new file mode 100644 index 00000000..6a2391db --- /dev/null +++ b/app/tests/macros/basic/native_posix.keymap @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/macros/behavior_keymap.dtsi b/app/tests/macros/behavior_keymap.dtsi new file mode 100644 index 00000000..7399cd5b --- /dev/null +++ b/app/tests/macros/behavior_keymap.dtsi @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +/ { + macros { + ZMK_MACRO(abc_macro, + wait-ms = <10>; + tap-ms = <50>; + bindings = <&kp A &kp B &kp C>; + ) + + ZMK_MACRO(hold_shift_macro, + bindings + = <¯o_press &kp LSHFT> + , <¯o_tap> + , <&kp D &kp O &kp G> + , <¯o_release &kp LSHFT> + ; + ) + + ZMK_MACRO(custom_timing, + bindings + = <¯o_wait_time 50> + , <&kp A> + , <¯o_tap_time 20> + , <&kp B &kp C> + ; + ) + + ZMK_MACRO(dual_sequence_macro, + wait-ms = <10>; + tap-ms = <40>; + bindings + = <¯o_press &kp LALT> + , <¯o_tap> + , <&kp TAB> + , <¯o_pause_for_release> + , <¯o_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>; + + }; + + }; +}; diff --git a/app/tests/macros/mo-plus-modifier-from-hold-tap/events.patterns b/app/tests/macros/mo-plus-modifier-from-hold-tap/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/macros/mo-plus-modifier-from-hold-tap/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/macros/mo-plus-modifier-from-hold-tap/keycode_events.snapshot b/app/tests/macros/mo-plus-modifier-from-hold-tap/keycode_events.snapshot new file mode 100644 index 00000000..9f47e064 --- /dev/null +++ b/app/tests/macros/mo-plus-modifier-from-hold-tap/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/mo-plus-modifier-from-hold-tap/native_posix.keymap b/app/tests/macros/mo-plus-modifier-from-hold-tap/native_posix.keymap new file mode 100644 index 00000000..2f3b943a --- /dev/null +++ b/app/tests/macros/mo-plus-modifier-from-hold-tap/native_posix.keymap @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +/ { + macros { + ZMK_MACRO( + mo_mod_macro, + wait-ms = <0>; + tap-ms = <20>; + bindings + = <¯o_press &mo 1 &kp LSHFT> + , <¯o_pause_for_release> + , <¯o_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 = ; +}; \ No newline at end of file diff --git a/app/tests/macros/mo-plus-modifier-macro/events.patterns b/app/tests/macros/mo-plus-modifier-macro/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/macros/mo-plus-modifier-macro/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/macros/mo-plus-modifier-macro/keycode_events.snapshot b/app/tests/macros/mo-plus-modifier-macro/keycode_events.snapshot new file mode 100644 index 00000000..9f47e064 --- /dev/null +++ b/app/tests/macros/mo-plus-modifier-macro/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/mo-plus-modifier-macro/native_posix.keymap b/app/tests/macros/mo-plus-modifier-macro/native_posix.keymap new file mode 100644 index 00000000..c264a9ab --- /dev/null +++ b/app/tests/macros/mo-plus-modifier-macro/native_posix.keymap @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +/ { + macros { + ZMK_MACRO( + mo_mod_macro, + wait-ms = <0>; + tap-ms = <20>; + bindings + = <¯o_press &mo 1 &kp LSHFT> + , <¯o_pause_for_release> + , <¯o_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 = ; +}; \ No newline at end of file diff --git a/app/tests/macros/press-mid-macro/events.patterns b/app/tests/macros/press-mid-macro/events.patterns new file mode 100644 index 00000000..cedbda8b --- /dev/null +++ b/app/tests/macros/press-mid-macro/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*keymap_apply_position_state/pos_state/p \ No newline at end of file diff --git a/app/tests/macros/press-mid-macro/keycode_events.snapshot b/app/tests/macros/press-mid-macro/keycode_events.snapshot new file mode 100644 index 00000000..22393a3a --- /dev/null +++ b/app/tests/macros/press-mid-macro/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/press-mid-macro/native_posix.keymap b/app/tests/macros/press-mid-macro/native_posix.keymap new file mode 100644 index 00000000..a075a443 --- /dev/null +++ b/app/tests/macros/press-mid-macro/native_posix.keymap @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/macros/press-release/events.patterns b/app/tests/macros/press-release/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/macros/press-release/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/macros/press-release/keycode_events.snapshot b/app/tests/macros/press-release/keycode_events.snapshot new file mode 100644 index 00000000..ebe69d5c --- /dev/null +++ b/app/tests/macros/press-release/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/press-release/native_posix.keymap b/app/tests/macros/press-release/native_posix.keymap new file mode 100644 index 00000000..6814d542 --- /dev/null +++ b/app/tests/macros/press-release/native_posix.keymap @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/macros/timing-override/events.patterns b/app/tests/macros/timing-override/events.patterns new file mode 100644 index 00000000..0a5f25ca --- /dev/null +++ b/app/tests/macros/timing-override/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*behavior_queue_process_next/queue_process_next/p \ No newline at end of file diff --git a/app/tests/macros/timing-override/keycode_events.snapshot b/app/tests/macros/timing-override/keycode_events.snapshot new file mode 100644 index 00000000..650d6747 --- /dev/null +++ b/app/tests/macros/timing-override/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/timing-override/native_posix.keymap b/app/tests/macros/timing-override/native_posix.keymap new file mode 100644 index 00000000..343926a7 --- /dev/null +++ b/app/tests/macros/timing-override/native_posix.keymap @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/macros/wait-macro-release/events.patterns b/app/tests/macros/wait-macro-release/events.patterns new file mode 100644 index 00000000..02e0c505 --- /dev/null +++ b/app/tests/macros/wait-macro-release/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode/kp/p +s/.*behavior_queue_process_next/queue_process_next/p +s/.*queue_macro/qm/p \ No newline at end of file diff --git a/app/tests/macros/wait-macro-release/keycode_events.snapshot b/app/tests/macros/wait-macro-release/keycode_events.snapshot new file mode 100644 index 00000000..509a1c48 --- /dev/null +++ b/app/tests/macros/wait-macro-release/keycode_events.snapshot @@ -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 diff --git a/app/tests/macros/wait-macro-release/native_posix.keymap b/app/tests/macros/wait-macro-release/native_posix.keymap new file mode 100644 index 00000000..6dabaeca --- /dev/null +++ b/app/tests/macros/wait-macro-release/native_posix.keymap @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file