Merge branch 'tapdance' into pr_tapdance

This commit is contained in:
kurtis-lew 2021-06-09 19:26:08 -07:00
commit 226a8d3dee
23 changed files with 310 additions and 127 deletions

View file

@ -46,6 +46,7 @@ jobs:
- lily58_right - lily58_right
- microdox_left - microdox_left
- microdox_right - microdox_right
- two_percent_milk
- nibble - nibble
- qaz - qaz
- quefrency_left - quefrency_left

View file

@ -43,6 +43,7 @@ target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/battery_state_changed
target_sources_ifdef(CONFIG_USB app PRIVATE src/events/usb_conn_state_changed.c) target_sources_ifdef(CONFIG_USB app PRIVATE src/events/usb_conn_state_changed.c)
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
target_sources(app PRIVATE src/behaviors/behavior_key_press.c) target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
target_sources(app PRIVATE src/behaviors/behavior_key_toggle.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c) target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c)
target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c) target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)

View file

@ -0,0 +1,9 @@
# Copyright (c) 2021 The ZMK Contributors
# SPDX-License-Identifier: MIT
if SHIELD_TWO_PERCENT_MILK
config ZMK_KEYBOARD_NAME
default "2% Milk"
endif

View file

@ -0,0 +1,5 @@
# Copyright (c) 2021 The ZMK Contributors
# SPDX-License-Identifier: MIT
config SHIELD_TWO_PERCENT_MILK
def_bool $(shields_list_contains,two_percent_milk)

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/bt.h>
#define DEFAULT 0
/ {
keymap {
compatible = "zmk,keymap";
default_layer {
bindings = <
&kp X
&kp Z
>;
};
};
};

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
/ {
chosen {
zmk,kscan = &kscan0;
};
kscan0: kscan {
compatible = "zmk,kscan-gpio-direct";
label = "KSCAN";
input-gpios
= <&pro_micro_d 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
, <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
;
};
};

View file

@ -1,4 +1,5 @@
#include <behaviors/key_press.dtsi> #include <behaviors/key_press.dtsi>
#include <behaviors/key_toggle.dtsi>
#include <behaviors/transparent.dtsi> #include <behaviors/transparent.dtsi>
#include <behaviors/none.dtsi> #include <behaviors/none.dtsi>
#include <behaviors/mod_tap.dtsi> #include <behaviors/mod_tap.dtsi>

View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
/ {
behaviors {
/omit-if-no-ref/ kt: behavior_key_toggle {
compatible = "zmk,behavior-key-toggle";
label = "KEY_TOGGLE";
#binding-cells = <1>;
};
};
};

View file

@ -0,0 +1,8 @@
# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT
description: Key toggle behavior
compatible: "zmk,behavior-key-toggle"
include: one_param.yaml

View file

@ -12,7 +12,7 @@
#define HID_USAGE(page, id) ((page << 16) | id) #define HID_USAGE(page, id) ((page << 16) | id)
#define HID_USAGE_ID(usage) (usage & 0xFFFF) #define HID_USAGE_ID(usage) (usage & 0xFFFF)
#define HID_USAGE_PAGE(usage) (usage >> 16) #define HID_USAGE_PAGE(usage) ((usage >> 16) & 0xFF)
/* WARNING: DEPRECATED from dt-bindings/zmk/keys.h */ /* WARNING: DEPRECATED from dt-bindings/zmk/keys.h */
#define USAGE_KEYPAD (0x07) // WARNING: DEPRECATED (DO NOT USE) #define USAGE_KEYPAD (0x07) // WARNING: DEPRECATED (DO NOT USE)

View file

