Merge branch 'pr_tapdance' of https://github.com/kurtis-lew/zmk into pr_tapdance
This commit is contained in:
commit
996e823a13
22 changed files with 255 additions and 71 deletions
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
|
@ -46,6 +46,7 @@ jobs:
|
|||
- lily58_right
|
||||
- microdox_left
|
||||
- microdox_right
|
||||
- two_percent_milk
|
||||
- nibble
|
||||
- qaz
|
||||
- quefrency_left
|
||||
|
|
|
@ -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)
|
||||
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_toggle.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_tap_dance.c)
|
||||
|
|
9
app/boards/shields/two_percent_milk/Kconfig.defconfig
Normal file
9
app/boards/shields/two_percent_milk/Kconfig.defconfig
Normal 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
|
5
app/boards/shields/two_percent_milk/Kconfig.shield
Normal file
5
app/boards/shields/two_percent_milk/Kconfig.shield
Normal 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)
|
24
app/boards/shields/two_percent_milk/two_percent_milk.keymap
Normal file
24
app/boards/shields/two_percent_milk/two_percent_milk.keymap
Normal 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
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
24
app/boards/shields/two_percent_milk/two_percent_milk.overlay
Normal file
24
app/boards/shields/two_percent_milk/two_percent_milk.overlay
Normal 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)>
|
||||
;
|
||||
|
||||
};
|
||||
|
||||
};
|
|
@ -1,4 +1,5 @@
|
|||
#include <behaviors/key_press.dtsi>
|
||||
#include <behaviors/key_toggle.dtsi>
|
||||
#include <behaviors/transparent.dtsi>
|
||||
#include <behaviors/none.dtsi>
|
||||
#include <behaviors/mod_tap.dtsi>
|
||||
|
|
15
app/dts/behaviors/key_toggle.dtsi
Normal file
15
app/dts/behaviors/key_toggle.dtsi
Normal 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>;
|
||||
};
|
||||
};
|
||||
};
|
8
app/dts/bindings/behaviors/zmk,behavior-key-toggle.yaml
Normal file
8
app/dts/bindings/behaviors/zmk,behavior-key-toggle.yaml
Normal 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
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#define HID_USAGE(page, id) ((page << 16) | id)
|
||||
#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 */
|
||||
#define USAGE_KEYPAD (0x07) // WARNING: DEPRECATED (DO NOT USE)
|
||||
|
|
|
@ -23,7 +23,7 @@ ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
|
|||
|
||||
static inline struct zmk_keycode_state_changed_event *
|
||||
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);
|
||||
uint8_t implicit_modifiers = 0x00;
|
||||
uint8_t explicit_modifiers = 0x00;
|
||||
|
|
|
@ -169,17 +169,26 @@ struct zmk_hid_consumer_report {
|
|||
zmk_mod_flags_t zmk_hid_get_explicit_mods();
|
||||
int zmk_hid_register_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_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_release();
|
||||
|
||||
int zmk_hid_keyboard_press(zmk_key_t key);
|
||||
int zmk_hid_keyboard_release(zmk_key_t key);
|
||||
void zmk_hid_keyboard_clear();
|
||||
bool zmk_hid_keyboard_is_pressed();
|
||||
|
||||
int zmk_hid_consumer_press(zmk_key_t key);
|
||||
int zmk_hid_consumer_release(zmk_key_t key);
|
||||
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_consumer_report *zmk_hid_get_consumer_report();
|
||||
|
|
50
app/src/behaviors/behavior_key_toggle.c
Normal file
50
app/src/behaviors/behavior_key_toggle.c
Normal 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) */
|
|
@ -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 &&
|
||||
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) {
|
||||
// don't catch key down events generated by the sticky key behavior itself
|
||||
continue;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "zmk/keys.h"
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
|
@ -51,6 +52,11 @@ int zmk_hid_unregister_mod(zmk_mod_t modifier) {
|
|||
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) {
|
||||
for (zmk_mod_t i = 0; i < 8; i++) {
|
||||
if (modifiers & (1 << i)) {
|
||||
|
@ -117,6 +123,18 @@ int zmk_hid_keyboard_release(zmk_key_t code) {
|
|||
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)); }
|
||||
|
||||
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)); }
|
||||
|
||||
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() {
|
||||
return &keyboard_report;
|
||||
}
|
||||
|
|
|
@ -20,21 +20,10 @@ static int hid_listener_keycode_pressed(const struct zmk_keycode_state_changed *
|
|||
int err;
|
||||
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);
|
||||
switch (ev->usage_page) {
|
||||
case HID_USAGE_KEY:
|
||||
err = zmk_hid_keyboard_press(ev->keycode);
|
||||
if (err) {
|
||||
LOG_ERR("Unable to press keycode");
|
||||
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;
|
||||
err = zmk_hid_press(ev->usage_page, ev->keycode);
|
||||
if (err) {
|
||||
LOG_DBG("Unable to press keycode");
|
||||
return err;
|
||||
}
|
||||
zmk_hid_register_mods(ev->explicit_modifiers);
|
||||
zmk_hid_implicit_modifiers_press(ev->implicit_modifiers);
|
||||
|
@ -45,20 +34,10 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed
|
|||
int err;
|
||||
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);
|
||||
switch (ev->usage_page) {
|
||||
case HID_USAGE_KEY:
|
||||
err = zmk_hid_keyboard_release(ev->keycode);
|
||||
if (err) {
|
||||
LOG_ERR("Unable to release keycode");
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
case HID_USAGE_CONSUMER:
|
||||
err = zmk_hid_consumer_release(ev->keycode);
|
||||
if (err) {
|
||||
LOG_ERR("Unable to release keycode");
|
||||
return err;
|
||||
}
|
||||
err = zmk_hid_release(ev->usage_page, ev->keycode);
|
||||
if (err) {
|
||||
LOG_DBG("Unable to release keycode");
|
||||
return err;
|
||||
}
|
||||
zmk_hid_unregister_mods(ev->explicit_modifiers);
|
||||
// There is a minor issue with this code.
|
||||
|
|
17
app/tests/keytoggle/behavior_keymap.dtsi
Normal file
17
app/tests/keytoggle/behavior_keymap.dtsi
Normal 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
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
1
app/tests/keytoggle/kt-press-release/events.patterns
Normal file
1
app/tests/keytoggle/kt-press-release/events.patterns
Normal file
|
@ -0,0 +1 @@
|
|||
s/.*hid_listener_keycode_//p
|
|
@ -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
|
10
app/tests/keytoggle/kt-press-release/native_posix.keymap
Normal file
10
app/tests/keytoggle/kt-press-release/native_posix.keymap
Normal 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)
|
||||
>;
|
||||
};
|
42
app/west.yml
42
app/west.yml
|
@ -1,41 +1,13 @@
|
|||
manifest:
|
||||
remotes:
|
||||
- name: zephyrproject-rtos
|
||||
url-base: https://github.com/zephyrproject-rtos
|
||||
- name: zmkfirmware
|
||||
url-base: https://github.com/zmkfirmware
|
||||
- name: microsoft
|
||||
url-base: https://github.com/microsoft
|
||||
- name: okke-formsma
|
||||
url-base: https://github.com/okke-formsma
|
||||
projects:
|
||||
- name: zephyr
|
||||
remote: zmkfirmware
|
||||
revision: v2.4.0+zmk-fixes
|
||||
clone-depth: 1
|
||||
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
|
||||
- name: zmk
|
||||
remote: okke-formsma
|
||||
revision: macros
|
||||
import: app/west.yml
|
||||
self:
|
||||
west-commands: scripts/west-commands.yml
|
||||
path: config
|
|
@ -18,7 +18,6 @@ Defines how much time in milliseconds after the tap dance is pressed before a ke
|
|||
#### `bindings`
|
||||
|
||||
A list of one or more keybinds. This list can include [any keycode in ZMK](../codes/) and keybinds for ZMK behaviors.
|
||||
|
||||
#### Example Usage
|
||||
|
||||
This example configures a tap dance that outputs the number of keypresses from 1-5:
|
||||
|
|
Loading…
Add table
Reference in a new issue