From 96fde775604be02f2aeee04f3cd6d4edff2815bd Mon Sep 17 00:00:00 2001 From: Kurtis Lew Date: Sun, 30 Aug 2020 20:12:53 -0700 Subject: Update key-press.md Specified keypress and consumer press pages --- docs/docs/behavior/key-press.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/docs/behavior/key-press.md b/docs/docs/behavior/key-press.md index 2edce1d..f58225d 100644 --- a/docs/docs/behavior/key-press.md +++ b/docs/docs/behavior/key-press.md @@ -8,7 +8,7 @@ sidebar_label: Key Press The most basic of behaviors, is the ability to send certain keycode presses and releases in response to activating a certain key. -For reference on keycode values, see the [USB HID Usage Tables](https://www.usb.org/document-library/hid-usage-tables-12). +For reference on keycode values, see pages 83-89 of the [USB HID Usage Tables](https://www.usb.org/document-library/hid-usage-tables-12). ## Keycode Defines -- cgit v1.3.1 From ca0f2bb074a103b871a3e0f7f5e1fed8b6b4069b Mon Sep 17 00:00:00 2001 From: CrossR Date: Tue, 1 Sep 2020 18:32:45 +0100 Subject: Add to setup. --- app/boards/shields/sofle/sofle.dtsi | 14 ++++++-------- docs/static/setup.sh | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'docs') diff --git a/app/boards/shields/sofle/sofle.dtsi b/app/boards/shields/sofle/sofle.dtsi index 9b3d3c0..653a772 100644 --- a/app/boards/shields/sofle/sofle.dtsi +++ b/app/boards/shields/sofle/sofle.dtsi @@ -47,19 +47,17 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,5) RC(4,6) RC(3,6) RC(3,7) left_encoder: encoder_left { compatible = "alps,ec11"; label = "LEFT_ENCODER"; - a-gpios = <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - b-gpios = <&pro_micro_a 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - resolution = <2>; - status = "disabled"; + a-gpios = <&pro_micro_a 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + b-gpios = <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + resolution = <4>; }; right_encoder: encoder_right { compatible = "alps,ec11"; label = "RIGHT_ENCODER"; - a-gpios = <&pro_micro_a 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - b-gpios = <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - resolution = <2>; - status = "disabled"; + a-gpios = <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + b-gpios = <&pro_micro_a 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + resolution = <4>; }; sensors { diff --git a/docs/static/setup.sh b/docs/static/setup.sh index 4dc740a..a32718d 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -38,7 +38,7 @@ echo "" echo "Keyboard Shield Selection:" prompt="Pick an keyboard:" -options=("Kyria" "Lily58" "Corne" "Splitreus62") +options=("Kyria" "Lily58" "Corne" "Splitreus62" "Sofle") PS3="$prompt " # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. @@ -51,6 +51,7 @@ select opt in "${options[@]}" "Quit"; do 2 ) shield_title="Lily58" shield="lily58"; split="y"; break;; 3 ) shield_title="Corne" shield="corne"; split="y"; break;; 4 ) shield_title="Splitreus62" shield="splitreus62"; split="y"; break;; + 5 ) shield_title="Sofle" shield="sofle"; split="y"; break;; # Add link to docs on adding your own custom shield in your ZMK config! # $(( ${#options[@]}+1 )) ) echo "Other!"; break;; -- cgit v1.3.1 From 29a23f018235ede8cfe65f5ede5014408eee879a Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Tue, 1 Sep 2020 16:04:58 +0200 Subject: Add tap-hold docs, update mod-tap docs --- docs/docs/assets/hold-tap/case1_2.png | Bin 0 -> 10323 bytes docs/docs/assets/hold-tap/case_hold_preferred.png | Bin 0 -> 6380 bytes docs/docs/assets/hold-tap/comparison.png | Bin 0 -> 158912 bytes docs/docs/behavior/hold-tap.md | 62 ++++++++++++++++++++++ docs/docs/behavior/mod-tap.md | 27 +++++++--- 5 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 docs/docs/assets/hold-tap/case1_2.png create mode 100644 docs/docs/assets/hold-tap/case_hold_preferred.png create mode 100644 docs/docs/assets/hold-tap/comparison.png create mode 100644 docs/docs/behavior/hold-tap.md (limited to 'docs') diff --git a/docs/docs/assets/hold-tap/case1_2.png b/docs/docs/assets/hold-tap/case1_2.png new file mode 100644 index 0000000..818ac83 Binary files /dev/null and b/docs/docs/assets/hold-tap/case1_2.png differ diff --git a/docs/docs/assets/hold-tap/case_hold_preferred.png b/docs/docs/assets/hold-tap/case_hold_preferred.png new file mode 100644 index 0000000..6d7fd43 Binary files /dev/null and b/docs/docs/assets/hold-tap/case_hold_preferred.png differ diff --git a/docs/docs/assets/hold-tap/comparison.png b/docs/docs/assets/hold-tap/comparison.png new file mode 100644 index 0000000..419b204 Binary files /dev/null and b/docs/docs/assets/hold-tap/comparison.png differ diff --git a/docs/docs/behavior/hold-tap.md b/docs/docs/behavior/hold-tap.md new file mode 100644 index 0000000..b586b90 --- /dev/null +++ b/docs/docs/behavior/hold-tap.md @@ -0,0 +1,62 @@ +--- +title: Hold-tap behavior +sidebar_label: Hold-Tap +--- + +## Summary +Hold-tap is the basis for other behaviors such as layer-tap and mod-tap. + +Simply put, the hold-tap key will output the 'hold' behavior if it's held for a while, and output the 'tap' behavior when it's tapped quickly. + + +### Hold-Tap +The `tapping_term_ms` parameter decides between a 'tap' and a 'hold'. + +![Simple behavior](../assets/hold-tap/case1_2.png) + +By default, the hold-tap is configured to also select the 'hold' functionality if another key is tapped while it's active: + +![Hold preferred behavior](../assets/hold-tap/case1_2.png) + +We call this the 'hold-preferred' flavor of hold-taps. While this flavor may work very well for a ctrl/escape key, it's not very well suited for home-row mods or layer-taps. That's why there are two more flavors to choose from: 'tap-preferred' and 'balanced'. + +![Hold-tap comparison](../assets/hold-tap/comparison.png) + +### Configuration +A code example which configures a mod-tap setting that works with homerow mods: + +``` +#include +#include + +/ { + behaviors { + &hm: homerow_mods { + compatible = "zmk,behavior-hold-tap"; + label = "homerow_mods"; + #binding-cells = <2>; + tapping_term_ms = <175>; + flavor = "balanced"; + bindings = <&kp>, <&kp>; + }; + }; + + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &hm LCTL A &hm LGUI S &hm LALT D &hm LSFT F + >; + }; + }; +}; + +``` + +If this config does not work for you, try the flavor "tap-preferred" and a short tapping_term_ms such as 120ms. + +If you want to use a tap-hold with a keycode from a different code page, you have to define another behavior with another "bindings" parameter.For example, if you want to use SHIFT and volume up, define the bindings like `bindings = <&kp>, <&cp>;`. Only single-argument behaviors are supported at the moment. + +#### Note +Astute readers may notice similarities between the possible behaviors in ZMK and other firmware, such as QMK. The hold-preferred flavor works similar to the `HOLD_ON_OTHER_KEY_PRESS` setting. The 'balanced' flavor is similar to the `PERMISSIVE_HOLD` setting, and the `tap-preferred` flavor is similar to `IGNORE_MOD_TAP_INTERRUPT`. \ No newline at end of file diff --git a/docs/docs/behavior/mod-tap.md b/docs/docs/behavior/mod-tap.md index 08e9b65..cbe95e4 100644 --- a/docs/docs/behavior/mod-tap.md +++ b/docs/docs/behavior/mod-tap.md @@ -5,13 +5,9 @@ sidebar_label: Mod-Tap ## Summary -The Mod-Tap behavior allows varying the effect of pressing and releasing a key position depending -on whether it is used with other simultaneous key presses at the same time. +The Mod-Tap sends a different keypress, if it's tapped or held. When you tap the key shortly, the first keycode is sent. If you hold the key for longer than 200ms, the second keycode is sent. -If pressed and released independently, the Mod-Tap behavior will send the press and release events -for the configure keycode. If pressed and held while another key is pressed and released, then -the configured modifiers will be applied to that _other_ key press, and no press will be generated -on the release of the Mod-Tap key. +If you press another key within the 200ms, the 'mod' behavior is also activated. ## Mod-Tap @@ -20,7 +16,7 @@ The Mod-Tap behavior either acts as a held modifier, or as a tapped keycode. ### Behavior Binding - Reference: `&mt` -- Parameter #1: The modifiers to be used when activating as a modifier, e.g. `MOD_LSFT` +- Parameter #1: The keycode to be sent when activating as a modifier, e.g. `LSFT` - Parameter #2: The keycode to sent when used as a tap, e.g. `A`, `B`. Example: @@ -28,3 +24,20 @@ Example: ``` &mt MOD_LSFT A ``` + +### Configuration + +You can configure a different tapping term in your keymap: + +``` +&mt { + tapping_term_ms: <400>; +} + +/ { + keymap { + ... + } +} +``` + -- cgit v1.3.1 From c5ca66441172114b57ca7f7b27d13d0d342d4fcc Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Wed, 2 Sep 2020 15:11:56 +0200 Subject: some fixes based on feedback --- app/dts/behaviors/homerow_tap.dtsi | 2 +- .../bindings/behaviors/zmk,behavior-hold-tap.yaml | 23 +++++++++++ .../bindings/behaviors/zmk,behavior-tap-hold.yaml | 23 ----------- app/include/zmk/event-manager.h | 9 +++-- app/run-test-debug.sh | 44 ---------------------- app/src/behaviors/behavior_hold_tap.c | 30 +++++++-------- app/src/event_manager.c | 22 ++++++++--- app/tests/hold-tap/README.md | 1 + docs/docs/behavior/mod-tap.md | 2 +- 9 files changed, 61 insertions(+), 95 deletions(-) create mode 100644 app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml delete mode 100644 app/dts/bindings/behaviors/zmk,behavior-tap-hold.yaml delete mode 100755 app/run-test-debug.sh create mode 100644 app/tests/hold-tap/README.md (limited to 'docs') diff --git a/app/dts/behaviors/homerow_tap.dtsi b/app/dts/behaviors/homerow_tap.dtsi index 21c1531..4162c28 100644 --- a/app/dts/behaviors/homerow_tap.dtsi +++ b/app/dts/behaviors/homerow_tap.dtsi @@ -2,7 +2,7 @@ behaviors { ht: behavior_homerow_mod { compatible = "zmk,behavior-hold-tap"; - label = "homerow_mod"; + label = "HOMEROW_MOD"; #binding-cells = <2>; flavor = "balanced"; tapping_term_ms = <200>; diff --git a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml new file mode 100644 index 0000000..a20578f --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml @@ -0,0 +1,23 @@ +# Copyright (c) 2020, Cody McGinnis; Okke Formsma +# SPDX-License-Identifier: MIT + +description: Hold or Tap behavior + +compatible: "zmk,behavior-hold-tap" + +include: two_param.yaml + +properties: + bindings: + type: phandles + required: true + tapping_term_ms: + type: int + flavor: + type: string + required: false + default: "hold-preferred" + enum: + - "hold-preferred" + - "balanced" + - "tap-preferred" \ No newline at end of file diff --git a/app/dts/bindings/behaviors/zmk,behavior-tap-hold.yaml b/app/dts/bindings/behaviors/zmk,behavior-tap-hold.yaml deleted file mode 100644 index a20578f..0000000 --- a/app/dts/bindings/behaviors/zmk,behavior-tap-hold.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2020, Cody McGinnis; Okke Formsma -# SPDX-License-Identifier: MIT - -description: Hold or Tap behavior - -compatible: "zmk,behavior-hold-tap" - -include: two_param.yaml - -properties: - bindings: - type: phandles - required: true - tapping_term_ms: - type: int - flavor: - type: string - required: false - default: "hold-preferred" - enum: - - "hold-preferred" - - "balanced" - - "tap-preferred" \ No newline at end of file diff --git a/app/include/zmk/event-manager.h b/app/include/zmk/event-manager.h index 07c0aa9..d9a56a4 100644 --- a/app/include/zmk/event-manager.h +++ b/app/include/zmk/event-manager.h @@ -75,13 +75,14 @@ struct zmk_event_subscription { #define ZMK_EVENT_RAISE_AFTER(ev, mod) \ zmk_event_manager_raise_after((struct zmk_event_header *)ev, &zmk_listener_##mod); + +#define ZMK_EVENT_RAISE_AT(ev, mod) \ + zmk_event_manager_raise_at((struct zmk_event_header *)ev, &zmk_listener_##mod); + #define ZMK_EVENT_RELEASE(ev) \ zmk_event_manager_release((struct zmk_event_header *)ev); -#define ZMK_EVENT_RELEASE_AGAIN(ev) \ - zmk_event_manager_release_again((struct zmk_event_header *)ev); - int zmk_event_manager_raise(struct zmk_event_header *event); int zmk_event_manager_raise_after(struct zmk_event_header *event, const struct zmk_listener *listener); +int zmk_event_manager_raise_at(struct zmk_event_header *event, const struct zmk_listener *listener); int zmk_event_manager_release(struct zmk_event_header *event); -int zmk_event_manager_release_again(struct zmk_event_header *event); diff --git a/app/run-test-debug.sh b/app/run-test-debug.sh deleted file mode 100755 index f6696a1..0000000 --- a/app/run-test-debug.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2020 Peter Johanson; Cody McGinnis; Okke Formsma -# -# SPDX-License-Identifier: MIT -# -set -e -set -x - -if [ -z "$1" ]; then - echo "Usage: ./run-test.sh " - exit 1 -elif [ "$1" = "all" ]; then - echo "" > ./build/tests/pass-fail.log - find tests -name native_posix.keymap -exec dirname \{\} \; | xargs -l -P 4 ./run-test.sh - err=$? - sort -k2 ./build/tests/pass-fail.log - exit $err -fi - -testcase="$1" -echo "Running $testcase:" - -west build -d build/$testcase -b native_posix --pristine -- -DZMK_CONFIG=$testcase -if [ $? -gt 0 ]; then - echo "FAIL: $testcase did not build" -else - ./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | tee build/$testcase/keycode_events_full.log | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log - cat build/$testcase/keycode_events_full.log - cat build/$testcase/keycode_events.log - diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log - if [ $? -gt 0 ]; then - if [ -f $testcase/pending ]; then - echo "PEND: $testcase" - exit 0 - else - echo "FAIL: $testcase" - exit 1 - fi - else - echo "PASS: $testcase" - exit 0 - fi -fi \ No newline at end of file diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 08fa139..cd788f7 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -23,7 +23,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if DT_NODE_EXISTS(DT_DRV_INST(0)) -/************************************************************ DATA SETUP */ #define ZMK_BHV_HOLD_TAP_MAX_HELD 10 #define ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS 40 @@ -40,7 +39,7 @@ typedef k_timeout_t (*timer_func)(); struct behavior_hold_tap_config { timer_func tapping_term_ms; struct behavior_hold_tap_behaviors *behaviors; - char *flavor; + int flavor; }; // this data is specific for each hold-tap @@ -65,7 +64,6 @@ struct active_hold_tap active_hold_taps[ZMK_BHV_HOLD_TAP_MAX_HELD] = {}; // We capture most position_state_changed events and some modifiers_state_changed events. const struct zmk_event_header *captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {}; -/************************************************************ CAPTURED POSITION HELPER FUNCTIONS */ static int capture_event(const struct zmk_event_header *event) { for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) { @@ -96,6 +94,8 @@ static struct position_state_changed *find_captured_keydown_event(u32_t position return last_match; } +const struct zmk_listener zmk_listener_behavior_hold_tap; + static void release_captured_events() { if (undecided_hold_tap != NULL) { @@ -143,13 +143,10 @@ static void release_captured_events() struct keycode_state_changed *modifier_event = cast_keycode_state_changed(captured_event); LOG_DBG("Releasing mods changed event 0x%02X %s", modifier_event->keycode, (modifier_event->state ? "pressed" : "released")); } - ZMK_EVENT_RELEASE_AGAIN(captured_event); + ZMK_EVENT_RAISE_AT(captured_event, behavior_hold_tap); } } - -/************************************************************ ACTIVE TAP HOLD HELPER FUNCTIONS */ - static struct active_hold_tap *find_hold_tap(u32_t position) { for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_HELD; i++) { @@ -256,12 +253,12 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_mome return; } - char *flavor = hold_tap->config->flavor; - if (strcmp(flavor, "balanced") == 0) { + int flavor = hold_tap->config->flavor; + if (flavor == 1) { decide_balanced(hold_tap, event); - } else if (strcmp(flavor, "tap-preferred") == 0) { + } else if (flavor == 2) { decide_tap_preferred(hold_tap, event); - } else if (strcmp(flavor, "hold-preferred") == 0) { + } else if (flavor == 0) { decide_hold_preferred(hold_tap, event); } @@ -269,7 +266,11 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_mome return; } - LOG_DBG("%d decided %s (%s event %d)", hold_tap->position, hold_tap->is_hold ? "hold" : "tap", flavor, event); + LOG_DBG("%d decided %s (%s event %d)", + hold_tap->position, + hold_tap->is_hold ? "hold" : "tap", + flavor == 0 ? "hold-preferred" : flavor == 1 ? "balanced": "tap-preferred", + event); undecided_hold_tap = NULL; struct zmk_behavior_binding *behavior; @@ -285,7 +286,6 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_mome release_captured_events(); } -/************************************************************ hold_tap_binding and key handlers */ static int on_hold_tap_binding_pressed(struct device *dev, u32_t position, u32_t param_hold, u32_t param_tap) { const struct behavior_hold_tap_config *cfg = dev->config_info; @@ -430,7 +430,6 @@ ZMK_SUBSCRIPTION(behavior_hold_tap, position_state_changed); // this should be modifiers_state_changed, but unfrotunately that's not implemented yet. ZMK_SUBSCRIPTION(behavior_hold_tap, keycode_state_changed); -/************************************************************ TIMER FUNCTIONS */ void behavior_hold_tap_timer_work_handler(struct k_work *item) { struct active_hold_tap *hold_tap = CONTAINER_OF(item, struct active_hold_tap, work); @@ -459,7 +458,6 @@ static int behavior_hold_tap_init(struct device *dev) struct behavior_hold_tap_data {}; static struct behavior_hold_tap_data behavior_hold_tap_data; -/************************************************************ NODE CONFIG */ #define _TRANSFORM_ENTRY(idx, node) \ { \ .behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(node, bindings, idx)), \ @@ -476,7 +474,7 @@ static struct behavior_hold_tap_data behavior_hold_tap_data; static struct behavior_hold_tap_config behavior_hold_tap_config_##n = { \ .behaviors = &behavior_hold_tap_behaviors_##n, \ .tapping_term_ms = &behavior_hold_tap_config_##n##_gettime, \ - .flavor = DT_INST_PROP(n, flavor), \ + .flavor = DT_ENUM_IDX(DT_DRV_INST(n), flavor), \ }; \ DEVICE_AND_API_INIT( \ behavior_hold_tap_##n, DT_INST_LABEL(n), behavior_hold_tap_init, \ diff --git a/app/src/event_manager.c b/app/src/event_manager.c index 2f423fc..47ad6b7 100644 --- a/app/src/event_manager.c +++ b/app/src/event_manager.c @@ -71,13 +71,23 @@ int zmk_event_manager_raise_after(struct zmk_event_header *event, const struct z return -EINVAL; } -int zmk_event_manager_release(struct zmk_event_header *event) +int zmk_event_manager_raise_at(struct zmk_event_header *event, const struct zmk_listener *listener) { - return zmk_event_manager_handle_from(event, event->last_listener_index + 1); -} + u8_t len = __event_subscriptions_end - __event_subscriptions_start; + for (int i = 0; i < len; i++) { + struct zmk_event_subscription *ev_sub = __event_subscriptions_start + i; + + if (ev_sub->event_type == event->event && ev_sub->listener == listener) { + return zmk_event_manager_handle_from(event, i); + } + } + LOG_WRN("Unable to find where to raise this event"); + + return -EINVAL; +} -int zmk_event_manager_release_again(struct zmk_event_header *event) +int zmk_event_manager_release(struct zmk_event_header *event) { - return zmk_event_manager_handle_from(event, event->last_listener_index); -} \ No newline at end of file + return zmk_event_manager_handle_from(event, event->last_listener_index + 1); +} diff --git a/app/tests/hold-tap/README.md b/app/tests/hold-tap/README.md new file mode 100644 index 0000000..0630132 --- /dev/null +++ b/app/tests/hold-tap/README.md @@ -0,0 +1 @@ +Refer to the pdf/open document "zmk-modtap-proposal.{pdf,odt}" in this directory for a visual representation of the numbered tests for hold-tap. diff --git a/docs/docs/behavior/mod-tap.md b/docs/docs/behavior/mod-tap.md index cbe95e4..dcac492 100644 --- a/docs/docs/behavior/mod-tap.md +++ b/docs/docs/behavior/mod-tap.md @@ -22,7 +22,7 @@ The Mod-Tap behavior either acts as a held modifier, or as a tapped keycode. Example: ``` -&mt MOD_LSFT A +&mt LSFT A ``` ### Configuration -- cgit v1.3.1 From c9a82d71d06146dfe706a2e8d223dab593dffffc Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Wed, 2 Sep 2020 16:41:39 +0200 Subject: fixes for feedback round 2 --- app/dts/behaviors.dtsi | 1 - app/dts/behaviors/homerow_tap.dtsi | 12 ----------- app/src/behaviors/behavior_hold_tap.c | 39 +++++++++++++++++++++++------------ docs/docs/behavior/hold-tap.md | 4 ++-- 4 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 app/dts/behaviors/homerow_tap.dtsi (limited to 'docs') diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index fdcf426..ab70bcc 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/app/dts/behaviors/homerow_tap.dtsi b/app/dts/behaviors/homerow_tap.dtsi deleted file mode 100644 index 4162c28..0000000 --- a/app/dts/behaviors/homerow_tap.dtsi +++ /dev/null @@ -1,12 +0,0 @@ -/ { - behaviors { - ht: behavior_homerow_mod { - compatible = "zmk,behavior-hold-tap"; - label = "HOMEROW_MOD"; - #binding-cells = <2>; - flavor = "balanced"; - tapping_term_ms = <200>; - bindings = <&kp>, <&kp>; - }; - }; -}; diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index cd788f7..2c6d996 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -29,6 +29,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); // increase if you have keyboard with more keys. #define ZMK_BHV_HOLD_TAP_POSITION_NOT_USED 9999 + +enum flavor { + ZMK_BHV_HOLD_TAP_FLAVOR_HOLD_PREFERRED = 0, + ZMK_BHV_HOLD_TAP_FLAVOR_BALANCED = 1, + ZMK_BHV_HOLD_TAP_FLAVOR_TAP_PREFERRED = 2, +}; + struct behavior_hold_tap_behaviors { struct zmk_behavior_binding tap; struct zmk_behavior_binding hold; @@ -39,7 +46,7 @@ typedef k_timeout_t (*timer_func)(); struct behavior_hold_tap_config { timer_func tapping_term_ms; struct behavior_hold_tap_behaviors *behaviors; - int flavor; + enum flavor flavor; }; // this data is specific for each hold-tap @@ -197,9 +204,6 @@ static void decide_balanced(struct active_hold_tap *hold_tap, enum decision_mome hold_tap->is_decided = true; break; case HT_OTHER_KEY_UP: - hold_tap->is_hold = 1; - hold_tap->is_decided = true; - break; case HT_TIMER_EVENT: hold_tap->is_hold = 1; hold_tap->is_decided = true; @@ -231,9 +235,6 @@ static void decide_hold_preferred(struct active_hold_tap *hold_tap, enum decisio hold_tap->is_decided = true; break; case HT_OTHER_KEY_DOWN: - hold_tap->is_hold = 1; - hold_tap->is_decided = true; - break; case HT_TIMER_EVENT: hold_tap->is_hold = 1; hold_tap->is_decided = true; @@ -242,6 +243,18 @@ static void decide_hold_preferred(struct active_hold_tap *hold_tap, enum decisio } } +static inline char* flavor_str(enum flavor flavor) { + switch(flavor) { + case ZMK_BHV_HOLD_TAP_FLAVOR_HOLD_PREFERRED: + return "hold-preferred"; + case ZMK_BHV_HOLD_TAP_FLAVOR_BALANCED: + return "balanced"; + case ZMK_BHV_HOLD_TAP_FLAVOR_TAP_PREFERRED: + return "tap-preferred"; + } + return "UNKNOWN FLAVOR"; +} + static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_moment event) { if (hold_tap->is_decided) { @@ -253,13 +266,13 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_mome return; } - int flavor = hold_tap->config->flavor; - if (flavor == 1) { + switch(hold_tap->config->flavor) { + case ZMK_BHV_HOLD_TAP_FLAVOR_HOLD_PREFERRED: + decide_hold_preferred(hold_tap, event); + case ZMK_BHV_HOLD_TAP_FLAVOR_BALANCED: decide_balanced(hold_tap, event); - } else if (flavor == 2) { + case ZMK_BHV_HOLD_TAP_FLAVOR_TAP_PREFERRED: decide_tap_preferred(hold_tap, event); - } else if (flavor == 0) { - decide_hold_preferred(hold_tap, event); } if (!hold_tap->is_decided) { @@ -269,7 +282,7 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, enum decision_mome LOG_DBG("%d decided %s (%s event %d)", hold_tap->position, hold_tap->is_hold ? "hold" : "tap", - flavor == 0 ? "hold-preferred" : flavor == 1 ? "balanced": "tap-preferred", + flavor_str(hold_tap->config->flavor), event); undecided_hold_tap = NULL; diff --git a/docs/docs/behavior/hold-tap.md b/docs/docs/behavior/hold-tap.md index b586b90..fa68538 100644 --- a/docs/docs/behavior/hold-tap.md +++ b/docs/docs/behavior/hold-tap.md @@ -31,9 +31,9 @@ A code example which configures a mod-tap setting that works with homerow mods: / { behaviors { - &hm: homerow_mods { + hm: homerow_mods { compatible = "zmk,behavior-hold-tap"; - label = "homerow_mods"; + label = "HOMEROW_MODS"; #binding-cells = <2>; tapping_term_ms = <175>; flavor = "balanced"; -- cgit v1.3.1