@ -23,7 +23,7 @@ ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
static inline struct zmk_keycode_state_changed_event * static inline struct zmk_keycode_state_changed_event *
zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) { zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
uint16_t page = HID_USAGE_PAGE(encoded) & 0xFF; uint16_t page = HID_USAGE_PAGE(encoded);
uint16_t id = HID_USAGE_ID(encoded); uint16_t id = HID_USAGE_ID(encoded);
uint8_t implicit_modifiers = 0x00; uint8_t implicit_modifiers = 0x00;
uint8_t explicit_modifiers = 0x00; uint8_t explicit_modifiers = 0x00;

View file

@ -169,17 +169,26 @@ struct zmk_hid_consumer_report {
zmk_mod_flags_t zmk_hid_get_explicit_mods(); zmk_mod_flags_t zmk_hid_get_explicit_mods();
int zmk_hid_register_mod(zmk_mod_t modifier); int zmk_hid_register_mod(zmk_mod_t modifier);
int zmk_hid_unregister_mod(zmk_mod_t modifier); int zmk_hid_unregister_mod(zmk_mod_t modifier);
bool zmk_hid_mod_is_pressed(zmk_mod_t modifier);
int zmk_hid_register_mods(zmk_mod_flags_t explicit_modifiers); int zmk_hid_register_mods(zmk_mod_flags_t explicit_modifiers);
int zmk_hid_unregister_mods(zmk_mod_flags_t explicit_modifiers); int zmk_hid_unregister_mods(zmk_mod_flags_t explicit_modifiers);
int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers); int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers);
int zmk_hid_implicit_modifiers_release(); int zmk_hid_implicit_modifiers_release();
int zmk_hid_keyboard_press(zmk_key_t key); int zmk_hid_keyboard_press(zmk_key_t key);
int zmk_hid_keyboard_release(zmk_key_t key); int zmk_hid_keyboard_release(zmk_key_t key);
void zmk_hid_keyboard_clear(); void zmk_hid_keyboard_clear();
bool zmk_hid_keyboard_is_pressed();
int zmk_hid_consumer_press(zmk_key_t key); int zmk_hid_consumer_press(zmk_key_t key);
int zmk_hid_consumer_release(zmk_key_t key); int zmk_hid_consumer_release(zmk_key_t key);
void zmk_hid_consumer_clear(); void zmk_hid_consumer_clear();
bool zmk_hid_consumer_is_pressed(zmk_key_t key);
int zmk_hid_press(uint8_t usage_page, zmk_key_t code);
int zmk_hid_release(uint8_t usage_page, zmk_key_t code);
bool zmk_hid_is_pressed(uint8_t usage_page, zmk_key_t code);
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report(); struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report(); struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#define DT_DRV_COMPAT zmk_behavior_key_toggle
#include <device.h>
#include <drivers/behavior.h>
#include <logging/log.h>
#include <zmk/hid.h>
#include <zmk/event_manager.h>
#include <zmk/events/keycode_state_changed.h>
#include <zmk/behavior.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
static int behavior_key_toggle_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
bool pressed =
zmk_hid_is_pressed(HID_USAGE_PAGE(binding->param1), HID_USAGE_ID(binding->param1));
return ZMK_EVENT_RAISE(
zmk_keycode_state_changed_from_encoded(binding->param1, !pressed, event.timestamp));
}
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 0;
}
static const struct behavior_driver_api behavior_key_toggle_driver_api = {
.binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released,
};
#define KP_INST(n) \
DEVICE_AND_API_INIT(behavior_key_toggle_##n, DT_INST_LABEL(n), behavior_key_toggle_init, NULL, \
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_key_toggle_driver_api);
DT_INST_FOREACH_STATUS_OKAY(KP_INST)
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */

View file

@ -195,7 +195,7 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) {
if (strcmp(sticky_key->config->behavior.behavior_dev, "KEY_PRESS") == 0 && if (strcmp(sticky_key->config->behavior.behavior_dev, "KEY_PRESS") == 0 &&
HID_USAGE_ID(sticky_key->param1) == ev->keycode && HID_USAGE_ID(sticky_key->param1) == ev->keycode &&
(HID_USAGE_PAGE(sticky_key->param1) & 0xFF) == ev->usage_page && HID_USAGE_PAGE(sticky_key->param1) == ev->usage_page &&
SELECT_MODS(sticky_key->param1) == ev->implicit_modifiers) { SELECT_MODS(sticky_key->param1) == ev->implicit_modifiers) {
// don't catch key down events generated by the sticky key behavior itself // don't catch key down events generated by the sticky key behavior itself
continue; continue;

View file

@ -42,7 +42,7 @@ struct active_tap_dance {
// timer data // timer data
bool timer_started; bool timer_started;
bool timer_cancelled; bool timer_cancelled;
bool timer_timeout; bool tap_dance_decided;
int64_t release_at; int64_t release_at;
struct k_delayed_work release_timer; struct k_delayed_work release_timer;
}; };
@ -60,8 +60,10 @@ static struct active_tap_dance *store_tap_dance(uint32_t position,
tap_dance->position = position; tap_dance->position = position;
tap_dance->config = config; tap_dance->config = config;
tap_dance->release_at = 0; tap_dance->release_at = 0;
tap_dance->is_pressed = true;
tap_dance->timer_started = true; tap_dance->timer_started = true;
tap_dance->timer_cancelled = false; tap_dance->timer_cancelled = false;
tap_dance->tap_dance_decided = false;
return tap_dance; return tap_dance;
} }
return NULL; return NULL;
@ -88,36 +90,47 @@ static int stop_timer(struct active_tap_dance *tap_dance) {
static void clear_tap_dance(struct active_tap_dance *tap_dance) { static void clear_tap_dance(struct active_tap_dance *tap_dance) {
LOG_DBG("Clearing Tap Dance"); LOG_DBG("Clearing Tap Dance");
tap_dance->position = ZMK_BHV_TAP_DANCE_POSITION_FREE; tap_dance->position = ZMK_BHV_TAP_DANCE_POSITION_FREE;
tap_dance->counter = 1;
}
static void reset_timer(struct active_tap_dance *tap_dance,
struct zmk_behavior_binding_event event) {
LOG_DBG("Resetting Timer");
// Start the timer.
tap_dance->release_at = event.timestamp + tap_dance->config->tapping_term_ms;
int32_t ms_left = tap_dance->release_at - k_uptime_get();
LOG_DBG("ms_left equal to: %d", ms_left);
if (ms_left > 0) {
k_delayed_work_submit(&tap_dance->release_timer, K_MSEC(ms_left));
}
} }
static inline int press_tap_dance_behavior(struct active_tap_dance *tap_dance, int64_t timestamp) { static inline int press_tap_dance_behavior(struct active_tap_dance *tap_dance, int64_t timestamp) {
LOG_DBG("Press Tap Dance Behavior"); LOG_DBG("Press Tap Dance Behavior");
struct zmk_behavior_binding binding = tap_dance->config->behaviors[(tap_dance->counter) - 1]; struct zmk_behavior_binding binding =
(tap_dance->counter < tap_dance->config->behavior_count)
? tap_dance->config->behaviors[(tap_dance->counter) - 1]
: tap_dance->config->behaviors[(tap_dance->config->behavior_count) - 1];
struct zmk_behavior_binding_event event = { struct zmk_behavior_binding_event event = {
.position = tap_dance->position, .position = tap_dance->position,
.timestamp = timestamp, .timestamp = timestamp,
}; };
if (tap_dance->counter <= tap_dance->config->behavior_count) {
behavior_keymap_binding_pressed(&binding, event); behavior_keymap_binding_pressed(&binding, event);
} else {
LOG_DBG("Counter exceeded number of keybinds");
}
return 0; return 0;
} }
static inline int release_tap_dance_behavior(struct active_tap_dance *tap_dance, static inline int release_tap_dance_behavior(struct active_tap_dance *tap_dance,
int64_t timestamp) { int64_t timestamp) {
LOG_DBG("Release Tap Dance Behavior"); LOG_DBG("Release Tap Dance Behavior");
struct zmk_behavior_binding binding = tap_dance->config->behaviors[(tap_dance->counter) - 1]; struct zmk_behavior_binding binding =
(tap_dance->counter < tap_dance->config->behavior_count)
? tap_dance->config->behaviors[(tap_dance->counter) - 1]
: tap_dance->config->behaviors[(tap_dance->config->behavior_count) - 1];
struct zmk_behavior_binding_event event = { struct zmk_behavior_binding_event event = {
.position = tap_dance->position, .position = tap_dance->position,
.timestamp = timestamp, .timestamp = timestamp,
}; };
if (tap_dance->counter <= tap_dance->config->behavior_count) {
behavior_keymap_binding_released(&binding, event); behavior_keymap_binding_released(&binding, event);
} else {
LOG_DBG("Counter exceeded number of keybinds");
}
clear_tap_dance(tap_dance); clear_tap_dance(tap_dance);
return 0; return 0;
} }
@ -129,28 +142,19 @@ static int on_tap_dance_binding_pressed(struct zmk_behavior_binding *binding,
const struct behavior_tap_dance_config *cfg = dev->config; const struct behavior_tap_dance_config *cfg = dev->config;
struct active_tap_dance *tap_dance; struct active_tap_dance *tap_dance;
tap_dance = find_tap_dance(event.position); tap_dance = find_tap_dance(event.position);
if (tap_dance != NULL) { if (tap_dance == NULL) {
tap_dance = store_tap_dance(event.position, cfg);
reset_timer(tap_dance, event);
return ZMK_BEHAVIOR_OPAQUE;
}
tap_dance->is_pressed = true;
stop_timer(tap_dance); stop_timer(tap_dance);
if (++tap_dance->counter >= cfg->behavior_count) { if (++tap_dance->counter >= cfg->behavior_count) {
press_tap_dance_behavior(tap_dance, event.timestamp); press_tap_dance_behavior(tap_dance, event.timestamp);
} tap_dance->tap_dance_decided = true;
} else {
tap_dance = store_tap_dance(event.position, cfg);
if (tap_dance == NULL) {
LOG_ERR("unable to store tap dance, did you press more than %d tap_dance?",
ZMK_BHV_TAP_DANCE_MAX_HELD);
return ZMK_BEHAVIOR_OPAQUE; return ZMK_BEHAVIOR_OPAQUE;
} }
} reset_timer(tap_dance, event);
tap_dance->is_pressed = true;
// No other key was pressed. Start the timer.
tap_dance->release_at = event.timestamp + tap_dance->config->tapping_term_ms;
// adjust timer in case this behavior was queued by a hold-tap
int32_t ms_left = tap_dance->release_at - k_uptime_get();
LOG_DBG("ms_left equal to: %d", ms_left);
if (ms_left > 0) {
k_delayed_work_submit(&tap_dance->release_timer, K_MSEC(ms_left));
}
return ZMK_BEHAVIOR_OPAQUE; return ZMK_BEHAVIOR_OPAQUE;
} }
@ -163,12 +167,10 @@ static int on_tap_dance_binding_released(struct zmk_behavior_binding *binding,
return ZMK_BEHAVIOR_OPAQUE; return ZMK_BEHAVIOR_OPAQUE;
} }
tap_dance->is_pressed = false; tap_dance->is_pressed = false;
int32_t ms_left = tap_dance->release_at - k_uptime_get(); if (tap_dance->tap_dance_decided) {
LOG_DBG("ms_left equal to: %d", ms_left);
if (ms_left <= 0) {
release_tap_dance_behavior(tap_dance, event.timestamp); release_tap_dance_behavior(tap_dance, event.timestamp);
tap_dance->tap_dance_decided = false;
} }
return ZMK_BEHAVIOR_OPAQUE; return ZMK_BEHAVIOR_OPAQUE;
} }
@ -181,13 +183,14 @@ void behavior_tap_dance_timer_handler(struct k_work *item) {
if (tap_dance->timer_cancelled) { if (tap_dance->timer_cancelled) {
tap_dance->timer_cancelled = false; tap_dance->timer_cancelled = false;
} else { } else {
if (!tap_dance->is_pressed) { if (tap_dance->is_pressed) {
press_tap_dance_behavior(tap_dance, tap_dance->release_at);
tap_dance->tap_dance_decided = true;
return;
}
press_tap_dance_behavior(tap_dance, tap_dance->release_at); press_tap_dance_behavior(tap_dance, tap_dance->release_at);
release_tap_dance_behavior(tap_dance, tap_dance->release_at); release_tap_dance_behavior(tap_dance, tap_dance->release_at);
return; return;
} else {
press_tap_dance_behavior(tap_dance, tap_dance->release_at);
}
} }
} }
@ -204,25 +207,21 @@ ZMK_SUBSCRIPTION(behavior_tap_dance, zmk_position_state_changed);
static int tap_dance_position_state_changed_listener(const zmk_event_t *eh) { static int tap_dance_position_state_changed_listener(const zmk_event_t *eh) {
LOG_DBG("Position state changed"); LOG_DBG("Position state changed");
struct zmk_position_state_changed *ev = as_zmk_position_state_changed(eh); struct zmk_position_state_changed *ev = as_zmk_position_state_changed(eh);
if (ev != NULL) { if (ev == NULL) {
return 0;
}
for (int i = 0; i < ZMK_BHV_TAP_DANCE_MAX_HELD; i++) { for (int i = 0; i < ZMK_BHV_TAP_DANCE_MAX_HELD; i++) {
struct active_tap_dance *tap_dance = &active_tap_dances[i]; struct active_tap_dance *tap_dance = &active_tap_dances[i];
if (tap_dance->position == ZMK_BHV_TAP_DANCE_POSITION_FREE) { if (tap_dance->position == ZMK_BHV_TAP_DANCE_POSITION_FREE) {
continue; continue;
} else { }
if (tap_dance->position != ev->position && tap_dance->timer_started) { if (tap_dance->position != ev->position && tap_dance->timer_started) {
stop_timer(tap_dance); stop_timer(tap_dance);
if (tap_dance->is_pressed) {
press_tap_dance_behavior(tap_dance, tap_dance->release_at); press_tap_dance_behavior(tap_dance, tap_dance->release_at);
release_tap_dance_behavior(tap_dance, tap_dance->release_at); release_tap_dance_behavior(tap_dance, tap_dance->release_at);
} }
} }
}
}
return ZMK_EV_EVENT_BUBBLE; return ZMK_EV_EVENT_BUBBLE;
} else {
return 0;
}
} }
#define _TRANSFORM_ENTRY(idx, node) \ #define _TRANSFORM_ENTRY(idx, node) \

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "zmk/keys.h"
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
@ -51,6 +52,11 @@ int zmk_hid_unregister_mod(zmk_mod_t modifier) {
return 0; return 0;
} }
bool zmk_hid_mod_is_pressed(zmk_mod_t modifier) {
zmk_mod_flags_t mod_flag = 1 << modifier;
return (zmk_hid_get_explicit_mods() & mod_flag) == mod_flag;
}
int zmk_hid_register_mods(zmk_mod_flags_t modifiers) { int zmk_hid_register_mods(zmk_mod_flags_t modifiers) {
for (zmk_mod_t i = 0; i < 8; i++) { for (zmk_mod_t i = 0; i < 8; i++) {
if (modifiers & (1 << i)) { if (modifiers & (1 << i)) {
@ -117,6 +123,18 @@ int zmk_hid_keyboard_release(zmk_key_t code) {
return 0; return 0;
}; };
bool zmk_hid_keyboard_is_pressed(zmk_key_t code) {
if (code >= HID_USAGE_KEY_KEYBOARD_LEFTCONTROL && code <= HID_USAGE_KEY_KEYBOARD_RIGHT_GUI) {
return zmk_hid_mod_is_pressed(code - HID_USAGE_KEY_KEYBOARD_LEFTCONTROL);
}
for (int idx = 0; idx < ZMK_HID_KEYBOARD_NKRO_SIZE; idx++) {
if (keyboard_report.body.keys[idx] == code) {
return true;
}
}
return false;
}
void zmk_hid_keyboard_clear() { memset(&keyboard_report.body, 0, sizeof(keyboard_report.body)); } void zmk_hid_keyboard_clear() { memset(&keyboard_report.body, 0, sizeof(keyboard_report.body)); }
int zmk_hid_consumer_press(zmk_key_t code) { int zmk_hid_consumer_press(zmk_key_t code) {
@ -131,6 +149,45 @@ int zmk_hid_consumer_release(zmk_key_t code) {
void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); } void zmk_hid_consumer_clear() { memset(&consumer_report.body, 0, sizeof(consumer_report.body)); }
bool zmk_hid_consumer_is_pressed(zmk_key_t key) {
for (int idx = 0; idx < ZMK_HID_CONSUMER_NKRO_SIZE; idx++) {
if (consumer_report.body.keys[idx] == key) {
return true;
}
}
return false;
}
int zmk_hid_press(uint8_t usage_page, zmk_key_t code) {
switch (usage_page) {
case HID_USAGE_KEY:
return zmk_hid_keyboard_press(code);
case HID_USAGE_CONSUMER:
return zmk_hid_consumer_press(code);
}
return -EINVAL;
}
int zmk_hid_release(uint8_t usage_page, zmk_key_t code) {
switch (usage_page) {
case HID_USAGE_KEY:
return zmk_hid_keyboard_release(code);
case HID_USAGE_CONSUMER:
return zmk_hid_consumer_release(code);
}
return -EINVAL;
}
bool zmk_hid_is_pressed(uint8_t usage_page, zmk_key_t code) {
switch (usage_page) {
case HID_USAGE_KEY:
return zmk_hid_keyboard_is_pressed(code);
case HID_USAGE_CONSUMER:
return zmk_hid_consumer_is_pressed(code);
}
return false;
}
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() { struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report() {
return &keyboard_report; return &keyboard_report;
} }

View file

@ -20,22 +20,11 @@ static int hid_listener_keycode_pressed(const struct zmk_keycode_state_changed *
int err; int err;
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X", LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers); ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
switch (ev->usage_page) { err = zmk_hid_press(ev->usage_page, ev->keycode);
case HID_USAGE_KEY:
err = zmk_hid_keyboard_press(ev->keycode);
if (err) { if (err) {
LOG_ERR("Unable to press keycode"); LOG_DBG("Unable to press keycode");
return err; return err;
} }
break;
case HID_USAGE_CONSUMER:
err = zmk_hid_consumer_press(ev->keycode);
if (err) {
LOG_ERR("Unable to press keycode");
return err;
}
break;
}
zmk_hid_register_mods(ev->explicit_modifiers); zmk_hid_register_mods(ev->explicit_modifiers);
zmk_hid_implicit_modifiers_press(ev->implicit_modifiers); zmk_hid_implicit_modifiers_press(ev->implicit_modifiers);
return zmk_endpoints_send_report(ev->usage_page); return zmk_endpoints_send_report(ev->usage_page);
@ -45,21 +34,11 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed
int err; int err;
LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X", LOG_DBG("usage_page 0x%02X keycode 0x%02X implicit_mods 0x%02X explicit_mods 0x%02X",
ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers); ev->usage_page, ev->keycode, ev->implicit_modifiers, ev->explicit_modifiers);
switch (ev->usage_page) { err = zmk_hid_release(ev->usage_page, ev->keycode);
case HID_USAGE_KEY:
err = zmk_hid_keyboard_release(ev->keycode);
if (err) { if (err) {
LOG_ERR("Unable to release keycode"); LOG_DBG("Unable to release keycode");
return err; return err;
} }
break;
case HID_USAGE_CONSUMER:
err = zmk_hid_consumer_release(ev->keycode);
if (err) {
LOG_ERR("Unable to release keycode");
return err;
}
}
zmk_hid_unregister_mods(ev->explicit_modifiers); zmk_hid_unregister_mods(ev->explicit_modifiers);
// There is a minor issue with this code. // There is a minor issue with this code.
// If LC(A) is pressed, then LS(B), then LC(A) is released, the shift for B will be released // If LC(A) is pressed, then LS(B), then LC(A) is released, the shift for B will be released

View file

@ -0,0 +1,17 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
/ {
keymap {
compatible = "zmk,keymap";
label ="Default keymap";
default_layer {
bindings = <
&kt B &none
&none &none
>;
};
};
};

View file

@ -0,0 +1 @@
s/.*hid_listener_keycode_//p

View file

@ -0,0 +1,2 @@
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00

View file

@ -0,0 +1,10 @@
#include "../behavior_keymap.dtsi"
&kscan {
events = <
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,10)
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,10)
>;
};

View file

@ -1,41 +1,13 @@
manifest: manifest:
remotes: remotes:
- name: zephyrproject-rtos
url-base: https://github.com/zephyrproject-rtos
- name: zmkfirmware - name: zmkfirmware
url-base: https://github.com/zmkfirmware url-base: https://github.com/zmkfirmware
- name: microsoft - name: okke-formsma
url-base: https://github.com/microsoft url-base: https://github.com/okke-formsma
projects: projects:
- name: zephyr - name: zmk
remote: zmkfirmware remote: okke-formsma
revision: v2.4.0+zmk-fixes revision: macros
clone-depth: 1 import: app/west.yml
import:
# TODO: Rename once upstream offers option like `exclude` or `denylist`
name-blacklist:
- ci-tools
- hal_altera
- hal_cypress
- hal_infineon
- hal_microchip
- hal_nxp
- hal_openisa
- hal_silabs
- hal_xtensa
- hal_st
- hal_ti
- loramac-node
- mcuboot
- mcumgr
- net-tools
- segger
- openthread
- edtt
- trusted-firmware-m
- name: uf2
remote: microsoft
path: tools/uf2
clone-depth: 1
self: self:
west-commands: scripts/west-commands.yml path: config

View file

@ -18,7 +18,6 @@ Defines how much time in milliseconds after the tap dance is pressed before a ke
#### `bindings` #### `bindings`
A list of one or more keybinds. This list can include [any keycode in ZMK](../codes/) and keybinds for ZMK behaviors. A list of one or more keybinds. This list can include [any keycode in ZMK](../codes/) and keybinds for ZMK behaviors.
#### Example Usage #### Example Usage
This example configures a tap dance that outputs the number of keypresses from 1-5: This example configures a tap dance that outputs the number of keypresses from 1-5: