From cdcf4ebfb6d53b6230a65a85f060b6343db3b40b Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Sat, 10 Feb 2024 11:01:24 -0500 Subject: [PATCH 001/134] feat(boards): allow use of blackpill_f401cc --- .../blackpill_f401cc/blackpill_f401cc.zmk.yml | 9 ++++ app/boards/blackpill_f401cc.conf | 6 +++ app/boards/blackpill_f401cc.overlay | 50 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 app/boards/arm/blackpill_f401cc/blackpill_f401cc.zmk.yml create mode 100644 app/boards/blackpill_f401cc.conf create mode 100644 app/boards/blackpill_f401cc.overlay diff --git a/app/boards/arm/blackpill_f401cc/blackpill_f401cc.zmk.yml b/app/boards/arm/blackpill_f401cc/blackpill_f401cc.zmk.yml new file mode 100644 index 00000000000..329b7371d54 --- /dev/null +++ b/app/boards/arm/blackpill_f401cc/blackpill_f401cc.zmk.yml @@ -0,0 +1,9 @@ +file_format: "1" +id: blackpill_f401cc +name: BlackPill F401CC +type: board +arch: arm +outputs: + - usb +url: https://github.com/WeActStudio/WeActStudio.MiniSTM32F4x1 +exposes: [blackpill] diff --git a/app/boards/blackpill_f401cc.conf b/app/boards/blackpill_f401cc.conf new file mode 100644 index 00000000000..c4252425b2d --- /dev/null +++ b/app/boards/blackpill_f401cc.conf @@ -0,0 +1,6 @@ +CONFIG_CONSOLE=n +CONFIG_SERIAL=n +CONFIG_UART_CONSOLE=n +CONFIG_UART_INTERRUPT_DRIVEN=n +CONFIG_ZMK_USB=y +CONFIG_ZMK_KSCAN_MATRIX_POLLING=y diff --git a/app/boards/blackpill_f401cc.overlay b/app/boards/blackpill_f401cc.overlay new file mode 100644 index 00000000000..6ed4c3cf844 --- /dev/null +++ b/app/boards/blackpill_f401cc.overlay @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/ { + blackpill: connector { + compatible = "blackpill"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map + = <2 0 &gpioc 13 0> /* PC13 */ + , <3 0 &gpioc 14 0> /* PC14 */ + , <4 0 &gpioc 15 0> /* PC15 */ + , <10 0 &gpioa 0 0> /* PA0 */ + , <11 0 &gpioa 1 0> /* PA1 */ + , <12 0 &gpioa 2 0> /* PA2 */ + , <13 0 &gpioa 3 0> /* PA3 */ + , <14 0 &gpioa 4 0> /* PA4 */ + , <15 0 &gpioa 5 0> /* PA5 */ + , <16 0 &gpioa 6 0> /* PA6 */ + , <17 0 &gpioa 7 0> /* PA7 */ + , <18 0 &gpiob 0 0> /* PB0 */ + , <19 0 &gpiob 1 0> /* PB1 */ + , <20 0 &gpiob 2 0> /* PB2 */ + , <21 0 &gpiob 10 0> /* PB10 */ + , <25 0 &gpiob 12 0> /* PB12 */ + , <26 0 &gpiob 13 0> /* PB13 */ + , <27 0 &gpiob 14 0> /* PB14 */ + , <28 0 &gpiob 15 0> /* PB15 */ + , <29 0 &gpioa 8 0> /* PA8 */ + , <30 0 &gpioa 9 0> /* PA9 */ + , <31 0 &gpioa 10 0> /* PA10 */ + , <38 0 &gpioa 15 0> /* PA15 */ + , <39 0 &gpiob 3 0> /* PB3 */ + , <40 0 &gpiob 4 0> /* PB4 */ + , <41 0 &gpiob 5 0> /* PB5 */ + , <42 0 &gpiob 6 0> /* PB6 */ + , <43 0 &gpiob 7 0> /* PB7 */ + , <45 0 &gpiob 8 0> /* PB8 */ + , <46 0 &gpiob 9 0> /* PB9 */ + ; + }; +}; + +blackpill_i2c: &i2c1 {}; +blackpill_spi: &spi1 {}; +blackpill_serial: &usart1 {}; From 40adb3858df5509bd6c67b0477e8832fe769a507 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:41:03 -0500 Subject: [PATCH 002/134] refactor(boards): remove superfluous conf settings --- app/boards/blackpill_f401ce.conf | 1 - app/boards/blackpill_f411ce.conf | 1 - 2 files changed, 2 deletions(-) diff --git a/app/boards/blackpill_f401ce.conf b/app/boards/blackpill_f401ce.conf index 07e304cfa5c..c4252425b2d 100644 --- a/app/boards/blackpill_f401ce.conf +++ b/app/boards/blackpill_f401ce.conf @@ -3,5 +3,4 @@ CONFIG_SERIAL=n CONFIG_UART_CONSOLE=n CONFIG_UART_INTERRUPT_DRIVEN=n CONFIG_ZMK_USB=y -CONFIG_ZMK_BLE=n CONFIG_ZMK_KSCAN_MATRIX_POLLING=y diff --git a/app/boards/blackpill_f411ce.conf b/app/boards/blackpill_f411ce.conf index 07e304cfa5c..c4252425b2d 100644 --- a/app/boards/blackpill_f411ce.conf +++ b/app/boards/blackpill_f411ce.conf @@ -3,5 +3,4 @@ CONFIG_SERIAL=n CONFIG_UART_CONSOLE=n CONFIG_UART_INTERRUPT_DRIVEN=n CONFIG_ZMK_USB=y -CONFIG_ZMK_BLE=n CONFIG_ZMK_KSCAN_MATRIX_POLLING=y From c7fb418e88bc3d5e82f04976c06a1aeeb9b5c736 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 14 Feb 2024 19:47:54 +0000 Subject: [PATCH 003/134] fix(build): Used a fixed temp dir for caching. * Improve GHA caching by using a fixed temporary directory when using one. --- .github/workflows/build-user-config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-user-config.yml b/.github/workflows/build-user-config.yml index af57520bcd2..d8ea057e56d 100644 --- a/.github/workflows/build-user-config.yml +++ b/.github/workflows/build-user-config.yml @@ -68,7 +68,8 @@ jobs: run: | if [ -e zephyr/module.yml ]; then export zmk_load_arg=" -DZMK_EXTRA_MODULES='${GITHUB_WORKSPACE}'" - export new_tmp_dir=$(mktemp -d) + new_tmp_dir="${TMPDIR:-/tmp}/zmk-config" + mkdir -p "${new_tmp_dir}" echo "base_dir=${new_tmp_dir}" >> $GITHUB_ENV else echo "base_dir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV From 0f49fa9ae49b3373ea701c3ecd9da3e149ca8d64 Mon Sep 17 00:00:00 2001 From: ctranstrum Date: Wed, 14 Feb 2024 18:29:19 -0700 Subject: [PATCH 004/134] fix(behavior): Proper init priority for ext_power. --- app/src/behaviors/behavior_ext_power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/behaviors/behavior_ext_power.c b/app/src/behaviors/behavior_ext_power.c index a51a9f6dbd6..b2aff3c8670 100644 --- a/app/src/behaviors/behavior_ext_power.c +++ b/app/src/behaviors/behavior_ext_power.c @@ -75,6 +75,6 @@ static const struct behavior_driver_api behavior_ext_power_driver_api = { }; BEHAVIOR_DT_INST_DEFINE(0, behavior_ext_power_init, NULL, NULL, NULL, POST_KERNEL, - CONFIG_APPLICATION_INIT_PRIORITY, &behavior_ext_power_driver_api); + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_ext_power_driver_api); #endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ From 604af2ebd318a2b8865f98db55b411a8e07f24c2 Mon Sep 17 00:00:00 2001 From: Dennis <47061464+dennisorlando@users.noreply.github.com> Date: Sun, 18 Feb 2024 06:51:09 +0100 Subject: [PATCH 005/134] feat(docs): Add pointers for peripheral battery monitoring (#2177) Co-authored-by: Cem Aksoylar Fixes #2166 --- docs/docs/config/battery.md | 11 +++++++++++ docs/docs/features/battery.md | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/docs/config/battery.md b/docs/docs/config/battery.md index 68de8fb8256..463dc087b6e 100644 --- a/docs/docs/config/battery.md +++ b/docs/docs/config/battery.md @@ -28,6 +28,17 @@ On macOS the BLE battery reporting packets can cause the computer to wakeup from ::: +### Peripheral battery monitoring + +You can [configure ZMK to allow support for peripheral battery monitoring over BLE](system.md#split-keyboards) (e.g. when having a split keyboard with two independent and wirelessly connected sides). +If you want to report the battery levels of both sides of a split keyboard, you should have both `CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_PROXY` and `CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING` set to `y`. + +:::note[Displaying both battery levels on your host] + +Host support for multiple battery levels is undefined. It appears that in most of the cases only the main battery is being reported. In order to correctly display all the battery values, you probably need a special application or script. + +::: + ### Devicetree Applies to: [`/chosen` node](https://docs.zephyrproject.org/3.5.0/build/dts/intro-syntax-structure.html#aliases-and-chosen-nodes) diff --git a/docs/docs/features/battery.md b/docs/docs/features/battery.md index 4bfeb129994..29142eedc01 100644 --- a/docs/docs/features/battery.md +++ b/docs/docs/features/battery.md @@ -5,7 +5,7 @@ sidebar_label: Battery Level If your keyboard has a battery sensor, ZMK will report its battery level to the connected bluetooth host and show it on the keyboard's display, if it has one. -For split keyboards, only the battery level of the central (usually left) side is reported over bluetooth. +For split keyboards, only the battery level of the central (usually left) side is reported over bluetooth by default. ZMK can be [configured to report the battery levels for peripherals](../config/battery.md#peripheral-battery-monitoring), but not many host systems will display this information without additional configuration or the use of third party utilities. :::note From fda6a5f18534ac7c480fdec5854f063432733f69 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 17 Feb 2024 21:32:24 -0800 Subject: [PATCH 006/134] fix(boards): Tweaks for Ferris rev0.2 for Zephyr. * Enable missing clock and set up USB pinctrl. --- app/boards/arm/ferris/ferris_rev02.dts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/boards/arm/ferris/ferris_rev02.dts b/app/boards/arm/ferris/ferris_rev02.dts index eb2194209da..4fecd280eec 100644 --- a/app/boards/arm/ferris/ferris_rev02.dts +++ b/app/boards/arm/ferris/ferris_rev02.dts @@ -112,6 +112,9 @@ &usb { status = "okay"; + + pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>; + pinctrl-names = "default"; cdc_acm_uart: cdc_acm_uart { compatible = "zephyr,cdc-acm-uart"; }; @@ -121,6 +124,10 @@ status = "okay"; }; +&clk_hsi48 { + status = "okay"; +}; + &pll { prediv = <1>; mul = <6>; From a9ae6796a088730d7377f660e78af17f11bb87c7 Mon Sep 17 00:00:00 2001 From: zhiayang <500236+zhiayang@users.noreply.github.com> Date: Mon, 19 Feb 2024 19:15:19 -0500 Subject: [PATCH 007/134] fix(display): Proper initial display of battery status * fix initial display of battery status on displays, and also fix a null deref --- app/boards/arm/corneish_zen/widgets/battery_status.c | 4 +++- app/boards/shields/nice_view/widgets/status.c | 4 +++- app/src/display/widgets/battery_status.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/boards/arm/corneish_zen/widgets/battery_status.c b/app/boards/arm/corneish_zen/widgets/battery_status.c index 011319c408f..39b811b53f3 100644 --- a/app/boards/arm/corneish_zen/widgets/battery_status.c +++ b/app/boards/arm/corneish_zen/widgets/battery_status.c @@ -66,8 +66,10 @@ void battery_status_update_cb(struct battery_status_state state) { } static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { + const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); + return (struct battery_status_state) { - .level = zmk_battery_state_of_charge(), + .level = (ev != NULL) ? ev->state_of_charge : zmk_battery_state_of_charge(), #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ diff --git a/app/boards/shields/nice_view/widgets/status.c b/app/boards/shields/nice_view/widgets/status.c index 93139eca0a5..061b7127cee 100644 --- a/app/boards/shields/nice_view/widgets/status.c +++ b/app/boards/shields/nice_view/widgets/status.c @@ -210,8 +210,10 @@ static void battery_status_update_cb(struct battery_status_state state) { } static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { + const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); + return (struct battery_status_state) { - .level = zmk_battery_state_of_charge(), + .level = (ev != NULL) ? ev->state_of_charge : zmk_battery_state_of_charge(), #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ diff --git a/app/src/display/widgets/battery_status.c b/app/src/display/widgets/battery_status.c index 06f55f3f405..bec6964ba94 100644 --- a/app/src/display/widgets/battery_status.c +++ b/app/src/display/widgets/battery_status.c @@ -9,6 +9,7 @@ #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#include #include #include #include @@ -63,8 +64,9 @@ void battery_status_update_cb(struct battery_status_state state) { static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); + return (struct battery_status_state) { - .level = ev->state_of_charge, + .level = (ev != NULL) ? ev->state_of_charge : zmk_battery_state_of_charge(), #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ From c082f8d80280a41fd4d023cd35d71309af167119 Mon Sep 17 00:00:00 2001 From: ton-im Date: Tue, 20 Feb 2024 08:32:12 +0800 Subject: [PATCH 008/134] fix(boards): Add ext power init delay for nrfMicro * Address issues with OLED init occurring before display is powered. --- app/boards/arm/nrfmicro/nrfmicro_11.dts | 1 + app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts | 1 + app/boards/arm/nrfmicro/nrfmicro_13.dts | 1 + app/boards/arm/nrfmicro/nrfmicro_13_52833.dts | 1 + 4 files changed, 4 insertions(+) diff --git a/app/boards/arm/nrfmicro/nrfmicro_11.dts b/app/boards/arm/nrfmicro/nrfmicro_11.dts index c0c02ee9e34..652df1011a6 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_11.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_11.dts @@ -31,6 +31,7 @@ EXT_POWER { compatible = "zmk,ext-power-generic"; control-gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>; + init-delay-ms = <50>; }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts b/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts index df3b224bc49..5095d64865d 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts @@ -31,6 +31,7 @@ EXT_POWER { compatible = "zmk,ext-power-generic"; control-gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>; + init-delay-ms = <50>; }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13.dts b/app/boards/arm/nrfmicro/nrfmicro_13.dts index f5ae81c9545..7a6a5d4d952 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13.dts @@ -32,6 +32,7 @@ EXT_POWER { compatible = "zmk,ext-power-generic"; control-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; + init-delay-ms = <50>; }; vbatt: vbatt { diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts b/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts index d6c88692d95..ff2e027fcb9 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts @@ -32,6 +32,7 @@ EXT_POWER { compatible = "zmk,ext-power-generic"; control-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; + init-delay-ms = <50>; }; vbatt: vbatt { From ccf038017993dd2e7f00bdd355e28c5009621dd5 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Sun, 11 Feb 2024 21:52:23 -0500 Subject: [PATCH 009/134] refactor: remove redundant Kconfig defaults bool symbols implicitly default to n. --- app/Kconfig | 5 ----- app/Kconfig.behaviors | 1 - app/src/display/Kconfig | 1 - 3 files changed, 7 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 8155efd0ae5..bb6997a43ae 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -177,7 +177,6 @@ config ZMK_BLE_EXPERIMENTAL_FEATURES config ZMK_BLE_PASSKEY_ENTRY bool "Require passkey entry on the keyboard to complete pairing" - default n select RING_BUFFER config BT_SMP_ALLOW_UNAUTH_OVERWRITE @@ -216,7 +215,6 @@ config ZMK_BLE_MOUSE_REPORT_QUEUE_SIZE config ZMK_BLE_CLEAR_BONDS_ON_START bool "Configuration that clears all bond information from the keyboard on startup." - default n # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. config BT_GATT_NOTIFY_MULTIPLE @@ -373,7 +371,6 @@ menu "Mouse Options" config ZMK_MOUSE bool "Enable ZMK mouse emulation" - default n #Mouse Options endmenu @@ -382,7 +379,6 @@ menu "Power Management" config ZMK_BATTERY_REPORTING bool "Battery level detection/reporting" - default n select SENSOR select ZMK_LOW_PRIORITY_WORK_QUEUE imply BT_BAS if ZMK_BLE @@ -616,7 +612,6 @@ config FPU config ZMK_WPM bool "Calculate WPM" - default n config ZMK_KEYMAP_SENSORS bool "Enable Keymap Sensors support" diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 11bc8c5900f..7a1e44f6db5 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -14,7 +14,6 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON bool - default n config ZMK_BEHAVIOR_SENSOR_ROTATE bool diff --git a/app/src/display/Kconfig b/app/src/display/Kconfig index 356b4760c1b..1cde0fe4e29 100644 --- a/app/src/display/Kconfig +++ b/app/src/display/Kconfig @@ -3,7 +3,6 @@ menuconfig ZMK_DISPLAY bool "Enable ZMK Display" - default n select DISPLAY select LVGL select LV_CONF_MINIMAL From b44ec381f69233d1c2d32c6501189e4e339ff876 Mon Sep 17 00:00:00 2001 From: Seth Milliken Date: Fri, 9 Feb 2024 01:02:49 -0800 Subject: [PATCH 010/134] feat(boards): add encoder support to planck --- app/boards/arm/planck/planck_rev6.dts | 14 ++++++++++++++ app/boards/arm/planck/planck_rev6.keymap | 6 ++++++ app/boards/arm/planck/planck_rev6.zmk.yml | 1 + app/boards/arm/planck/planck_rev6_defconfig | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/app/boards/arm/planck/planck_rev6.dts b/app/boards/arm/planck/planck_rev6.dts index b6f6fca431d..5b8e16b2efe 100644 --- a/app/boards/arm/planck/planck_rev6.dts +++ b/app/boards/arm/planck/planck_rev6.dts @@ -44,6 +44,20 @@ ; }; + encoder: encoder { + compatible = "alps,ec11"; + a-gpios = <&gpiob 12 GPIO_PULL_UP>; + b-gpios = <&gpiob 13 GPIO_PULL_UP>; + steps = <80>; + status = "disabled"; + }; + + sensors: sensors { + compatible = "zmk,keymap-sensors"; + sensors = <&encoder>; + triggers-per-rotation = <20>; + }; + layout_grid_transform: keymap_transform_0 { compatible = "zmk,matrix-transform"; diff --git a/app/boards/arm/planck/planck_rev6.keymap b/app/boards/arm/planck/planck_rev6.keymap index 65138057283..1386eadd18b 100644 --- a/app/boards/arm/planck/planck_rev6.keymap +++ b/app/boards/arm/planck/planck_rev6.keymap @@ -7,6 +7,11 @@ #include #include +/* Uncomment this block if using an encoder */ +//&encoder { +// status = "okay"; +//}; + / { keymap { compatible = "zmk,keymap"; @@ -23,6 +28,7 @@ &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp SLASH &kp RET &trans &kp LCTL &kp LALT &kp LGUI &mo 1 &trans &kp SPACE &mo 2 &kp LEFT &kp DOWN &kp UP &kp RIGHT >; + sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; }; lower { diff --git a/app/boards/arm/planck/planck_rev6.zmk.yml b/app/boards/arm/planck/planck_rev6.zmk.yml index 56c0000671f..f9d42424742 100644 --- a/app/boards/arm/planck/planck_rev6.zmk.yml +++ b/app/boards/arm/planck/planck_rev6.zmk.yml @@ -5,6 +5,7 @@ type: board arch: arm features: - keys + - encoder outputs: - usb url: https://olkb.com/collections/planck diff --git a/app/boards/arm/planck/planck_rev6_defconfig b/app/boards/arm/planck/planck_rev6_defconfig index ce08f41dff8..f453063900f 100644 --- a/app/boards/arm/planck/planck_rev6_defconfig +++ b/app/boards/arm/planck/planck_rev6_defconfig @@ -14,3 +14,7 @@ CONFIG_GPIO=y CONFIG_CLOCK_CONTROL=y CONFIG_ZMK_USB=y + +# Uncomment these two lines to add support for encoder to your firmware +#CONFIG_EC11=y +#CONFIG_EC11_TRIGGER_OWN_THREAD=y From 104c73d303dea42d8abe23230035597e5cfa4863 Mon Sep 17 00:00:00 2001 From: Xudong Zheng <7pkvm5aw@slicealias.com> Date: Thu, 9 Nov 2023 10:42:56 -0500 Subject: [PATCH 011/134] refactor: address transport switch enumeration warning When building without USB or Bluetooth, the compiler emits a warning due to ZMK_TRANSPORT_USB or ZMK_TRANSPORT_BLE not being handled. --- app/src/endpoints.c | 48 +++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/app/src/endpoints.c b/app/src/endpoints.c index 395d6ba502a..f8452d93fbb 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -122,57 +122,69 @@ struct zmk_endpoint_instance zmk_endpoints_selected(void) { static int send_keyboard_report(void) { switch (current_instance.transport) { -#if IS_ENABLED(CONFIG_ZMK_USB) case ZMK_TRANSPORT_USB: { +#if IS_ENABLED(CONFIG_ZMK_USB) int err = zmk_usb_hid_send_keyboard_report(); if (err) { LOG_ERR("FAILED TO SEND OVER USB: %d", err); } return err; - } +#else + LOG_ERR("USB endpoint is not supported"); + return -ENOTSUP; #endif /* IS_ENABLED(CONFIG_ZMK_USB) */ + } -#if IS_ENABLED(CONFIG_ZMK_BLE) case ZMK_TRANSPORT_BLE: { +#if IS_ENABLED(CONFIG_ZMK_BLE) struct zmk_hid_keyboard_report *keyboard_report = zmk_hid_get_keyboard_report(); int err = zmk_hog_send_keyboard_report(&keyboard_report->body); if (err) { LOG_ERR("FAILED TO SEND OVER HOG: %d", err); } return err; - } +#else + LOG_ERR("BLE HOG endpoint is not supported"); + return -ENOTSUP; #endif /* IS_ENABLED(CONFIG_ZMK_BLE) */ } + } - LOG_ERR("Unsupported endpoint transport %d", current_instance.transport); + LOG_ERR("Unhandled endpoint transport %d", current_instance.transport); return -ENOTSUP; } static int send_consumer_report(void) { switch (current_instance.transport) { -#if IS_ENABLED(CONFIG_ZMK_USB) case ZMK_TRANSPORT_USB: { +#if IS_ENABLED(CONFIG_ZMK_USB) int err = zmk_usb_hid_send_consumer_report(); if (err) { LOG_ERR("FAILED TO SEND OVER USB: %d", err); } return err; - } +#else + LOG_ERR("USB endpoint is not supported"); + return -ENOTSUP; #endif /* IS_ENABLED(CONFIG_ZMK_USB) */ + } -#if IS_ENABLED(CONFIG_ZMK_BLE) case ZMK_TRANSPORT_BLE: { +#if IS_ENABLED(CONFIG_ZMK_BLE) struct zmk_hid_consumer_report *consumer_report = zmk_hid_get_consumer_report(); int err = zmk_hog_send_consumer_report(&consumer_report->body); if (err) { LOG_ERR("FAILED TO SEND OVER HOG: %d", err); } return err; - } +#else + LOG_ERR("BLE HOG endpoint is not supported"); + return -ENOTSUP; #endif /* IS_ENABLED(CONFIG_ZMK_BLE) */ } + } - LOG_ERR("Unsupported endpoint transport %d", current_instance.transport); + LOG_ERR("Unhandled endpoint transport %d", current_instance.transport); return -ENOTSUP; } @@ -194,29 +206,35 @@ int zmk_endpoints_send_report(uint16_t usage_page) { #if IS_ENABLED(CONFIG_ZMK_MOUSE) int zmk_endpoints_send_mouse_report() { switch (current_instance.transport) { -#if IS_ENABLED(CONFIG_ZMK_USB) case ZMK_TRANSPORT_USB: { +#if IS_ENABLED(CONFIG_ZMK_USB) int err = zmk_usb_hid_send_mouse_report(); if (err) { LOG_ERR("FAILED TO SEND OVER USB: %d", err); } return err; - } +#else + LOG_ERR("USB endpoint is not supported"); + return -ENOTSUP; #endif /* IS_ENABLED(CONFIG_ZMK_USB) */ + } -#if IS_ENABLED(CONFIG_ZMK_BLE) case ZMK_TRANSPORT_BLE: { +#if IS_ENABLED(CONFIG_ZMK_BLE) struct zmk_hid_mouse_report *mouse_report = zmk_hid_get_mouse_report(); int err = zmk_hog_send_mouse_report(&mouse_report->body); if (err) { LOG_ERR("FAILED TO SEND OVER HOG: %d", err); } return err; - } +#else + LOG_ERR("BLE HOG endpoint is not supported"); + return -ENOTSUP; #endif /* IS_ENABLED(CONFIG_ZMK_BLE) */ } + } - LOG_ERR("Unsupported endpoint transport %d", current_instance.transport); + LOG_ERR("Unhandled endpoint transport %d", current_instance.transport); return -ENOTSUP; } #endif // IS_ENABLED(CONFIG_ZMK_MOUSE) From c007d6035778fc3e34d56e82756e747c745085b8 Mon Sep 17 00:00:00 2001 From: Theo Lemay Date: Mon, 22 May 2023 19:34:29 -0700 Subject: [PATCH 012/134] feat(behaviors): hold while undecided --- .../behaviors/zmk,behavior-hold-tap.yaml | 4 + app/src/behaviors/behavior_hold_tap.c | 105 ++++++++++++++---- .../1-tap/events.patterns | 4 + .../1-tap/keycode_events.snapshot | 8 ++ .../1-tap/native_posix_64.keymap | 36 ++++++ .../2-hold/events.patterns | 4 + .../2-hold/keycode_events.snapshot | 6 + .../2-hold/native_posix_64.keymap | 36 ++++++ .../3-linger/events.patterns | 4 + .../3-linger/keycode_events.snapshot | 8 ++ .../3-linger/native_posix_64.keymap | 37 ++++++ .../4-linger-sk/events.patterns | 4 + .../4-linger-sk/keycode_events.snapshot | 7 ++ .../4-linger-sk/native_posix_64.keymap | 37 ++++++ docs/docs/behaviors/hold-tap.mdx | 12 ++ docs/docs/config/behaviors.md | 22 ++-- 16 files changed, 303 insertions(+), 31 deletions(-) create mode 100644 app/tests/hold-tap/hold-while-undecided/1-tap/events.patterns create mode 100644 app/tests/hold-tap/hold-while-undecided/1-tap/keycode_events.snapshot create mode 100644 app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap create mode 100644 app/tests/hold-tap/hold-while-undecided/2-hold/events.patterns create mode 100644 app/tests/hold-tap/hold-while-undecided/2-hold/keycode_events.snapshot create mode 100644 app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap create mode 100644 app/tests/hold-tap/hold-while-undecided/3-linger/events.patterns create mode 100644 app/tests/hold-tap/hold-while-undecided/3-linger/keycode_events.snapshot create mode 100644 app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap create mode 100644 app/tests/hold-tap/hold-while-undecided/4-linger-sk/events.patterns create mode 100644 app/tests/hold-tap/hold-while-undecided/4-linger-sk/keycode_events.snapshot create mode 100644 app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap diff --git a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml index 575754116b1..76f14d12d4e 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml @@ -37,6 +37,10 @@ properties: - "balanced" - "tap-preferred" - "tap-unless-interrupted" + hold-while-undecided: + type: boolean + hold-while-undecided-linger: + type: boolean retro-tap: type: boolean hold-trigger-key-positions: diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index efc96c1a3f2..01587caf5e4 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -45,6 +45,7 @@ enum status { }; enum decision_moment { + HT_KEY_DOWN, HT_KEY_UP, HT_OTHER_KEY_DOWN, HT_OTHER_KEY_UP, @@ -59,6 +60,8 @@ struct behavior_hold_tap_config { int quick_tap_ms; int require_prior_idle_ms; enum flavor flavor; + bool hold_while_undecided; + bool hold_while_undecided_linger; bool retro_tap; bool hold_trigger_on_release; int32_t hold_trigger_key_positions_len; @@ -387,47 +390,87 @@ static inline const char *decision_moment_str(enum decision_moment decision_mome } } -static int press_binding(struct active_hold_tap *hold_tap) { - if (hold_tap->config->retro_tap && hold_tap->status == STATUS_HOLD_TIMER) { - return 0; - } +static int press_hold_binding(struct active_hold_tap *hold_tap) { + struct zmk_behavior_binding_event event = { + .position = hold_tap->position, + .timestamp = hold_tap->timestamp, + }; + struct zmk_behavior_binding binding = {0}; + binding.behavior_dev = hold_tap->config->hold_behavior_dev; + binding.param1 = hold_tap->param_hold; + return behavior_keymap_binding_pressed(&binding, event); +} + +static int press_tap_binding(struct active_hold_tap *hold_tap) { struct zmk_behavior_binding_event event = { .position = hold_tap->position, .timestamp = hold_tap->timestamp, }; struct zmk_behavior_binding binding = {0}; - if (hold_tap->status == STATUS_HOLD_TIMER || hold_tap->status == STATUS_HOLD_INTERRUPT) { - binding.behavior_dev = hold_tap->config->hold_behavior_dev; - binding.param1 = hold_tap->param_hold; - } else { - binding.behavior_dev = hold_tap->config->tap_behavior_dev; - binding.param1 = hold_tap->param_tap; - store_last_hold_tapped(hold_tap); - } + binding.behavior_dev = hold_tap->config->tap_behavior_dev; + binding.param1 = hold_tap->param_tap; + store_last_hold_tapped(hold_tap); return behavior_keymap_binding_pressed(&binding, event); } -static int release_binding(struct active_hold_tap *hold_tap) { - if (hold_tap->config->retro_tap && hold_tap->status == STATUS_HOLD_TIMER) { - return 0; - } +static int release_hold_binding(struct active_hold_tap *hold_tap) { + struct zmk_behavior_binding_event event = { + .position = hold_tap->position, + .timestamp = hold_tap->timestamp, + }; + struct zmk_behavior_binding binding = {0}; + binding.behavior_dev = hold_tap->config->hold_behavior_dev; + binding.param1 = hold_tap->param_hold; + return behavior_keymap_binding_released(&binding, event); +} + +static int release_tap_binding(struct active_hold_tap *hold_tap) { struct zmk_behavior_binding_event event = { .position = hold_tap->position, .timestamp = hold_tap->timestamp, }; struct zmk_behavior_binding binding = {0}; + binding.behavior_dev = hold_tap->config->tap_behavior_dev; + binding.param1 = hold_tap->param_tap; + return behavior_keymap_binding_released(&binding, event); +} + +static int press_binding(struct active_hold_tap *hold_tap) { + if (hold_tap->config->retro_tap && hold_tap->status == STATUS_HOLD_TIMER) { + return 0; + } + if (hold_tap->status == STATUS_HOLD_TIMER || hold_tap->status == STATUS_HOLD_INTERRUPT) { - binding.behavior_dev = hold_tap->config->hold_behavior_dev; - binding.param1 = hold_tap->param_hold; + if (hold_tap->config->hold_while_undecided) { + // the hold is already active, so we don't need to press it again + return 0; + } else { + return press_hold_binding(hold_tap); + } } else { - binding.behavior_dev = hold_tap->config->tap_behavior_dev; - binding.param1 = hold_tap->param_tap; + if (hold_tap->config->hold_while_undecided && + !hold_tap->config->hold_while_undecided_linger) { + // time to release the hold before pressing the tap + release_hold_binding(hold_tap); + } + return press_tap_binding(hold_tap); + } +} + +static int release_binding(struct active_hold_tap *hold_tap) { + if (hold_tap->config->retro_tap && hold_tap->status == STATUS_HOLD_TIMER) { + return 0; + } + + if (hold_tap->status == STATUS_HOLD_TIMER || hold_tap->status == STATUS_HOLD_INTERRUPT) { + return release_hold_binding(hold_tap); + } else { + return release_tap_binding(hold_tap); } - return behavior_keymap_binding_released(&binding, event); } static bool is_first_other_key_pressed_trigger_key(struct active_hold_tap *hold_tap) { @@ -474,6 +517,12 @@ static void decide_hold_tap(struct active_hold_tap *hold_tap, return; } + if (hold_tap->config->hold_while_undecided && decision_moment == HT_KEY_DOWN) { + LOG_DBG("%d hold behavior pressed while undecided", hold_tap->position); + press_hold_binding(hold_tap); + return; + } + // If the hold-tap behavior is still undecided, attempt to decide it. switch (hold_tap->config->flavor) { case FLAVOR_HOLD_PREFERRED: @@ -561,6 +610,8 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding, decide_hold_tap(hold_tap, HT_QUICK_TAP); } + decide_hold_tap(hold_tap, HT_KEY_DOWN); + // if this behavior was queued we have to adjust the timer to only // wait for the remaining time. int32_t tapping_term_ms_left = (hold_tap->timestamp + cfg->tapping_term_ms) - k_uptime_get(); @@ -588,6 +639,10 @@ static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding, decide_retro_tap(hold_tap); release_binding(hold_tap); + if (hold_tap->config->hold_while_undecided && hold_tap->config->hold_while_undecided_linger) { + release_hold_binding(hold_tap); + } + if (work_cancel_result == -EINPROGRESS) { // let the timer handler clean up // if we'd clear now, the timer may call back for an uninitialized active_hold_tap. @@ -685,6 +740,12 @@ static int keycode_state_changed_listener(const zmk_event_t *eh) { return ZMK_EV_EVENT_BUBBLE; } + // hold-while-undecided can produce a mod, but we don't want to capture it. + if (undecided_hold_tap->config->hold_while_undecided && + undecided_hold_tap->status == STATUS_UNDECIDED) { + return ZMK_EV_EVENT_BUBBLE; + } + // only key-up events will bubble through position_state_changed_listener // if a undecided_hold_tap is active. LOG_DBG("%d capturing 0x%02X %s event", undecided_hold_tap->position, ev->keycode, @@ -743,6 +804,8 @@ static int behavior_hold_tap_init(const struct device *dev) { ? DT_INST_PROP(n, quick_tap_ms) \ : DT_INST_PROP(n, require_prior_idle_ms), \ .flavor = DT_ENUM_IDX(DT_DRV_INST(n), flavor), \ + .hold_while_undecided = DT_INST_PROP(n, hold_while_undecided), \ + .hold_while_undecided_linger = DT_INST_PROP(n, hold_while_undecided_linger), \ .retro_tap = DT_INST_PROP(n, retro_tap), \ .hold_trigger_on_release = DT_INST_PROP(n, hold_trigger_on_release), \ .hold_trigger_key_positions = DT_INST_PROP(n, hold_trigger_key_positions), \ diff --git a/app/tests/hold-tap/hold-while-undecided/1-tap/events.patterns b/app/tests/hold-tap/hold-while-undecided/1-tap/events.patterns new file mode 100644 index 00000000000..fdf2b15cf25 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/1-tap/events.patterns @@ -0,0 +1,4 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*on_hold_tap_binding/ht_binding/p +s/.*decide_hold_tap/ht_decide/p \ No newline at end of file diff --git a/app/tests/hold-tap/hold-while-undecided/1-tap/keycode_events.snapshot b/app/tests/hold-tap/hold-while-undecided/1-tap/keycode_events.snapshot new file mode 100644 index 00000000000..7cbc8268869 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/1-tap/keycode_events.snapshot @@ -0,0 +1,8 @@ +ht_binding_pressed: 0 new undecided hold_tap +ht_decide: 0 hold behavior pressed while undecided +kp_pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_decide: 0 decided tap (balanced decision moment key-up) +kp_released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +ht_binding_released: 0 cleaning up hold-tap diff --git a/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap new file mode 100644 index 00000000000..09396dd8248 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap @@ -0,0 +1,36 @@ +#include +#include +#include + +/ { + behaviors { + ht_bal: behavior_hold_tap_balanced { + compatible = "zmk,behavior-hold-tap"; + label = "HOLD_TAP_BALANCED"; + #binding-cells = <2>; + flavor = "balanced"; + tapping-term-ms = <300>; + quick-tap-ms = <200>; + bindings = <&kp>, <&kp>; + hold-while-undecided; + }; + }; + + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &ht_bal LEFT_SHIFT A &ht_bal LEFT_CONTROL B + &kp D &kp RIGHT_CONTROL>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + >; +}; diff --git a/app/tests/hold-tap/hold-while-undecided/2-hold/events.patterns b/app/tests/hold-tap/hold-while-undecided/2-hold/events.patterns new file mode 100644 index 00000000000..fdf2b15cf25 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/2-hold/events.patterns @@ -0,0 +1,4 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*on_hold_tap_binding/ht_binding/p +s/.*decide_hold_tap/ht_decide/p \ No newline at end of file diff --git a/app/tests/hold-tap/hold-while-undecided/2-hold/keycode_events.snapshot b/app/tests/hold-tap/hold-while-undecided/2-hold/keycode_events.snapshot new file mode 100644 index 00000000000..d9eed61285d --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/2-hold/keycode_events.snapshot @@ -0,0 +1,6 @@ +ht_binding_pressed: 0 new undecided hold_tap +ht_decide: 0 hold behavior pressed while undecided +kp_pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_decide: 0 decided hold-timer (balanced decision moment timer) +kp_released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_binding_released: 0 cleaning up hold-tap diff --git a/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap new file mode 100644 index 00000000000..e3eaa8e05eb --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap @@ -0,0 +1,36 @@ +#include +#include +#include + +/ { + behaviors { + ht_bal: behavior_hold_tap_balanced { + compatible = "zmk,behavior-hold-tap"; + label = "HOLD_TAP_BALANCED"; + #binding-cells = <2>; + flavor = "balanced"; + tapping-term-ms = <100>; + quick-tap-ms = <200>; + bindings = <&kp>, <&kp>; + hold-while-undecided; + }; + }; + + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &ht_bal LEFT_SHIFT A &ht_bal LEFT_CONTROL B + &kp D &kp RIGHT_CONTROL>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,150) + ZMK_MOCK_RELEASE(0,0,10) + >; +}; diff --git a/app/tests/hold-tap/hold-while-undecided/3-linger/events.patterns b/app/tests/hold-tap/hold-while-undecided/3-linger/events.patterns new file mode 100644 index 00000000000..fdf2b15cf25 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/3-linger/events.patterns @@ -0,0 +1,4 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*on_hold_tap_binding/ht_binding/p +s/.*decide_hold_tap/ht_decide/p \ No newline at end of file diff --git a/app/tests/hold-tap/hold-while-undecided/3-linger/keycode_events.snapshot b/app/tests/hold-tap/hold-while-undecided/3-linger/keycode_events.snapshot new file mode 100644 index 00000000000..55c9bb32f76 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/3-linger/keycode_events.snapshot @@ -0,0 +1,8 @@ +ht_binding_pressed: 0 new undecided hold_tap +ht_decide: 0 hold behavior pressed while undecided +kp_pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_decide: 0 decided tap (balanced decision moment key-up) +kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +kp_released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_binding_released: 0 cleaning up hold-tap diff --git a/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap new file mode 100644 index 00000000000..4b694eb2d14 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap @@ -0,0 +1,37 @@ +#include +#include +#include + +/ { + behaviors { + ht_bal: behavior_hold_tap_balanced { + compatible = "zmk,behavior-hold-tap"; + label = "HOLD_TAP_BALANCED"; + #binding-cells = <2>; + flavor = "balanced"; + tapping-term-ms = <100>; + quick-tap-ms = <300>; + bindings = <&kp>, <&kp>; + hold-while-undecided; + hold-while-undecided-linger; + }; + }; + + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &ht_bal LEFT_SHIFT A &ht_bal LEFT_CONTROL B + &kp D &kp RIGHT_CONTROL>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + >; +}; diff --git a/app/tests/hold-tap/hold-while-undecided/4-linger-sk/events.patterns b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/events.patterns new file mode 100644 index 00000000000..fdf2b15cf25 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/events.patterns @@ -0,0 +1,4 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*on_hold_tap_binding/ht_binding/p +s/.*decide_hold_tap/ht_decide/p \ No newline at end of file diff --git a/app/tests/hold-tap/hold-while-undecided/4-linger-sk/keycode_events.snapshot b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/keycode_events.snapshot new file mode 100644 index 00000000000..74f88195b36 --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/keycode_events.snapshot @@ -0,0 +1,7 @@ +ht_binding_pressed: 0 new undecided hold_tap +ht_decide: 0 hold behavior pressed while undecided +kp_pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_decide: 0 decided tap (balanced decision moment key-up) +kp_pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +kp_released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +ht_binding_released: 0 cleaning up hold-tap diff --git a/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap new file mode 100644 index 00000000000..a748ae51fcf --- /dev/null +++ b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap @@ -0,0 +1,37 @@ +#include +#include +#include + +/ { + behaviors { + ht_bal: behavior_hold_tap_balanced { + compatible = "zmk,behavior-hold-tap"; + label = "HOLD_TAP_BALANCED"; + #binding-cells = <2>; + flavor = "balanced"; + tapping-term-ms = <100>; + quick-tap-ms = <200>; + bindings = <&kp>, <&sk>; + hold-while-undecided; + hold-while-undecided-linger; + }; + }; + + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &ht_bal LEFT_SHIFT LEFT_SHIFT &ht_bal LEFT_SHIFT LEFT_CONTROL + &kp D &kp RIGHT_CONTROL>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + >; +}; diff --git a/docs/docs/behaviors/hold-tap.mdx b/docs/docs/behaviors/hold-tap.mdx index 26af9f1d83a..191e820dd43 100644 --- a/docs/docs/behaviors/hold-tap.mdx +++ b/docs/docs/behaviors/hold-tap.mdx @@ -83,6 +83,18 @@ For example, if you press `&mt LEFT_SHIFT A` and then release it without pressin }; ``` +#### `hold-while-undecided` + +If enabled, the hold behavior will immediately be held on hold-tap press, and will release before the behavior is sent in the event the hold-tap resolves into a tap. With most modifiers this will not affect typing, and is useful for using modifiers with the mouse. + +:::note Alt/Win/Cmd behavior +In some applications/desktop environments, pressing Alt keycodes by itself will have its own behavior like activate a menu and Gui keycodes will bring up the start menu or an application launcher. +::: + +#### `hold-while-undecided-linger` + +If your tap behavior activates the same modifier as the hold behavior, and you want to avoid a double tap when transitioning from the hold to the tap, you can use `hold-while-undecided-linger`. When enabled, the hold behavior will continue to be held until _after_ the tap behavior is released. For example, if the hold is `&kp LGUI` and the tap is `&sk LGUI`, then with `hold-while-undecided-linger` enabled, the host will see `LGUI` held down continuously until the sticky key is finished, instead of seeing a release and press when transitioning from hold to sticky key. + #### Positional hold-tap and `hold-trigger-key-positions` Including `hold-trigger-key-positions` in your hold-tap definition turns on the positional hold-tap feature. With positional hold-tap enabled, if you press any key **NOT** listed in `hold-trigger-key-positions` before `tapping-term-ms` expires, it will produce a tap. diff --git a/docs/docs/config/behaviors.md b/docs/docs/config/behaviors.md index c31de5dd0a4..f8d2fe39eb6 100644 --- a/docs/docs/config/behaviors.md +++ b/docs/docs/config/behaviors.md @@ -57,16 +57,18 @@ Definition file: [zmk/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml](htt Applies to: `compatible = "zmk,behavior-hold-tap"` -| Property | Type | Description | Default | -| ---------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------- | ------------------ | -| `#binding-cells` | int | Must be `<2>` | | -| `bindings` | phandle array | A list of two behaviors (without parameters): one for hold and one for tap | | -| `flavor` | string | Adjusts how the behavior chooses between hold and tap | `"hold-preferred"` | -| `tapping-term-ms` | int | How long in milliseconds the key must be held to trigger a hold | | -| `quick-tap-ms` | int | Tap twice within this period (in milliseconds) to trigger a tap, even when held | -1 (disabled) | -| `require-prior-idle-ms` | int | Triggers a tap immediately if any non-modifier key was pressed within `require-prior-idle-ms` of the hold-tap. | -1 (disabled) | -| `retro-tap` | bool | Triggers the tap behavior on release if no other key was pressed during a hold | false | -| `hold-trigger-key-positions` | array | If set, pressing the hold-tap and then any key position _not_ in the list triggers a tap. | | +| Property | Type | Description | Default | +| ----------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------- | ------------------ | +| `#binding-cells` | int | Must be `<2>` | | +| `bindings` | phandle array | A list of two behaviors (without parameters): one for hold and one for tap | | +| `flavor` | string | Adjusts how the behavior chooses between hold and tap | `"hold-preferred"` | +| `tapping-term-ms` | int | How long in milliseconds the key must be held to trigger a hold | | +| `quick-tap-ms` | int | Tap twice within this period (in milliseconds) to trigger a tap, even when held | -1 (disabled) | +| `require-prior-idle-ms` | int | Triggers a tap immediately if any non-modifier key was pressed within `require-prior-idle-ms` of the hold-tap. | -1 (disabled) | +| `retro-tap` | bool | Triggers the tap behavior on release if no other key was pressed during a hold | false | +| `hold-while-undecided` | bool | Triggers the hold behavior immediately on press and releases before a tap | false | +| `hold-while-undecided-linger` | bool | Continues to hold the hold behavior until after the tap is released | false | +| `hold-trigger-key-positions` | array | If set, pressing the hold-tap and then any key position _not_ in the list triggers a tap. | | This behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. From 8b20874c99ea191afbfc5ec3169e7f211986a853 Mon Sep 17 00:00:00 2001 From: Theo Lemay Date: Mon, 18 Dec 2023 21:34:38 -0500 Subject: [PATCH 013/134] chore: remove label in test --- .../hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap | 2 -- .../hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap | 2 -- .../hold-while-undecided/3-linger/native_posix_64.keymap | 2 -- .../hold-while-undecided/4-linger-sk/native_posix_64.keymap | 2 -- 4 files changed, 8 deletions(-) diff --git a/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap index 09396dd8248..5f42c30c8b2 100644 --- a/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap +++ b/app/tests/hold-tap/hold-while-undecided/1-tap/native_posix_64.keymap @@ -6,7 +6,6 @@ behaviors { ht_bal: behavior_hold_tap_balanced { compatible = "zmk,behavior-hold-tap"; - label = "HOLD_TAP_BALANCED"; #binding-cells = <2>; flavor = "balanced"; tapping-term-ms = <300>; @@ -18,7 +17,6 @@ keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < diff --git a/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap index e3eaa8e05eb..381a7414a87 100644 --- a/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap +++ b/app/tests/hold-tap/hold-while-undecided/2-hold/native_posix_64.keymap @@ -6,7 +6,6 @@ behaviors { ht_bal: behavior_hold_tap_balanced { compatible = "zmk,behavior-hold-tap"; - label = "HOLD_TAP_BALANCED"; #binding-cells = <2>; flavor = "balanced"; tapping-term-ms = <100>; @@ -18,7 +17,6 @@ keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < diff --git a/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap index 4b694eb2d14..0a296b70fae 100644 --- a/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap +++ b/app/tests/hold-tap/hold-while-undecided/3-linger/native_posix_64.keymap @@ -6,7 +6,6 @@ behaviors { ht_bal: behavior_hold_tap_balanced { compatible = "zmk,behavior-hold-tap"; - label = "HOLD_TAP_BALANCED"; #binding-cells = <2>; flavor = "balanced"; tapping-term-ms = <100>; @@ -19,7 +18,6 @@ keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < diff --git a/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap index a748ae51fcf..557076bc4eb 100644 --- a/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap +++ b/app/tests/hold-tap/hold-while-undecided/4-linger-sk/native_posix_64.keymap @@ -6,7 +6,6 @@ behaviors { ht_bal: behavior_hold_tap_balanced { compatible = "zmk,behavior-hold-tap"; - label = "HOLD_TAP_BALANCED"; #binding-cells = <2>; flavor = "balanced"; tapping-term-ms = <100>; @@ -19,7 +18,6 @@ keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < From c9c620d19f603ea0c9d4264eff885912803ff74d Mon Sep 17 00:00:00 2001 From: Theo Lemay Date: Sat, 3 Feb 2024 17:25:50 -0500 Subject: [PATCH 014/134] fix: inline initialise --- app/src/behaviors/behavior_hold_tap.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 01587caf5e4..204e50f478b 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -396,9 +396,8 @@ static int press_hold_binding(struct active_hold_tap *hold_tap) { .timestamp = hold_tap->timestamp, }; - struct zmk_behavior_binding binding = {0}; - binding.behavior_dev = hold_tap->config->hold_behavior_dev; - binding.param1 = hold_tap->param_hold; + struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev, + .param1 = hold_tap->param_hold}; return behavior_keymap_binding_pressed(&binding, event); } @@ -408,9 +407,8 @@ static int press_tap_binding(struct active_hold_tap *hold_tap) { .timestamp = hold_tap->timestamp, }; - struct zmk_behavior_binding binding = {0}; - binding.behavior_dev = hold_tap->config->tap_behavior_dev; - binding.param1 = hold_tap->param_tap; + struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev, + .param1 = hold_tap->param_tap}; store_last_hold_tapped(hold_tap); return behavior_keymap_binding_pressed(&binding, event); } @@ -421,9 +419,8 @@ static int release_hold_binding(struct active_hold_tap *hold_tap) { .timestamp = hold_tap->timestamp, }; - struct zmk_behavior_binding binding = {0}; - binding.behavior_dev = hold_tap->config->hold_behavior_dev; - binding.param1 = hold_tap->param_hold; + struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev, + .param1 = hold_tap->param_hold}; return behavior_keymap_binding_released(&binding, event); } @@ -433,9 +430,8 @@ static int release_tap_binding(struct active_hold_tap *hold_tap) { .timestamp = hold_tap->timestamp, }; - struct zmk_behavior_binding binding = {0}; - binding.behavior_dev = hold_tap->config->tap_behavior_dev; - binding.param1 = hold_tap->param_tap; + struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev, + .param1 = hold_tap->param_tap}; return behavior_keymap_binding_released(&binding, event); } From db7b197790c57c3fb5b8281bd8242286921ae77c Mon Sep 17 00:00:00 2001 From: Andrew Kannan Date: Wed, 28 Feb 2024 13:39:04 -0500 Subject: [PATCH 015/134] fix(docs): Add underglow brightness min/max (#2180) --- docs/docs/config/underglow.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/docs/config/underglow.md b/docs/docs/config/underglow.md index 1209e60ecc0..e742e79192e 100644 --- a/docs/docs/config/underglow.md +++ b/docs/docs/config/underglow.md @@ -28,6 +28,8 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ | `CONFIG_ZMK_RGB_UNDERGLOW_SPD_START` | int | Default effect speed (1-5) | 3 | | `CONFIG_ZMK_RGB_UNDERGLOW_EFF_START` | int | Default effect index from the effect list (see below) | 0 | | `CONFIG_ZMK_RGB_UNDERGLOW_ON_START` | bool | Default on state | y | +| `CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN` | int | Minimum brightness in percent (0-100) | 0 | +| `CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX` | int | Maximum brightness in percent (0-100) | 100 | Values for `CONFIG_ZMK_RGB_UNDERGLOW_EFF_START`: From 37af94edde7b42f1894484831b6d958bc4b27124 Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:05:00 -0800 Subject: [PATCH 016/134] feat(docs): Add warning to new shield docs how Kconfig treats whitspaces Added a warning to the shield section explaining that Kconfig does not ignore whitespaces on function calls and therefore adding whitespaces after the comma will break functionality. --- docs/docs/development/new-shield.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index 0dcface373b..2cd82bc67e9 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -79,6 +79,10 @@ config SHIELD_MY_BOARD def_bool $(shields_list_contains,my_board) ``` +:::warning +Kconfig uses only commas for delimiters, and keeps all whitespaces in the function call. Therefore do not add a whitespace after the comma when configuring your shield as this would be treated as  my_board (with a leading whitespace) and will cause issues. +::: + This will make sure that a new configuration value named `SHIELD_MY_BOARD` is set to true whenever `my_board` is used as the shield name, either as the `SHIELD` variable [in a local build](build-flash.mdx) or in your `build.yaml` file [when using Github Actions](../customization). Note that this configuration value will be used in `Kconfig.defconfig` to set other properties about your shield, so make sure that they match. **For split boards**, you will need to add configurations for the left and right sides. For example, if your split halves are named `my_board_left` and `my_board_right`, it would look like this: From 08ab45fc7875a042c787d353ff0e3512319af030 Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:10:14 -0800 Subject: [PATCH 017/134] feat(CONTRIBUTING.md): Add info regarding ESLint --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe7292a8fee..bcc2aef190a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,6 +86,12 @@ documentation to areas not currently covered are greatly appreciated. ZMK uses `prettier` to format documentation files. You can run prettier with `npm run prettier:format`. You can setup git to run prettier automatically when you commit by installing the pre-commit hooks: `pip3 install pre-commit`, `pre-commit install`. +### Linting + +This repository utilizes ESLint for code linting to ensure consistent code style and identify potential errors or bugs early in the development process. + +You can run ESLint with `npm run lint` to verify your changes. + ## Code Contributions ### Development Setup From 2adaa00d1092e41ce11dfae46ce7d2a5bad97ead Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 8 Mar 2024 10:17:02 -0800 Subject: [PATCH 018/134] fix(build): Properly board revision keymaps. * Handle board keymap location for boards with Zephyr board revisions included. * Includes bare non-revision file and a revision specific keymap in case newer revision changes the layout/key positions. --- app/keymap-module/modules/modules.cmake | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/keymap-module/modules/modules.cmake b/app/keymap-module/modules/modules.cmake index c286809df1c..f513bcc4f5f 100644 --- a/app/keymap-module/modules/modules.cmake +++ b/app/keymap-module/modules/modules.cmake @@ -63,6 +63,13 @@ if(DEFINED SHIELD) string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}") endif() +string(FIND "${BOARD}" "@" REVISION_SEPARATOR_INDEX) +if(NOT (REVISION_SEPARATOR_INDEX EQUAL -1)) + math(EXPR BOARD_REVISION_INDEX "${REVISION_SEPARATOR_INDEX} + 1") + string(SUBSTRING ${BOARD} ${BOARD_REVISION_INDEX} -1 BOARD_REVISION) + string(SUBSTRING ${BOARD} 0 ${REVISION_SEPARATOR_INDEX} BOARD) +endif() + foreach(root ${BOARD_ROOT}) set(shield_dir ${root}/boards/shields) # Match the Kconfig.shield files in the shield directories to make sure we are @@ -107,6 +114,21 @@ foreach(root ${BOARD_ROOT}) endif() endforeach() +if(EXISTS ${BOARD_DIR}/revision.cmake) + # Board provides revision handling. + include(${BOARD_DIR}/revision.cmake) +elseif(BOARD_REVISION) + message(WARNING "Board revision ${BOARD_REVISION} specified for ${BOARD}, \ + but board has no revision so revision will be ignored.") +endif() + +if(DEFINED BOARD_REVISION) + string(REPLACE "." "_" BOARD_REVISION_STRING ${BOARD_REVISION}) + set(KEYMAP_BOARD_REVISION_PREFIX "${BOARD}_${BOARD_REVISION_STRING}") +else() + set(KEYMAP_BOARD_REVISION_PREFIX "") +endif() + # Give a shield like `kyria_rev2_left` we want to use `kyria_rev2` and `kyria` as candidate names for # overlay/conf/keymap files. if(DEFINED SHIELD) @@ -178,7 +200,7 @@ endif() if(NOT KEYMAP_FILE) foreach(keymap_dir ${KEYMAP_DIRS}) - foreach(keymap_prefix ${shield_candidate_names} ${SHIELD_AS_LIST} ${SHIELD_DIR} ${BOARD} ${BOARD_DIR_NAME}) + foreach(keymap_prefix ${shield_candidate_names} ${SHIELD_AS_LIST} ${SHIELD_DIR} ${KEYMAP_BOARD_REVISION_PREFIX} ${BOARD} ${BOARD_DIR_NAME}) if (EXISTS ${keymap_dir}/${keymap_prefix}.keymap) set(KEYMAP_FILE "${keymap_dir}/${keymap_prefix}.keymap" CACHE STRING "Selected keymap file") message(STATUS "Using keymap file: ${KEYMAP_FILE}") From 610a806c848ba53a454bbc66631fa3f3faaef19f Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 26 Nov 2023 12:27:12 -0600 Subject: [PATCH 019/134] feat: Add function to erase all settings Added a zmk_settings_erase() function to clear all saved settings. This does not go through Zephyr's settings subsystem, but instead directly clears the data from the setting storage backend, so a reboot is needed for it to take effect. --- app/CMakeLists.txt | 1 + app/include/zmk/settings.h | 15 ++++++++++ app/src/settings/CMakeLists.txt | 7 +++++ app/src/settings/reset_settings_fcb.c | 15 ++++++++++ app/src/settings/reset_settings_file.c | 23 +++++++++++++++ app/src/settings/reset_settings_none.c | 12 ++++++++ app/src/settings/reset_settings_nvs.c | 39 ++++++++++++++++++++++++++ 7 files changed, 112 insertions(+) create mode 100644 app/include/zmk/settings.h create mode 100644 app/src/settings/CMakeLists.txt create mode 100644 app/src/settings/reset_settings_fcb.c create mode 100644 app/src/settings/reset_settings_file.c create mode 100644 app/src/settings/reset_settings_none.c create mode 100644 app/src/settings/reset_settings_nvs.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 6ef00311027..b12d04742ee 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -99,5 +99,6 @@ target_sources_ifdef(CONFIG_ZMK_LOW_PRIORITY_WORK_QUEUE app PRIVATE src/workqueu target_sources(app PRIVATE src/main.c) add_subdirectory(src/display/) +add_subdirectory_ifdef(CONFIG_SETTINGS src/settings/) zephyr_cc_option(-Wfatal-errors) diff --git a/app/include/zmk/settings.h b/app/include/zmk/settings.h new file mode 100644 index 00000000000..5567d61b421 --- /dev/null +++ b/app/include/zmk/settings.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +/** + * Erases all saved settings. + * + * @note This does not automatically update any code using Zephyr's settings + * subsystem. This should typically be followed by a call to sys_reboot(). + */ +int zmk_settings_erase(void); diff --git a/app/src/settings/CMakeLists.txt b/app/src/settings/CMakeLists.txt new file mode 100644 index 00000000000..63bcd7f9522 --- /dev/null +++ b/app/src/settings/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +target_sources_ifdef(CONFIG_SETTINGS_NONE app PRIVATE reset_settings_none.c) +target_sources_ifdef(CONFIG_SETTINGS_FCB app PRIVATE reset_settings_fcb.c) +target_sources_ifdef(CONFIG_SETTINGS_FILE app PRIVATE reset_settings_file.c) +target_sources_ifdef(CONFIG_SETTINGS_NVS app PRIVATE reset_settings_nvs.c) diff --git a/app/src/settings/reset_settings_fcb.c b/app/src/settings/reset_settings_fcb.c new file mode 100644 index 00000000000..1d555d341e3 --- /dev/null +++ b/app/src/settings/reset_settings_fcb.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +int zmk_settings_erase(void) { + LOG_ERR("Settings reset is not implemented for deprecated FCB backend."); + return -ENOSYS; +} diff --git a/app/src/settings/reset_settings_file.c b/app/src/settings/reset_settings_file.c new file mode 100644 index 00000000000..1d142868d30 --- /dev/null +++ b/app/src/settings/reset_settings_file.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +int zmk_settings_erase(void) { + LOG_INF("Erasing settings file"); + + int rc = fs_unlink(CONFIG_SETTINGS_FS_FILE); + if (rc) { + LOG_ERR("Failed to unlink '%s': %d", CONFIG_SETTINGS_FS_FILE, rc); + } + + return rc; +} diff --git a/app/src/settings/reset_settings_none.c b/app/src/settings/reset_settings_none.c new file mode 100644 index 00000000000..c5e0ae0419c --- /dev/null +++ b/app/src/settings/reset_settings_none.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +int zmk_settings_erase(void) { + // No storage backend; nothing to do + return 0; +} diff --git a/app/src/settings/reset_settings_nvs.c b/app/src/settings/reset_settings_nvs.c new file mode 100644 index 00000000000..65157b3d154 --- /dev/null +++ b/app/src/settings/reset_settings_nvs.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +// SETTINGS_PARTITION must match settings_nvs.c +#if DT_HAS_CHOSEN(zephyr_settings_partition) +#define SETTINGS_PARTITION DT_FIXED_PARTITION_ID(DT_CHOSEN(zephyr_settings_partition)) +#else +#define SETTINGS_PARTITION FIXED_PARTITION_ID(storage_partition) +#endif + +int zmk_settings_erase(void) { + LOG_INF("Erasing settings flash partition"); + + const struct flash_area *fa; + int rc = flash_area_open(SETTINGS_PARTITION, &fa); + if (rc) { + LOG_ERR("Failed to open settings flash: %d", rc); + return rc; + } + + rc = flash_area_erase(fa, 0, fa->fa_size); + if (rc) { + LOG_ERR("Failed to erase settings flash: %d", rc); + } + + flash_area_close(fa); + + return rc; +} From 1dfcfc7d3f074e538900a6df684cc99e92c60a21 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 26 Nov 2023 12:28:27 -0600 Subject: [PATCH 020/134] feat(shields): Make settings_reset shield reset all settings Added a new CONFIG_ZMK_SETTINGS_RESET_ON_START option which enables init code to call zmk_settings_erase(), and changed the settings_reset shield to use it instead of CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START, so it now resets all settings instead of just clearing BLE bonds. CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START is left in place for now in case someone still needs it. It may be replaced in the future once we find a better way to repair a broken split connection. --- app/Kconfig | 3 +++ .../settings_reset/settings_reset.conf | 5 ++++- app/src/settings/CMakeLists.txt | 2 ++ app/src/settings/reset_settings_on_start.c | 19 +++++++++++++++++++ docs/docs/config/system.md | 13 +++++++------ 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 app/src/settings/reset_settings_on_start.c diff --git a/app/Kconfig b/app/Kconfig index bb6997a43ae..3f797abd41d 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -565,6 +565,9 @@ endmenu if SETTINGS +config ZMK_SETTINGS_RESET_ON_START + bool "Delete all persistent settings when the keyboard boots" + config ZMK_SETTINGS_SAVE_DEBOUNCE int "Milliseconds to debounce settings saves" default 60000 diff --git a/app/boards/shields/settings_reset/settings_reset.conf b/app/boards/shields/settings_reset/settings_reset.conf index 8052a6cf258..4ed84df856a 100644 --- a/app/boards/shields/settings_reset/settings_reset.conf +++ b/app/boards/shields/settings_reset/settings_reset.conf @@ -1 +1,4 @@ -CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y +CONFIG_SETTINGS=y +CONFIG_ZMK_SETTINGS_RESET_ON_START=y +# Disable BLE so splits don't try to re-pair until normal firmware is flashed. +CONFIG_ZMK_BLE=n diff --git a/app/src/settings/CMakeLists.txt b/app/src/settings/CMakeLists.txt index 63bcd7f9522..28664a4ef13 100644 --- a/app/src/settings/CMakeLists.txt +++ b/app/src/settings/CMakeLists.txt @@ -5,3 +5,5 @@ target_sources_ifdef(CONFIG_SETTINGS_NONE app PRIVATE reset_settings_none.c) target_sources_ifdef(CONFIG_SETTINGS_FCB app PRIVATE reset_settings_fcb.c) target_sources_ifdef(CONFIG_SETTINGS_FILE app PRIVATE reset_settings_file.c) target_sources_ifdef(CONFIG_SETTINGS_NVS app PRIVATE reset_settings_nvs.c) + +target_sources_ifdef(CONFIG_ZMK_SETTINGS_RESET_ON_START app PRIVATE reset_settings_on_start.c) diff --git a/app/src/settings/reset_settings_on_start.c b/app/src/settings/reset_settings_on_start.c new file mode 100644 index 00000000000..3b3890f469b --- /dev/null +++ b/app/src/settings/reset_settings_on_start.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include + +static int reset_settings_init(const struct device *dev) { + ARG_UNUSED(dev); + return zmk_settings_erase(); +} + +// Reset after the kernel is initialized but before any application code to +// ensure settings are cleared before anything tries to use them. +SYS_INIT(reset_settings_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 83f2f06545b..d60fa24e93f 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -13,12 +13,13 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ ### General -| Config | Type | Description | Default | -| ----------------------------------- | ------ | ----------------------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_KEYBOARD_NAME` | string | The name of the keyboard (max 16 characters) | | -| `CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE` | int | Milliseconds to wait after a setting change before writing it to flash memory | 60000 | -| `CONFIG_ZMK_WPM` | bool | Enable calculating words per minute | n | -| `CONFIG_HEAP_MEM_POOL_SIZE` | int | Size of the heap memory pool | 8192 | +| Config | Type | Description | Default | +| ------------------------------------ | ------ | ----------------------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_KEYBOARD_NAME` | string | The name of the keyboard (max 16 characters) | | +| `CONFIG_ZMK_SETTINGS_RESET_ON_START` | bool | Clears all persistent settings from the keyboard at startup | n | +| `CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE` | int | Milliseconds to wait after a setting change before writing it to flash memory | 60000 | +| `CONFIG_ZMK_WPM` | bool | Enable calculating words per minute | n | +| `CONFIG_HEAP_MEM_POOL_SIZE` | int | Size of the heap memory pool | 8192 | ### HID From 14b06a36bf5acecb52db57daf29046b334bf18df Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 4 Feb 2024 12:34:26 -0600 Subject: [PATCH 021/134] docs: Update settings_reset documentation Updated the section for troubleshooting split halves unable to pair now that the settings_reset shield resets all settings and explicitly disables CONFIG_ZMK_BLE: - Added a note that all settings will be reset. - Removed the section about immediately putting the halves into bootloader mode to prevent pairing, as this is not necessary anymore. - Added a note that you will not be able to see or pair the Bluetooth keyboard until you have flashed regular firmware again. - Added a sentence to clarify that you will need to re-pair the keyboard to all host devices. Also added some text describing common scenarios where this procedure might be needed. --- docs/docs/troubleshooting.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md index 769852d137c..bfa92218f5a 100644 --- a/docs/docs/troubleshooting.md +++ b/docs/docs/troubleshooting.md @@ -68,7 +68,20 @@ A common mistake that leads to this error is to use [key press keycodes](behavio ### Split Keyboard Halves Unable to Pair -Split keyboard halves pairing issue can be resolved by flashing a settings reset firmware to both controllers. You will first need to acquire the reset UF2 image file with one of the following options: +Split keyboard halves will automatically pair with one another, but there are some cases where this breaks, and the pairing needs to be reset, for example: + +- Switching which halves are the central/peripheral. +- Replacing the controller for one of the halves. + +These issues can be resolved by flashing a settings reset firmware to both controllers. + +:::warning + +This procedure will erase all settings, such as Bluetooth profiles, output selection, RGB underglow color, etc. + +::: + +First, acquire the reset UF2 image file with one of the following options: #### Option 1: Build Reset UF2 in 'zmk-config' @@ -101,8 +114,16 @@ Save the file, commit the changes and push them to GitHub. Download the new firm Perform the following steps to reset both halves of your split keyboard: 1. Put each half of the split keyboard into bootloader mode. -1. Flash one of the halves of the split with the downloaded settings reset UF2 image. Immediately after flashing the chosen half, put it into bootloader mode to avoid accidental bonding between the halves. +1. Flash one of the halves of the split with the downloaded settings reset UF2 image. 1. Repeat step 2 with the other half of the split keyboard. 1. Flash the actual image for each half of the split keyboard (e.g `my_board_left.uf2` to the left half, `my_board_right.uf2` to the right half). After completing these steps, pair the halves of the split keyboard together by resetting them at the same time. Most commonly, this is done by grounding the reset pins for each of your keyboard's microcontrollers or pressing the reset buttons at the same time. + +Once this is done, you can remove/forget the keyboard on each host device and pair it again. + +:::info + +The settings reset firmware has Bluetooth disabled to prevent the two sides from automatically re-pairing until you are done resetting them both. You will not be able to pair your keyboard or see it in any Bluetooth device lists until you have flashed the normal firmware again. + +::: From a77288f5274b8cd64aed5dc03bb6c03ec205240f Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sat, 24 Feb 2024 12:14:37 -0600 Subject: [PATCH 022/134] fix: Update settings reset for Zephyr 3.5 --- app/src/settings/reset_settings_on_start.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/settings/reset_settings_on_start.c b/app/src/settings/reset_settings_on_start.c index 3b3890f469b..47f5e8f2259 100644 --- a/app/src/settings/reset_settings_on_start.c +++ b/app/src/settings/reset_settings_on_start.c @@ -4,16 +4,10 @@ * SPDX-License-Identifier: MIT */ -#include #include #include -static int reset_settings_init(const struct device *dev) { - ARG_UNUSED(dev); - return zmk_settings_erase(); -} - // Reset after the kernel is initialized but before any application code to // ensure settings are cleared before anything tries to use them. -SYS_INIT(reset_settings_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); +SYS_INIT(zmk_settings_erase, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); From 388ad71385efe858a73c24c8dd7a373485ff4c83 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:54:47 +0000 Subject: [PATCH 023/134] feat(build): Explicit missing keymap node error * Explicit error if zmk,keymap not set * Document keymap error --------- Co-authored-by: Cem Aksoylar --- app/src/keymap.c | 6 ++++++ docs/docs/troubleshooting.md | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/app/src/keymap.c b/app/src/keymap.c index 75a2dcbe64b..94bd12048cf 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -31,6 +31,12 @@ static uint8_t _zmk_keymap_layer_default = 0; #define DT_DRV_COMPAT zmk_keymap +#if !DT_NODE_EXISTS(DT_DRV_INST(0)) + +#error "Keymap node not found, check a keymap is available and is has compatible = "zmk,keymap" set" + +#endif + #define TRANSFORMED_LAYER(node) \ { LISTIFY(DT_PROP_LEN(node, bindings), ZMK_KEYMAP_EXTRACT_BINDING, (, ), node) } diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md index bfa92218f5a..1f3c1706e34 100644 --- a/docs/docs/troubleshooting.md +++ b/docs/docs/troubleshooting.md @@ -40,6 +40,10 @@ West build errors usually indicate syntax problems in the `.keymap` fi If you are reviewing these errors in the GitHub Actions tab, they can be found in the `West Build` step of the build process. ::: +#### Keymap error + +If you get an error stating `Keymap node not found, check a keymap is available and is has compatible = "zmk,keymap" set` this is an indication that the build process cannot find the keymap. Double check that the `.keymap` file is present and has been discovered by the build process. This can be checked by looking for a line in the build log stating `-- Using keymap file: /path/to/keymap/file/.keymap`. Inside the keymap file ensure the keymap node has `compatible = zmk,keymap` and it's not misspelled. For more information see the [Keymap](features/keymaps.mdx) and [Config](config/index.md) documentation. + #### devicetree error A `devicetree error` followed by a reference to the line number on `.keymap` refers to an issue at the exact line position in that file. For example, below error message indicates a missing `;` at line 109 of the `cradio.keymap` file: From bddee70b6b73ccd8f3ff299d5b36dd0537e639e1 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Tue, 27 Feb 2024 11:08:58 -0800 Subject: [PATCH 024/134] refactor(docs): Remove outdated Windows battery advice and unnecessary header --- docs/docs/features/bluetooth.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/docs/docs/features/bluetooth.md b/docs/docs/features/bluetooth.md index c4e91fafd33..307ac7e18a5 100644 --- a/docs/docs/features/bluetooth.md +++ b/docs/docs/features/bluetooth.md @@ -56,18 +56,6 @@ This setting can also improve the connection strength between the keyboard halve If you want to test bluetooth output on your keyboard and are powering it through the USB connection rather than a battery, you will be able to pair with a host device but may not see keystrokes sent. In this case you need to use the [output selection behavior](../behaviors/outputs.md) to prefer sending keystrokes over bluetooth rather than USB. This might be necessary even if you are not powering from a device capable of receiving USB inputs, such as a USB charger. -## Known Issues - -There are a few known issues related to BLE and ZMK: - -### Windows Battery Reporting - -There is a known issue with Windows failing to update the battery information after connecting to a ZMK keyboard. You can work around this Windows bug by overriding a [Bluetooth config variable](../config/bluetooth.md) to force battery notifications even if a host neglects to subscribe to them: - -```ini -CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=n -``` - ### macOS Connected But Not Working If you attempt to pair a ZMK keyboard from macOS in a way that causes a bonding issue, macOS may report the keyboard as connected, but fail to actually work. If this occurs: From aa6cfe250d3324f918742c4e0ff232264d44f42c Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Tue, 27 Feb 2024 11:25:15 -0800 Subject: [PATCH 025/134] feat(docs): Document refreshing the HID descriptor --- docs/docs/features/bluetooth.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/docs/features/bluetooth.md b/docs/docs/features/bluetooth.md index 307ac7e18a5..1f2d795527a 100644 --- a/docs/docs/features/bluetooth.md +++ b/docs/docs/features/bluetooth.md @@ -36,6 +36,19 @@ Failure to manage the profiles can result in unexpected/broken behavior with hos Management of the bluetooth in ZMK is accomplished using the [`&bt` behavior](../behaviors/bluetooth.md). Be sure to refer to that documentation to learn how to manage profiles, switch between connected hosts, etc. +## Refreshing the HID Descriptor + +Enabling certain features or behaviors in ZMK changes the data structure that ZMK sends over USB or BLE to host devices. +This in turn requires [HID report descriptors](https://docs.kernel.org/hid/hidintro.html) to be modified for the reports to be parsed correctly. +Firmware changes that would modify the descriptor include the following: + +- Changing any of the settings under the [HID category](../config/system.md#hid), including enabling/disabling NKRO or HID indicators +- Enabling mouse features, such as adding [mouse keys](../behaviors/mouse-emulation.md) to your keymap + +While the descriptor refresh happens on boot for USB, hosts will frequently cache this descriptor for BLE devices. +In order to refresh this cache, you need to remove the keyboard from the host device, clear the profile associated with the host on the keyboard, then pair again. +For Windows systems you might need to follow the instructions in [this troubleshooting section](#windows-connected-but-not-working) below. + ## Troubleshooting ### Connectivity Issues From 325e2077817c096feef696a057e29ef4807d3d14 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Tue, 27 Feb 2024 11:30:33 -0800 Subject: [PATCH 026/134] feat(docs): Add pointers to HID descriptor refresh --- docs/docs/behaviors/mouse-emulation.md | 7 ++++++- docs/docs/config/system.md | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/docs/behaviors/mouse-emulation.md b/docs/docs/behaviors/mouse-emulation.md index 9ed0dd8e07b..7b80bae65d9 100644 --- a/docs/docs/behaviors/mouse-emulation.md +++ b/docs/docs/behaviors/mouse-emulation.md @@ -8,7 +8,12 @@ sidebar_label: Mouse Emulation Mouse emulation behaviors send mouse events. Currently, only mouse button presses are supported, but movement and scroll action support is planned for the future. -Whenever the Mouse Emulation feature is turned on or off, the HID protocol used to communicate events to hosts changes. Unfortunately, those changes are not always detected automatically, and might require re-pairing your keyboard to your devices to work over bluetooth. If mouse behaviors are still not recognized by your device after doing that, you can try [these troubleshooting steps](../features/bluetooth.md#windows-connected-but-not-working). +:::warning[Refreshing the HID descriptor] + +Enabling or disabling the mouse emulation feature modifies the HID report descriptor and requires it to be [refreshed](../features/bluetooth.md#refreshing-the-hid-descriptor). +The mouse functionality will not work over BLE until that is done. + +::: ## Configuration Option diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index d60fa24e93f..675830e4944 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -23,6 +23,12 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ ### HID +:::warning[Refreshing the HID descriptor] + +Making changes to any of the settings in this section modifies the HID report descriptor and requires it to be [refreshed](../features/bluetooth.md#refreshing-the-hid-descriptor). + +::: + | Config | Type | Description | Default | | ------------------------------------- | ---- | -------------------------------------------------------------- | ------- | | `CONFIG_ZMK_HID_INDICATORS` | bool | Enable reciept of HID/LED indicator state from connected hosts | n | From c6e0551fb0d29e4bbba967b4ea0264a1b2440b80 Mon Sep 17 00:00:00 2001 From: Hans Kruse Date: Mon, 18 Mar 2024 18:06:09 +0100 Subject: [PATCH 027/134] fix(hid): Fix typo in HID usage alias --- app/include/dt-bindings/zmk/hid_usage.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/include/dt-bindings/zmk/hid_usage.h b/app/include/dt-bindings/zmk/hid_usage.h index 0555f004c11..8c0e9470829 100644 --- a/app/include/dt-bindings/zmk/hid_usage.h +++ b/app/include/dt-bindings/zmk/hid_usage.h @@ -1109,7 +1109,7 @@ #define HID_USAGE_CONSUMER_AC_RENAME (0x298) // Sel #define HID_USAGE_CONSUMER_AC_MERGE (0x299) // Sel #define HID_USAGE_CONSUMER_AC_SPLIT (0x29A) // Sel -#define HID_USAGE_CONSUMER_AC_DISRIBUTE_HORIZONTALLY (0x29B) // Sel +#define HID_USAGE_CONSUMER_AC_DISTRIBUTE_HORIZONTALLY (0x29B) // Sel #define HID_USAGE_CONSUMER_AC_DISTRIBUTE_VERTICALLY (0x29C) // Sel #define HID_USAGE_CONSUMER_AC_NEXT_KEYBOARD_LAYOUT_SELECT (0x29D) // Sel #define HID_USAGE_CONSUMER_AC_NAVIGATION_GUIDANCE (0x29E) // Sel @@ -2563,4 +2563,4 @@ #define HID_USAGE_FIDO_UNDEFINED (0x00) #define HID_USAGE_FIDO_U2F_AUTHENTICATOR_DEVICE (0x01) // CA #define HID_USAGE_FIDO_INPUT_REPORT_DATA (0x20) // DV -#define HID_USAGE_FIDO_OUTPUT_REPORT_DATA (0x21) // DV \ No newline at end of file +#define HID_USAGE_FIDO_OUTPUT_REPORT_DATA (0x21) // DV From 3a3897968461141bcf6cf2fadef039ea9ecbd727 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:21:14 -0500 Subject: [PATCH 028/134] refactor: replace tapping_term_ms with tapping-term-ms * The underscore form of this property is deprecated. --- app/boards/arm/ferris/ferris_rev02.keymap | 2 +- app/boards/shields/clog/clog.keymap | 2 +- app/boards/shields/hummingbird/hummingbird.keymap | 2 +- app/boards/shields/osprette/osprette.keymap | 2 +- .../shields/splitkb_aurora_sweep/splitkb_aurora_sweep.keymap | 2 +- app/tests/hold-tap/balanced/6-retro-tap/native_posix_64.keymap | 2 +- .../hold-tap/hold-preferred/6-retro-tap/native_posix_64.keymap | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/boards/arm/ferris/ferris_rev02.keymap b/app/boards/arm/ferris/ferris_rev02.keymap index dc298ec8d52..9733570c273 100644 --- a/app/boards/arm/ferris/ferris_rev02.keymap +++ b/app/boards/arm/ferris/ferris_rev02.keymap @@ -21,7 +21,7 @@ hm: homerow_mods { compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; - tapping_term_ms = <200>; + tapping-term-ms = <200>; flavor = "tap-preferred"; bindings = <&kp>, <&kp>; }; diff --git a/app/boards/shields/clog/clog.keymap b/app/boards/shields/clog/clog.keymap index 885404f7325..d00b00c9d5b 100644 --- a/app/boards/shields/clog/clog.keymap +++ b/app/boards/shields/clog/clog.keymap @@ -15,7 +15,7 @@ &mt { flavor = "tap-preferred"; - tapping_term_ms = <140>; + tapping-term-ms = <140>; }; / { diff --git a/app/boards/shields/hummingbird/hummingbird.keymap b/app/boards/shields/hummingbird/hummingbird.keymap index 9f1a24c2d03..0b9ee76bb02 100644 --- a/app/boards/shields/hummingbird/hummingbird.keymap +++ b/app/boards/shields/hummingbird/hummingbird.keymap @@ -20,7 +20,7 @@ hm: homerow_mods { compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; - tapping_term_ms = <225>; + tapping-term-ms = <225>; flavor = "tap-preferred"; bindings = <&kp>, <&kp>; }; diff --git a/app/boards/shields/osprette/osprette.keymap b/app/boards/shields/osprette/osprette.keymap index 9c9213b6ff2..77e62fa015b 100644 --- a/app/boards/shields/osprette/osprette.keymap +++ b/app/boards/shields/osprette/osprette.keymap @@ -15,7 +15,7 @@ &mt { flavor = "tap-preferred"; - tapping_term_ms = <140>; + tapping-term-ms = <140>; }; / { diff --git a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep.keymap b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep.keymap index 4b57beac644..9198a5572f0 100644 --- a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep.keymap +++ b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep.keymap @@ -11,7 +11,7 @@ &mt { // flavor = "tap-preferred"; - // tapping_term_ms = <200>; + // tapping-term-ms = <200>; }; / { diff --git a/app/tests/hold-tap/balanced/6-retro-tap/native_posix_64.keymap b/app/tests/hold-tap/balanced/6-retro-tap/native_posix_64.keymap index f9bda1cfd99..c820d191c2e 100644 --- a/app/tests/hold-tap/balanced/6-retro-tap/native_posix_64.keymap +++ b/app/tests/hold-tap/balanced/6-retro-tap/native_posix_64.keymap @@ -8,7 +8,7 @@ compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; flavor = "balanced"; - tapping_term_ms = <300>; + tapping-term-ms = <300>; bindings = <&kp>, <&kp>; retro-tap; }; diff --git a/app/tests/hold-tap/hold-preferred/6-retro-tap/native_posix_64.keymap b/app/tests/hold-tap/hold-preferred/6-retro-tap/native_posix_64.keymap index 8aa29dec443..0b80ea95b3f 100644 --- a/app/tests/hold-tap/hold-preferred/6-retro-tap/native_posix_64.keymap +++ b/app/tests/hold-tap/hold-preferred/6-retro-tap/native_posix_64.keymap @@ -8,7 +8,7 @@ compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; flavor = "hold-preferred"; - tapping_term_ms = <300>; + tapping-term-ms = <300>; bindings = <&kp>, <&kp>; retro-tap; }; From 6f2e19ff88efcd4ca9da2da4996d10f24d30b333 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:29:11 -0500 Subject: [PATCH 029/134] refactor: replace quick_tap_ms with quick-tap-ms * The underscore form of this property is deprecated. --- app/boards/arm/ferris/ferris_rev02.keymap | 2 +- app/boards/shields/hummingbird/hummingbird.keymap | 2 +- app/boards/shields/jian/jian.keymap | 4 ++-- app/tests/tap-dance/behavior_keymap.dtsi | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/boards/arm/ferris/ferris_rev02.keymap b/app/boards/arm/ferris/ferris_rev02.keymap index 9733570c273..b7668416b3c 100644 --- a/app/boards/arm/ferris/ferris_rev02.keymap +++ b/app/boards/arm/ferris/ferris_rev02.keymap @@ -14,7 +14,7 @@ #define SYM_L 4 // Using layer taps on thumbs, having quick tap as well helps w/ repeating space/backspace -< { quick_tap_ms = <200>; }; +< { quick-tap-ms = <200>; }; / { behaviors { diff --git a/app/boards/shields/hummingbird/hummingbird.keymap b/app/boards/shields/hummingbird/hummingbird.keymap index 0b9ee76bb02..c96071f6c25 100644 --- a/app/boards/shields/hummingbird/hummingbird.keymap +++ b/app/boards/shields/hummingbird/hummingbird.keymap @@ -13,7 +13,7 @@ #define SYM_L 3 // Using layer taps on thumbs, having quick tap as well helps w/ repeating space/backspace -< { quick_tap_ms = <200>; }; +< { quick-tap-ms = <200>; }; / { behaviors { diff --git a/app/boards/shields/jian/jian.keymap b/app/boards/shields/jian/jian.keymap index e8f7dcc87a1..bfd2918cc74 100644 --- a/app/boards/shields/jian/jian.keymap +++ b/app/boards/shields/jian/jian.keymap @@ -13,8 +13,8 @@ #define RSE 2 #define ADJ 3 -< { quick_tap_ms = <200>; }; -&mt { quick_tap_ms = <200>; }; +< { quick-tap-ms = <200>; }; +&mt { quick-tap-ms = <200>; }; / { keymap { diff --git a/app/tests/tap-dance/behavior_keymap.dtsi b/app/tests/tap-dance/behavior_keymap.dtsi index 66ffdf2e0cc..e45aba4001a 100644 --- a/app/tests/tap-dance/behavior_keymap.dtsi +++ b/app/tests/tap-dance/behavior_keymap.dtsi @@ -8,7 +8,7 @@ compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; tapping-term-ms = <200>; - quick_tap_ms = <0>; + quick-tap-ms = <0>; flavor = "tap-preferred"; bindings = <&kp>, <&kp>; }; From 8929355ac018ba293f53d6759c9f130d67751e09 Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 18 Mar 2024 14:19:27 -0300 Subject: [PATCH 030/134] fix(keymap): Replace some keypad keycodes * Change KP_MULTIPLY to ASTRK in defaults keymap --- app/boards/arm/corneish_zen/corneish_zen.keymap | 6 +++--- app/boards/shields/corne/corne.keymap | 6 +++--- app/boards/shields/iris/iris.keymap | 8 ++++---- app/boards/shields/lily58/lily58.keymap | 8 ++++---- app/boards/shields/microdox/microdox.keymap | 6 +++--- app/boards/shields/sofle/sofle.keymap | 10 +++++----- .../splitkb_aurora_corne/splitkb_aurora_corne.keymap | 6 +++--- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/boards/arm/corneish_zen/corneish_zen.keymap b/app/boards/arm/corneish_zen/corneish_zen.keymap index 636c05135eb..06eee01c1fa 100644 --- a/app/boards/arm/corneish_zen/corneish_zen.keymap +++ b/app/boards/arm/corneish_zen/corneish_zen.keymap @@ -58,9 +58,9 @@ // | SHFT | | | | | | | _ | + | { | } | "|" | ~ | // | GUI | | SPC | | ENT | | ALT | bindings = < -&kp TAB &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp BSPC -&kp LCTRL &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH &kp GRAVE -&kp LSHFT &trans &trans &trans &trans &trans &kp UNDER &kp PLUS &kp LBRC &kp RBRC &kp PIPE &kp TILDE +&kp TAB &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR &kp BSPC +&kp LCTRL &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH &kp GRAVE +&kp LSHFT &trans &trans &trans &trans &trans &kp UNDER &kp PLUS &kp LBRC &kp RBRC &kp PIPE &kp TILDE &kp LGUI &trans &kp SPACE &kp RET &trans &kp RALT >; }; diff --git a/app/boards/shields/corne/corne.keymap b/app/boards/shields/corne/corne.keymap index 0555cf41757..01350bd5b51 100644 --- a/app/boards/shields/corne/corne.keymap +++ b/app/boards/shields/corne/corne.keymap @@ -46,9 +46,9 @@ // | SHFT | | | | | | | _ | + | { | } | "|" | ~ | // | GUI | | SPC | | ENT | | ALT | bindings = < - &kp TAB &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp BSPC - &kp LCTRL &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH &kp GRAVE - &kp LSHFT &trans &trans &trans &trans &trans &kp UNDER &kp PLUS &kp LBRC &kp RBRC &kp PIPE &kp TILDE + &kp TAB &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR &kp BSPC + &kp LCTRL &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH &kp GRAVE + &kp LSHFT &trans &trans &trans &trans &trans &kp UNDER &kp PLUS &kp LBRC &kp RBRC &kp PIPE &kp TILDE &kp LGUI &trans &kp SPACE &kp RET &trans &kp RALT >; }; diff --git a/app/boards/shields/iris/iris.keymap b/app/boards/shields/iris/iris.keymap index 209c2277071..1846509f7e9 100644 --- a/app/boards/shields/iris/iris.keymap +++ b/app/boards/shields/iris/iris.keymap @@ -36,10 +36,10 @@ // | | | | | | | | | | | _ | + | { | } | "|" | // | | | | | | | | bindings = < -&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &trans &trans &trans &trans &trans &trans -&kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 -&kp GRAVE &kp EXCL &kp AT &kp HASH &kp DOLLAR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp TILDE -&trans &trans &trans &trans &trans &trans &trans &trans &trans &kp MINUS &kp KP_PLUS &kp LBRC &kp RBRC &kp PIPE +&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &trans &trans &trans &trans &trans &trans +&kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 +&kp GRAVE &kp EXCL &kp AT &kp HASH &kp DOLLAR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR &kp TILDE +&trans &trans &trans &trans &trans &trans &trans &trans &trans &kp MINUS &kp PLUS &kp LBRC &kp RBRC &kp PIPE &trans &trans &trans &trans &trans &trans >; }; diff --git a/app/boards/shields/lily58/lily58.keymap b/app/boards/shields/lily58/lily58.keymap index 7df3277f780..75a2e8ae4c2 100644 --- a/app/boards/shields/lily58/lily58.keymap +++ b/app/boards/shields/lily58/lily58.keymap @@ -39,10 +39,10 @@ // | | | | | | | | | | | _ | + | { | } | "|" | // | | | | | | | | | | bindings = < -&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &trans &trans &trans &trans &trans &trans -&kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 -&kp GRAVE &kp EXCL &kp AT &kp HASH &kp DOLLAR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp TILDE -&trans &ext_power EP_ON &ext_power EP_OFF &ext_power EP_TOG &trans &trans &trans &trans &trans &kp MINUS &kp KP_PLUS &kp LBRC &kp RBRC &kp PIPE +&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &trans &trans &trans &trans &trans &trans +&kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 +&kp GRAVE &kp EXCL &kp AT &kp HASH &kp DOLLAR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR &kp TILDE +&trans &ext_power EP_ON &ext_power EP_OFF &ext_power EP_TOG &trans &trans &trans &trans &trans &kp MINUS &kp PLUS &kp LBRC &kp RBRC &kp PIPE &trans &trans &trans &trans &trans &trans &trans &trans >; diff --git a/app/boards/shields/microdox/microdox.keymap b/app/boards/shields/microdox/microdox.keymap index c9298ff8cf4..34b2984bca8 100644 --- a/app/boards/shields/microdox/microdox.keymap +++ b/app/boards/shields/microdox/microdox.keymap @@ -46,9 +46,9 @@ // | | | | | | | _ | + | [ | ] | \ | // | GUI | | SPC | | ENT | | ALT | bindings = < - &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR - &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp PIPE - &trans &trans &trans &trans &trans &trans &trans &trans &trans &kp BSLH + &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR + &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp PIPE + &trans &trans &trans &trans &trans &trans &trans &trans &trans &kp BSLH &kp LGUI &trans &kp SPACE &kp RET &trans &kp RALT >; }; diff --git a/app/boards/shields/sofle/sofle.keymap b/app/boards/shields/sofle/sofle.keymap index ed9f0f4f42c..c9db56ceb4d 100644 --- a/app/boards/shields/sofle/sofle.keymap +++ b/app/boards/shields/sofle/sofle.keymap @@ -58,11 +58,11 @@ // | | = | - | + | { | } | | | | [ | ] | ; | : | \ | | // | | | | | | | | | | | | bindings = < -&trans &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 -&kp GRAVE &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp F12 -&trans &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp PIPE -&trans &kp EQUAL &kp MINUS &kp KP_PLUS &kp LBRC &kp RBRC &trans &trans &kp LBKT &kp RBKT &kp SEMI &kp COLON &kp BSLH &trans - &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans +&trans &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 +&kp GRAVE &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp F12 +&trans &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR &kp PIPE +&trans &kp EQUAL &kp MINUS &kp PLUS &kp LBRC &kp RBRC &trans &trans &kp LBKT &kp RBKT &kp SEMI &kp COLON &kp BSLH &trans + &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans >; sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>; diff --git a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne.keymap b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne.keymap index 0555cf41757..01350bd5b51 100644 --- a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne.keymap +++ b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne.keymap @@ -46,9 +46,9 @@ // | SHFT | | | | | | | _ | + | { | } | "|" | ~ | // | GUI | | SPC | | ENT | | ALT | bindings = < - &kp TAB &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp KP_MULTIPLY &kp LPAR &kp RPAR &kp BSPC - &kp LCTRL &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH &kp GRAVE - &kp LSHFT &trans &trans &trans &trans &trans &kp UNDER &kp PLUS &kp LBRC &kp RBRC &kp PIPE &kp TILDE + &kp TAB &kp EXCL &kp AT &kp HASH &kp DLLR &kp PRCNT &kp CARET &kp AMPS &kp ASTRK &kp LPAR &kp RPAR &kp BSPC + &kp LCTRL &trans &trans &trans &trans &trans &kp MINUS &kp EQUAL &kp LBKT &kp RBKT &kp BSLH &kp GRAVE + &kp LSHFT &trans &trans &trans &trans &trans &kp UNDER &kp PLUS &kp LBRC &kp RBRC &kp PIPE &kp TILDE &kp LGUI &trans &kp SPACE &kp RET &trans &kp RALT >; }; From 341534aa15ebcb1d42f917d2a530f21dd823cae2 Mon Sep 17 00:00:00 2001 From: Theo Lemay Date: Sun, 28 May 2023 23:59:48 -0700 Subject: [PATCH 031/134] feat(behaviors): lazy sticky keys --- .../behaviors/zmk,behavior-sticky-key.yaml | 2 + app/src/behaviors/behavior_sticky_key.c | 93 ++++++++++++++----- .../10-callum-mods/keycode_events.snapshot | 2 +- .../11-lazy-timeout-during/events.patterns | 1 + .../keycode_events.snapshot | 6 ++ .../native_posix_64.keymap | 37 ++++++++ .../11-lazy-timeout/events.patterns | 1 + .../11-lazy-timeout/keycode_events.snapshot | 4 + .../11-lazy-timeout/native_posix_64.keymap | 43 +++++++++ app/tests/sticky-keys/11-lazy/events.patterns | 1 + .../11-lazy/keycode_events.snapshot | 16 ++++ .../11-lazy/native_posix_64.keymap | 67 +++++++++++++ .../keycode_events.snapshot | 4 +- .../keycode_events.snapshot | 2 +- .../keycode_events.snapshot | 2 +- .../keycode_events.snapshot | 4 +- docs/docs/behaviors/sticky-key.md | 6 ++ docs/docs/config/behaviors.md | 1 + 18 files changed, 260 insertions(+), 32 deletions(-) create mode 100644 app/tests/sticky-keys/11-lazy-timeout-during/events.patterns create mode 100644 app/tests/sticky-keys/11-lazy-timeout-during/keycode_events.snapshot create mode 100644 app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap create mode 100644 app/tests/sticky-keys/11-lazy-timeout/events.patterns create mode 100644 app/tests/sticky-keys/11-lazy-timeout/keycode_events.snapshot create mode 100644 app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap create mode 100644 app/tests/sticky-keys/11-lazy/events.patterns create mode 100644 app/tests/sticky-keys/11-lazy/keycode_events.snapshot create mode 100644 app/tests/sticky-keys/11-lazy/native_posix_64.keymap diff --git a/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml b/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml index 172f20a2b18..a0e52879829 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml @@ -16,5 +16,7 @@ properties: required: true quick-release: type: boolean + lazy: + type: boolean ignore-modifiers: type: boolean diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 05f6846be12..193a2370699 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -33,6 +33,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct behavior_sticky_key_config { uint32_t release_after_ms; bool quick_release; + bool lazy; bool ignore_modifiers; struct zmk_behavior_binding behavior; }; @@ -146,8 +147,11 @@ static int on_sticky_key_binding_pressed(struct zmk_behavior_binding *binding, return ZMK_BEHAVIOR_OPAQUE; } - press_sticky_key_behavior(sticky_key, event.timestamp); LOG_DBG("%d new sticky_key", event.position); + if (!sticky_key->config->lazy) { + // press the key now if it's not lazy + press_sticky_key_behavior(sticky_key, event.timestamp); + } return ZMK_BEHAVIOR_OPAQUE; } @@ -191,14 +195,21 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { return ZMK_EV_EVENT_BUBBLE; } - // keep track whether the event has been reraised, so we only reraise it once - bool event_reraised = false; + // we want to make sure every sticky key is given a chance to lazy press their behavior before + // the event gets reraised, and release their behavior after the event is reraised, so we keep + // track of them. this allows us to ensure the sticky key is pressed and released "around" the + // other key, especially in the case of lazy keys. + struct active_sticky_key *sticky_keys_to_press_before_reraise[ZMK_BHV_STICKY_KEY_MAX_HELD]; + struct active_sticky_key *sticky_keys_to_release_after_reraise[ZMK_BHV_STICKY_KEY_MAX_HELD]; // reraising the event frees it, so make a copy of any event data we might // need after it's been freed. const struct zmk_keycode_state_changed ev_copy = *ev; for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { + sticky_keys_to_press_before_reraise[i] = NULL; + sticky_keys_to_release_after_reraise[i] = NULL; + struct active_sticky_key *sticky_key = &active_sticky_keys[i]; if (sticky_key->position == ZMK_BHV_STICKY_KEY_POSITION_FREE) { continue; @@ -212,14 +223,6 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { continue; } - // If this event was queued, the timer may be triggered late or not at all. - // Release the sticky key if the timer should've run out in the meantime. - if (sticky_key->release_at != 0 && ev_copy.timestamp > sticky_key->release_at) { - stop_timer(sticky_key); - release_sticky_key_behavior(sticky_key, sticky_key->release_at); - continue; - } - if (ev_copy.state) { // key down if (sticky_key->config->ignore_modifiers && is_mod(ev_copy.usage_page, ev_copy.keycode)) { @@ -231,17 +234,30 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { // this sticky key is already in use for a keycode continue; } + + // we don't want the timer to release the sticky key before the other key is released + stop_timer(sticky_key); + + // If this event was queued, the timer may be triggered late or not at all. + // Release the sticky key if the timer should've run out in the meantime. + if (sticky_key->release_at != 0 && ev_copy.timestamp > sticky_key->release_at) { + // If the key is lazy, a release is not needed on timeout + if (sticky_key->config->lazy) { + clear_sticky_key(sticky_key); + } else { + release_sticky_key_behavior(sticky_key, sticky_key->release_at); + } + continue; + } + + if (sticky_key->config->lazy) { + // if the sticky key is lazy, we need to press it before the event is reraised + sticky_keys_to_press_before_reraise[i] = sticky_key; + } if (sticky_key->timer_started) { - stop_timer(sticky_key); if (sticky_key->config->quick_release) { // immediately release the sticky key after the key press is handled. - if (!event_reraised) { - struct zmk_keycode_state_changed_event dupe_ev = - copy_raised_zmk_keycode_state_changed(ev); - ZMK_EVENT_RAISE_AFTER(dupe_ev, behavior_sticky_key); - event_reraised = true; - } - release_sticky_key_behavior(sticky_key, ev_copy.timestamp); + sticky_keys_to_release_after_reraise[i] = sticky_key; } } sticky_key->modified_key_usage_page = ev_copy.usage_page; @@ -251,14 +267,35 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { sticky_key->modified_key_usage_page == ev_copy.usage_page && sticky_key->modified_key_keycode == ev_copy.keycode) { stop_timer(sticky_key); - release_sticky_key_behavior(sticky_key, ev_copy.timestamp); + sticky_keys_to_release_after_reraise[i] = sticky_key; } } } - if (event_reraised) { - return ZMK_EV_EVENT_CAPTURED; + + // give each sticky key a chance to press their behavior before the event is reraised + for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { + struct active_sticky_key *sticky_key = sticky_keys_to_press_before_reraise[i]; + if (sticky_key) { + press_sticky_key_behavior(sticky_key, ev_copy.timestamp); + } } - return ZMK_EV_EVENT_BUBBLE; + // give each sticky key a chance to release their behavior after the event is reraised, lazily + // reraising. keep track whether the event has been reraised so we only reraise it once + bool event_reraised = false; + for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { + struct active_sticky_key *sticky_key = sticky_keys_to_release_after_reraise[i]; + if (sticky_key) { + if (!event_reraised) { + struct zmk_keycode_state_changed_event dupe_ev = + copy_raised_zmk_keycode_state_changed(ev); + ZMK_EVENT_RAISE_AFTER(dupe_ev, behavior_sticky_key); + event_reraised = true; + } + release_sticky_key_behavior(sticky_key, ev_copy.timestamp); + } + } + + return event_reraised ? ZMK_EV_EVENT_CAPTURED : ZMK_EV_EVENT_BUBBLE; } void behavior_sticky_key_timer_handler(struct k_work *item) { @@ -271,7 +308,12 @@ void behavior_sticky_key_timer_handler(struct k_work *item) { if (sticky_key->timer_cancelled) { sticky_key->timer_cancelled = false; } else { - release_sticky_key_behavior(sticky_key, sticky_key->release_at); + // If the key is lazy, a release is not needed on timeout + if (sticky_key->config->lazy) { + clear_sticky_key(sticky_key); + } else { + release_sticky_key_behavior(sticky_key, sticky_key->release_at); + } } } @@ -295,8 +337,9 @@ static struct behavior_sticky_key_data behavior_sticky_key_data; static struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \ .behavior = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ .release_after_ms = DT_INST_PROP(n, release_after_ms), \ - .ignore_modifiers = DT_INST_PROP(n, ignore_modifiers), \ .quick_release = DT_INST_PROP(n, quick_release), \ + .lazy = DT_INST_PROP(n, lazy), \ + .ignore_modifiers = DT_INST_PROP(n, ignore_modifiers), \ }; \ BEHAVIOR_DT_INST_DEFINE(n, behavior_sticky_key_init, NULL, &behavior_sticky_key_data, \ &behavior_sticky_key_config_##n, POST_KERNEL, \ diff --git a/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot b/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot index 3e46e581165..29be00ff5ac 100644 --- a/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot +++ b/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot @@ -1,8 +1,8 @@ pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/11-lazy-timeout-during/events.patterns b/app/tests/sticky-keys/11-lazy-timeout-during/events.patterns new file mode 100644 index 00000000000..b1342af4d97 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy-timeout-during/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p diff --git a/app/tests/sticky-keys/11-lazy-timeout-during/keycode_events.snapshot b/app/tests/sticky-keys/11-lazy-timeout-during/keycode_events.snapshot new file mode 100644 index 00000000000..8fc9315f55d --- /dev/null +++ b/app/tests/sticky-keys/11-lazy-timeout-during/keycode_events.snapshot @@ -0,0 +1,6 @@ +pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap new file mode 100644 index 00000000000..fb60ba41ed9 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap @@ -0,0 +1,37 @@ +#include +#include +#include + +/* this test ensures that timing out while the other key is being held results in correct behavior */ + +&sk { + lazy; + release-after-ms = <50>; +}; + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &sk LEFT_CONTROL &kp A + &sk LEFT_SHIFT &sk LEFT_ALT>; + }; + }; +}; + +&kscan { + events = < + /* tap sk LEFT_CONTROL */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* tap A */ + ZMK_MOCK_PRESS(0,1,60) + ZMK_MOCK_RELEASE(0,1,10) + /* tap A */ + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; diff --git a/app/tests/sticky-keys/11-lazy-timeout/events.patterns b/app/tests/sticky-keys/11-lazy-timeout/events.patterns new file mode 100644 index 00000000000..b1342af4d97 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy-timeout/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p diff --git a/app/tests/sticky-keys/11-lazy-timeout/keycode_events.snapshot b/app/tests/sticky-keys/11-lazy-timeout/keycode_events.snapshot new file mode 100644 index 00000000000..4d5604616b6 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy-timeout/keycode_events.snapshot @@ -0,0 +1,4 @@ +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap new file mode 100644 index 00000000000..d6b34149001 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap @@ -0,0 +1,43 @@ +#include +#include +#include + +/* this test ensures that lazy sticky keys don't emit anything on timeout */ + +&sk { + lazy; + release-after-ms = <50>; +}; + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &sk LEFT_CONTROL &kp A + &sk LEFT_SHIFT &sk LEFT_ALT>; + }; + }; +}; + +&kscan { + events = < + /* tap sk LEFT_CONTROL */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* tap sk LEFT_SHIFT */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,60) + /* tap sk LEFT_ALT */ + ZMK_MOCK_PRESS(1,1,10) + ZMK_MOCK_RELEASE(1,1,60) + /* tap A */ + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + /* tap A */ + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; diff --git a/app/tests/sticky-keys/11-lazy/events.patterns b/app/tests/sticky-keys/11-lazy/events.patterns new file mode 100644 index 00000000000..b1342af4d97 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p diff --git a/app/tests/sticky-keys/11-lazy/keycode_events.snapshot b/app/tests/sticky-keys/11-lazy/keycode_events.snapshot new file mode 100644 index 00000000000..1c1f86140b0 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy/keycode_events.snapshot @@ -0,0 +1,16 @@ +pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x1D implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x1D implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/11-lazy/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy/native_posix_64.keymap new file mode 100644 index 00000000000..4eea1fb9654 --- /dev/null +++ b/app/tests/sticky-keys/11-lazy/native_posix_64.keymap @@ -0,0 +1,67 @@ +#include +#include +#include + +/* this test verifies that lazy sticky keys work similarly to regular sticky keys, and includes cases from 10-callum-mods and 8-lsk-osk. + the only difference is that the lazy key does not exit the sticky layer */ + +&sk { + lazy; +}; + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &sk LEFT_CONTROL &sl 1 + &kp A &mo 1>; + }; + + lower_layer { + bindings = < + &sk LEFT_CONTROL &kp X + &sk LEFT_SHIFT &kp Z>; + }; + }; +}; + +&kscan { + events = < + /* tap LEFT_CONTROL on base layer */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* tap A */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + + /* tap sl lower_layer */ + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + /* tap sk LEFT_CONTROL */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* tap Z */ + ZMK_MOCK_PRESS(1,1,10) + ZMK_MOCK_RELEASE(1,1,10) + + /* press mo lower_layer */ + ZMK_MOCK_PRESS(1,1,10) + /* tap sk LEFT_CONTROL */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* tap sk LEFT_SHIFT */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + /* release mo lower_layer */ + ZMK_MOCK_RELEASE(1,1,10) + /* tap A (with left control and left shift enabled) */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + /* tap A (no sticky keys anymore) */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + >; +}; \ No newline at end of file diff --git a/app/tests/sticky-keys/2-os-dn-up-kcdn-kcup/keycode_events.snapshot b/app/tests/sticky-keys/2-os-dn-up-kcdn-kcup/keycode_events.snapshot index addbca8c155..1b4c078ced3 100644 --- a/app/tests/sticky-keys/2-os-dn-up-kcdn-kcup/keycode_events.snapshot +++ b/app/tests/sticky-keys/2-os-dn-up-kcdn-kcup/keycode_events.snapshot @@ -1,8 +1,8 @@ pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/4-os-dn-up-kcdn-timer-kcup/keycode_events.snapshot b/app/tests/sticky-keys/4-os-dn-up-kcdn-timer-kcup/keycode_events.snapshot index 6e004ec2b46..1b091a6a144 100644 --- a/app/tests/sticky-keys/4-os-dn-up-kcdn-timer-kcup/keycode_events.snapshot +++ b/app/tests/sticky-keys/4-os-dn-up-kcdn-timer-kcup/keycode_events.snapshot @@ -1,4 +1,4 @@ pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/7-os-dn-up-kc1dn-kc2dn-kc1up-kc2up/keycode_events.snapshot b/app/tests/sticky-keys/7-os-dn-up-kc1dn-kc2dn-kc1up-kc2up/keycode_events.snapshot index 3c757bbb2f2..2b1619b4515 100644 --- a/app/tests/sticky-keys/7-os-dn-up-kc1dn-kc2dn-kc1up-kc2up/keycode_events.snapshot +++ b/app/tests/sticky-keys/7-os-dn-up-kc1dn-kc2dn-kc1up-kc2up/keycode_events.snapshot @@ -1,6 +1,6 @@ pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/8-lsk-osk-combination/keycode_events.snapshot b/app/tests/sticky-keys/8-lsk-osk-combination/keycode_events.snapshot index f1aa915bf05..0c4054f7719 100644 --- a/app/tests/sticky-keys/8-lsk-osk-combination/keycode_events.snapshot +++ b/app/tests/sticky-keys/8-lsk-osk-combination/keycode_events.snapshot @@ -1,8 +1,8 @@ pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 -released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xE0 implicit_mods 0x00 explicit_mods 0x00 diff --git a/docs/docs/behaviors/sticky-key.md b/docs/docs/behaviors/sticky-key.md index f40bb521e10..8c3962f5450 100644 --- a/docs/docs/behaviors/sticky-key.md +++ b/docs/docs/behaviors/sticky-key.md @@ -34,6 +34,12 @@ By default, sticky keys stay pressed for a second if you don't press any other k Some typists may find that using a sticky shift key interspersed with rapid typing results in two or more capitalized letters instead of one. This happens as the sticky key is active until the next key is released, under which other keys may be pressed and will receive the modifier. You can enable the `quick-release` setting to instead deactivate the sticky key on the next key being pressed, as opposed to released. +#### `lazy` + +By default, sticky keys are activated on press until another key is pressed. You can enable the `lazy` setting to instead activate the sticky key right _before_ the other key is pressed. This is useful for mouse interaction or situations where you don't want the host to see anything during a sticky-key timeout, for example `&sk LGUI`, which can trigger a menu if pressed alone. + +Note that tapping a lazy sticky key will not trigger other behaviors such as the release of other sticky keys or layers. If you want to use a lazy sticky key to activate the release of a sticky layer, potential solutions include wrappping the sticky key in a simple macro which presses the sticky behavior around the sticky key press, doing the same with `&mo LAYER`, or triggering a tap of some key like `K_CANCEL` on sticky key press. + #### `ignore-modifiers` This setting is enabled by default. It ensures that if a sticky key modifier is pressed before a previously pressed sticky key is released, the modifiers will get combined so you can add more sticky keys or press a regular key to apply the modifiers. This is to accommodate _callum-style mods_ where you are prone to rolling sticky keys. If you want sticky key modifiers to only chain after release, you can disable this setting. Please note that activating multiple modifiers via [modifier functions](https://zmk.dev/docs/codes/modifiers#modifier-functions) such as `&sk LS(LALT)`, require `ignore-modifiers` enabled in order to function properly. diff --git a/docs/docs/config/behaviors.md b/docs/docs/config/behaviors.md index f8d2fe39eb6..1a5b899ab97 100644 --- a/docs/docs/config/behaviors.md +++ b/docs/docs/config/behaviors.md @@ -230,6 +230,7 @@ Applies to: `compatible = "zmk,behavior-sticky-key"` | `bindings` | phandle array | A behavior (without parameters) to trigger | | | `release-after-ms` | int | Releases the key after this many milliseconds if no other key is pressed | 1000 | | `quick-release` | bool | Release the sticky key on the next key press instead of release | false | +| `lazy` | bool | Wait until the next key press to activate the sticky key behavior | false | | `ignore-modifiers` | bool | If enabled, pressing a modifier key does not cancel the sticky key | true | This behavior forwards the one parameter it receives to the parameter of the behavior specified in `bindings`. From 94d9d837e3674a7127190a00361c899197a66ba4 Mon Sep 17 00:00:00 2001 From: Theo Lemay Date: Mon, 18 Dec 2023 17:34:42 -0500 Subject: [PATCH 032/134] refactor: extract duplicate logic --- app/src/behaviors/behavior_sticky_key.c | 47 +++++++++++++------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 193a2370699..2c279c3be44 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -121,6 +121,15 @@ static inline int release_sticky_key_behavior(struct active_sticky_key *sticky_k return behavior_keymap_binding_released(&binding, event); } +static inline int on_sticky_key_timeout(struct active_sticky_key *sticky_key) { + // If the key is lazy, a release is not needed on timeout + if (sticky_key->config->lazy) { + clear_sticky_key(sticky_key); + } else { + release_sticky_key_behavior(sticky_key, sticky_key->release_at); + } +} + static int stop_timer(struct active_sticky_key *sticky_key) { int timer_cancel_result = k_work_cancel_delayable(&sticky_key->release_timer); if (timer_cancel_result == -EINPROGRESS) { @@ -241,12 +250,7 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { // If this event was queued, the timer may be triggered late or not at all. // Release the sticky key if the timer should've run out in the meantime. if (sticky_key->release_at != 0 && ev_copy.timestamp > sticky_key->release_at) { - // If the key is lazy, a release is not needed on timeout - if (sticky_key->config->lazy) { - clear_sticky_key(sticky_key); - } else { - release_sticky_key_behavior(sticky_key, sticky_key->release_at); - } + on_sticky_key_timeout(sticky_key); continue; } @@ -275,24 +279,28 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { // give each sticky key a chance to press their behavior before the event is reraised for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { struct active_sticky_key *sticky_key = sticky_keys_to_press_before_reraise[i]; - if (sticky_key) { - press_sticky_key_behavior(sticky_key, ev_copy.timestamp); + if (!sticky_key) { + continue; } + + press_sticky_key_behavior(sticky_key, ev_copy.timestamp); } // give each sticky key a chance to release their behavior after the event is reraised, lazily // reraising. keep track whether the event has been reraised so we only reraise it once bool event_reraised = false; for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { struct active_sticky_key *sticky_key = sticky_keys_to_release_after_reraise[i]; - if (sticky_key) { - if (!event_reraised) { - struct zmk_keycode_state_changed_event dupe_ev = - copy_raised_zmk_keycode_state_changed(ev); - ZMK_EVENT_RAISE_AFTER(dupe_ev, behavior_sticky_key); - event_reraised = true; - } - release_sticky_key_behavior(sticky_key, ev_copy.timestamp); + if (!sticky_key) { + continue; } + + if (!event_reraised) { + struct zmk_keycode_state_changed_event dupe_ev = + copy_raised_zmk_keycode_state_changed(ev); + ZMK_EVENT_RAISE_AFTER(dupe_ev, behavior_sticky_key); + event_reraised = true; + } + release_sticky_key_behavior(sticky_key, ev_copy.timestamp); } return event_reraised ? ZMK_EV_EVENT_CAPTURED : ZMK_EV_EVENT_BUBBLE; @@ -308,12 +316,7 @@ void behavior_sticky_key_timer_handler(struct k_work *item) { if (sticky_key->timer_cancelled) { sticky_key->timer_cancelled = false; } else { - // If the key is lazy, a release is not needed on timeout - if (sticky_key->config->lazy) { - clear_sticky_key(sticky_key); - } else { - release_sticky_key_behavior(sticky_key, sticky_key->release_at); - } + on_sticky_key_timeout(sticky_key); } } From af7e4198ae3cd2fab16320ebb0ee3a5215e0f674 Mon Sep 17 00:00:00 2001 From: Theo Lemay Date: Mon, 18 Dec 2023 21:31:29 -0500 Subject: [PATCH 033/134] chore: remove label in test --- .../sticky-keys/11-lazy-timeout-during/native_posix_64.keymap | 1 - app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap | 1 - app/tests/sticky-keys/11-lazy/native_posix_64.keymap | 1 - 3 files changed, 3 deletions(-) diff --git a/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap index fb60ba41ed9..75d997cb34c 100644 --- a/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap +++ b/app/tests/sticky-keys/11-lazy-timeout-during/native_posix_64.keymap @@ -12,7 +12,6 @@ / { keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < diff --git a/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap index d6b34149001..05db46c84ac 100644 --- a/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap +++ b/app/tests/sticky-keys/11-lazy-timeout/native_posix_64.keymap @@ -12,7 +12,6 @@ / { keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < diff --git a/app/tests/sticky-keys/11-lazy/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy/native_posix_64.keymap index 4eea1fb9654..193354e297b 100644 --- a/app/tests/sticky-keys/11-lazy/native_posix_64.keymap +++ b/app/tests/sticky-keys/11-lazy/native_posix_64.keymap @@ -12,7 +12,6 @@ / { keymap { compatible = "zmk,keymap"; - label ="Default keymap"; default_layer { bindings = < From ce743f2b3566d198e06cb3afe3d335f90f377244 Mon Sep 17 00:00:00 2001 From: Theo Lemay <16546293+theol0403@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:07:19 -0500 Subject: [PATCH 034/134] chore: fix whitespace --- app/tests/sticky-keys/11-lazy/native_posix_64.keymap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/tests/sticky-keys/11-lazy/native_posix_64.keymap b/app/tests/sticky-keys/11-lazy/native_posix_64.keymap index 193354e297b..8031987265c 100644 --- a/app/tests/sticky-keys/11-lazy/native_posix_64.keymap +++ b/app/tests/sticky-keys/11-lazy/native_posix_64.keymap @@ -2,7 +2,7 @@ #include #include -/* this test verifies that lazy sticky keys work similarly to regular sticky keys, and includes cases from 10-callum-mods and 8-lsk-osk. +/* this test verifies that lazy sticky keys work similarly to regular sticky keys, and includes cases from 10-callum-mods and 8-lsk-osk. the only difference is that the lazy key does not exit the sticky layer */ &sk { From 736c5fb46eeb570e81a3f1dd0a6dc10b17b31769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:51:47 +0800 Subject: [PATCH 035/134] feat(docs): Add a note on macOS v14.3 file copy error message --- docs/docs/troubleshooting.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md index 1f3c1706e34..808808c4ca7 100644 --- a/docs/docs/troubleshooting.md +++ b/docs/docs/troubleshooting.md @@ -27,6 +27,10 @@ Variations of the warnings shown below occur when flashing the `.uf2` macOS 13.0 (Ventura) Finder may report an error code 100093 when copying `.uf2` files into microcontrollers. This bug is limited to the operating system's Finder. You can work around it by copying on Terminal command line or use a third party file manager. Issue is fixed in macOS version 13.1. +### macOS Sonoma error + +macOS 14.x (Sonoma) Finder may report an "Error code -36" when copying `.uf2` files into microcontrollers. A similar "fcopyfile failed: Input/output error" will also be reported when copying is performed using Terminal command line. These errors can be ignored because they are reported when the bootloader disconnects automatically after the uf2 file is copied successfully. + ### CMake Error An error along the lines of `CMake Error at (zmk directory)/zephyr/cmake/generic_toolchain.cmake:64 (include): include could not find load file:` during firmware compilation indicates that the Zephyr Environment Variables are not properly defined. From 828943156ab5619f54be629dcee7c0ffc74a22be Mon Sep 17 00:00:00 2001 From: Theo Lemay <16546293+theol0403@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:34:45 -0400 Subject: [PATCH 036/134] fix(docs): Fix hold-tap info callout (#2211) The hold-while-undecided callout does not properly render in the docs. This fixes it. --- docs/docs/behaviors/hold-tap.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/behaviors/hold-tap.mdx b/docs/docs/behaviors/hold-tap.mdx index 191e820dd43..5217cf79e29 100644 --- a/docs/docs/behaviors/hold-tap.mdx +++ b/docs/docs/behaviors/hold-tap.mdx @@ -87,7 +87,7 @@ For example, if you press `&mt LEFT_SHIFT A` and then release it without pressin If enabled, the hold behavior will immediately be held on hold-tap press, and will release before the behavior is sent in the event the hold-tap resolves into a tap. With most modifiers this will not affect typing, and is useful for using modifiers with the mouse. -:::note Alt/Win/Cmd behavior +:::info[Alt/Win/Cmd behavior] In some applications/desktop environments, pressing Alt keycodes by itself will have its own behavior like activate a menu and Gui keycodes will bring up the start menu or an application launcher. ::: From 1f7cd7a107789055bf58ac6c01af502773cef76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:49:16 +0800 Subject: [PATCH 037/134] feat(docs): Add troubleshooting section for empty_file error --- docs/docs/troubleshooting.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md index 808808c4ca7..2e9ab4dcb80 100644 --- a/docs/docs/troubleshooting.md +++ b/docs/docs/troubleshooting.md @@ -56,6 +56,14 @@ A `devicetree error` followed by a reference to the line number on `.k devicetree error: /__w/zmk-config/zmk-config/config/cradio.keymap:109 (column 4): parse error: expected ';' or ',' ``` +A `devicetree error` followed by an `empty_file.c` reference with `lacks #binding-cells` string indicates possible problems with improper parameters for specific bindings: + +``` +devicetree error: lacks #binding-cells +``` + +This error can be triggered by incorrect binding syntax such as `&kp BT_SEL 0` instead of `&bt BT_SEL 0`. + #### devicetree_unfixed.h error A `devicetree_unfixed.h` error that follows with an "undeclared here" string indicates a problem with key bindings, like behavior nodes (e.g. `&kp` or `&mt`) with incorrect number of parameters: From 3a3eed2960b9388b8554eb778d56dfd99a477962 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 19 Mar 2024 10:50:04 -0700 Subject: [PATCH 038/134] fix: Add settings reset on start init priority. * Add a dedicated settings reset on start init priority and default it to lower priority (high number) than default FLASH_INIT_PRIORITY to be sure flash is initialized before we open the area. --- app/Kconfig | 13 +++++++++++++ app/src/settings/reset_settings_on_start.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index 3f797abd41d..c430bcb2d32 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -568,6 +568,19 @@ if SETTINGS config ZMK_SETTINGS_RESET_ON_START bool "Delete all persistent settings when the keyboard boots" +if ZMK_SETTINGS_RESET_ON_START + +config ZMK_SETTINGS_RESET_ON_START_INIT_PRIORITY + int "Settings Reset ON Start Initialization Priority" + default 60 + help + Initialization priority for the settings reset on start. Must be lower priority/ + higher value than FLASH_INIT_PRIORITY if using the NVS/Flash settings backend. + + +endif + + config ZMK_SETTINGS_SAVE_DEBOUNCE int "Milliseconds to debounce settings saves" default 60000 diff --git a/app/src/settings/reset_settings_on_start.c b/app/src/settings/reset_settings_on_start.c index 47f5e8f2259..0f6d4fae9fb 100644 --- a/app/src/settings/reset_settings_on_start.c +++ b/app/src/settings/reset_settings_on_start.c @@ -10,4 +10,4 @@ // Reset after the kernel is initialized but before any application code to // ensure settings are cleared before anything tries to use them. -SYS_INIT(zmk_settings_erase, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(zmk_settings_erase, POST_KERNEL, CONFIG_ZMK_SETTINGS_RESET_ON_START_INIT_PRIORITY); From 931a36ff4ad0b30c8165024bbfc0286d05b74b53 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Wed, 28 Feb 2024 00:09:27 -0800 Subject: [PATCH 039/134] feat(docs): Add a note on using BT with dual boot systems --- docs/docs/features/bluetooth.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/docs/features/bluetooth.md b/docs/docs/features/bluetooth.md index 1f2d795527a..28ba21367d1 100644 --- a/docs/docs/features/bluetooth.md +++ b/docs/docs/features/bluetooth.md @@ -69,6 +69,11 @@ This setting can also improve the connection strength between the keyboard halve If you want to test bluetooth output on your keyboard and are powering it through the USB connection rather than a battery, you will be able to pair with a host device but may not see keystrokes sent. In this case you need to use the [output selection behavior](../behaviors/outputs.md) to prefer sending keystrokes over bluetooth rather than USB. This might be necessary even if you are not powering from a device capable of receiving USB inputs, such as a USB charger. +### Issues with dual boot setups + +Since ZMK associates pairing/bond keys with hardware addresses of hosts, you cannot pair to two different operating systems in a dual boot system at the same time. +While you can find [documented workarounds](https://wiki.archlinux.org/title/bluetooth#Dual_boot_pairing) that involve copying pairing keys across operating systems and use both OS with a single profile, they can be fairly involved and should be followed with caution. + ### macOS Connected But Not Working If you attempt to pair a ZMK keyboard from macOS in a way that causes a bonding issue, macOS may report the keyboard as connected, but fail to actually work. If this occurs: From 44358798d3dae71cc1af118e5a5bc5792f9f7761 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 15 Mar 2024 21:00:37 +0000 Subject: [PATCH 040/134] feat: Add ability to fetch battery voltage. * To be able to use the Zephyr `voltage-divider` driver, add a mode for fetching raw voltage from the sensor and do state of charge calculation outside of the driver. --- app/Kconfig | 14 ++++++++++++++ app/src/battery.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index c430bcb2d32..21e97ac6354 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -383,6 +383,20 @@ config ZMK_BATTERY_REPORTING select ZMK_LOW_PRIORITY_WORK_QUEUE imply BT_BAS if ZMK_BLE +if ZMK_BATTERY_REPORTING + +choice ZMK_BATTERY_REPORTING_FETCH_MODE + prompt "Battery Reporting Fetch Mode" + +config ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE + bool "State of charge" + +config ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE + bool "Lithium Voltage" + +endchoice +endif + config ZMK_IDLE_TIMEOUT int "Milliseconds of inactivity before entering idle state (OLED shutoff, etc)" default 30000 diff --git a/app/src/battery.c b/app/src/battery.c index 1295f822486..ae79d5f794c 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -34,11 +34,29 @@ static const struct device *const battery = DEVICE_DT_GET(DT_CHOSEN(zmk_battery) static const struct device *battery; #endif +#if IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE) +static uint8_t lithium_ion_mv_to_pct(int16_t bat_mv) { + // Simple linear approximation of a battery based off adafruit's discharge graph: + // https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages + + if (bat_mv >= 4200) { + return 100; + } else if (bat_mv <= 3450) { + return 0; + } + + return bat_mv * 2 / 15 - 459; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE) + static int zmk_battery_update(const struct device *battery) { struct sensor_value state_of_charge; + int rc; - int rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE); +#if IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE) + rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE); if (rc != 0) { LOG_DBG("Failed to fetch battery values: %d", rc); return rc; @@ -50,6 +68,28 @@ static int zmk_battery_update(const struct device *battery) { LOG_DBG("Failed to get battery state of charge: %d", rc); return rc; } +#elif IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE) + rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_VOLTAGE); + if (rc != 0) { + LOG_DBG("Failed to fetch battery values: %d", rc); + return rc; + } + + struct sensor_value voltage; + rc = sensor_channel_get(battery, SENSOR_CHAN_VOLTAGE, &voltage); + + if (rc != 0) { + LOG_DBG("Failed to get battery voltage: %d", rc); + return rc; + } + + uint16_t mv = voltage.val1 * 1000 + (voltage.val2 / 1000); + state_of_charge.val1 = lithium_ion_mv_to_pct(mv); + + LOG_DBG("State of change %d from %d mv", state_of_charge.val1, mv); +#else +#error "Not a supported reporting fetch mode" +#endif if (last_state_of_charge != state_of_charge.val1) { last_state_of_charge = state_of_charge.val1; From f2d8b9b0a31398d9880de6a960b41e3603b3b837 Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Wed, 20 Mar 2024 07:18:44 -0700 Subject: [PATCH 041/134] feat(docs): Add Behavior overview page Co-authored-by: Cem Aksoylar --- docs/docs/behaviors/index.mdx | 82 +++++++++++++++++++++++++++++++++++ docs/sidebars.js | 1 + 2 files changed, 83 insertions(+) create mode 100644 docs/docs/behaviors/index.mdx diff --git a/docs/docs/behaviors/index.mdx b/docs/docs/behaviors/index.mdx new file mode 100644 index 00000000000..32f4b29a97f --- /dev/null +++ b/docs/docs/behaviors/index.mdx @@ -0,0 +1,82 @@ +--- +title: Behavior Overview +sidebar_label: Overview +--- + +# Behaviors Overview + +"Behaviors" are bindings that are assigned to and triggered by key positions on keymap layers, sensors (like an encoder) or combos. They describe what happens e.g. when a certain key position is pressed or released, or an encoder triggers a rotation event. They can also be recursively invoked by other behaviors, such as macros. + +Below is a summary of pre-defined behavior bindings and user-definable behaviors available in ZMK, with references to documentation pages describing them. + +## Key press behaviors + +| Binding | Behavior | Description | +| ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `&kp` | [Key Press](key-press.md) | Send keycodes to the connected host when a key is pressed | +| `&mt` | [Mod Tap](mod-tap.md) | Sends a different key press depending on whether a key is held or tapped | +| `&kt` | [Key Toggle](key-toggle.md) | Toggles the press of a key. If the key is not currently pressed, key toggle will press it, holding it until the key toggle is pressed again or the key is released in some other way. If the key is currently pressed, key toggle will release it | +| `&sk` | [Sticky Key](sticky-key.md) | Stays pressed until another key is pressed, then is released. It is often used for modifier keys like shift, which allows typing capital letters without holding it down | +| `&gresc` | [Grave Escape](mod-morph.md#behavior-binding) | Sends Grave Accent `` ` `` keycode if shift or GUI is held, sends Escape keycode otherwise | +| `&caps_word` | [Caps Word](caps-word.md) | Behaves similar to caps lock, but automatically deactivates when any key not in a continue list is pressed, or if the caps word key is pressed again | +| `&key_repeat` | [Key Repeat](key-repeat.md) | Sends again whatever keycode was last sent | + +## Miscellaneous behaviors + +| Binding | Behavior | Description | +| -------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| `&trans` | [Transparent](misc.md#transparent) | Passes the key press down to the next active layer in the stack for processing | +| `&none` | [None](misc.md#none) | Swallows and stops the key press, no keycode will be sent nor will the key press be passed down to the next active layer in the stack | + +## Layer navigation behaviors + +| Binding | Behavior | Description | +| ------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| `&mo` | [Momentary Layer](layers.md#momentary-layer) | Enables a layer while a key is pressed | +| `<` | [Layer-tap](layers.md#layer-tap) | Enables a layer when a key is held, and outputs a key press when the key is only tapped for a short time | +| `&to` | [To Layer](layers.md#to-layer) | Enables a layer and disables all other layers except the default layer | +| `&tog` | [Toggle Layer](layers.md#toggle-layer) | Enables a layer until the layer is manually disabled | +| `&sl` | [Sticky Layer](sticky-layer.md) | Activates a layer until another key is pressed, then deactivates it | + +## Mouse emulation behaviors + +| Binding | Behavior | Description | +| ------- | ----------------------------------------------------------- | ------------------------------- | +| `&mkp` | [Mouse Button Press](mouse-emulation.md#mouse-button-press) | Emulates pressing mouse buttons | + +## Reset behaviors + +| Binding | Behavior | Description | +| ------------- | --------------------------------- | ---------------------------------------------------------------------------------------- | +| `&sys_reset` | [Reset](reset.md#reset) | Resets the keyboard and re-runs the firmware flashed to the device | +| `&bootloader` | [Bootloader](reset.md#bootloader) | Resets the keyboard and puts it into bootloader mode, allowing you to flash new firmware | + +## Output selection behaviors + +| Binding | Behavior | Description | +| ------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | +| `&bt` | [Bluetooth](bluetooth.md#bluetooth-behavior) | Completes a bluetooth action given on press, for example switching between devices | +| `&out` | [Output Selection](outputs.md#output-selection-behavior) | Allows selecting whether output is sent to the USB or bluetooth connection when both are connected | + +## Lighting behaviors + +| Binding | Behavior | Description | +| --------- | ---------------------------------------------- | ---------------------------------------------------------------------------- | +| `&rgb_ug` | [RGB Underglow](underglow.md#behavior-binding) | Controls the RGB underglow, usually placed underneath the keyboard | +| `&bl` | [Backlight](backlight.md#behavior-binding) | Controls the keyboard backlighting, usually placed through or under switches | + +## Power management behaviors + +| Binding | Behavior | Description | +| ------------ | --------------------------------------------- | --------------------------------------------------------------- | +| `&ext_power` | [Power management](power.md#behavior-binding) | Allows enabling or disabling the VCC power output to save power | + +## User-defined behaviors + +| Behavior | Description | +| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [Macros](macros.md) | Allows configuring a list of other behaviors to invoke when the key is pressed and/or released | +| [Hold-Tap](hold-tap.mdx) | Invokes different behaviors depending on key press duration or interrupting keys. This is the basis for [layer-tap](layers.md#layer-tap) and [mod-tap](mod-tap.md) | +| [Tap Dance](tap-dance.mdx) | Invokes different behaviors corresponding to how many times a key is pressed | +| [Mod-Morph](mod-morph.md) | Invokes different behaviors depending on whether a specified modifier is held during a key press | +| [Sensor Rotation](sensor-rotate.md) | Invokes different behaviors depending on whether a sensor is rotated clockwise or counter-clockwise | diff --git a/docs/sidebars.js b/docs/sidebars.js index 284eb09b38e..37613d568a0 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -22,6 +22,7 @@ module.exports = { "features/beta-testing", ], Behaviors: [ + "behaviors/index", "behaviors/key-press", "behaviors/layers", "behaviors/misc", From c684cee76f6732d1da3dc23564b64e9a1ea08671 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Sun, 24 Mar 2024 17:58:20 -0700 Subject: [PATCH 042/134] refactor(docs): Refer to overview page for behaviors --- docs/docs/development/new-behavior.mdx | 2 +- docs/docs/development/new-shield.mdx | 2 +- docs/docs/features/keymaps.mdx | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/docs/development/new-behavior.mdx b/docs/docs/development/new-behavior.mdx index cabc417f8d3..914abf52063 100644 --- a/docs/docs/development/new-behavior.mdx +++ b/docs/docs/development/new-behavior.mdx @@ -8,7 +8,7 @@ import TabItem from "@theme/TabItem"; ## Overview -This document outlines how to develop a behavior for ZMK and prepare the changes for a pull request. +This document outlines how to develop a [behavior](../behaviors/index.mdx) for ZMK and prepare the changes for a pull request. Behaviors are assigned to key positions and determine what happens when they are pressed and released. They are implemented in Zephyr as "devices": they consist of a devicetree binding file, which specifies the properties of the behavior, and a driver written in C code. This allows for the ability to create unique instances of these behaviors in [keymaps](../features/keymaps.mdx) or devicetree-source-include files (`.dtsi`). While instances of behaviors stored in keymaps are created by end-users for their personal needs, the instances that live in the .dtsi files are stored and documented in ZMK directly, which removes the need for end-users to set up common use-cases of these behaviors in their personal keymaps. diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index 2cd82bc67e9..e99332a8076 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -386,7 +386,7 @@ The two `#include` lines at the top of the keymap are required in order to bring ### Keymap Behaviors -For the full documentation on the available behaviors for use in keymaps, start with reviewing [`kp`](../behaviors/key-press.md) and then use the sidebar to review the others available within ZMK. +For documentation on the available behaviors for use in keymaps, see the [overview page for behaviors](../behaviors/index.mdx). ## Metadata diff --git a/docs/docs/features/keymaps.mdx b/docs/docs/features/keymaps.mdx index c8d46ef941b..105ca794ab4 100644 --- a/docs/docs/features/keymaps.mdx +++ b/docs/docs/features/keymaps.mdx @@ -33,7 +33,7 @@ For example, the simplest behavior in ZMK is the "key press" behavior, which res (a certain spot on the keyboard), and when that position is pressed, send a keycode to the host, and when the key position is released, updates the host to notify of the keycode being released. -For the full set of possible behaviors, start at the [Key Press](../behaviors/key-press.md) behavior. +For the full set of possible behaviors, see the [overview page for behaviors](../behaviors/index.mdx). ## Layers @@ -128,11 +128,9 @@ that defines just one layer for this keymap: Each layer should have: -1. A `bindings` property this will be a list of behavior bindings, one for each key position for the keyboard. +1. A `bindings` property this will be a list of [behavior bindings](../behaviors/index.mdx), one for each key position for the keyboard. 1. (Optional) A `sensor-bindings` property that will be a list of behavior bindings for each sensor on the keyboard. (Currently, only encoders are supported as sensor hardware, but in the future devices like trackpoints would be supported the same way) -For the full set of possible behaviors, start at the [Key Press](../behaviors/key-press.md) behavior. - ### Complete Example Putting this all together, a complete [`kyria.keymap`](https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/kyria/kyria.keymap) looks like: From 94c3b9a24607c966e28d44b6634c6084a21f84b2 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 24 Mar 2024 21:09:16 +0000 Subject: [PATCH 043/134] feat(build): Allow specifying snippets for a build. * Allow using snippets https://docs.zephyrproject.org/latest/build/snippets/using.html for user builds in a `snippets` array properly. --- .github/workflows/build-user-config.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-user-config.yml b/.github/workflows/build-user-config.yml index d8ea057e56d..c3e4789dc5d 100644 --- a/.github/workflows/build-user-config.yml +++ b/.github/workflows/build-user-config.yml @@ -65,6 +65,7 @@ jobs: board: ${{ matrix.board }} shield: ${{ matrix.shield }} artifact_name: ${{ matrix.artifact-name }} + snippet: ${{ matrix.snippet }} run: | if [ -e zephyr/module.yml ]; then export zmk_load_arg=" -DZMK_EXTRA_MODULES='${GITHUB_WORKSPACE}'" @@ -75,7 +76,12 @@ jobs: echo "base_dir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV fi + if [ -n "${snippet}" ]; then + extra_west_args="-S \"${snippet}\"" + fi + echo "zephyr_version=${ZEPHYR_VERSION}" >> $GITHUB_ENV + echo "extra_west_args=${extra_west_args}" >> $GITHUB_ENV echo "extra_cmake_args=${shield:+-DSHIELD=\"$shield\"}${zmk_load_arg}" >> $GITHUB_ENV echo "display_name=${shield:+$shield - }${board}" >> $GITHUB_ENV echo "artifact_name=${artifact_name:-${shield:+$shield-}${board}-zmk}" >> $GITHUB_ENV @@ -120,7 +126,7 @@ jobs: - name: West Build (${{ env.display_name }}) working-directory: ${{ env.base_dir }} shell: sh -x {0} - run: west build -s zmk/app -d "${{ env.build_dir }}" -b "${{ matrix.board }}" -- -DZMK_CONFIG=${{ env.base_dir }}/${{ inputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }} + run: west build -s zmk/app -d "${{ env.build_dir }}" -b "${{ matrix.board }}" ${{ env.extra_west_args }} -- -DZMK_CONFIG=${{ env.base_dir }}/${{ inputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }} - name: ${{ env.display_name }} Kconfig file run: | From e806cd6da1cd8239f6bf549f2956c567c31cccbc Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:20:53 -0700 Subject: [PATCH 044/134] feat(gitignore): add clangd cache folder --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 4ddd08521ed..1ef282a9f82 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,14 @@ /zephyr /zmk-config /build + +# macOS *.DS_Store + +# Python __pycache__ .python-version .venv + +# clangd +app/.cache/ From 58ccc5970dc804857d81609857d4217278ec025c Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:16:34 -0700 Subject: [PATCH 045/134] fix(build): Modify function return type Change return type of `sticky_key_timeout` function to `void` given it does not return any value to remove compiler warnings. --- app/src/behaviors/behavior_sticky_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 2c279c3be44..b0e9f3ed0c0 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -121,7 +121,7 @@ static inline int release_sticky_key_behavior(struct active_sticky_key *sticky_k return behavior_keymap_binding_released(&binding, event); } -static inline int on_sticky_key_timeout(struct active_sticky_key *sticky_key) { +static inline void on_sticky_key_timeout(struct active_sticky_key *sticky_key) { // If the key is lazy, a release is not needed on timeout if (sticky_key->config->lazy) { clear_sticky_key(sticky_key); From adb3a13dc583e1876d5aa17da0ade4c1024cad7d Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 15 Mar 2023 21:48:30 -0400 Subject: [PATCH 046/134] feat: Add soft on/off support. Initial work on a soft on/off support for ZMK. Triggering soft off puts the device into deep sleep with only a specific GPIO pin configured to wake the device, avoiding waking from other key presses in the matrix like the normal deep sleep. Co-authored-by: Cem Aksoylar --- app/CMakeLists.txt | 4 + app/Kconfig | 9 + app/Kconfig.behaviors | 10 + app/dts/behaviors.dtsi | 1 + app/dts/behaviors/soft_off.dtsi | 15 ++ .../bindings/zmk,behavior-key-scanned.yaml | 31 +++ app/dts/bindings/zmk,behavior-key.yaml | 31 +++ .../bindings/zmk,soft-off-wakeup-sources.yaml | 14 ++ app/dts/bindings/zmk,wakeup-trigger-key.yaml | 18 ++ app/include/zmk/pm.h | 9 + app/src/behavior_key.c | 159 ++++++++++++++ app/src/behavior_key_scanned.c | 194 ++++++++++++++++++ app/src/kscan.c | 6 + app/src/pm.c | 59 ++++++ app/src/wakeup_trigger_key.c | 87 ++++++++ docs/docs/behaviors/soft-off.md | 38 ++++ docs/docs/development/new-shield.mdx | 1 + docs/docs/features/soft-off.md | 164 +++++++++++++++ docs/sidebars.js | 2 + 19 files changed, 852 insertions(+) create mode 100644 app/dts/behaviors/soft_off.dtsi create mode 100644 app/dts/bindings/zmk,behavior-key-scanned.yaml create mode 100644 app/dts/bindings/zmk,behavior-key.yaml create mode 100644 app/dts/bindings/zmk,soft-off-wakeup-sources.yaml create mode 100644 app/dts/bindings/zmk,wakeup-trigger-key.yaml create mode 100644 app/include/zmk/pm.h create mode 100644 app/src/behavior_key.c create mode 100644 app/src/behavior_key_scanned.c create mode 100644 app/src/pm.c create mode 100644 app/src/wakeup_trigger_key.c create mode 100644 docs/docs/behaviors/soft-off.md create mode 100644 docs/docs/features/soft-off.md diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index b12d04742ee..ac83091c5ef 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -29,7 +29,11 @@ target_sources(app PRIVATE src/matrix_transform.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) +target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY app PRIVATE src/behavior_key.c) +target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_SCANNED app PRIVATE src/behavior_key_scanned.c) +target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) +target_sources_ifdef(CONFIG_ZMK_WAKEUP_TRIGGER_KEY app PRIVATE src/wakeup_trigger_key.c) target_sources(app PRIVATE src/events/activity_state_changed.c) target_sources(app PRIVATE src/events/position_state_changed.c) target_sources(app PRIVATE src/events/sensor_event.c) diff --git a/app/Kconfig b/app/Kconfig index 21e97ac6354..60a959d4986 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -423,6 +423,15 @@ config ZMK_EXT_POWER bool "Enable support to control external power output" default y +config ZMK_PM_SOFT_OFF + bool "Soft-off support" + select PM_DEVICE + +config ZMK_WAKEUP_TRIGGER_KEY + bool "Hardware supported wakeup (GPIO)" + default y + depends on DT_HAS_ZMK_WAKEUP_TRIGGER_KEY_ENABLED && ZMK_PM_SOFT_OFF + #Power Management endmenu diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 7a1e44f6db5..e5e0c4d7a23 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,6 +1,16 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT +config ZMK_BEHAVIOR_KEY + bool + default y + depends on DT_HAS_ZMK_BEHAVIOR_KEY_ENABLED + +config ZMK_BEHAVIOR_KEY_SCANNED + bool + default y + depends on DT_HAS_ZMK_BEHAVIOR_KEY_SCANNED_ENABLED + config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 23f2fee2806..fde75271891 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -20,3 +20,4 @@ #include #include #include +#include diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi new file mode 100644 index 00000000000..fa6571a1117 --- /dev/null +++ b/app/dts/behaviors/soft_off.dtsi @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/ { + behaviors { + /omit-if-no-ref/ soft_off: behavior_soft_off { + compatible = "zmk,behavior-soft-off"; + label = "SOFTOFF"; + #binding-cells = <0>; + }; + }; +}; diff --git a/app/dts/bindings/zmk,behavior-key-scanned.yaml b/app/dts/bindings/zmk,behavior-key-scanned.yaml new file mode 100644 index 00000000000..bdb3abaff0e --- /dev/null +++ b/app/dts/bindings/zmk,behavior-key-scanned.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Driver for a dedicated key triggered by matrix scanning for invoking a connected behavior. + +compatible: "zmk,behavior-key-scanned" + +include: base.yaml + +properties: + key: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + bindings: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + debounce-press-ms: + type: int + default: 5 + description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. + debounce-release-ms: + type: int + default: 5 + description: Debounce time for key release in milliseconds. + debounce-scan-period-ms: + type: int + default: 1 + description: Time between reads in milliseconds when any key is pressed. diff --git a/app/dts/bindings/zmk,behavior-key.yaml b/app/dts/bindings/zmk,behavior-key.yaml new file mode 100644 index 00000000000..ff7a585eafa --- /dev/null +++ b/app/dts/bindings/zmk,behavior-key.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Driver for a dedicated key for invoking a connected behavior. + +compatible: "zmk,behavior-key" + +include: base.yaml + +properties: + key: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + bindings: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + debounce-press-ms: + type: int + default: 5 + description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. + debounce-release-ms: + type: int + default: 5 + description: Debounce time for key release in milliseconds. + debounce-scan-period-ms: + type: int + default: 1 + description: Time between reads in milliseconds when any key is pressed. diff --git a/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml new file mode 100644 index 00000000000..f98039a0ca9 --- /dev/null +++ b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Description of all possible wakeup-sources from a forces + soft-off state. + +compatible: "zmk,soft-off-wakeup-sources" + +properties: + wakeup-sources: + type: phandles + required: true + description: List of wakeup-sources that should be enabled to wake the system from forces soft-off state. diff --git a/app/dts/bindings/zmk,wakeup-trigger-key.yaml b/app/dts/bindings/zmk,wakeup-trigger-key.yaml new file mode 100644 index 00000000000..fa7636d1f32 --- /dev/null +++ b/app/dts/bindings/zmk,wakeup-trigger-key.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Driver for a dedicated key for waking the device from sleep + +compatible: "zmk,wakeup-trigger-key" + +include: base.yaml + +properties: + trigger: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + extra-gpios: + type: phandle-array + description: Optional set of pins that should be set active before sleeping. diff --git a/app/include/zmk/pm.h b/app/include/zmk/pm.h new file mode 100644 index 00000000000..dff217afd29 --- /dev/null +++ b/app/include/zmk/pm.h @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +int zmk_pm_soft_off(void); \ No newline at end of file diff --git a/app/src/behavior_key.c b/app/src/behavior_key.c new file mode 100644 index 00000000000..3633ce39a40 --- /dev/null +++ b/app/src/behavior_key.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_key + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_key_config { + struct zmk_debounce_config debounce_config; + int32_t debounce_scan_period_ms; + struct gpio_dt_spec key; +}; + +struct behavior_key_data { + struct zmk_behavior_binding binding; + struct zmk_debounce_state debounce_state; + struct gpio_callback key_callback; + const struct device *dev; + struct k_work_delayable update_work; + uint32_t read_time; +}; + +static void bk_enable_interrupt(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_LEVEL_ACTIVE); +} + +static void bk_disable_interrupt(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); +} + +static void bk_read(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + struct behavior_key_data *data = dev->data; + + zmk_debounce_update(&data->debounce_state, gpio_pin_get_dt(&config->key), + config->debounce_scan_period_ms, &config->debounce_config); + + if (zmk_debounce_get_changed(&data->debounce_state)) { + const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); + + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&data->binding, event); + } else { + behavior_keymap_binding_released(&data->binding, event); + } + } + + if (zmk_debounce_is_active(&data->debounce_state)) { + data->read_time += config->debounce_scan_period_ms; + + k_work_reschedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); + } else { + bk_enable_interrupt(dev); + } +} + +static void bk_update_work(struct k_work *work) { + struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); + struct behavior_key_data *data = CONTAINER_OF(dwork, struct behavior_key_data, update_work); + bk_read(data->dev); +} + +static void bk_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct behavior_key_data *data = CONTAINER_OF(cb, struct behavior_key_data, key_callback); + + bk_disable_interrupt(data->dev); + + data->read_time = k_uptime_get(); + k_work_reschedule(&data->update_work, K_NO_WAIT); +} + +static int behavior_key_init(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + struct behavior_key_data *data = dev->data; + + if (!device_is_ready(config->key.port)) { + LOG_ERR("GPIO port is not ready"); + return -ENODEV; + } + + k_work_init_delayable(&data->update_work, bk_update_work); + data->dev = dev; + + gpio_pin_configure_dt(&config->key, GPIO_INPUT); + gpio_init_callback(&data->key_callback, bk_gpio_irq_callback, BIT(config->key.pin)); + gpio_add_callback(config->key.port, &data->key_callback); + + while (gpio_pin_get_dt(&config->key)) { + k_sleep(K_MSEC(100)); + } + + bk_enable_interrupt(dev); + + return 0; +} + +static int behavior_key_pm_action(const struct device *dev, enum pm_device_action action) { + const struct behavior_key_config *config = dev->config; + struct behavior_key_data *data = dev->data; + + int ret; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + bk_disable_interrupt(dev); + ret = gpio_remove_callback(config->key.port, &data->key_callback); + break; + case PM_DEVICE_ACTION_RESUME: + ret = gpio_add_callback(config->key.port, &data->key_callback); + bk_enable_interrupt(dev); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#define BK_INST(n) \ + const struct behavior_key_config bk_config_##n = { \ + .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ + .debounce_config = \ + { \ + .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ + .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ + }, \ + .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ + }; \ + struct behavior_key_data bk_data_##n = { \ + .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, behavior_key_pm_action); \ + DEVICE_DT_INST_DEFINE(n, behavior_key_init, PM_DEVICE_DT_INST_GET(n), &bk_data_##n, \ + &bk_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DT_INST_FOREACH_STATUS_OKAY(BK_INST) diff --git a/app/src/behavior_key_scanned.c b/app/src/behavior_key_scanned.c new file mode 100644 index 00000000000..c961b292622 --- /dev/null +++ b/app/src/behavior_key_scanned.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_key_scanned + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_key_scanned_config { + struct zmk_debounce_config debounce_config; + int32_t debounce_scan_period_ms; + struct gpio_dt_spec key; +}; + +struct behavior_key_scanned_data { + struct zmk_behavior_binding binding; + struct zmk_debounce_state debounce_state; + struct gpio_callback key_callback; + const struct device *dev; + struct k_work_delayable update_work; + uint32_t read_time; + bool pin_active; + bool active_scan_detected; + struct k_sem sem; +}; + +static void bks_enable_interrupt(const struct device *dev, bool active_scanning) { + const struct behavior_key_scanned_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, active_scanning ? GPIO_INT_EDGE_TO_ACTIVE + : GPIO_INT_LEVEL_ACTIVE); +} + +static void bks_disable_interrupt(const struct device *dev) { + const struct behavior_key_scanned_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); +} + +static void bks_read(const struct device *dev) { + const struct behavior_key_scanned_config *config = dev->config; + struct behavior_key_scanned_data *data = dev->data; + + if (k_sem_take(&data->sem, K_NO_WAIT) < 0) { + // k_work_reschedule(&data->update_work, K_NO_WAIT); + return; + } + + zmk_debounce_update(&data->debounce_state, data->active_scan_detected, + config->debounce_scan_period_ms, &config->debounce_config); + + if (zmk_debounce_get_changed(&data->debounce_state)) { + const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); + + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&data->binding, event); + } else { + behavior_keymap_binding_released(&data->binding, event); + } + } + + if (zmk_debounce_is_active(&data->debounce_state)) { + data->active_scan_detected = false; + data->read_time += config->debounce_scan_period_ms; + + k_work_schedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); + } else { + bks_enable_interrupt(dev, false); + } + + k_sem_give(&data->sem); +} + +static void bks_update_work(struct k_work *work) { + struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); + struct behavior_key_scanned_data *data = + CONTAINER_OF(dwork, struct behavior_key_scanned_data, update_work); + bks_read(data->dev); +} + +static void bks_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct behavior_key_scanned_data *data = + CONTAINER_OF(cb, struct behavior_key_scanned_data, key_callback); + const struct behavior_key_scanned_config *config = data->dev->config; + + uint32_t time = k_uptime_get(); + + if (k_sem_take(&data->sem, K_MSEC(10)) < 0) { + LOG_ERR("FAILED TO TAKE THE SEMAPHORE"); + // Do more? + return; + } + + data->active_scan_detected = true; + data->read_time = time; + + if (!zmk_debounce_is_active(&data->debounce_state)) { + // When we get that very first interrupt, we need to schedule the update checks to fall in + // between each of the real scans, so we can do our checks for state *after* each scan has + // occurred. + k_work_reschedule(&data->update_work, + K_TIMEOUT_ABS_MS(time + (config->debounce_scan_period_ms / 2))); + + bks_enable_interrupt(data->dev, true); + } + + k_sem_give(&data->sem); +} + +static int behavior_key_scanned_init(const struct device *dev) { + const struct behavior_key_scanned_config *config = dev->config; + struct behavior_key_scanned_data *data = dev->data; + + if (!device_is_ready(config->key.port)) { + LOG_ERR("GPIO port is not ready"); + return -ENODEV; + } + + k_work_init_delayable(&data->update_work, bks_update_work); + k_sem_init(&data->sem, 1, 1); + data->dev = dev; + + gpio_pin_configure_dt(&config->key, GPIO_INPUT); + gpio_init_callback(&data->key_callback, bks_gpio_irq_callback, BIT(config->key.pin)); + gpio_add_callback(config->key.port, &data->key_callback); + + while (gpio_pin_get_dt(&config->key)) { + k_sleep(K_MSEC(100)); + } + + bks_enable_interrupt(dev, false); + + return 0; +} + +static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_device_action action) { + const struct behavior_key_scanned_config *config = dev->config; + struct behavior_key_scanned_data *data = dev->data; + + int ret; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + bks_disable_interrupt(dev); + ret = gpio_remove_callback(config->key.port, &data->key_callback); + break; + case PM_DEVICE_ACTION_RESUME: + ret = gpio_add_callback(config->key.port, &data->key_callback); + bks_enable_interrupt(dev, false); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#define BK_INST(n) \ + const struct behavior_key_scanned_config bks_config_##n = { \ + .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ + .debounce_config = \ + { \ + .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ + .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ + }, \ + .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ + }; \ + struct behavior_key_scanned_data bks_data_##n = { \ + .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_pm_action); \ + DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_init, PM_DEVICE_DT_INST_GET(n), &bks_data_##n, \ + &bks_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + NULL); + +DT_INST_FOREACH_STATUS_OKAY(BK_INST) diff --git a/app/src/kscan.c b/app/src/kscan.c index ff55290a3c2..c04ce2d8799 100644 --- a/app/src/kscan.c +++ b/app/src/kscan.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -75,6 +76,11 @@ int zmk_kscan_init(const struct device *dev) { kscan_config(dev, zmk_kscan_callback); kscan_enable_callback(dev); +#if IS_ENABLED(CONFIG_PM_DEVICE) + if (pm_device_wakeup_is_capable(dev)) { + pm_device_wakeup_enable(dev, true); + } +#endif // IS_ENABLED(CONFIG_PM_DEVICE) return 0; } diff --git a/app/src/pm.c b/app/src/pm.c new file mode 100644 index 00000000000..af12623918f --- /dev/null +++ b/app/src/pm.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) + +#if HAS_WAKERS + +#define DEVICE_WITH_SEP(node_id, prop, idx) DEVICE_DT_GET(DT_PROP_BY_IDX(node_id, prop, idx)), + +const struct device *soft_off_wakeup_sources[] = { + DT_FOREACH_PROP_ELEM(DT_INST(0, zmk_soft_off_wakeup_sources), wakeup_sources, DEVICE_WITH_SEP)}; + +#endif + +int zmk_pm_soft_off(void) { +#if IS_ENABLED(CONFIG_PM_DEVICE) + size_t device_count; + const struct device *devs; + + device_count = z_device_get_all_static(&devs); + + // There may be some matrix/direct kscan devices that would be used for wakeup + // from normal "inactive goes to sleep" behavior, so disable them as wakeup devices + // and then suspend them so we're ready to take over setting up our system + // and then putting it into an off state. + for (int i = 0; i < device_count; i++) { + const struct device *dev = &devs[i]; + + LOG_DBG("soft-on-off pressed cb: suspend device"); + if (pm_device_wakeup_is_enabled(dev)) { + pm_device_wakeup_enable(dev, false); + } + pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); + } +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + +#if HAS_WAKERS + for (int i = 0; i < ARRAY_SIZE(soft_off_wakeup_sources); i++) { + const struct device *dev = soft_off_wakeup_sources[i]; + pm_device_wakeup_enable(dev, true); + pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME); + } +#endif // HAS_WAKERS + + LOG_DBG("soft-on-off interrupt: go to sleep"); + return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); +} diff --git a/app/src/wakeup_trigger_key.c b/app/src/wakeup_trigger_key.c new file mode 100644 index 00000000000..0cc4f250707 --- /dev/null +++ b/app/src/wakeup_trigger_key.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define DT_DRV_COMPAT zmk_wakeup_trigger_key + +struct wakeup_trigger_key_config { + struct gpio_dt_spec trigger; + size_t extra_gpios_count; + struct gpio_dt_spec extra_gpios[]; +}; + +static int zmk_wakeup_trigger_key_init(const struct device *dev) { +#if IS_ENABLED(CONFIG_PM_DEVICE) + pm_device_init_suspended(dev); + pm_device_wakeup_enable(dev, true); +#endif + + return 0; +} + +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int wakeup_trigger_key_pm_action(const struct device *dev, enum pm_device_action action) { + const struct wakeup_trigger_key_config *config = dev->config; + int ret = 0; + + switch (action) { + case PM_DEVICE_ACTION_RESUME: + ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + return ret; + } + + for (int i = 0; i < config->extra_gpios_count; i++) { + ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); + } + } + break; + case PM_DEVICE_ACTION_SUSPEND: + + ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_DISABLE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + return ret; + } + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + +#define WAKEUP_TRIGGER_EXTRA_GPIO_SPEC(idx, n) \ + GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), extra_gpios, idx) + +#define WAKEUP_TRIGGER_KEY_INST(n) \ + const struct wakeup_trigger_key_config wtk_cfg_##n = { \ + .trigger = GPIO_DT_SPEC_GET(DT_INST_PROP(n, trigger), gpios), \ + .extra_gpios = {LISTIFY(DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + WAKEUP_TRIGGER_EXTRA_GPIO_SPEC, (, ), n)}, \ + .extra_gpios_count = DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, wakeup_trigger_key_pm_action); \ + DEVICE_DT_INST_DEFINE(n, zmk_wakeup_trigger_key_init, PM_DEVICE_DT_INST_GET(n), NULL, \ + &wtk_cfg_##n, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DT_INST_FOREACH_STATUS_OKAY(WAKEUP_TRIGGER_KEY_INST) diff --git a/docs/docs/behaviors/soft-off.md b/docs/docs/behaviors/soft-off.md new file mode 100644 index 00000000000..05374004955 --- /dev/null +++ b/docs/docs/behaviors/soft-off.md @@ -0,0 +1,38 @@ +--- +title: Soft Off Behavior +sidebar_label: Soft Off +--- + +## Summary + +The soft off behavior is used to force the keyboard into an off state. Depending on the specific keyboard hardware, the keyboard can be turned back on again either with a dedicated on/off button that is available, or using the reset button found on the device. + +For more information, see the [Soft Off Feature](../features/soft-off.md) page. + +### Behavior Binding + +- Reference: `&soft_off` + +Example: + +``` +&soft_off +``` + +### Configuration + +#### Hold Time + +By default, the keyboard will be turned off as soon as the key bound to the behavior is released, even if the key is only tapped briefly. If you would prefer that the key need be held a certain amount of time before releasing, you can set the `hold-time-ms` to a non-zero value in your keymap: + +``` +&soft_off { + hold-time-ms = <5000>; // Only turn off it the key is held for 5 seconds or longer. +}; + +/ { + keymap { + ... + }; +}; +``` diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index e99332a8076..867ccbc8cee 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -171,6 +171,7 @@ this might look something like: kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; diode-direction = "col2row"; + wakeup-source; col-gpios = <&pro_micro 15 GPIO_ACTIVE_HIGH> diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md new file mode 100644 index 00000000000..b0206825cbc --- /dev/null +++ b/docs/docs/features/soft-off.md @@ -0,0 +1,164 @@ +--- +title: Soft Off Feature +sidebar_label: Soft Off +--- + +Similar to the deep sleep feature that sends the keyboard into a low power state after a certain period of inactivity, the soft off feature is used to turn the keyboard on and off explicitly. Depending on the keyboard, this may be through a dedicated on/off push button, or merely through an additional binding in the keymap to turn the device off and the existing reset button to turn the device back on. + +The feature is intended as an alternative to using a hardware switch to physically cut power from the battery to the keyboard. This can be useful for existing PCBs not designed for wireless that don't have a power switch, or for new designs that favor a push button on/off like found on other devices. + +:::note + +The power off is accomplished by putting the MCU into a "soft off" state. Power is _not_ technically removed from the entire system, but the device will only be woken from the state by a few possible events. + +::: + +Once powered off, the keyboard will only wake up when: + +- You press the same button/sequence that you pressed to power off the keyboard, or +- You press a reset button found on the keyboard. + +## Soft Off With Existing Designs + +For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. For splits, at least for now, you'll need to place it somewhere on each side of your keymap and trigger on both sides, starting from the peripheral side first. + +You can then wake up the keyboard by pressing the reset button once, and repeating this for each side for split keyboards. + +## Adding Soft On/Off To New Designs + +### Hardware Design + +ZMK's soft on/off requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the +soft off state when it goes active again later. + +#### Simple Direct Pin + +The simplest way to achieve this is with a push button between a GPIO pin and ground. + +#### Matrix-Integrated Hardware Combo + +Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. + +### Firmware Changes + +Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. + +#### GPIO Key + +Zephyr's basic GPIO Key concept is used to configure the GPIO pin that will be used for both triggering soft off and waking the device later. Here is an example for a keyboard with a dedicated on/off push button that is a direct wire between the GPIO pin and ground: + +``` +/ { + keys { + compatible = "gpio-keys"; + wakeup_key: wakeup_key { + gpios = <&gpio0 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + }; + }; +}; +``` + +GPIO keys are defined using child nodes under the `gpio-keys` compatible node. Each child needs just one property defined: + +- The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. + +#### Behavior Key + +Next, we will create a new "behavior key". Behavior keys are an easy way to tie a keymap behavior to a GPIO key outside of the normal keymap processing. They do _not_ do the normal keymap processing, so they are only suitable for use with basic behaviors, not complicated macros, hold-taps, etc. + +In this case, we will be creating a dedicated instance of the [Soft Off Behavior](../behaviors/soft-off.md) that will be used only for our hardware on/off button, then binding it to our key: + +``` +/ { + behaviors { + hw_soft_off: behavior_hw_soft_off { + compatible = "zmk,behavior-soft-off"; + #binding-cells = <0>; + label = "HW_SO"; + hold-time-ms = <5000>; + }; + }; + + soft_off_behavior_key { + compatible = "zmk,behavior-key"; + bindings = <&hw_soft_off>; + key = <&wakeup_key>; + }; +}; +``` + +Here are the properties for the behavior key node: + +- The `compatible` property for the node must be `zmk,behavior-key`. +- The `bindings` property is a phandle to the soft off behavior defined above. +- The `key` property is a phandle to the GPIO key defined earlier. + +If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key needs use a different driver that will handle detecting the pressed state when the pin is toggled by the other matrix kscan driver: + +``` +/ { + soft_off_behavior_key { + compatible = "zmk,behavior-key-scanned"; + status = "okay"; + bindings = <&hw_soft_off>; + key = <&wakeup_key>; + }; +}; +``` + +Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,behavior-key-scanned`. + +#### Wakeup Sources + +Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property, e.g.: + +``` +/ { + kscan0: kscan_0 { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + wakeup-source; + + ... + }; +}; +``` + +#### Soft Off Waker + +Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. + +``` +/ { + wakeup_source: wakeup_source { + compatible = "zmk,wakeup-trigger-key"; + + trigger = <&wakeup_key>; + wakeup-source; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,wakeup-trigger-key`. +- The `trigger` property is a phandle to the GPIO key defined earlier. +- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. +- An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. + +Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&wakeup_source>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. diff --git a/docs/sidebars.js b/docs/sidebars.js index 37613d568a0..ebf0aef76e6 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -19,6 +19,7 @@ module.exports = { "features/underglow", "features/backlight", "features/battery", + "features/soft-off", "features/beta-testing", ], Behaviors: [ @@ -44,6 +45,7 @@ module.exports = { "behaviors/underglow", "behaviors/backlight", "behaviors/power", + "behaviors/soft-off", ], Codes: [ "codes/index", From 738c3c0e3b3878ddaebafae65becdf5e5f68fe86 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 13 Sep 2023 19:58:53 +0000 Subject: [PATCH 047/134] feat(kscan): Add PM support to GPIO kscan drivers. * Add PM device hook to the kscan direct & matrix drivers. --- app/module/drivers/kscan/kscan_gpio_direct.c | 27 +++++++++++++++++++- app/module/drivers/kscan/kscan_gpio_matrix.c | 27 +++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index b5e77f63301..2bc35f4c0b3 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -318,6 +319,28 @@ static int kscan_direct_init(const struct device *dev) { return 0; } +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) { + int ret = 0; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + kscan_direct_disable(dev); + break; + case PM_DEVICE_ACTION_RESUME: + kscan_direct_enable(dev); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + static const struct kscan_driver_api kscan_direct_api = { .config = kscan_direct_configure, .enable_callback = kscan_direct_enable, @@ -354,7 +377,9 @@ static const struct kscan_driver_api kscan_direct_api = { .toggle_mode = DT_INST_PROP(n, toggle_mode), \ }; \ \ - DEVICE_DT_INST_DEFINE(n, &kscan_direct_init, NULL, &kscan_direct_data_##n, \ + PM_DEVICE_DT_INST_DEFINE(n, kscan_direct_pm_action); \ + \ + DEVICE_DT_INST_DEFINE(n, &kscan_direct_init, PM_DEVICE_DT_INST_GET(n), &kscan_direct_data_##n, \ &kscan_direct_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \ &kscan_direct_api); diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index 6e91bf95fb0..3917196e6c8 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -421,6 +422,28 @@ static int kscan_matrix_init(const struct device *dev) { return 0; } +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) { + int ret = 0; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + kscan_matrix_disable(dev); + break; + case PM_DEVICE_ACTION_RESUME: + kscan_matrix_enable(dev); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + static const struct kscan_driver_api kscan_matrix_api = { .config = kscan_matrix_configure, .enable_callback = kscan_matrix_enable, @@ -465,7 +488,9 @@ static const struct kscan_driver_api kscan_matrix_api = { .diode_direction = INST_DIODE_DIR(n), \ }; \ \ - DEVICE_DT_INST_DEFINE(n, &kscan_matrix_init, NULL, &kscan_matrix_data_##n, \ + PM_DEVICE_DT_INST_DEFINE(n, kscan_matrix_pm_action); \ + \ + DEVICE_DT_INST_DEFINE(n, &kscan_matrix_init, PM_DEVICE_DT_INST_GET(n), &kscan_matrix_data_##n, \ &kscan_matrix_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \ &kscan_matrix_api); From b19df0cbf053a88a9389bdf463df431e5b7e70a5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 13 Sep 2023 20:01:02 +0000 Subject: [PATCH 048/134] feat(behaviors): Add soft off behavior. * New soft-off behavior that can be used to force the device into soft-off state with only certain configured wakeup devices. --- app/CMakeLists.txt | 1 + app/Kconfig.behaviors | 6 ++ app/dts/behaviors/soft_off.dtsi | 3 +- .../behaviors/zmk,behavior-soft-off.yaml | 14 ++++ app/src/behaviors/behavior_soft_off.c | 70 +++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml create mode 100644 app/src/behaviors/behavior_soft_off.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index ac83091c5ef..bf7cfeefb40 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -42,6 +42,7 @@ target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c) target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c) +target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SOFT_OFF app PRIVATE src/behaviors/behavior_soft_off.c) if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/hid.c) target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse.c) diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index e5e0c4d7a23..7c30f50ec97 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -22,6 +22,12 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED imply ZMK_MOUSE +config ZMK_BEHAVIOR_SOFT_OFF + bool + default y + select ZMK_PM_SOFT_OFF + depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED + config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON bool diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index fa6571a1117..c68230f3231 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,9 +6,8 @@ / { behaviors { - /omit-if-no-ref/ soft_off: behavior_soft_off { + soft_off: soft_off { compatible = "zmk,behavior-soft-off"; - label = "SOFTOFF"; #binding-cells = <0>; }; }; diff --git a/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml new file mode 100644 index 00000000000..1467ede4772 --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Soft-Off Behavior + +compatible: "zmk,behavior-soft-off" + +include: zero_param.yaml + +properties: + hold-time-ms: + type: int + required: false + description: Number of milliseconds the behavior must be held before releasing will actually trigger a soft-off. diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c new file mode 100644 index 00000000000..0f24a644d9a --- /dev/null +++ b/app/src/behaviors/behavior_soft_off.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_soft_off + +#include +#include +#include + +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_soft_off_config { + uint32_t hold_time_ms; +}; + +struct behavior_soft_off_data { + uint32_t press_start; +}; + +static int behavior_soft_off_init(const struct device *dev) { return 0; }; + +static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); + struct behavior_soft_off_data *data = dev->data; + +#if IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) + zmk_pm_soft_off(); +#else + data->press_start = k_uptime_get(); +#endif + + return ZMK_BEHAVIOR_OPAQUE; +} + +static int on_keymap_binding_released(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); + struct behavior_soft_off_data *data = dev->data; + const struct behavior_soft_off_config *config = dev->config; + + if (config->hold_time_ms == 0 || (k_uptime_get() - data->press_start) >= config->hold_time_ms) { + zmk_pm_soft_off(); + } + + return ZMK_BEHAVIOR_OPAQUE; +} + +static const struct behavior_driver_api behavior_soft_off_driver_api = { + .binding_pressed = on_keymap_binding_pressed, + .binding_released = on_keymap_binding_released, + .locality = BEHAVIOR_LOCALITY_GLOBAL, +}; + +#define BSO_INST(n) \ + static const struct behavior_soft_off_config bso_config_##n = { \ + .hold_time_ms = DT_INST_PROP_OR(n, hold_time_ms, 0), \ + }; \ + static struct behavior_soft_off_data bso_data_##n = {}; \ + BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + &behavior_soft_off_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(BSO_INST) From d3fffb9e8913105bc732eb9cbfbd380a9b98167e Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 16 Sep 2023 11:50:12 -0700 Subject: [PATCH 049/134] feat(shields): Add soft-off to the nrf52840dk ZMK Uno * Use Button 1 for soft off on the nrf52840 when using the ZMK Uno shield. --- .../boards/nrf52840dk_nrf52840.overlay | 43 ++++++++++++++++++- app/boards/shields/zmk_uno/zmk_uno.dtsi | 2 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index 05c7ed9d8e9..d08105c6889 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -12,6 +12,15 @@ bias-pull-up; }; }; + + qdec_sleep: qdec_sleep { + group1 { + psels = , + ; + bias-pull-up; + low-power-enable; + }; + }; }; // Set up the QDEC hardware based driver and give it the same label as the deleted node. @@ -20,6 +29,38 @@ encoder: &qdec0 { led-pre = <0>; steps = <80>; pinctrl-0 = <&qdec_default>; - pinctrl-1 = <&qdec_default>; + pinctrl-1 = <&qdec_sleep>; pinctrl-names = "default", "sleep"; }; + +/ { + behaviors { + soft_off: soft_off { + compatible = "zmk,behavior-soft-off"; + #binding-cells = <0>; + status = "okay"; + }; + }; + + wakeup_source: wakeup_source { + compatible = "zmk,wakeup-trigger-key"; + status = "okay"; + + trigger = <&button0>; + wakeup-source; + }; + + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + status = "okay"; + + wakeup-sources = <&wakeup_source>; + }; + + soft_off_behavior_key { + compatible = "zmk,behavior-key"; + status = "okay"; + bindings = <&soft_off>; + key = <&button0>; + }; +}; \ No newline at end of file diff --git a/app/boards/shields/zmk_uno/zmk_uno.dtsi b/app/boards/shields/zmk_uno/zmk_uno.dtsi index 63deb06a4d1..196ac8b5002 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno.dtsi @@ -124,6 +124,7 @@ nice_view_spi: &arduino_spi { kscan_matrix: kscan_matrix { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; @@ -141,6 +142,7 @@ nice_view_spi: &arduino_spi { kscan_direct: kscan_direct { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; status = "disabled"; input-gpios From 860e53b33ac3b09b233a0ec4c6cb0621895fb16c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 7 Dec 2023 00:36:02 +0000 Subject: [PATCH 050/134] refactor: Promote new endpoints API * Add ability for external callers to clear the current endpoint. --- app/include/zmk/endpoints.h | 2 ++ app/src/endpoints.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/include/zmk/endpoints.h b/app/include/zmk/endpoints.h index 70240183e36..f2aff2bcc2d 100644 --- a/app/include/zmk/endpoints.h +++ b/app/include/zmk/endpoints.h @@ -73,3 +73,5 @@ int zmk_endpoints_send_report(uint16_t usage_page); #if IS_ENABLED(CONFIG_ZMK_MOUSE) int zmk_endpoints_send_mouse_report(); #endif // IS_ENABLE(CONFIG_ZMK_MOUSE) + +void zmk_endpoints_clear_current(void); diff --git a/app/src/endpoints.c b/app/src/endpoints.c index f8452d93fbb..7c9d15a31fe 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -340,7 +340,7 @@ static int zmk_endpoints_init(void) { return 0; } -static void disconnect_current_endpoint(void) { +void zmk_endpoints_clear_current(void) { zmk_hid_keyboard_clear(); zmk_hid_consumer_clear(); #if IS_ENABLED(CONFIG_ZMK_MOUSE) @@ -356,7 +356,7 @@ static void update_current_endpoint(void) { if (!zmk_endpoint_instance_eq(new_instance, current_instance)) { // Cancel all current keypresses so keys don't stay held on the old endpoint. - disconnect_current_endpoint(); + zmk_endpoints_clear_current(); current_instance = new_instance; From 0d4d4fb2b5bdfd2b259febe14a9b1dfbf991872d Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 7 Dec 2023 00:37:31 +0000 Subject: [PATCH 051/134] feat(pm): Clear HID data before soft off. * Make sure the connected host has no held HID usages before we sleep. --- app/src/pm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/pm.c b/app/src/pm.c index af12623918f..a78b6ae53cb 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -13,6 +13,8 @@ #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#include + #define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) #if HAS_WAKERS @@ -29,6 +31,10 @@ int zmk_pm_soft_off(void) { size_t device_count; const struct device *devs; +#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) + zmk_endpoints_clear_current(); +#endif + device_count = z_device_get_all_static(&devs); // There may be some matrix/direct kscan devices that would be used for wakeup From e78249ee067910725cd7fcf447b016ce3cdcf318 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 7 Dec 2023 04:04:13 +0000 Subject: [PATCH 052/134] fix(bt): Fix BT tests after soft off work. * Move to explicit enable of `ZMK_PM_SOFT_OFF` to turn on the feature and use the behaviors, which matches how other features work, and helps with split and testing schemes. --- app/Kconfig.behaviors | 3 +-- .../shields/zmk_uno/boards/nrf52840dk_nrf52840.conf | 1 + app/dts/behaviors/soft_off.dtsi | 3 ++- docs/docs/config/power.md | 12 ++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 7c30f50ec97..18fd5c15b0f 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -25,8 +25,7 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS config ZMK_BEHAVIOR_SOFT_OFF bool default y - select ZMK_PM_SOFT_OFF - depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED + depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED && ZMK_PM_SOFT_OFF config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON bool diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 00000000000..ac92c4d8f00 --- /dev/null +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1 @@ +CONFIG_ZMK_PM_SOFT_OFF=y \ No newline at end of file diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index c68230f3231..c88e1b51f12 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,8 +6,9 @@ / { behaviors { - soft_off: soft_off { + /omit-if-no-ref/ soft_off: soft_off { compatible = "zmk,behavior-soft-off"; + label = "SOFTOFF"; #binding-cells = <0>; }; }; diff --git a/docs/docs/config/power.md b/docs/docs/config/power.md index 75e1b26ab8b..396456b2589 100644 --- a/docs/docs/config/power.md +++ b/docs/docs/config/power.md @@ -24,6 +24,18 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ | `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n | | `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 | +## Soft Off + +The [soft off feature](../features/soft-off.md) allows turning the keyboard on/off from either dedicated hardware of using the [`&soft_off` behavior](../behaviors/soft-off.md) to turn off and a reset button to turn back on again. + +### Kconfig + +Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/Kconfig) + +| Config | Type | Description | Default | +| ------------------------ | ---- | ------------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap of dedicated hardware | n | + ## External Power Control Driver for enabling or disabling power to peripherals such as displays and lighting. This driver must be configured to use [power management behaviors](../behaviors/power.md). From 96968514e378cd134889637ee3e0c6311e08e13a Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sat, 9 Dec 2023 17:18:04 -0500 Subject: [PATCH 053/134] fix(docs): Apply suggestions from code review Co-authored-by: Cem Aksoylar --- docs/docs/config/kscan.md | 8 +++++++- docs/docs/config/power.md | 4 ++-- docs/docs/features/soft-off.md | 9 ++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index b49529d9965..3076edc0f41 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -79,6 +79,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml]( | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | | `poll-period-ms` | int | Time between reads in milliseconds when no key is pressed and `CONFIG_ZMK_KSCAN_DIRECT_POLLING` is enabled. | 10 | | `toggle-mode` | bool | Use toggle switch mode. | n | +| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | By default, a switch will drain current through the internal pull up/down resistor whenever it is pressed. This is not ideal for a toggle switch, where the switch may be left in the "pressed" state for a long time. Enabling `toggle-mode` will make the driver flip between pull up and down as the switch is toggled to optimize for power. @@ -89,6 +90,7 @@ Assuming the switches connect each GPIO pin to the ground, the [GPIO flags](http ```dts kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; input-gpios = <&pro_micro 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> @@ -123,6 +125,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-matrix.yaml]( | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | | `diode-direction` | string | The direction of the matrix diodes | `"row2col"` | | `poll-period-ms` | int | Time between reads in milliseconds when no key is pressed and `CONFIG_ZMK_KSCAN_MATRIX_POLLING` is enabled. | 10 | +| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | The `diode-direction` property must be one of: @@ -137,6 +140,7 @@ The output pins (e.g. columns for `col2row`) should have the flag `GPIO_ACTIVE_H ```dts kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios = <&pro_micro 4 GPIO_ACTIVE_HIGH> @@ -177,6 +181,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-charlieplex.y | `debounce-release-ms` | int | Debounce time for key release in milliseconds. | 5 | | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | | `poll-period-ms` | int | Time between reads in milliseconds when no key is pressed and `interrupt-gpois` is not set. | 10 | +| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | Define the transform with a [matrix transform](#matrix-transform). The row is always the driven pin, and the column always the receiving pin (input to the controller). For example, in `RC(5,0)` power flows from the 6th pin in `gpios` to the 1st pin in `gpios`. @@ -450,7 +455,8 @@ Note that the entire addressable space does not need to be mapped. }; kscan0: kscan { - compatible = "zmk,kscan-gpio-charlieplex"; + compatible = "zmk,kscan-gpio-charlieplex";k + wakeup-source; interrupt-gpios = <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) >; gpios diff --git a/docs/docs/config/power.md b/docs/docs/config/power.md index 396456b2589..1a142eb2e4b 100644 --- a/docs/docs/config/power.md +++ b/docs/docs/config/power.md @@ -26,7 +26,7 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ ## Soft Off -The [soft off feature](../features/soft-off.md) allows turning the keyboard on/off from either dedicated hardware of using the [`&soft_off` behavior](../behaviors/soft-off.md) to turn off and a reset button to turn back on again. +The [soft off feature](../features/soft-off.md) allows turning the keyboard on/off from either dedicated hardware, or using the [`&soft_off` behavior](../behaviors/soft-off.md) to turn off and a reset button to turn back on again. ### Kconfig @@ -34,7 +34,7 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ | Config | Type | Description | Default | | ------------------------ | ---- | ------------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap of dedicated hardware | n | +| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap or dedicated hardware | n | ## External Power Control diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index b0206825cbc..a3a5d7a1cb7 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -20,15 +20,15 @@ Once powered off, the keyboard will only wake up when: ## Soft Off With Existing Designs -For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. For splits, at least for now, you'll need to place it somewhere on each side of your keymap and trigger on both sides, starting from the peripheral side first. +For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. You can then wake up the keyboard by pressing the reset button once, and repeating this for each side for split keyboards. -## Adding Soft On/Off To New Designs +## Adding Dedicated Soft On/Off GPIO Pin To New Designs ### Hardware Design -ZMK's soft on/off requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the +ZMK's dedicated soft on/off pin feature requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the soft off state when it goes active again later. #### Simple Direct Pin @@ -71,10 +71,9 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior ``` / { behaviors { - hw_soft_off: behavior_hw_soft_off { + hw_soft_off: hw_soft_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; - label = "HW_SO"; hold-time-ms = <5000>; }; }; From fceb0351a58622e7a89a649efdb387c1c2ea2df1 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 20 Dec 2023 18:08:40 -0800 Subject: [PATCH 054/134] refactor: Fixes for soft-off based on review. * Better naming for gpio-key behavior triggers. * Tweaks to scanned behavior trigger to avoid bad semaphore use, and reduce chance of issues with slowly scanned matrixes. * Various code cleanups of style issues. --- app/CMakeLists.txt | 6 +- app/Kconfig | 4 +- app/Kconfig.behaviors | 8 +- app/boards/shields/zmk_uno/Kconfig.defconfig | 3 + .../zmk_uno/boards/nrf52840dk_nrf52840.conf | 1 - .../boards/nrf52840dk_nrf52840.overlay | 4 +- app/dts/behaviors/soft_off.dtsi | 1 - ...aml => zmk,gpio-key-behavior-trigger.yaml} | 4 +- ....yaml => zmk,gpio-key-wakeup-trigger.yaml} | 2 +- ...mk,gpio-scanned-key-behavior-trigger.yaml} | 4 +- .../bindings/zmk,soft-off-wakeup-sources.yaml | 4 +- app/module/drivers/kscan/kscan_gpio_direct.c | 7 +- app/module/drivers/kscan/kscan_gpio_matrix.c | 7 +- app/src/behaviors/behavior_soft_off.c | 2 +- ...vior_key.c => gpio_key_behavior_trigger.c} | 88 +++++++------ app/src/gpio_key_wakeup_trigger.c | 96 +++++++++++++++ ....c => gpio_scanned_key_behavior_trigger.c} | 116 ++++++++---------- app/src/pm.c | 4 +- app/src/wakeup_trigger_key.c | 87 ------------- docs/docs/config/kscan.md | 2 +- docs/docs/features/soft-off.md | 12 +- 21 files changed, 230 insertions(+), 232 deletions(-) delete mode 100644 app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf rename app/dts/bindings/{zmk,behavior-key.yaml => zmk,gpio-key-behavior-trigger.yaml} (86%) rename app/dts/bindings/{zmk,wakeup-trigger-key.yaml => zmk,gpio-key-wakeup-trigger.yaml} (90%) rename app/dts/bindings/{zmk,behavior-key-scanned.yaml => zmk,gpio-scanned-key-behavior-trigger.yaml} (86%) rename app/src/{behavior_key.c => gpio_key_behavior_trigger.c} (61%) create mode 100644 app/src/gpio_key_wakeup_trigger.c rename app/src/{behavior_key_scanned.c => gpio_scanned_key_behavior_trigger.c} (57%) delete mode 100644 app/src/wakeup_trigger_key.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index bf7cfeefb40..908800db7d8 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -29,11 +29,11 @@ target_sources(app PRIVATE src/matrix_transform.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) -target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY app PRIVATE src/behavior_key.c) -target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_SCANNED app PRIVATE src/behavior_key_scanned.c) +target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) +target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) -target_sources_ifdef(CONFIG_ZMK_WAKEUP_TRIGGER_KEY app PRIVATE src/wakeup_trigger_key.c) +target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) target_sources(app PRIVATE src/events/activity_state_changed.c) target_sources(app PRIVATE src/events/position_state_changed.c) target_sources(app PRIVATE src/events/sensor_event.c) diff --git a/app/Kconfig b/app/Kconfig index 60a959d4986..3ca56793605 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -427,10 +427,10 @@ config ZMK_PM_SOFT_OFF bool "Soft-off support" select PM_DEVICE -config ZMK_WAKEUP_TRIGGER_KEY +config ZMK_GPIO_KEY_WAKEUP_TRIGGER bool "Hardware supported wakeup (GPIO)" default y - depends on DT_HAS_ZMK_WAKEUP_TRIGGER_KEY_ENABLED && ZMK_PM_SOFT_OFF + depends on DT_HAS_ZMK_GPIO_KEY_WAKEUP_TRIGGER_ENABLED && ZMK_PM_SOFT_OFF #Power Management endmenu diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 18fd5c15b0f..ecd06ffbff1 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,15 +1,15 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT -config ZMK_BEHAVIOR_KEY +config ZMK_GPIO_KEY_BEHAVIOR_TRIGGER bool default y - depends on DT_HAS_ZMK_BEHAVIOR_KEY_ENABLED + depends on DT_HAS_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER_ENABLED -config ZMK_BEHAVIOR_KEY_SCANNED +config ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER bool default y - depends on DT_HAS_ZMK_BEHAVIOR_KEY_SCANNED_ENABLED + depends on DT_HAS_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER_ENABLED config ZMK_BEHAVIOR_KEY_TOGGLE bool diff --git a/app/boards/shields/zmk_uno/Kconfig.defconfig b/app/boards/shields/zmk_uno/Kconfig.defconfig index cccca1d2dee..95602ca73f9 100644 --- a/app/boards/shields/zmk_uno/Kconfig.defconfig +++ b/app/boards/shields/zmk_uno/Kconfig.defconfig @@ -20,4 +20,7 @@ config ZMK_RGB_UNDERGLOW select WS2812_STRIP select SPI +config ZMK_PM_SOFT_OFF + default y if BOARD_NRF52840DK_NRF52840 + endif diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index ac92c4d8f00..00000000000 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ZMK_PM_SOFT_OFF=y \ No newline at end of file diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index d08105c6889..b068b431e25 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -43,7 +43,7 @@ encoder: &qdec0 { }; wakeup_source: wakeup_source { - compatible = "zmk,wakeup-trigger-key"; + compatible = "zmk,gpio-key-wakeup-trigger"; status = "okay"; trigger = <&button0>; @@ -58,7 +58,7 @@ encoder: &qdec0 { }; soft_off_behavior_key { - compatible = "zmk,behavior-key"; + compatible = "zmk,gpio-key-behavior-trigger"; status = "okay"; bindings = <&soft_off>; key = <&button0>; diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index c88e1b51f12..1e58c7711d0 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -8,7 +8,6 @@ behaviors { /omit-if-no-ref/ soft_off: soft_off { compatible = "zmk,behavior-soft-off"; - label = "SOFTOFF"; #binding-cells = <0>; }; }; diff --git a/app/dts/bindings/zmk,behavior-key.yaml b/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml similarity index 86% rename from app/dts/bindings/zmk,behavior-key.yaml rename to app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml index ff7a585eafa..2a1387f0220 100644 --- a/app/dts/bindings/zmk,behavior-key.yaml +++ b/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml @@ -4,7 +4,7 @@ description: | Driver for a dedicated key for invoking a connected behavior. -compatible: "zmk,behavior-key" +compatible: "zmk,gpio-key-behavior-trigger" include: base.yaml @@ -16,7 +16,7 @@ properties: bindings: type: phandle required: true - description: The GPIO key that triggers wake via interrupt + description: The behavior to invoke when the GPIO key is pressed debounce-press-ms: type: int default: 5 diff --git a/app/dts/bindings/zmk,wakeup-trigger-key.yaml b/app/dts/bindings/zmk,gpio-key-wakeup-trigger.yaml similarity index 90% rename from app/dts/bindings/zmk,wakeup-trigger-key.yaml rename to app/dts/bindings/zmk,gpio-key-wakeup-trigger.yaml index fa7636d1f32..4e16ff3307d 100644 --- a/app/dts/bindings/zmk,wakeup-trigger-key.yaml +++ b/app/dts/bindings/zmk,gpio-key-wakeup-trigger.yaml @@ -4,7 +4,7 @@ description: | Driver for a dedicated key for waking the device from sleep -compatible: "zmk,wakeup-trigger-key" +compatible: "zmk,gpio-key-wakeup-trigger" include: base.yaml diff --git a/app/dts/bindings/zmk,behavior-key-scanned.yaml b/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml similarity index 86% rename from app/dts/bindings/zmk,behavior-key-scanned.yaml rename to app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml index bdb3abaff0e..860155dda72 100644 --- a/app/dts/bindings/zmk,behavior-key-scanned.yaml +++ b/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml @@ -4,7 +4,7 @@ description: | Driver for a dedicated key triggered by matrix scanning for invoking a connected behavior. -compatible: "zmk,behavior-key-scanned" +compatible: "zmk,gpio-scanned-key-behavior-trigger" include: base.yaml @@ -16,7 +16,7 @@ properties: bindings: type: phandle required: true - description: The GPIO key that triggers wake via interrupt + description: The behavior to invoke when the GPIO key is pressed debounce-press-ms: type: int default: 5 diff --git a/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml index f98039a0ca9..6b55d5d265a 100644 --- a/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml +++ b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml @@ -2,7 +2,7 @@ # SPDX-License-Identifier: MIT description: | - Description of all possible wakeup-sources from a forces + Description of all possible wakeup-sources from a forced soft-off state. compatible: "zmk,soft-off-wakeup-sources" @@ -11,4 +11,4 @@ properties: wakeup-sources: type: phandles required: true - description: List of wakeup-sources that should be enabled to wake the system from forces soft-off state. + description: List of wakeup-sources that should be enabled to wake the system from forced soft-off state. diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index 2bc35f4c0b3..7cfdb480f10 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -322,8 +322,6 @@ static int kscan_direct_init(const struct device *dev) { #if IS_ENABLED(CONFIG_PM_DEVICE) static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) { - int ret = 0; - switch (action) { case PM_DEVICE_ACTION_SUSPEND: kscan_direct_disable(dev); @@ -332,11 +330,8 @@ static int kscan_direct_pm_action(const struct device *dev, enum pm_device_actio kscan_direct_enable(dev); break; default: - ret = -ENOTSUP; - break; + return -ENOTSUP; } - - return ret; } #endif // IS_ENABLED(CONFIG_PM_DEVICE) diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index 3917196e6c8..0daf97dc22d 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -425,8 +425,6 @@ static int kscan_matrix_init(const struct device *dev) { #if IS_ENABLED(CONFIG_PM_DEVICE) static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) { - int ret = 0; - switch (action) { case PM_DEVICE_ACTION_SUSPEND: kscan_matrix_disable(dev); @@ -435,11 +433,8 @@ static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_actio kscan_matrix_enable(dev); break; default: - ret = -ENOTSUP; - break; + return -ENOTSUP; } - - return ret; } #endif // IS_ENABLED(CONFIG_PM_DEVICE) diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 0f24a644d9a..e6096bb4841 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 The ZMK Contributors + * Copyright (c) 2023 The ZMK Contributors * * SPDX-License-Identifier: MIT */ diff --git a/app/src/behavior_key.c b/app/src/gpio_key_behavior_trigger.c similarity index 61% rename from app/src/behavior_key.c rename to app/src/gpio_key_behavior_trigger.c index 3633ce39a40..a72f8e48925 100644 --- a/app/src/behavior_key.c +++ b/app/src/gpio_key_behavior_trigger.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -#define DT_DRV_COMPAT zmk_behavior_key +#define DT_DRV_COMPAT zmk_gpio_key_behavior_trigger #include #include @@ -19,13 +19,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -struct behavior_key_config { +struct gkbt_config { struct zmk_debounce_config debounce_config; int32_t debounce_scan_period_ms; struct gpio_dt_spec key; }; -struct behavior_key_data { +struct gkbt_data { struct zmk_behavior_binding binding; struct zmk_debounce_state debounce_state; struct gpio_callback key_callback; @@ -34,21 +34,21 @@ struct behavior_key_data { uint32_t read_time; }; -static void bk_enable_interrupt(const struct device *dev) { - const struct behavior_key_config *config = dev->config; +static void gkbt_enable_interrupt(const struct device *dev) { + const struct gkbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_LEVEL_ACTIVE); } -static void bk_disable_interrupt(const struct device *dev) { - const struct behavior_key_config *config = dev->config; +static void gkbt_disable_interrupt(const struct device *dev) { + const struct gkbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); } -static void bk_read(const struct device *dev) { - const struct behavior_key_config *config = dev->config; - struct behavior_key_data *data = dev->data; +static void gkbt_read(const struct device *dev) { + const struct gkbt_config *config = dev->config; + struct gkbt_data *data = dev->data; zmk_debounce_update(&data->debounce_state, gpio_pin_get_dt(&config->key), config->debounce_scan_period_ms, &config->debounce_config); @@ -71,65 +71,72 @@ static void bk_read(const struct device *dev) { k_work_reschedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); } else { - bk_enable_interrupt(dev); + gkbt_enable_interrupt(dev); } } -static void bk_update_work(struct k_work *work) { +static void gkbt_update_work(struct k_work *work) { struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct behavior_key_data *data = CONTAINER_OF(dwork, struct behavior_key_data, update_work); - bk_read(data->dev); + struct gkbt_data *data = CONTAINER_OF(dwork, struct gkbt_data, update_work); + gkbt_read(data->dev); } -static void bk_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct behavior_key_data *data = CONTAINER_OF(cb, struct behavior_key_data, key_callback); +static void gkbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct gkbt_data *data = CONTAINER_OF(cb, struct gkbt_data, key_callback); - bk_disable_interrupt(data->dev); + gkbt_disable_interrupt(data->dev); data->read_time = k_uptime_get(); k_work_reschedule(&data->update_work, K_NO_WAIT); } -static int behavior_key_init(const struct device *dev) { - const struct behavior_key_config *config = dev->config; - struct behavior_key_data *data = dev->data; +static void gkbt_wait_for_key_release(const struct device *dev) { + const struct gkbt_config *config = dev->config; + + while (gpio_pin_get_dt(&config->key)) { + k_sleep(K_MSEC(100)); + } +} + +static int gkbt_init(const struct device *dev) { + const struct gkbt_config *config = dev->config; + struct gkbt_data *data = dev->data; if (!device_is_ready(config->key.port)) { - LOG_ERR("GPIO port is not ready"); + LOG_ERR("GPIO port %s is not ready", config->key.port->name); return -ENODEV; } - k_work_init_delayable(&data->update_work, bk_update_work); + k_work_init_delayable(&data->update_work, gkbt_update_work); data->dev = dev; gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, bk_gpio_irq_callback, BIT(config->key.pin)); + gpio_init_callback(&data->key_callback, gkbt_gpio_irq_callback, BIT(config->key.pin)); gpio_add_callback(config->key.port, &data->key_callback); - while (gpio_pin_get_dt(&config->key)) { - k_sleep(K_MSEC(100)); - } + // Be sure our wakeup key is released before startup continues to avoid wake/sleep loop. + gkbt_wait_for_key_release(dev); - bk_enable_interrupt(dev); + gkbt_enable_interrupt(dev); return 0; } -static int behavior_key_pm_action(const struct device *dev, enum pm_device_action action) { - const struct behavior_key_config *config = dev->config; - struct behavior_key_data *data = dev->data; +static int gkbt_pm_action(const struct device *dev, enum pm_device_action action) { + const struct gkbt_config *config = dev->config; + struct gkbt_data *data = dev->data; int ret; switch (action) { case PM_DEVICE_ACTION_SUSPEND: - bk_disable_interrupt(dev); + gkbt_disable_interrupt(dev); ret = gpio_remove_callback(config->key.port, &data->key_callback); break; case PM_DEVICE_ACTION_RESUME: ret = gpio_add_callback(config->key.port, &data->key_callback); - bk_enable_interrupt(dev); + gkbt_enable_interrupt(dev); break; default: ret = -ENOTSUP; @@ -139,8 +146,8 @@ static int behavior_key_pm_action(const struct device *dev, enum pm_device_actio return ret; } -#define BK_INST(n) \ - const struct behavior_key_config bk_config_##n = { \ +#define GKBT_INST(n) \ + const struct gkbt_config gkbt_config_##n = { \ .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ .debounce_config = \ { \ @@ -149,11 +156,12 @@ static int behavior_key_pm_action(const struct device *dev, enum pm_device_actio }, \ .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ }; \ - struct behavior_key_data bk_data_##n = { \ + struct gkbt_data gkbt_data_##n = { \ .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ }; \ - PM_DEVICE_DT_INST_DEFINE(n, behavior_key_pm_action); \ - DEVICE_DT_INST_DEFINE(n, behavior_key_init, PM_DEVICE_DT_INST_GET(n), &bk_data_##n, \ - &bk_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + PM_DEVICE_DT_INST_DEFINE(n, gkbt_pm_action); \ + DEVICE_DT_INST_DEFINE(n, gkbt_init, PM_DEVICE_DT_INST_GET(n), &gkbt_data_##n, \ + &gkbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + NULL); -DT_INST_FOREACH_STATUS_OKAY(BK_INST) +DT_INST_FOREACH_STATUS_OKAY(GKBT_INST) diff --git a/app/src/gpio_key_wakeup_trigger.c b/app/src/gpio_key_wakeup_trigger.c new file mode 100644 index 00000000000..ac0c6b228db --- /dev/null +++ b/app/src/gpio_key_wakeup_trigger.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define DT_DRV_COMPAT zmk_gpio_key_wakeup_trigger + +struct gpio_key_wakeup_trigger_config { + struct gpio_dt_spec trigger; + size_t extra_gpios_count; + struct gpio_dt_spec extra_gpios[]; +}; + +static int zmk_gpio_key_wakeup_trigger_init(const struct device *dev) { +#if IS_ENABLED(CONFIG_PM_DEVICE) + pm_device_init_suspended(dev); + pm_device_wakeup_enable(dev, true); +#endif + + return 0; +} + +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int gpio_key_wakeup_trigger_pm_resume(const struct device *dev) { + const struct gpio_key_wakeup_trigger_config *config = dev->config; + + int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + goto exit; + } + + for (int i = 0; i < config->extra_gpios_count; i++) { + ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); + goto exit; + } + } + +exit: + return ret; +} + +static int gpio_key_wakeup_trigger_pm_suspend(const struct device *dev) { + const struct gpio_key_wakeup_trigger_config *config = dev->config; + + int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_DISABLE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + } + + return ret; +} + +static int gpio_key_wakeup_trigger_pm_action(const struct device *dev, + enum pm_device_action action) { + switch (action) { + case PM_DEVICE_ACTION_RESUME: + return gpio_key_wakeup_trigger_pm_resume(dev); + case PM_DEVICE_ACTION_SUSPEND: + return gpio_key_wakeup_trigger_pm_suspend(dev); + default: + return -ENOTSUP; + } +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + +#define WAKEUP_TRIGGER_EXTRA_GPIO_SPEC(idx, n) \ + GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), extra_gpios, idx) + +#define GPIO_KEY_WAKEUP_TRIGGER_INST(n) \ + const struct gpio_key_wakeup_trigger_config wtk_cfg_##n = { \ + .trigger = GPIO_DT_SPEC_GET(DT_INST_PROP(n, trigger), gpios), \ + .extra_gpios = {LISTIFY(DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + WAKEUP_TRIGGER_EXTRA_GPIO_SPEC, (, ), n)}, \ + .extra_gpios_count = DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, gpio_key_wakeup_trigger_pm_action); \ + DEVICE_DT_INST_DEFINE(n, zmk_gpio_key_wakeup_trigger_init, PM_DEVICE_DT_INST_GET(n), NULL, \ + &wtk_cfg_##n, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DT_INST_FOREACH_STATUS_OKAY(GPIO_KEY_WAKEUP_TRIGGER_INST) diff --git a/app/src/behavior_key_scanned.c b/app/src/gpio_scanned_key_behavior_trigger.c similarity index 57% rename from app/src/behavior_key_scanned.c rename to app/src/gpio_scanned_key_behavior_trigger.c index c961b292622..d27b162b191 100644 --- a/app/src/behavior_key_scanned.c +++ b/app/src/gpio_scanned_key_behavior_trigger.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -#define DT_DRV_COMPAT zmk_behavior_key_scanned +#define DT_DRV_COMPAT zmk_gpio_scanned_key_behavior_trigger #include #include @@ -19,45 +19,41 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -struct behavior_key_scanned_config { +struct gskbt_config { struct zmk_debounce_config debounce_config; int32_t debounce_scan_period_ms; struct gpio_dt_spec key; }; -struct behavior_key_scanned_data { +struct gskbt_data { struct zmk_behavior_binding binding; struct zmk_debounce_state debounce_state; struct gpio_callback key_callback; const struct device *dev; struct k_work_delayable update_work; + struct k_work gpio_trigger_work; uint32_t read_time; + uint32_t trigger_time; bool pin_active; bool active_scan_detected; - struct k_sem sem; }; -static void bks_enable_interrupt(const struct device *dev, bool active_scanning) { - const struct behavior_key_scanned_config *config = dev->config; +static void gskbt_enable_interrupt(const struct device *dev, bool active_scanning) { + const struct gskbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, active_scanning ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_LEVEL_ACTIVE); } -static void bks_disable_interrupt(const struct device *dev) { - const struct behavior_key_scanned_config *config = dev->config; +static void gskbt_disable_interrupt(const struct device *dev) { + const struct gskbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); } -static void bks_read(const struct device *dev) { - const struct behavior_key_scanned_config *config = dev->config; - struct behavior_key_scanned_data *data = dev->data; - - if (k_sem_take(&data->sem, K_NO_WAIT) < 0) { - // k_work_reschedule(&data->update_work, K_NO_WAIT); - return; - } +static void gskbt_read(const struct device *dev) { + const struct gskbt_config *config = dev->config; + struct gskbt_data *data = dev->data; zmk_debounce_update(&data->debounce_state, data->active_scan_detected, config->debounce_scan_period_ms, &config->debounce_config); @@ -81,89 +77,83 @@ static void bks_read(const struct device *dev) { k_work_schedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); } else { - bks_enable_interrupt(dev, false); + gskbt_enable_interrupt(dev, false); } - - k_sem_give(&data->sem); } -static void bks_update_work(struct k_work *work) { +static void gskbt_update_work(struct k_work *work) { struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct behavior_key_scanned_data *data = - CONTAINER_OF(dwork, struct behavior_key_scanned_data, update_work); - bks_read(data->dev); + struct gskbt_data *data = CONTAINER_OF(dwork, struct gskbt_data, update_work); + gskbt_read(data->dev); } -static void bks_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct behavior_key_scanned_data *data = - CONTAINER_OF(cb, struct behavior_key_scanned_data, key_callback); - const struct behavior_key_scanned_config *config = data->dev->config; - - uint32_t time = k_uptime_get(); - - if (k_sem_take(&data->sem, K_MSEC(10)) < 0) { - LOG_ERR("FAILED TO TAKE THE SEMAPHORE"); - // Do more? - return; - } +static void gskbt_gpio_interrupt_work(struct k_work *work) { + struct gskbt_data *data = CONTAINER_OF(work, struct gskbt_data, gpio_trigger_work); - data->active_scan_detected = true; - data->read_time = time; + const struct gskbt_config *config = data->dev->config; if (!zmk_debounce_is_active(&data->debounce_state)) { - // When we get that very first interrupt, we need to schedule the update checks to fall in - // between each of the real scans, so we can do our checks for state *after* each scan has + // When we get that very first interrupt, we need to schedule the update checks right before + // the next real scan, so we can do our checks for state *after* each scan has // occurred. + data->read_time = data->trigger_time; k_work_reschedule(&data->update_work, - K_TIMEOUT_ABS_MS(time + (config->debounce_scan_period_ms / 2))); - - bks_enable_interrupt(data->dev, true); + K_TIMEOUT_ABS_MS(data->read_time + config->debounce_scan_period_ms - 1)); } +} - k_sem_give(&data->sem); +static void gskbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct gskbt_data *data = CONTAINER_OF(cb, struct gskbt_data, key_callback); + + // LOG_DBG("IRQ"); + data->active_scan_detected = true; + data->trigger_time = k_uptime_get(); + gskbt_enable_interrupt(data->dev, true); + k_work_submit(&data->gpio_trigger_work); } -static int behavior_key_scanned_init(const struct device *dev) { - const struct behavior_key_scanned_config *config = dev->config; - struct behavior_key_scanned_data *data = dev->data; +static int gskbt_init(const struct device *dev) { + const struct gskbt_config *config = dev->config; + struct gskbt_data *data = dev->data; if (!device_is_ready(config->key.port)) { LOG_ERR("GPIO port is not ready"); return -ENODEV; } - k_work_init_delayable(&data->update_work, bks_update_work); - k_sem_init(&data->sem, 1, 1); + k_work_init_delayable(&data->update_work, gskbt_update_work); + k_work_init(&data->gpio_trigger_work, gskbt_gpio_interrupt_work); + data->dev = dev; gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, bks_gpio_irq_callback, BIT(config->key.pin)); + gpio_init_callback(&data->key_callback, gskbt_gpio_irq_callback, BIT(config->key.pin)); gpio_add_callback(config->key.port, &data->key_callback); while (gpio_pin_get_dt(&config->key)) { k_sleep(K_MSEC(100)); } - bks_enable_interrupt(dev, false); + gskbt_enable_interrupt(dev, false); return 0; } -static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_device_action action) { - const struct behavior_key_scanned_config *config = dev->config; - struct behavior_key_scanned_data *data = dev->data; +static int gskbt_pm_action(const struct device *dev, enum pm_device_action action) { + const struct gskbt_config *config = dev->config; + struct gskbt_data *data = dev->data; int ret; switch (action) { case PM_DEVICE_ACTION_SUSPEND: - bks_disable_interrupt(dev); + gskbt_disable_interrupt(dev); ret = gpio_remove_callback(config->key.port, &data->key_callback); break; case PM_DEVICE_ACTION_RESUME: ret = gpio_add_callback(config->key.port, &data->key_callback); - bks_enable_interrupt(dev, false); + gskbt_enable_interrupt(dev, false); break; default: ret = -ENOTSUP; @@ -173,8 +163,8 @@ static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_devi return ret; } -#define BK_INST(n) \ - const struct behavior_key_scanned_config bks_config_##n = { \ +#define GSKBT_INST(n) \ + const struct gskbt_config gskbt_config_##n = { \ .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ .debounce_config = \ { \ @@ -183,12 +173,12 @@ static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_devi }, \ .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ }; \ - struct behavior_key_scanned_data bks_data_##n = { \ + struct gskbt_data gskbt_data_##n = { \ .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ }; \ - PM_DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_pm_action); \ - DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_init, PM_DEVICE_DT_INST_GET(n), &bks_data_##n, \ - &bks_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + PM_DEVICE_DT_INST_DEFINE(n, gskbt_pm_action); \ + DEVICE_DT_INST_DEFINE(n, gskbt_init, PM_DEVICE_DT_INST_GET(n), &gskbt_data_##n, \ + &gskbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ NULL); -DT_INST_FOREACH_STATUS_OKAY(BK_INST) +DT_INST_FOREACH_STATUS_OKAY(GSKBT_INST) diff --git a/app/src/pm.c b/app/src/pm.c index a78b6ae53cb..41d72eeed30 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -41,10 +41,10 @@ int zmk_pm_soft_off(void) { // from normal "inactive goes to sleep" behavior, so disable them as wakeup devices // and then suspend them so we're ready to take over setting up our system // and then putting it into an off state. + LOG_DBG("soft-on-off pressed cb: suspend devices"); for (int i = 0; i < device_count; i++) { const struct device *dev = &devs[i]; - LOG_DBG("soft-on-off pressed cb: suspend device"); if (pm_device_wakeup_is_enabled(dev)) { pm_device_wakeup_enable(dev, false); } @@ -60,6 +60,6 @@ int zmk_pm_soft_off(void) { } #endif // HAS_WAKERS - LOG_DBG("soft-on-off interrupt: go to sleep"); + LOG_DBG("soft-off: go to sleep"); return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); } diff --git a/app/src/wakeup_trigger_key.c b/app/src/wakeup_trigger_key.c deleted file mode 100644 index 0cc4f250707..00000000000 --- a/app/src/wakeup_trigger_key.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#include -#include -#include -#include -#include - -#include - -LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); - -#define DT_DRV_COMPAT zmk_wakeup_trigger_key - -struct wakeup_trigger_key_config { - struct gpio_dt_spec trigger; - size_t extra_gpios_count; - struct gpio_dt_spec extra_gpios[]; -}; - -static int zmk_wakeup_trigger_key_init(const struct device *dev) { -#if IS_ENABLED(CONFIG_PM_DEVICE) - pm_device_init_suspended(dev); - pm_device_wakeup_enable(dev, true); -#endif - - return 0; -} - -#if IS_ENABLED(CONFIG_PM_DEVICE) - -static int wakeup_trigger_key_pm_action(const struct device *dev, enum pm_device_action action) { - const struct wakeup_trigger_key_config *config = dev->config; - int ret = 0; - - switch (action) { - case PM_DEVICE_ACTION_RESUME: - ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); - if (ret < 0) { - LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); - return ret; - } - - for (int i = 0; i < config->extra_gpios_count; i++) { - ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); - if (ret < 0) { - LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); - } - } - break; - case PM_DEVICE_ACTION_SUSPEND: - - ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_DISABLE); - if (ret < 0) { - LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); - return ret; - } - break; - default: - ret = -ENOTSUP; - break; - } - - return ret; -} - -#endif // IS_ENABLED(CONFIG_PM_DEVICE) - -#define WAKEUP_TRIGGER_EXTRA_GPIO_SPEC(idx, n) \ - GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), extra_gpios, idx) - -#define WAKEUP_TRIGGER_KEY_INST(n) \ - const struct wakeup_trigger_key_config wtk_cfg_##n = { \ - .trigger = GPIO_DT_SPEC_GET(DT_INST_PROP(n, trigger), gpios), \ - .extra_gpios = {LISTIFY(DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ - WAKEUP_TRIGGER_EXTRA_GPIO_SPEC, (, ), n)}, \ - .extra_gpios_count = DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ - }; \ - PM_DEVICE_DT_INST_DEFINE(n, wakeup_trigger_key_pm_action); \ - DEVICE_DT_INST_DEFINE(n, zmk_wakeup_trigger_key_init, PM_DEVICE_DT_INST_GET(n), NULL, \ - &wtk_cfg_##n, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); - -DT_INST_FOREACH_STATUS_OKAY(WAKEUP_TRIGGER_KEY_INST) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 3076edc0f41..4a3954f9f03 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -455,7 +455,7 @@ Note that the entire addressable space does not need to be mapped. }; kscan0: kscan { - compatible = "zmk,kscan-gpio-charlieplex";k + compatible = "zmk,kscan-gpio-charlieplex"; wakeup-source; interrupt-gpios = <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) >; diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index a3a5d7a1cb7..6b6b5cf4b33 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -79,7 +79,7 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior }; soft_off_behavior_key { - compatible = "zmk,behavior-key"; + compatible = "zmk,gpio-key-behavior-trigger"; bindings = <&hw_soft_off>; key = <&wakeup_key>; }; @@ -88,7 +88,7 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior Here are the properties for the behavior key node: -- The `compatible` property for the node must be `zmk,behavior-key`. +- The `compatible` property for the node must be `zmk,gpio-key-behavior-trigger`. - The `bindings` property is a phandle to the soft off behavior defined above. - The `key` property is a phandle to the GPIO key defined earlier. @@ -97,7 +97,7 @@ If you have set up your on/off to be controlled by a matrix-integrated combo, th ``` / { soft_off_behavior_key { - compatible = "zmk,behavior-key-scanned"; + compatible = "zmk,gpio-scanned-key-behavior-trigger"; status = "okay"; bindings = <&hw_soft_off>; key = <&wakeup_key>; @@ -105,7 +105,7 @@ If you have set up your on/off to be controlled by a matrix-integrated combo, th }; ``` -Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,behavior-key-scanned`. +Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,gpio-scanned-key-behavior-trigger`. #### Wakeup Sources @@ -131,7 +131,7 @@ Next, we need to add another device which will be enabled only when the keyboard ``` / { wakeup_source: wakeup_source { - compatible = "zmk,wakeup-trigger-key"; + compatible = "zmk,gpio-key-wakeup-trigger"; trigger = <&wakeup_key>; wakeup-source; @@ -141,7 +141,7 @@ Next, we need to add another device which will be enabled only when the keyboard Here are the properties for the node: -- The `compatible` property for the node must be `zmk,wakeup-trigger-key`. +- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. - The `trigger` property is a phandle to the GPIO key defined earlier. - The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. - An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. From 5ebe924e941ba00e81d1c66ad2333e6a73826754 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 29 Dec 2023 15:03:14 -0800 Subject: [PATCH 055/134] chore: Various soft-off review fixes * Code style to avoid goto. * Enable pm.c compilation via dedicated Kconfig flag. * Comment wakeup trigger PM behavior. --- app/CMakeLists.txt | 2 +- app/Kconfig | 4 ++++ app/module/drivers/kscan/kscan_gpio_direct.c | 6 ++---- app/module/drivers/kscan/kscan_gpio_matrix.c | 6 ++---- app/src/gpio_key_wakeup_trigger.c | 16 +++++++++++++--- app/src/pm.c | 4 ++++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 908800db7d8..a56a63b369d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -31,7 +31,7 @@ target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c) -target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c) +target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) target_sources(app PRIVATE src/events/activity_state_changed.c) diff --git a/app/Kconfig b/app/Kconfig index 3ca56793605..df84d97d253 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -423,8 +423,12 @@ config ZMK_EXT_POWER bool "Enable support to control external power output" default y +config ZMK_PM + bool + config ZMK_PM_SOFT_OFF bool "Soft-off support" + select ZMK_PM select PM_DEVICE config ZMK_GPIO_KEY_WAKEUP_TRIGGER diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index 7cfdb480f10..a10190da9e7 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -324,11 +324,9 @@ static int kscan_direct_init(const struct device *dev) { static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) { switch (action) { case PM_DEVICE_ACTION_SUSPEND: - kscan_direct_disable(dev); - break; + return kscan_direct_disable(dev); case PM_DEVICE_ACTION_RESUME: - kscan_direct_enable(dev); - break; + return kscan_direct_enable(dev); default: return -ENOTSUP; } diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index 0daf97dc22d..8a3c39f2ba9 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -427,11 +427,9 @@ static int kscan_matrix_init(const struct device *dev) { static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) { switch (action) { case PM_DEVICE_ACTION_SUSPEND: - kscan_matrix_disable(dev); - break; + return kscan_matrix_disable(dev); case PM_DEVICE_ACTION_RESUME: - kscan_matrix_enable(dev); - break; + return kscan_matrix_enable(dev); default: return -ENOTSUP; } diff --git a/app/src/gpio_key_wakeup_trigger.c b/app/src/gpio_key_wakeup_trigger.c index ac0c6b228db..308c4973d67 100644 --- a/app/src/gpio_key_wakeup_trigger.c +++ b/app/src/gpio_key_wakeup_trigger.c @@ -39,18 +39,17 @@ static int gpio_key_wakeup_trigger_pm_resume(const struct device *dev) { int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); if (ret < 0) { LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); - goto exit; + return ret; } for (int i = 0; i < config->extra_gpios_count; i++) { ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); if (ret < 0) { LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); - goto exit; + return ret; } } -exit: return ret; } @@ -62,9 +61,20 @@ static int gpio_key_wakeup_trigger_pm_suspend(const struct device *dev) { LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); } + for (int i = 0; i < config->extra_gpios_count; i++) { + ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_DISCONNECTED); + if (ret < 0) { + LOG_WRN("Failed to set extra GPIO pin disconnected for waker (%d)", ret); + return ret; + } + } + return ret; } +// The waker is "backwards", in as much as it is designed to be resumed/enabled immediately +// before a soft-off state is entered, so it can wake the device from that state later. +// So this waker correctly resumes and is ready to wake the device later. static int gpio_key_wakeup_trigger_pm_action(const struct device *dev, enum pm_device_action action) { switch (action) { diff --git a/app/src/pm.c b/app/src/pm.c index 41d72eeed30..a4599ac8fce 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -15,6 +15,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include +#if IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) + #define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) #if HAS_WAKERS @@ -63,3 +65,5 @@ int zmk_pm_soft_off(void) { LOG_DBG("soft-off: go to sleep"); return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); } + +#endif // IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) \ No newline at end of file From 933fdcd36400ea9d2f73284ff5936e0c6cefe879 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 29 Dec 2023 16:28:22 -0800 Subject: [PATCH 056/134] refactor(pm): Remove scanned behavior trigger. * Remove the painful scanned behavior trigger for now, future enhancement will restore this high level functionality using kscan directly. --- app/CMakeLists.txt | 1 - app/Kconfig.behaviors | 5 - ...zmk,gpio-scanned-key-behavior-trigger.yaml | 31 --- app/src/gpio_scanned_key_behavior_trigger.c | 184 ------------------ docs/docs/features/soft-off.md | 17 +- 5 files changed, 2 insertions(+), 236 deletions(-) delete mode 100644 app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml delete mode 100644 app/src/gpio_scanned_key_behavior_trigger.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a56a63b369d..4ee9135d23c 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -30,7 +30,6 @@ target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) -target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index ecd06ffbff1..6abdbddd774 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -6,11 +6,6 @@ config ZMK_GPIO_KEY_BEHAVIOR_TRIGGER default y depends on DT_HAS_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER_ENABLED -config ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER - bool - default y - depends on DT_HAS_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER_ENABLED - config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml b/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml deleted file mode 100644 index 860155dda72..00000000000 --- a/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2023 The ZMK Contributors -# SPDX-License-Identifier: MIT - -description: | - Driver for a dedicated key triggered by matrix scanning for invoking a connected behavior. - -compatible: "zmk,gpio-scanned-key-behavior-trigger" - -include: base.yaml - -properties: - key: - type: phandle - required: true - description: The GPIO key that triggers wake via interrupt - bindings: - type: phandle - required: true - description: The behavior to invoke when the GPIO key is pressed - debounce-press-ms: - type: int - default: 5 - description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. - debounce-release-ms: - type: int - default: 5 - description: Debounce time for key release in milliseconds. - debounce-scan-period-ms: - type: int - default: 1 - description: Time between reads in milliseconds when any key is pressed. diff --git a/app/src/gpio_scanned_key_behavior_trigger.c b/app/src/gpio_scanned_key_behavior_trigger.c deleted file mode 100644 index d27b162b191..00000000000 --- a/app/src/gpio_scanned_key_behavior_trigger.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#define DT_DRV_COMPAT zmk_gpio_scanned_key_behavior_trigger - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); - -struct gskbt_config { - struct zmk_debounce_config debounce_config; - int32_t debounce_scan_period_ms; - struct gpio_dt_spec key; -}; - -struct gskbt_data { - struct zmk_behavior_binding binding; - struct zmk_debounce_state debounce_state; - struct gpio_callback key_callback; - const struct device *dev; - struct k_work_delayable update_work; - struct k_work gpio_trigger_work; - uint32_t read_time; - uint32_t trigger_time; - bool pin_active; - bool active_scan_detected; -}; - -static void gskbt_enable_interrupt(const struct device *dev, bool active_scanning) { - const struct gskbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, active_scanning ? GPIO_INT_EDGE_TO_ACTIVE - : GPIO_INT_LEVEL_ACTIVE); -} - -static void gskbt_disable_interrupt(const struct device *dev) { - const struct gskbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); -} - -static void gskbt_read(const struct device *dev) { - const struct gskbt_config *config = dev->config; - struct gskbt_data *data = dev->data; - - zmk_debounce_update(&data->debounce_state, data->active_scan_detected, - config->debounce_scan_period_ms, &config->debounce_config); - - if (zmk_debounce_get_changed(&data->debounce_state)) { - const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); - - struct zmk_behavior_binding_event event = {.position = INT32_MAX, - .timestamp = k_uptime_get()}; - - if (pressed) { - behavior_keymap_binding_pressed(&data->binding, event); - } else { - behavior_keymap_binding_released(&data->binding, event); - } - } - - if (zmk_debounce_is_active(&data->debounce_state)) { - data->active_scan_detected = false; - data->read_time += config->debounce_scan_period_ms; - - k_work_schedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); - } else { - gskbt_enable_interrupt(dev, false); - } -} - -static void gskbt_update_work(struct k_work *work) { - struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct gskbt_data *data = CONTAINER_OF(dwork, struct gskbt_data, update_work); - gskbt_read(data->dev); -} - -static void gskbt_gpio_interrupt_work(struct k_work *work) { - struct gskbt_data *data = CONTAINER_OF(work, struct gskbt_data, gpio_trigger_work); - - const struct gskbt_config *config = data->dev->config; - - if (!zmk_debounce_is_active(&data->debounce_state)) { - // When we get that very first interrupt, we need to schedule the update checks right before - // the next real scan, so we can do our checks for state *after* each scan has - // occurred. - data->read_time = data->trigger_time; - k_work_reschedule(&data->update_work, - K_TIMEOUT_ABS_MS(data->read_time + config->debounce_scan_period_ms - 1)); - } -} - -static void gskbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct gskbt_data *data = CONTAINER_OF(cb, struct gskbt_data, key_callback); - - // LOG_DBG("IRQ"); - data->active_scan_detected = true; - data->trigger_time = k_uptime_get(); - gskbt_enable_interrupt(data->dev, true); - k_work_submit(&data->gpio_trigger_work); -} - -static int gskbt_init(const struct device *dev) { - const struct gskbt_config *config = dev->config; - struct gskbt_data *data = dev->data; - - if (!device_is_ready(config->key.port)) { - LOG_ERR("GPIO port is not ready"); - return -ENODEV; - } - - k_work_init_delayable(&data->update_work, gskbt_update_work); - k_work_init(&data->gpio_trigger_work, gskbt_gpio_interrupt_work); - - data->dev = dev; - - gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, gskbt_gpio_irq_callback, BIT(config->key.pin)); - gpio_add_callback(config->key.port, &data->key_callback); - - while (gpio_pin_get_dt(&config->key)) { - k_sleep(K_MSEC(100)); - } - - gskbt_enable_interrupt(dev, false); - - return 0; -} - -static int gskbt_pm_action(const struct device *dev, enum pm_device_action action) { - const struct gskbt_config *config = dev->config; - struct gskbt_data *data = dev->data; - - int ret; - - switch (action) { - case PM_DEVICE_ACTION_SUSPEND: - gskbt_disable_interrupt(dev); - ret = gpio_remove_callback(config->key.port, &data->key_callback); - break; - case PM_DEVICE_ACTION_RESUME: - ret = gpio_add_callback(config->key.port, &data->key_callback); - gskbt_enable_interrupt(dev, false); - break; - default: - ret = -ENOTSUP; - break; - } - - return ret; -} - -#define GSKBT_INST(n) \ - const struct gskbt_config gskbt_config_##n = { \ - .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ - .debounce_config = \ - { \ - .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ - .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ - }, \ - .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ - }; \ - struct gskbt_data gskbt_data_##n = { \ - .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ - }; \ - PM_DEVICE_DT_INST_DEFINE(n, gskbt_pm_action); \ - DEVICE_DT_INST_DEFINE(n, gskbt_init, PM_DEVICE_DT_INST_GET(n), &gskbt_data_##n, \ - &gskbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - NULL); - -DT_INST_FOREACH_STATUS_OKAY(GSKBT_INST) diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index 6b6b5cf4b33..370a3880769 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -37,7 +37,7 @@ The simplest way to achieve this is with a push button between a GPIO pin and gr #### Matrix-Integrated Hardware Combo -Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. +Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. Support for this mode will be coming soon. ### Firmware Changes @@ -92,20 +92,7 @@ Here are the properties for the behavior key node: - The `bindings` property is a phandle to the soft off behavior defined above. - The `key` property is a phandle to the GPIO key defined earlier. -If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key needs use a different driver that will handle detecting the pressed state when the pin is toggled by the other matrix kscan driver: - -``` -/ { - soft_off_behavior_key { - compatible = "zmk,gpio-scanned-key-behavior-trigger"; - status = "okay"; - bindings = <&hw_soft_off>; - key = <&wakeup_key>; - }; -}; -``` - -Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,gpio-scanned-key-behavior-trigger`. +If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key will need to be integrated into your existing kscan setup. Full details to come when this is supported. #### Wakeup Sources From e78b25a445b5bfc4b0c9b979d68964729c3e8fa1 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 31 Dec 2023 00:34:20 +0000 Subject: [PATCH 057/134] feat(kscan): Direct kscan driver can use gpio-keys. * Allow specifying direct kscan driver pins using gpio-key list as an alternative. --- app/module/drivers/kscan/kscan_gpio_direct.c | 11 +++++++++-- .../dts/bindings/kscan/zmk,kscan-gpio-direct.yaml | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index a10190da9e7..e05eb2f3da1 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -42,9 +42,14 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define COND_POLL_OR_INTERRUPTS(pollcode, intcode) \ COND_CODE_1(CONFIG_ZMK_KSCAN_DIRECT_POLLING, pollcode, intcode) -#define INST_INPUTS_LEN(n) DT_INST_PROP_LEN(n, input_gpios) +#define INST_INPUTS_LEN(n) \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), (DT_INST_PROP_LEN(n, input_gpios)), \ + (DT_INST_PROP_LEN(n, input_keys))) + #define KSCAN_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_GET_BY_IDX(DT_DRV_INST(inst_idx), input_gpios, idx) +#define KSCAN_KEY_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ + KSCAN_GPIO_GET_BY_IDX(DT_INST_PROP_BY_IDX(inst_idx, input_keys, idx), gpios, 0) struct kscan_direct_irq_callback { const struct device *dev; @@ -347,7 +352,9 @@ static const struct kscan_driver_api kscan_direct_api = { "ZMK_KSCAN_DEBOUNCE_RELEASE_MS or debounce-release-ms is too large"); \ \ static struct kscan_gpio kscan_direct_inputs_##n[] = { \ - LISTIFY(INST_INPUTS_LEN(n), KSCAN_DIRECT_INPUT_CFG_INIT, (, ), n)}; \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), \ + (LISTIFY(INST_INPUTS_LEN(n), KSCAN_DIRECT_INPUT_CFG_INIT, (, ), n)), \ + (LISTIFY(INST_INPUTS_LEN(n), KSCAN_KEY_DIRECT_INPUT_CFG_INIT, (, ), n)))}; \ \ static struct zmk_debounce_state kscan_direct_state_##n[INST_INPUTS_LEN(n)]; \ \ diff --git a/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml b/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml index f477b591f87..4953d5cfaf9 100644 --- a/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml +++ b/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml @@ -10,7 +10,11 @@ include: kscan.yaml properties: input-gpios: type: phandle-array - required: true + required: false + input-keys: + type: phandles + required: false + description: List of gpio-key references debounce-period: type: int required: false From a0ad1d4c9402fbfe5e3dee8996057150a3f0f209 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 30 Dec 2023 16:38:52 -0800 Subject: [PATCH 058/134] refactor: Add kscan sideband behavior driver * Instead of gpio key behavior trigger, add new kscan driver that decorates/wraps a given kscan driver and will invoke basic system behavior assigned to a given row + column, without the need for keymap mapping in the matrix transform, bypassing keymaps entirely. --- app/CMakeLists.txt | 2 +- app/Kconfig | 6 + app/Kconfig.behaviors | 5 - .../boards/nrf52840dk_nrf52840.overlay | 19 +- .../kscan/zmk,kscan-sideband-behaviors.yaml | 29 +++ .../zmk,gpio-key-behavior-trigger.yaml | 31 ---- app/src/gpio_key_behavior_trigger.c | 167 ------------------ app/src/kscan_sideband_behaviors.c | 142 +++++++++++++++ 8 files changed, 192 insertions(+), 209 deletions(-) create mode 100644 app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml delete mode 100644 app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml delete mode 100644 app/src/gpio_key_behavior_trigger.c create mode 100644 app/src/kscan_sideband_behaviors.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 4ee9135d23c..2abf943fb39 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -25,11 +25,11 @@ target_sources(app PRIVATE src/stdlib.c) target_sources(app PRIVATE src/activity.c) target_sources(app PRIVATE src/behavior.c) target_sources(app PRIVATE src/kscan.c) +target_sources_ifdef(CONFIG_ZMK_KSCAN_SIDEBAND_BEHAVIORS app PRIVATE src/kscan_sideband_behaviors.c) target_sources(app PRIVATE src/matrix_transform.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) -target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) diff --git a/app/Kconfig b/app/Kconfig index df84d97d253..15c31375d3c 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -512,6 +512,12 @@ config ZMK_KSCAN_EVENT_QUEUE_SIZE endif # ZMK_KSCAN +config ZMK_KSCAN_SIDEBAND_BEHAVIORS + bool + default y + depends on DT_HAS_ZMK_KSCAN_SIDEBAND_BEHAVIORS_ENABLED + select KSCAN + menu "Logging" config ZMK_LOGGING_MINIMAL diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 6abdbddd774..c9754bf7d83 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,11 +1,6 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT -config ZMK_GPIO_KEY_BEHAVIOR_TRIGGER - bool - default y - depends on DT_HAS_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER_ENABLED - config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index b068b431e25..47b67dc0029 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -57,10 +57,19 @@ encoder: &qdec0 { wakeup-sources = <&wakeup_source>; }; - soft_off_behavior_key { - compatible = "zmk,gpio-key-behavior-trigger"; - status = "okay"; - bindings = <&soft_off>; - key = <&button0>; + soft_off_direct_kscan: soft_off_direct_kscan { + compatible = "zmk,kscan-gpio-direct"; + input-keys = <&button0>; }; + + soft_off_sideband_behaviors { + compatible = "zmk,kscan-sideband-behaviors"; + kscan = <&soft_off_direct_kscan>; + soft_off { + row = <0>; + column = <0>; + bindings = <&soft_off>; + }; + }; + }; \ No newline at end of file diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml new file mode 100644 index 00000000000..7289b9e1692 --- /dev/null +++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml @@ -0,0 +1,29 @@ +# Copyright (c) 2023, The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + kscan sideband behavior runner. Only basic system behavior should be used, + since no keymap processing occurs when using them. + +compatible: "zmk,kscan-sideband-behaviors" + +include: [kscan.yaml] + +properties: + kscan: + type: phandle + required: true + +child-binding: + description: "A sideband behavior tied to a row/column pair" + + properties: + row: + type: int + required: true + column: + type: int + required: true + bindings: + type: phandle-array + required: true diff --git a/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml b/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml deleted file mode 100644 index 2a1387f0220..00000000000 --- a/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2023 The ZMK Contributors -# SPDX-License-Identifier: MIT - -description: | - Driver for a dedicated key for invoking a connected behavior. - -compatible: "zmk,gpio-key-behavior-trigger" - -include: base.yaml - -properties: - key: - type: phandle - required: true - description: The GPIO key that triggers wake via interrupt - bindings: - type: phandle - required: true - description: The behavior to invoke when the GPIO key is pressed - debounce-press-ms: - type: int - default: 5 - description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. - debounce-release-ms: - type: int - default: 5 - description: Debounce time for key release in milliseconds. - debounce-scan-period-ms: - type: int - default: 1 - description: Time between reads in milliseconds when any key is pressed. diff --git a/app/src/gpio_key_behavior_trigger.c b/app/src/gpio_key_behavior_trigger.c deleted file mode 100644 index a72f8e48925..00000000000 --- a/app/src/gpio_key_behavior_trigger.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#define DT_DRV_COMPAT zmk_gpio_key_behavior_trigger - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); - -struct gkbt_config { - struct zmk_debounce_config debounce_config; - int32_t debounce_scan_period_ms; - struct gpio_dt_spec key; -}; - -struct gkbt_data { - struct zmk_behavior_binding binding; - struct zmk_debounce_state debounce_state; - struct gpio_callback key_callback; - const struct device *dev; - struct k_work_delayable update_work; - uint32_t read_time; -}; - -static void gkbt_enable_interrupt(const struct device *dev) { - const struct gkbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_LEVEL_ACTIVE); -} - -static void gkbt_disable_interrupt(const struct device *dev) { - const struct gkbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); -} - -static void gkbt_read(const struct device *dev) { - const struct gkbt_config *config = dev->config; - struct gkbt_data *data = dev->data; - - zmk_debounce_update(&data->debounce_state, gpio_pin_get_dt(&config->key), - config->debounce_scan_period_ms, &config->debounce_config); - - if (zmk_debounce_get_changed(&data->debounce_state)) { - const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); - - struct zmk_behavior_binding_event event = {.position = INT32_MAX, - .timestamp = k_uptime_get()}; - - if (pressed) { - behavior_keymap_binding_pressed(&data->binding, event); - } else { - behavior_keymap_binding_released(&data->binding, event); - } - } - - if (zmk_debounce_is_active(&data->debounce_state)) { - data->read_time += config->debounce_scan_period_ms; - - k_work_reschedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); - } else { - gkbt_enable_interrupt(dev); - } -} - -static void gkbt_update_work(struct k_work *work) { - struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct gkbt_data *data = CONTAINER_OF(dwork, struct gkbt_data, update_work); - gkbt_read(data->dev); -} - -static void gkbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct gkbt_data *data = CONTAINER_OF(cb, struct gkbt_data, key_callback); - - gkbt_disable_interrupt(data->dev); - - data->read_time = k_uptime_get(); - k_work_reschedule(&data->update_work, K_NO_WAIT); -} - -static void gkbt_wait_for_key_release(const struct device *dev) { - const struct gkbt_config *config = dev->config; - - while (gpio_pin_get_dt(&config->key)) { - k_sleep(K_MSEC(100)); - } -} - -static int gkbt_init(const struct device *dev) { - const struct gkbt_config *config = dev->config; - struct gkbt_data *data = dev->data; - - if (!device_is_ready(config->key.port)) { - LOG_ERR("GPIO port %s is not ready", config->key.port->name); - return -ENODEV; - } - - k_work_init_delayable(&data->update_work, gkbt_update_work); - data->dev = dev; - - gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, gkbt_gpio_irq_callback, BIT(config->key.pin)); - gpio_add_callback(config->key.port, &data->key_callback); - - // Be sure our wakeup key is released before startup continues to avoid wake/sleep loop. - gkbt_wait_for_key_release(dev); - - gkbt_enable_interrupt(dev); - - return 0; -} - -static int gkbt_pm_action(const struct device *dev, enum pm_device_action action) { - const struct gkbt_config *config = dev->config; - struct gkbt_data *data = dev->data; - - int ret; - - switch (action) { - case PM_DEVICE_ACTION_SUSPEND: - gkbt_disable_interrupt(dev); - ret = gpio_remove_callback(config->key.port, &data->key_callback); - break; - case PM_DEVICE_ACTION_RESUME: - ret = gpio_add_callback(config->key.port, &data->key_callback); - gkbt_enable_interrupt(dev); - break; - default: - ret = -ENOTSUP; - break; - } - - return ret; -} - -#define GKBT_INST(n) \ - const struct gkbt_config gkbt_config_##n = { \ - .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ - .debounce_config = \ - { \ - .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ - .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ - }, \ - .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ - }; \ - struct gkbt_data gkbt_data_##n = { \ - .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ - }; \ - PM_DEVICE_DT_INST_DEFINE(n, gkbt_pm_action); \ - DEVICE_DT_INST_DEFINE(n, gkbt_init, PM_DEVICE_DT_INST_GET(n), &gkbt_data_##n, \ - &gkbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - NULL); - -DT_INST_FOREACH_STATUS_OKAY(GKBT_INST) diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c new file mode 100644 index 00000000000..3a03a293839 --- /dev/null +++ b/app/src/kscan_sideband_behaviors.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_kscan_sideband_behaviors + +#include +#include +#include +#include +#include + +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct ksbb_entry { + uint8_t row; + uint8_t column; + struct zmk_behavior_binding binding; +}; + +struct ksbb_config { + const struct device *kscan; + struct ksbb_entry *entries; + size_t entries_len; +}; + +struct ksbb_data { + kscan_callback_t callback; + bool enabled; +}; + +#define GET_KSBB_DEV(n) DEVICE_DT_GET(DT_DRV_INST(n)), + +// The kscan callback has no context with it, so we keep a static array of all possible +// KSBBs to check when a kscan callback from the "wrapped" inner kscan fires. +static const struct device *ksbbs[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)] = { + DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; + +void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, + bool pressed) { + for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) { + const struct device *ksbb = ksbbs[i]; + const struct ksbb_config *cfg = ksbb->config; + struct ksbb_data *data = ksbb->data; + + if (cfg->kscan != dev) { + continue; + } + + for (int e = 0; e < cfg->entries_len; e++) { + struct ksbb_entry *entry = &cfg->entries[e]; + if (entry->row == row && entry->column == column) { + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&entry->binding, event); + } else { + behavior_keymap_binding_released(&entry->binding, event); + } + return; + } + } + + if (data->enabled && data->callback) { + data->callback(ksbb, row, column, pressed); + } + } +} + +static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { + struct ksbb_data *data = dev->data; + + if (!callback) { + return -EINVAL; + } + + data->callback = callback; + return 0; +} + +static int ksbb_enable(const struct device *dev) { + struct ksbb_data *data = dev->data; + data->enabled = true; + + return 0; +} + +static int ksbb_disable(const struct device *dev) { + struct ksbb_data *data = dev->data; + data->enabled = false; + + return 0; +} + +static int ksbb_init(const struct device *dev) { + const struct ksbb_config *config = dev->config; + + if (!device_is_ready(config->kscan)) { + LOG_ERR("kscan %s is not ready", config->kscan->name); + return -ENODEV; + } + + kscan_config(config->kscan, &ksbb_inner_kscan_callback); + kscan_enable_callback(config->kscan); + + return 0; +} + +static const struct kscan_driver_api ksbb_api = { + .config = ksbb_configure, + .enable_callback = ksbb_enable, + .disable_callback = ksbb_disable, +}; + +#define JUST_ONE(_id) 1 + +#define ENTRY(e) \ + { \ + .row = DT_PROP(e, row), .column = DT_PROP(e, column), \ + .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, e), \ + } + +#define KSBB_INST(n) \ + static struct ksbb_entry entries_##n[] = { \ + DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, ENTRY, (, ))}; \ + const struct ksbb_config ksbb_config_##n = { \ + .kscan = DEVICE_DT_GET(DT_INST_PHANDLE(n, kscan)), \ + .entries = entries_##n, \ + .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ + }; \ + struct ksbb_data ksbb_data_##n = {}; \ + DEVICE_DT_INST_DEFINE(n, ksbb_init, NULL, &ksbb_data_##n, &ksbb_config_##n, APPLICATION, \ + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ksbb_api); + +DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From c3144055e8534169bf1a6d798b1ee712f6c1d002 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 31 Dec 2023 00:57:00 +0000 Subject: [PATCH 059/134] refactor(boards): Move ZMK Uno 1P3T slider to sideband * Invoke output selection from the slider on the ZMK Uno via sideband behavior setup, to simplify keymap. --- app/boards/shields/zmk_uno/zmk_uno.dtsi | 36 +---------------- app/boards/shields/zmk_uno/zmk_uno.keymap | 21 +--------- app/boards/shields/zmk_uno/zmk_uno.overlay | 40 +++++++++++++++++++ app/boards/shields/zmk_uno/zmk_uno_split.dtsi | 10 ++--- .../shields/zmk_uno/zmk_uno_split.keymap | 18 --------- 5 files changed, 46 insertions(+), 79 deletions(-) diff --git a/app/boards/shields/zmk_uno/zmk_uno.dtsi b/app/boards/shields/zmk_uno/zmk_uno.dtsi index 196ac8b5002..e8ba79d6d09 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno.dtsi @@ -40,7 +40,7 @@ nice_view_spi: &arduino_spi { / { chosen { - zmk,kscan = &kscan_matrix_comp; + zmk,kscan = &kscan_matrix; zmk,backlight = &backlight; zmk,underglow = &led_strip; zmk,matrix-transform = &matrix_transform; @@ -74,7 +74,6 @@ nice_view_spi: &arduino_spi { map = < RC(0,0) RC(0,1) RC(1,0) RC(1,1) - RC(2,0) RC(2,1) RC(2,2) >; }; @@ -86,42 +85,9 @@ nice_view_spi: &arduino_spi { map = < RC(0,0) RC(0,1) RC(0,2) RC(0,3) - RC(1,0) RC(1,1) RC(1,2) >; }; - - kscan_matrix_comp: kscan_matrix_comp { - compatible = "zmk,kscan-composite"; - rows = <1>; - columns = <7>; - - matrix { - kscan = <&kscan_matrix>; - }; - - toggle { - kscan = <&kscan_sp3t_toggle>; - row-offset = <2>; - }; - - }; - - kscan_direct_comp: kscan_direct_comp { - compatible = "zmk,kscan-composite"; - status = "disabled"; - - matrix { - kscan = <&kscan_direct>; - }; - - toggle { - kscan = <&kscan_sp3t_toggle>; - row-offset = <1>; - }; - - }; - kscan_matrix: kscan_matrix { compatible = "zmk,kscan-gpio-matrix"; wakeup-source; diff --git a/app/boards/shields/zmk_uno/zmk_uno.keymap b/app/boards/shields/zmk_uno/zmk_uno.keymap index 0e0fc7954c1..e416ff5e6c8 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno.keymap @@ -9,42 +9,25 @@ #include #include #include -#include #include // Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. /* :REMOVE ME -&kscan_direct_comp { status = "okay"; }; &kscan_direct { status = "okay"; }; -&kscan_matrix_comp { status = "disabled"; }; &kscan_matrix { status = "disabled"; }; / { chosen { zmk,matrix-transform = &direct_matrix_transform; - zmk,kscan = &kscan_direct_comp; + zmk,kscan = &kscan_direct; }; }; REMOVE ME: */ - / { - macros { - ZMK_MACRO(ble_zero, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 0>; - ) - ZMK_MACRO(ble_one, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 1>; - ) - }; - keymap { compatible = "zmk,keymap"; @@ -52,8 +35,6 @@ REMOVE ME: */ bindings = < &kp A &bl BL_TOG &rgb_ug RGB_EFF &bt BT_CLR - - &out OUT_USB &ble_zero &ble_one >; sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; diff --git a/app/boards/shields/zmk_uno/zmk_uno.overlay b/app/boards/shields/zmk_uno/zmk_uno.overlay index 4999c82c7e1..c86f6e5c9ee 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.overlay +++ b/app/boards/shields/zmk_uno/zmk_uno.overlay @@ -6,6 +6,10 @@ #include "zmk_uno.dtsi" +#include +#include +#include + / { chosen { zmk,matrix-transform = &matrix_transform; @@ -19,4 +23,40 @@ }; }; + macros { + ZMK_MACRO(ble_zero, + wait-ms = <1>; + tap-ms = <1>; + bindings = <&out OUT_BLE &bt BT_SEL 0>; + ) + ZMK_MACRO(ble_one, + wait-ms = <1>; + tap-ms = <1>; + bindings = <&out OUT_BLE &bt BT_SEL 1>; + ) + }; + + endpoint_sideband_behaviors { + compatible = "zmk,kscan-sideband-behaviors"; + kscan = <&kscan_sp3t_toggle>; + + usb { + row = <0>; + column = <0>; + bindings = <&out OUT_USB>; + }; + + ble_zero { + row = <0>; + column = <1>; + bindings = <&ble_zero>; + }; + + ble_one { + row = <0>; + column = <2>; + bindings = <&ble_one>; + }; + }; + }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.dtsi b/app/boards/shields/zmk_uno/zmk_uno_split.dtsi index 516213bd442..dac6fc3e4ee 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno_split.dtsi @@ -17,16 +17,15 @@ split_matrix_transform: split_matrix_transform { compatible = "zmk,matrix-transform"; - rows = <3>; - columns = <4>; + rows = <4>; + columns = <2>; map = < RC(0,0) RC(0,1) RC(1,0) RC(1,1) - RC(2,0) RC(2,1) RC(2,2) + RC(3,0) RC(3,1) RC(4,0) RC(4,1) - RC(5,0) RC(5,1) RC(5,2) >; }; @@ -38,10 +37,9 @@ map = < RC(0,0) RC(0,1) RC(0,2) RC(0,3) - RC(1,0) RC(1,1) RC(1,2) + RC(2,0) RC(2,1) RC(2,2) RC(2,3) - RC(3,0) RC(3,1) RC(3,2) >; }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap index 05f0ffb0b04..1e46042a7e1 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -16,9 +16,7 @@ /* :REMOVE ME -&kscan_direct_comp { status = "okay"; }; &kscan_direct { status = "okay"; }; -&kscan_matrix_comp { status = "disabled"; }; &kscan_matrix { status = "disabled"; }; / { @@ -30,20 +28,7 @@ REMOVE ME: */ - / { - macros { - ZMK_MACRO(ble_zero, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 0>; - ) - ZMK_MACRO(ble_one, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 1>; - ) - }; keymap { compatible = "zmk,keymap"; @@ -53,11 +38,8 @@ REMOVE ME: */ &kp A &bl BL_TOG &rgb_ug RGB_EFF &bt BT_CLR - &out OUT_USB &ble_zero &ble_one - &kp C &kp D &kp E &kp F - &none &none &none >; sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>; From 09111f1cf36099690bf96091b46214c421b1fb3b Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 31 Dec 2023 06:36:52 +0000 Subject: [PATCH 060/134] fix: Sleep after clearing endpoints to wait for send. * Add a small sleep to allow other threads to send data for the endpoint clearing before sleep. --- app/src/pm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/pm.c b/app/src/pm.c index a4599ac8fce..8525046f049 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -35,6 +35,8 @@ int zmk_pm_soft_off(void) { #if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) zmk_endpoints_clear_current(); + // Need to sleep to give any other threads a chance so submit endpoint data. + k_sleep(K_MSEC(100)); #endif device_count = z_device_get_all_static(&devs); From 4198fac90f4f35e7464cb3793632f81601bbf1d5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 3 Jan 2024 11:11:24 -0800 Subject: [PATCH 061/134] fix(pm): Fix deep sleep with sideband behaviors. * Properly implement the PM hook needed for sideband behavior kscan device to have wakeup source enabled on it. --- .../kscan/zmk,kscan-sideband-behaviors.yaml | 2 +- app/src/kscan.c | 5 ++-- app/src/kscan_sideband_behaviors.c | 29 +++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml index 7289b9e1692..57b54a6041c 100644 --- a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml +++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml @@ -7,7 +7,7 @@ description: | compatible: "zmk,kscan-sideband-behaviors" -include: [kscan.yaml] +include: kscan.yaml properties: kscan: diff --git a/app/src/kscan.c b/app/src/kscan.c index c04ce2d8799..5c7a5535a5b 100644 --- a/app/src/kscan.c +++ b/app/src/kscan.c @@ -74,13 +74,14 @@ int zmk_kscan_init(const struct device *dev) { k_work_init(&msg_processor.work, zmk_kscan_process_msgq); - kscan_config(dev, zmk_kscan_callback); - kscan_enable_callback(dev); #if IS_ENABLED(CONFIG_PM_DEVICE) if (pm_device_wakeup_is_capable(dev)) { pm_device_wakeup_enable(dev, true); } #endif // IS_ENABLED(CONFIG_PM_DEVICE) + kscan_config(dev, zmk_kscan_callback); + kscan_enable_callback(dev); + return 0; } diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index 3a03a293839..cff28e49d18 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -75,6 +75,7 @@ void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t } static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { + const struct ksbb_config *cfg = dev->config; struct ksbb_data *data = dev->data; if (!callback) { @@ -82,6 +83,13 @@ static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { } data->callback = callback; + +#if IS_ENABLED(CONFIG_PM_DEVICE) + if (pm_device_wakeup_is_enabled(dev) && pm_device_wakeup_is_capable(cfg->kscan)) { + pm_device_wakeup_enable(cfg->kscan, true); + } +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + return 0; } @@ -119,6 +127,21 @@ static const struct kscan_driver_api ksbb_api = { .disable_callback = ksbb_disable, }; +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int ksbb_pm_action(const struct device *dev, enum pm_device_action action) { + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + return ksbb_disable(dev); + case PM_DEVICE_ACTION_RESUME: + return ksbb_disable(dev); + default: + return -ENOTSUP; + } +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + #define JUST_ONE(_id) 1 #define ENTRY(e) \ @@ -136,7 +159,9 @@ static const struct kscan_driver_api ksbb_api = { .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ }; \ struct ksbb_data ksbb_data_##n = {}; \ - DEVICE_DT_INST_DEFINE(n, ksbb_init, NULL, &ksbb_data_##n, &ksbb_config_##n, APPLICATION, \ - CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ksbb_api); + PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ + DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \ + &ksbb_config_##n, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + &ksbb_api); DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From 5d960a758f6067ae82eccb01d8508114b2a98c6a Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 22 Jan 2024 13:39:08 -0800 Subject: [PATCH 062/134] fix: Cleanups of sideband and direct kscan from review. * Add dedicated init priority for the sideband kscan. * Refactor sideband code for clarity. * Tweaks to direct kscan for clarity. * Make sideband behavior row optional for brevity. * Allow overriding ZMK Uno sideband behaviors. --- app/Kconfig | 9 +++ app/boards/shields/zmk_uno/zmk_uno.keymap | 22 +++--- app/boards/shields/zmk_uno/zmk_uno.overlay | 9 +-- .../shields/zmk_uno/zmk_uno_split.keymap | 21 +++--- .../kscan/zmk,kscan-sideband-behaviors.yaml | 7 +- app/module/drivers/kscan/kscan_gpio_direct.c | 4 +- app/src/kscan_sideband_behaviors.c | 69 ++++++++++++------- 7 files changed, 79 insertions(+), 62 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 15c31375d3c..a719875e6b1 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -518,6 +518,15 @@ config ZMK_KSCAN_SIDEBAND_BEHAVIORS depends on DT_HAS_ZMK_KSCAN_SIDEBAND_BEHAVIORS_ENABLED select KSCAN +if ZMK_KSCAN_SIDEBAND_BEHAVIORS + +config ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY + int "Keyboard scan sideband behaviors driver init priority" + # The default kscan init priority is 90, so be sure we are lower. + default 95 + +endif # ZMK_KSCAN_SIDEBAND_BEHAVIORS + menu "Logging" config ZMK_LOGGING_MINIMAL diff --git a/app/boards/shields/zmk_uno/zmk_uno.keymap b/app/boards/shields/zmk_uno/zmk_uno.keymap index e416ff5e6c8..a7f6a2675d5 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno.keymap @@ -11,21 +11,17 @@ #include #include -// Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. +// Uncomment the following lines if using the "Direct Wire" jumper to switch the matrix to a direct wire. -/* :REMOVE ME +// &kscan_direct { status = "okay"; }; +// &kscan_matrix { status = "disabled"; }; -&kscan_direct { status = "okay"; }; -&kscan_matrix { status = "disabled"; }; - -/ { - chosen { - zmk,matrix-transform = &direct_matrix_transform; - zmk,kscan = &kscan_direct; - }; -}; - -REMOVE ME: */ +// / { +// chosen { +// zmk,matrix-transform = &direct_matrix_transform; +// zmk,kscan = &kscan_direct; +// }; +// }; / { keymap { diff --git a/app/boards/shields/zmk_uno/zmk_uno.overlay b/app/boards/shields/zmk_uno/zmk_uno.overlay index c86f6e5c9ee..3d105abf8d7 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.overlay +++ b/app/boards/shields/zmk_uno/zmk_uno.overlay @@ -40,20 +40,17 @@ compatible = "zmk,kscan-sideband-behaviors"; kscan = <&kscan_sp3t_toggle>; - usb { - row = <0>; + first_toggle_sideband: first_toggle_sideband { column = <0>; bindings = <&out OUT_USB>; }; - ble_zero { - row = <0>; + second_toggle_sideband: second_toggle_sideband { column = <1>; bindings = <&ble_zero>; }; - ble_one { - row = <0>; + third_toggle_sideband: third_toggle_sideband { column = <2>; bindings = <&ble_one>; }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap index 1e46042a7e1..37672a7dbdb 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -12,21 +12,18 @@ #include #include -// Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. +// Uncomment the following lines if using the "Direct Wire" jumper to switch the matrix to a direct wire. -/* :REMOVE ME -&kscan_direct { status = "okay"; }; -&kscan_matrix { status = "disabled"; }; +// &kscan_direct { status = "okay"; }; +// &kscan_matrix { status = "disabled"; }; -/ { - chosen { - zmk,matrix-transform = &split_direct_matrix_transform; - zmk,kscan = &kscan_direct_comp; - }; -}; - -REMOVE ME: */ +// / { +// chosen { +// zmk,matrix-transform = &split_direct_matrix_transform; +// zmk,kscan = &kscan_direct_comp; +// }; +// }; / { diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml index 57b54a6041c..f3ed180d14b 100644 --- a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml +++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml @@ -2,8 +2,9 @@ # SPDX-License-Identifier: MIT description: | - kscan sideband behavior runner. Only basic system behavior should be used, - since no keymap processing occurs when using them. + kscan sideband behavior runner. Only basic system behaviors should be used, + since no keymap processing occurs when using them. Primarily, that means avoiding + using tap-holds, sticky keys, etc. as sideband behaviors. compatible: "zmk,kscan-sideband-behaviors" @@ -20,7 +21,7 @@ child-binding: properties: row: type: int - required: true + default: 0 column: type: int required: true diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index e05eb2f3da1..fa24e69e895 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -46,7 +46,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), (DT_INST_PROP_LEN(n, input_gpios)), \ (DT_INST_PROP_LEN(n, input_keys))) -#define KSCAN_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ +#define KSCAN_GPIO_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_GET_BY_IDX(DT_DRV_INST(inst_idx), input_gpios, idx) #define KSCAN_KEY_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_GET_BY_IDX(DT_INST_PROP_BY_IDX(inst_idx, input_keys, idx), gpios, 0) @@ -353,7 +353,7 @@ static const struct kscan_driver_api kscan_direct_api = { \ static struct kscan_gpio kscan_direct_inputs_##n[] = { \ COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), \ - (LISTIFY(INST_INPUTS_LEN(n), KSCAN_DIRECT_INPUT_CFG_INIT, (, ), n)), \ + (LISTIFY(INST_INPUTS_LEN(n), KSCAN_GPIO_DIRECT_INPUT_CFG_INIT, (, ), n)), \ (LISTIFY(INST_INPUTS_LEN(n), KSCAN_KEY_DIRECT_INPUT_CFG_INIT, (, ), n)))}; \ \ static struct zmk_debounce_state kscan_direct_state_##n[INST_INPUTS_LEN(n)]; \ diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index cff28e49d18..5b8a30a85e3 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -19,9 +19,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct ksbb_entry { + struct zmk_behavior_binding binding; uint8_t row; uint8_t column; - struct zmk_behavior_binding binding; }; struct ksbb_config { @@ -39,32 +39,53 @@ struct ksbb_data { // The kscan callback has no context with it, so we keep a static array of all possible // KSBBs to check when a kscan callback from the "wrapped" inner kscan fires. -static const struct device *ksbbs[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)] = { - DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; +static const struct device *ksbbs[] = {DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; -void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, - bool pressed) { +int find_ksbb_for_inner(const struct device *inner_dev, const struct device **ksbb_dev) { for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) { const struct device *ksbb = ksbbs[i]; const struct ksbb_config *cfg = ksbb->config; - struct ksbb_data *data = ksbb->data; - if (cfg->kscan != dev) { - continue; + if (cfg->kscan == inner_dev) { + *ksbb_dev = ksbb; + return 0; + } + } + + return -ENODEV; +} + +int find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column, + struct ksbb_entry **entry) { + const struct ksbb_config *cfg = dev->config; + + for (int e = 0; e < cfg->entries_len; e++) { + struct ksbb_entry *candidate = &cfg->entries[e]; + + if (candidate->row == row && candidate->column == column) { + *entry = candidate; + return 0; } + } - for (int e = 0; e < cfg->entries_len; e++) { - struct ksbb_entry *entry = &cfg->entries[e]; - if (entry->row == row && entry->column == column) { - struct zmk_behavior_binding_event event = {.position = INT32_MAX, - .timestamp = k_uptime_get()}; - - if (pressed) { - behavior_keymap_binding_pressed(&entry->binding, event); - } else { - behavior_keymap_binding_released(&entry->binding, event); - } - return; + return -ENODEV; +} + +void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, + bool pressed) { + struct ksbb_entry *entry = NULL; + const struct device *ksbb = NULL; + + if (find_ksbb_for_inner(dev, &ksbb) >= 0) { + struct ksbb_data *data = ksbb->data; + if (find_sideband_behavior(ksbb, row, column, &entry) >= 0) { + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&entry->binding, event); + } else { + behavior_keymap_binding_released(&entry->binding, event); } } @@ -78,10 +99,6 @@ static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { const struct ksbb_config *cfg = dev->config; struct ksbb_data *data = dev->data; - if (!callback) { - return -EINVAL; - } - data->callback = callback; #if IS_ENABLED(CONFIG_PM_DEVICE) @@ -161,7 +178,7 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action struct ksbb_data ksbb_data_##n = {}; \ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \ - &ksbb_config_##n, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - &ksbb_api); + &ksbb_config_##n, POST_KERNEL, \ + CONFIG_ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY, &ksbb_api); DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From bd21f41412eaff5822a17efa86ce1dadf831cbcc Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 26 Jan 2024 01:48:46 -0800 Subject: [PATCH 063/134] refactor: Fixes for review feedback. --- app/Kconfig | 2 +- app/src/kscan_sideband_behaviors.c | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index a719875e6b1..28d3c22ac5a 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -522,7 +522,7 @@ if ZMK_KSCAN_SIDEBAND_BEHAVIORS config ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY int "Keyboard scan sideband behaviors driver init priority" - # The default kscan init priority is 90, so be sure we are lower. + # The default kscan init priority is 90, so be sure we are initialized later. default 95 endif # ZMK_KSCAN_SIDEBAND_BEHAVIORS diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index 5b8a30a85e3..7a9922afdae 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -41,44 +41,41 @@ struct ksbb_data { // KSBBs to check when a kscan callback from the "wrapped" inner kscan fires. static const struct device *ksbbs[] = {DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; -int find_ksbb_for_inner(const struct device *inner_dev, const struct device **ksbb_dev) { +const struct device *find_ksbb_for_inner(const struct device *inner_dev) { for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) { const struct device *ksbb = ksbbs[i]; const struct ksbb_config *cfg = ksbb->config; if (cfg->kscan == inner_dev) { - *ksbb_dev = ksbb; - return 0; + return ksbb; } } - return -ENODEV; + return NULL; } -int find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column, - struct ksbb_entry **entry) { +struct ksbb_entry *find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column) { const struct ksbb_config *cfg = dev->config; for (int e = 0; e < cfg->entries_len; e++) { struct ksbb_entry *candidate = &cfg->entries[e]; if (candidate->row == row && candidate->column == column) { - *entry = candidate; - return 0; + return candidate; } } - return -ENODEV; + return NULL; } void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, bool pressed) { - struct ksbb_entry *entry = NULL; - const struct device *ksbb = NULL; - - if (find_ksbb_for_inner(dev, &ksbb) >= 0) { + const struct device *ksbb = find_ksbb_for_inner(dev); + if (ksbb) { struct ksbb_data *data = ksbb->data; - if (find_sideband_behavior(ksbb, row, column, &entry) >= 0) { + + struct ksbb_entry *entry = find_sideband_behavior(ksbb, row, column); + if (entry) { struct zmk_behavior_binding_event event = {.position = INT32_MAX, .timestamp = k_uptime_get()}; @@ -159,8 +156,6 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action #endif // IS_ENABLED(CONFIG_PM_DEVICE) -#define JUST_ONE(_id) 1 - #define ENTRY(e) \ { \ .row = DT_PROP(e, row), .column = DT_PROP(e, column), \ @@ -173,7 +168,7 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action const struct ksbb_config ksbb_config_##n = { \ .kscan = DEVICE_DT_GET(DT_INST_PHANDLE(n, kscan)), \ .entries = entries_##n, \ - .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ + .entries_len = ARRAY_SIZE(entries_##n), \ }; \ struct ksbb_data ksbb_data_##n = {}; \ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ From 8d54e287f019baa44540c8d8120eac594a630b03 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 19 Feb 2024 02:18:23 -0800 Subject: [PATCH 064/134] fix: Adjustments for Zephyr 3.5. --- app/Kconfig | 6 +++ app/include/zmk/pm.h | 3 ++ app/src/activity.c | 61 +----------------------- app/src/behaviors/behavior_soft_off.c | 2 +- app/src/pm.c | 68 ++++++++++++++++++++++++++- 5 files changed, 79 insertions(+), 61 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 28d3c22ac5a..5068e91fdfc 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -405,6 +405,7 @@ config ZMK_SLEEP bool "Enable deep sleep support" depends on HAS_POWEROFF select POWEROFF + select ZMK_PM_DEVICE_SUSPEND_RESUME imply USB if ZMK_SLEEP @@ -426,10 +427,15 @@ config ZMK_EXT_POWER config ZMK_PM bool +config ZMK_PM_DEVICE_SUSPEND_RESUME + bool + select ZMK_PM + config ZMK_PM_SOFT_OFF bool "Soft-off support" select ZMK_PM select PM_DEVICE + select ZMK_PM_DEVICE_SUSPEND_RESUME config ZMK_GPIO_KEY_WAKEUP_TRIGGER bool "Hardware supported wakeup (GPIO)" diff --git a/app/include/zmk/pm.h b/app/include/zmk/pm.h index dff217afd29..a733856d09a 100644 --- a/app/include/zmk/pm.h +++ b/app/include/zmk/pm.h @@ -6,4 +6,7 @@ #pragma once +int zmk_pm_suspend_devices(void); +void zmk_pm_resume_devices(void); + int zmk_pm_soft_off(void); \ No newline at end of file diff --git a/app/src/activity.c b/app/src/activity.c index 8f421f85d02..454e91e5da0 100644 --- a/app/src/activity.c +++ b/app/src/activity.c @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include #include @@ -20,69 +18,14 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include +#include + #include #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) #include #endif -// Reimplement some of the device work from Zephyr PM to work with the new `sys_poweroff` API. -// TODO: Tweak this to smarter runtime PM of subsystems on sleep. - -#ifdef CONFIG_PM_DEVICE -TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots); - -#if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE) -/* Number of devices successfully suspended. */ -static size_t zmk_num_susp; - -static int zmk_pm_suspend_devices(void) { - const struct device *devs; - size_t devc; - - devc = z_device_get_all_static(&devs); - - zmk_num_susp = 0; - - for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) { - int ret; - - /* - * Ignore uninitialized devices, busy devices, wake up sources, and - * devices with runtime PM enabled. - */ - if (!device_is_ready(dev) || pm_device_is_busy(dev) || pm_device_state_is_locked(dev) || - pm_device_wakeup_is_enabled(dev) || pm_device_runtime_is_enabled(dev)) { - continue; - } - - ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); - /* ignore devices not supporting or already at the given state */ - if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) { - continue; - } else if (ret < 0) { - LOG_ERR("Device %s did not enter %s state (%d)", dev->name, - pm_device_state_str(PM_DEVICE_STATE_SUSPENDED), ret); - return ret; - } - - TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev; - zmk_num_susp++; - } - - return 0; -} - -static void zmk_pm_resume_devices(void) { - for (int i = (zmk_num_susp - 1); i >= 0; i--) { - pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); - } - - zmk_num_susp = 0; -} -#endif /* !CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE */ -#endif /* CONFIG_PM_DEVICE */ - bool is_usb_power_present(void) { #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) return zmk_usb_is_powered(); diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index e6096bb4841..878a2fc5869 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -64,7 +64,7 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = { }; \ static struct behavior_soft_off_data bso_data_##n = {}; \ BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ - APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ &behavior_soft_off_driver_api); DT_INST_FOREACH_STATUS_OKAY(BSO_INST) diff --git a/app/src/pm.c b/app/src/pm.c index 8525046f049..4f151875ba3 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -8,13 +8,72 @@ #include #include #include +#include #include +#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include +// Reimplement some of the device work from Zephyr PM to work with the new `sys_poweroff` API. +// TODO: Tweak this to smarter runtime PM of subsystems on sleep. + +#ifdef CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME +TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots); + +#if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE) +/* Number of devices successfully suspended. */ +static size_t zmk_num_susp; + +int zmk_pm_suspend_devices(void) { + const struct device *devs; + size_t devc; + + devc = z_device_get_all_static(&devs); + + zmk_num_susp = 0; + + for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) { + int ret; + + /* + * Ignore uninitialized devices, busy devices, wake up sources, and + * devices with runtime PM enabled. + */ + if (!device_is_ready(dev) || pm_device_is_busy(dev) || pm_device_state_is_locked(dev) || + pm_device_wakeup_is_enabled(dev) || pm_device_runtime_is_enabled(dev)) { + continue; + } + + ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); + /* ignore devices not supporting or already at the given state */ + if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) { + continue; + } else if (ret < 0) { + LOG_ERR("Device %s did not enter %s state (%d)", dev->name, + pm_device_state_str(PM_DEVICE_STATE_SUSPENDED), ret); + return ret; + } + + TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev; + zmk_num_susp++; + } + + return 0; +} + +void zmk_pm_resume_devices(void) { + for (int i = (zmk_num_susp - 1); i >= 0; i--) { + pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); + } + + zmk_num_susp = 0; +} +#endif /* !CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE */ +#endif /* CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME */ + #if IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) #define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) @@ -64,8 +123,15 @@ int zmk_pm_soft_off(void) { } #endif // HAS_WAKERS + int err = zmk_pm_suspend_devices(); + if (err < 0) { + zmk_pm_resume_devices(); + return err; + } + LOG_DBG("soft-off: go to sleep"); - return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); + sys_poweroff(); + return 0; } #endif // IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) \ No newline at end of file From cac999b1d6f09cb9f11fbdb832bed64b888baef5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 20 Feb 2024 07:59:26 +0000 Subject: [PATCH 065/134] feat: Updated soft-off docs. * Document new sideband behavior kscan driver for integrated soft-off support. --- docs/docs/features/soft-off.md | 193 +++++++++++++++++++++++++-------- 1 file changed, 149 insertions(+), 44 deletions(-) diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index 370a3880769..ff47e7f15b4 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -37,11 +37,28 @@ The simplest way to achieve this is with a push button between a GPIO pin and gr #### Matrix-Integrated Hardware Combo -Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. Support for this mode will be coming soon. +Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to connect the switch to two MOSFETs that trigger both the regular matrix connect and the connect to the AND gate to ensure both pins are active/high at the same time even if scanning sets them high at different times. ### Firmware Changes -Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. +Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. In addition, some small changes are needed to keep the regular idle deep sleep functionality working. + +#### Wakeup Sources + +Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property to ensure they will still work to wake the device from regular inactive deep sleep, e.g.: + +``` +/ { + kscan0: kscan_0 { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + wakeup-source; + + ... + }; +}; +``` #### GPIO Key @@ -62,11 +79,47 @@ GPIO keys are defined using child nodes under the `gpio-keys` compatible node. E - The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. -#### Behavior Key +#### Soft Off Waker -Next, we will create a new "behavior key". Behavior keys are an easy way to tie a keymap behavior to a GPIO key outside of the normal keymap processing. They do _not_ do the normal keymap processing, so they are only suitable for use with basic behaviors, not complicated macros, hold-taps, etc. +Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. -In this case, we will be creating a dedicated instance of the [Soft Off Behavior](../behaviors/soft-off.md) that will be used only for our hardware on/off button, then binding it to our key: +``` +/ { + wakeup_source: wakeup_source { + compatible = "zmk,gpio-key-wakeup-trigger"; + + trigger = <&wakeup_key>; + wakeup-source; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. +- The `trigger` property is a phandle to the GPIO key defined earlier. +- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. +- An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. + +Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&wakeup_source>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. + +#### Soft Off Behavior Instance + +To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, add an instance of the behavior to your `.overlay`/`.dts` file: ``` / { @@ -77,74 +130,126 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior hold-time-ms = <5000>; }; }; - - soft_off_behavior_key { - compatible = "zmk,gpio-key-behavior-trigger"; - bindings = <&hw_soft_off>; - key = <&wakeup_key>; - }; }; ``` -Here are the properties for the behavior key node: +#### KScan Sideband Behavior -- The `compatible` property for the node must be `zmk,gpio-key-behavior-trigger`. -- The `bindings` property is a phandle to the soft off behavior defined above. -- The `key` property is a phandle to the GPIO key defined earlier. +The kscan sideband behavior driver will be used to trigger the [soft off behavior](../behaviors/soft-off.md) "out of band" from the normal keymap processing. To do so, it will decorate/wrap an underlying kscan driver. What kscan driver will vary for simple direct pin vs. matrix-integrated hardware combo. -If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key will need to be integrated into your existing kscan setup. Full details to come when this is supported. +##### Simple Direct Pin -#### Wakeup Sources +With a simple direct pin setup, the The [direct kscan](../config/kscan.md) driver can be used with a GPIO key, to make a small "side matrix": -Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property, e.g.: +``` + soft_off_direct_scan: soft_off_direct_scan { + compatible = "zmk,kscan-gpio-direct"; + input-keys = <&wakeup_key>; + }; +``` + +With that in place, the kscan sideband behavior will wrap the new driver: ``` / { - kscan0: kscan_0 { - compatible = "zmk,kscan-gpio-matrix"; - label = "KSCAN"; - diode-direction = "col2row"; + side_band_behavior_triggers: side_band_behavior_triggers { + compatible = "zmk,kscan-sideband-behaviors"; + + kscan = <&soft_off_direct_scan>; wakeup-source; - ... + soft_off { + column = <0>; + row = <0>; + bindings = <&hw_soft_off>; + }; }; }; ``` -#### Soft Off Waker +##### Matrix-Integrated Hardware Combo -Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. +For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in +the `row-gpios`/`col-gpios` for whichever pins are used to read the matrix state. For example, for an existing matrix like: ``` -/ { - wakeup_source: wakeup_source { - compatible = "zmk,gpio-key-wakeup-trigger"; + kscan: kscan { + compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + label = "KSCAN"; + debounce-press-ms = <1>; + debounce-release-ms = <5>; - trigger = <&wakeup_key>; + diode-direction = "col2row"; + + col-gpios + = <&gpio0 12 (GPIO_ACTIVE_HIGH)> + , <&gpio1 9 (GPIO_ACTIVE_HIGH)> + ; + row-gpios + = <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&gpio0 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + }; +``` + +you would add another row value: + +``` + kscan: kscan { + compatible = "zmk,kscan-gpio-matrix"; wakeup-source; + label = "KSCAN"; + debounce-press-ms = <1>; + debounce-release-ms = <5>; + + diode-direction = "col2row"; + + col-gpios + = <&gpio0 12 (GPIO_ACTIVE_HIGH)> + , <&gpio1 9 (GPIO_ACTIVE_HIGH)> + ; + row-gpios + = <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&gpio0 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; }; -}; ``` -Here are the properties for the node: +With that in place, you would decorate the kscan driver: -- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. -- The `trigger` property is a phandle to the GPIO key defined earlier. -- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. -- An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. +``` + side_band_behavior_triggers: side_band_behavior_triggers { + compatible = "zmk,kscan-sideband-behaviors"; + wakeup-source; + kscan = <&kscan>; + soft_off { + column = <0>; + row = <3>; + bindings = <&hw_soft_off>; + }; + }; +``` -Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: +Critically, the `column` and `row` values would correspond to the location of the added entry. + +Lastly, which is critical, you would update the `zmk,kscan` chosen value to point to the new kscan instance: ``` -/ { - soft_off_wakers { - compatible = "zmk,soft-off-wakeup-sources"; - wakeup-sources = <&wakeup_source>; + chosen { + ... + zmk,kscan = &side_band_behavior_triggers; + ... }; -}; ``` -Here are the properties for the node: +Here are the properties for the kscan sideband behaviors node: -- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. -- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. +- The `compatible` property for the node must be `zmk,kscan-sideband-behaviors`. +- The `kscan` property is a phandle to the inner kscan instance that will have press/release events intercepted. + +The child nodes allow setting up the behaviors to invoke directly for a certain row and column: + +- The `row` and `column` properties set the values to intercept and trigger the behavior for. +- The `bindings` property references the behavior that should be triggered when the matching row and column event triggers. From bb94a7aafeb3d3d2f4165f58a654e79f8f6e6c9f Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 20 Feb 2024 00:10:15 -0800 Subject: [PATCH 066/134] fix: Fixes for building soft off without deep sleep. --- app/CMakeLists.txt | 2 +- app/Kconfig | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2abf943fb39..2744f53d595 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -8,7 +8,7 @@ set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/modul find_package(Zephyr REQUIRED HINTS ../zephyr) project(zmk) -if(CONFIG_ZMK_SLEEP) +if(CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME) zephyr_linker_sources(SECTIONS include/linker/zmk-pm-devices.ld) endif() diff --git a/app/Kconfig b/app/Kconfig index 5068e91fdfc..8f2fe837317 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -433,9 +433,11 @@ config ZMK_PM_DEVICE_SUSPEND_RESUME config ZMK_PM_SOFT_OFF bool "Soft-off support" + depends on HAS_POWEROFF select ZMK_PM select PM_DEVICE select ZMK_PM_DEVICE_SUSPEND_RESUME + select POWEROFF config ZMK_GPIO_KEY_WAKEUP_TRIGGER bool "Hardware supported wakeup (GPIO)" From fa9ea9ea8b171a86765b5b08bed31922e9b2af76 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 15 Mar 2024 20:22:54 -0400 Subject: [PATCH 067/134] fix(docs): Fix soft off waker prop name, headers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use the correct property for extra GPIOs to make active for the waker before going into soft off state. * Change header depth for easier navigation of the soft off feature page. Co-authored-by: Pablo Martínez <58857054+elpekenin@users.noreply.github.com> --- docs/docs/features/soft-off.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index ff47e7f15b4..20a5bbe4709 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -24,26 +24,24 @@ For existing designs, using soft off is as simple as placing the [Soft Off Behav You can then wake up the keyboard by pressing the reset button once, and repeating this for each side for split keyboards. -## Adding Dedicated Soft On/Off GPIO Pin To New Designs - -### Hardware Design +## Hardware Changes For New Designs ZMK's dedicated soft on/off pin feature requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the soft off state when it goes active again later. -#### Simple Direct Pin +### Simple Direct Pin The simplest way to achieve this is with a push button between a GPIO pin and ground. -#### Matrix-Integrated Hardware Combo +### Matrix-Integrated Hardware Combo Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to connect the switch to two MOSFETs that trigger both the regular matrix connect and the connect to the AND gate to ensure both pins are active/high at the same time even if scanning sets them high at different times. -### Firmware Changes +## Firmware Changes For New Designs Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. In addition, some small changes are needed to keep the regular idle deep sleep functionality working. -#### Wakeup Sources +### Wakeup Sources Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property to ensure they will still work to wake the device from regular inactive deep sleep, e.g.: @@ -60,7 +58,7 @@ Zephyr has general support for the concept of a device as a "wakeup source", whi }; ``` -#### GPIO Key +### GPIO Key Zephyr's basic GPIO Key concept is used to configure the GPIO pin that will be used for both triggering soft off and waking the device later. Here is an example for a keyboard with a dedicated on/off push button that is a direct wire between the GPIO pin and ground: @@ -79,7 +77,7 @@ GPIO keys are defined using child nodes under the `gpio-keys` compatible node. E - The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. -#### Soft Off Waker +### Soft Off Waker Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. @@ -99,7 +97,7 @@ Here are the properties for the node: - The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. - The `trigger` property is a phandle to the GPIO key defined earlier. - The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. -- An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. +- An optional `extra-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: @@ -117,7 +115,7 @@ Here are the properties for the node: - The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. - The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. -#### Soft Off Behavior Instance +### Soft Off Behavior Instance To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, add an instance of the behavior to your `.overlay`/`.dts` file: @@ -133,11 +131,11 @@ To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, ad }; ``` -#### KScan Sideband Behavior +### KScan Sideband Behavior The kscan sideband behavior driver will be used to trigger the [soft off behavior](../behaviors/soft-off.md) "out of band" from the normal keymap processing. To do so, it will decorate/wrap an underlying kscan driver. What kscan driver will vary for simple direct pin vs. matrix-integrated hardware combo. -##### Simple Direct Pin +#### Simple Direct Pin With a simple direct pin setup, the The [direct kscan](../config/kscan.md) driver can be used with a GPIO key, to make a small "side matrix": @@ -167,7 +165,7 @@ With that in place, the kscan sideband behavior will wrap the new driver: }; ``` -##### Matrix-Integrated Hardware Combo +#### Matrix-Integrated Hardware Combo For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in the `row-gpios`/`col-gpios` for whichever pins are used to read the matrix state. For example, for an existing matrix like: From 2df6dcd973776c0c0d1047d13178a72b5c0b6ca7 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 16 Mar 2024 14:15:52 -0700 Subject: [PATCH 068/134] feat(behaviors): More logging in soft off. --- app/src/behaviors/behavior_soft_off.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 878a2fc5869..8b8ba4f9add 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -45,8 +45,18 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, struct behavior_soft_off_data *data = dev->data; const struct behavior_soft_off_config *config = dev->config; - if (config->hold_time_ms == 0 || (k_uptime_get() - data->press_start) >= config->hold_time_ms) { + if (config->hold_time_ms == 0) { + LOG_DBG("No hold time set, triggering soft off"); zmk_pm_soft_off(); + } else { + uint32_t hold_time = k_uptime_get() - data->press_start; + + if (hold_time > config->hold_time_ms) { + zmk_pm_soft_off(); + } else { + LOG_INF("Not triggering soft off: held for %d and hold time is %d", hold_time, + config->hold_time_ms); + } } return ZMK_BEHAVIOR_OPAQUE; From d0e0ecb4e3d11b5303c1dc5c857ff1f75c1d0aaa Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 01:47:11 -0700 Subject: [PATCH 069/134] refactor: Use kscan directly to wake when we can. * When adding a dedicated GPIO pin for soft off/on, use the direct kscan as the waker, instead of adding an additional node. --- .../boards/nrf52840dk_nrf52840.overlay | 22 ++--- docs/docs/features/soft-off.md | 95 +++++++++++-------- 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index 47b67dc0029..b9c68e5a2ff 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -42,24 +42,10 @@ encoder: &qdec0 { }; }; - wakeup_source: wakeup_source { - compatible = "zmk,gpio-key-wakeup-trigger"; - status = "okay"; - - trigger = <&button0>; - wakeup-source; - }; - - soft_off_wakers { - compatible = "zmk,soft-off-wakeup-sources"; - status = "okay"; - - wakeup-sources = <&wakeup_source>; - }; - soft_off_direct_kscan: soft_off_direct_kscan { compatible = "zmk,kscan-gpio-direct"; input-keys = <&button0>; + wakeup-source; }; soft_off_sideband_behaviors { @@ -72,4 +58,10 @@ encoder: &qdec0 { }; }; + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + status = "okay"; + + wakeup-sources = <&soft_off_direct_kscan>; + }; }; \ No newline at end of file diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index 20a5bbe4709..b08e1643fcc 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -66,7 +66,7 @@ Zephyr's basic GPIO Key concept is used to configure the GPIO pin that will be u / { keys { compatible = "gpio-keys"; - wakeup_key: wakeup_key { + soft_off_key: soft_off_key { gpios = <&gpio0 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; }; }; @@ -77,44 +77,6 @@ GPIO keys are defined using child nodes under the `gpio-keys` compatible node. E - The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. -### Soft Off Waker - -Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. - -``` -/ { - wakeup_source: wakeup_source { - compatible = "zmk,gpio-key-wakeup-trigger"; - - trigger = <&wakeup_key>; - wakeup-source; - }; -}; -``` - -Here are the properties for the node: - -- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. -- The `trigger` property is a phandle to the GPIO key defined earlier. -- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. -- An optional `extra-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. - -Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: - -``` -/ { - soft_off_wakers { - compatible = "zmk,soft-off-wakeup-sources"; - wakeup-sources = <&wakeup_source>; - }; -}; -``` - -Here are the properties for the node: - -- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. -- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. - ### Soft Off Behavior Instance To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, add an instance of the behavior to your `.overlay`/`.dts` file: @@ -143,6 +105,7 @@ With a simple direct pin setup, the The [direct kscan](../config/kscan.md) drive soft_off_direct_scan: soft_off_direct_scan { compatible = "zmk,kscan-gpio-direct"; input-keys = <&wakeup_key>; + wakeup-source; }; ``` @@ -165,6 +128,22 @@ With that in place, the kscan sideband behavior will wrap the new driver: }; ``` +Finally, we will list the kscan instance in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing so it can _also_ wake the keyboard from soft off when pressed: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&soft_off_direct_scan>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. + #### Matrix-Integrated Hardware Combo For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in @@ -251,3 +230,41 @@ The child nodes allow setting up the behaviors to invoke directly for a certain - The `row` and `column` properties set the values to intercept and trigger the behavior for. - The `bindings` property references the behavior that should be triggered when the matching row and column event triggers. + +### Soft Off Waker + +Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. + +``` +/ { + wakeup_source: wakeup_source { + compatible = "zmk,gpio-key-wakeup-trigger"; + + trigger = <&wakeup_key>; + wakeup-source; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. +- The `trigger` property is a phandle to the GPIO key defined earlier. +- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. +- An optional `extra-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. + +Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&wakeup_source>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. From 41d81801ed11a1dca918c9c0088351856e4e1808 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 09:37:14 +0000 Subject: [PATCH 070/134] fix(pm): Use Zephyr created device slots. * Avoid overwriting random memory by using iterable section created by Zephyr PM. --- app/CMakeLists.txt | 4 ---- app/include/linker/zmk-pm-devices.ld | 9 --------- app/src/pm.c | 6 +++--- 3 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 app/include/linker/zmk-pm-devices.ld diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2744f53d595..0b681ea9531 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -8,10 +8,6 @@ set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/modul find_package(Zephyr REQUIRED HINTS ../zephyr) project(zmk) -if(CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME) - zephyr_linker_sources(SECTIONS include/linker/zmk-pm-devices.ld) -endif() - zephyr_linker_sources(SECTIONS include/linker/zmk-behaviors.ld) zephyr_linker_sources(RODATA include/linker/zmk-events.ld) diff --git a/app/include/linker/zmk-pm-devices.ld b/app/include/linker/zmk-pm-devices.ld deleted file mode 100644 index 93ec5025ded..00000000000 --- a/app/include/linker/zmk-pm-devices.ld +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#include - -ITERABLE_SECTION_RAM(zmk_pm_device_slots, 4) diff --git a/app/src/pm.c b/app/src/pm.c index 4f151875ba3..447eb351c9b 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -21,7 +21,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); // TODO: Tweak this to smarter runtime PM of subsystems on sleep. #ifdef CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME -TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots); +TYPE_SECTION_START_EXTERN(const struct device *, pm_device_slots); #if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE) /* Number of devices successfully suspended. */ @@ -57,7 +57,7 @@ int zmk_pm_suspend_devices(void) { return ret; } - TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev; + TYPE_SECTION_START(pm_device_slots)[zmk_num_susp] = dev; zmk_num_susp++; } @@ -66,7 +66,7 @@ int zmk_pm_suspend_devices(void) { void zmk_pm_resume_devices(void) { for (int i = (zmk_num_susp - 1); i >= 0; i--) { - pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); + pm_device_action_run(TYPE_SECTION_START(pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); } zmk_num_susp = 0; From 7e7110d85f0fe24948b319382bed723e38f5336c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 02:39:54 -0700 Subject: [PATCH 071/134] fix(pm): Fixes for dedicated on/off on peripherals. * Add new flag to differentiate soft off on peripherals that is invoked by split GATT svc and dedicated additional ones tied to GPIO pin. --- .../zmk_uno/boards/nrf52840dk_nrf52840.overlay | 5 ++--- app/dts/behaviors/soft_off.dtsi | 3 ++- .../behaviors/zmk,behavior-soft-off.yaml | 3 +++ app/src/behaviors/behavior_soft_off.c | 17 ++++++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index b9c68e5a2ff..d798eca7acc 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -35,10 +35,9 @@ encoder: &qdec0 { / { behaviors { - soft_off: soft_off { + hw_soft_off: hw_soft_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; - status = "okay"; }; }; @@ -54,7 +53,7 @@ encoder: &qdec0 { soft_off { row = <0>; column = <0>; - bindings = <&soft_off>; + bindings = <&hw_soft_off>; }; }; diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index 1e58c7711d0..63c04b1dd7e 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,9 +6,10 @@ / { behaviors { - /omit-if-no-ref/ soft_off: soft_off { + /omit-if-no-ref/ soft_off: keymap_soft_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; + split-peripheral-off-on-press; }; }; }; diff --git a/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml index 1467ede4772..865e656f0d1 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml @@ -12,3 +12,6 @@ properties: type: int required: false description: Number of milliseconds the behavior must be held before releasing will actually trigger a soft-off. + split-peripheral-off-on-press: + type: boolean + description: When built for a split peripheral, turn off on press, not release diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 8b8ba4f9add..3a4ae42486d 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -16,6 +16,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct behavior_soft_off_config { + bool split_peripheral_turn_off_on_press; uint32_t hold_time_ms; }; @@ -23,18 +24,22 @@ struct behavior_soft_off_data { uint32_t press_start; }; +#define IS_SPLIT_PERIPHERAL \ + (IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)) + static int behavior_soft_off_init(const struct device *dev) { return 0; }; static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); struct behavior_soft_off_data *data = dev->data; + const struct behavior_soft_off_config *config = dev->config; -#if IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) - zmk_pm_soft_off(); -#else - data->press_start = k_uptime_get(); -#endif + if (IS_SPLIT_PERIPHERAL && config->split_peripheral_turn_off_on_press) { + zmk_pm_soft_off(); + } else { + data->press_start = k_uptime_get(); + } return ZMK_BEHAVIOR_OPAQUE; } @@ -71,6 +76,8 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = { #define BSO_INST(n) \ static const struct behavior_soft_off_config bso_config_##n = { \ .hold_time_ms = DT_INST_PROP_OR(n, hold_time_ms, 0), \ + .split_peripheral_turn_off_on_press = \ + DT_INST_PROP_OR(n, split_peripheral_off_on_press, false), \ }; \ static struct behavior_soft_off_data bso_data_##n = {}; \ BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ From 29c0cdb3abce98708f5961e01d96eefc9efb7d42 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 09:41:33 +0000 Subject: [PATCH 072/134] fix(shields): Fix for direct use with ZMK Uno split. --- app/boards/shields/zmk_uno/zmk_uno_split.keymap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap index 37672a7dbdb..0e50a2833f0 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -21,7 +21,7 @@ // / { // chosen { // zmk,matrix-transform = &split_direct_matrix_transform; -// zmk,kscan = &kscan_direct_comp; +// zmk,kscan = &kscan_direct; // }; // }; From e66f068fb5d53f3e6071359970021d04a338c176 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 27 Mar 2024 20:35:40 -0700 Subject: [PATCH 073/134] fix(docs): Minor soft-off docs tweaks from review. --- docs/docs/behaviors/soft-off.md | 2 ++ docs/docs/config/kscan.md | 2 +- docs/docs/features/soft-off.md | 8 ++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/docs/behaviors/soft-off.md b/docs/docs/behaviors/soft-off.md index 05374004955..14b5f36aee7 100644 --- a/docs/docs/behaviors/soft-off.md +++ b/docs/docs/behaviors/soft-off.md @@ -7,6 +7,8 @@ sidebar_label: Soft Off The soft off behavior is used to force the keyboard into an off state. Depending on the specific keyboard hardware, the keyboard can be turned back on again either with a dedicated on/off button that is available, or using the reset button found on the device. +Refer to the [soft off config](../config/power.md#soft-off) for details on enabling soft off in order to use this behavior. + For more information, see the [Soft Off Feature](../features/soft-off.md) page. ### Behavior Binding diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 4a3954f9f03..3aa1b37875c 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -73,7 +73,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml]( | Property | Type | Description | Default | | ------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------- | ------- | -| `input-gpios` | GPIO array | Input GPIOs (one per key) | | +| `input-gpios` | GPIO array | Input GPIOs (one per key). Can be either direct GPIO pin or `gpio-key` references. | | | `debounce-press-ms` | int | Debounce time for key press in milliseconds. Use 0 for eager debouncing. | 5 | | `debounce-release-ms` | int | Debounce time for key release in milliseconds. | 5 | | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index b08e1643fcc..bd631f1b42e 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -18,6 +18,10 @@ Once powered off, the keyboard will only wake up when: - You press the same button/sequence that you pressed to power off the keyboard, or - You press a reset button found on the keyboard. +## Config + +Refer to the [soft off config](../config/power.md#soft-off) for details on enabling soft off. + ## Soft Off With Existing Designs For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. @@ -104,7 +108,7 @@ With a simple direct pin setup, the The [direct kscan](../config/kscan.md) drive ``` soft_off_direct_scan: soft_off_direct_scan { compatible = "zmk,kscan-gpio-direct"; - input-keys = <&wakeup_key>; + input-keys = <&on_off_key>; wakeup-source; }; ``` @@ -240,7 +244,7 @@ Next, we need to add another device which will be enabled only when the keyboard wakeup_source: wakeup_source { compatible = "zmk,gpio-key-wakeup-trigger"; - trigger = <&wakeup_key>; + trigger = <&on_off_key>; wakeup-source; }; }; From f9bb18b67631288a7ee8046e796775e34b61c0f6 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 28 Mar 2024 04:14:02 +0000 Subject: [PATCH 074/134] fix(docs): Add `&soft_off` to behaviors index. --- docs/docs/behaviors/index.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/behaviors/index.mdx b/docs/docs/behaviors/index.mdx index 32f4b29a97f..4a05f5653a0 100644 --- a/docs/docs/behaviors/index.mdx +++ b/docs/docs/behaviors/index.mdx @@ -70,6 +70,7 @@ Below is a summary of pre-defined behavior bindings and user-definable behaviors | Binding | Behavior | Description | | ------------ | --------------------------------------------- | --------------------------------------------------------------- | | `&ext_power` | [Power management](power.md#behavior-binding) | Allows enabling or disabling the VCC power output to save power | +| `&soft_off` | [Soft off](soft-off.md#behavior-binding) | Turns the keyboard off. | ## User-defined behaviors From 34910787ff68d7e977a2f74b4bc51ef8f99d2cb7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Mar 2024 06:44:29 +0000 Subject: [PATCH 075/134] chore(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docs Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 5.3.3 to 5.3.4. - [Release notes](https://github.com/webpack/webpack-dev-middleware/releases) - [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md) - [Commits](https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4) --- updated-dependencies: - dependency-name: webpack-dev-middleware dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 16525e7c4ef..b0b7e4f6058 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -21538,9 +21538,9 @@ } }, "node_modules/webpack-dev-middleware": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz", - "integrity": "sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA==", + "version": "5.3.4", + "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz", + "integrity": "sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q==", "dependencies": { "colorette": "^2.0.10", "memfs": "^3.4.3", From 25bb126a11736545401e351a68649b7626763963 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:16:57 +0000 Subject: [PATCH 076/134] chore(deps): bump express from 4.18.2 to 4.19.2 in /docs Bumps [express](https://github.com/expressjs/express) from 4.18.2 to 4.19.2. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](https://github.com/expressjs/express/compare/4.18.2...4.19.2) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index b0b7e4f6058..afdc8248cf4 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -4809,12 +4809,12 @@ } }, "node_modules/body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "dependencies": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -4822,7 +4822,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -5542,9 +5542,9 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" }, "node_modules/cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", "engines": { "node": ">= 0.6" } @@ -9042,16 +9042,16 @@ } }, "node_modules/express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.1", + "body-parser": "1.20.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -17802,9 +17802,9 @@ } }, "node_modules/raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", From 18b86b7720201dde045fddb42965cd64d1082a9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:23:05 +0000 Subject: [PATCH 077/134] chore(deps): bump follow-redirects from 1.15.5 to 1.15.6 in /docs Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.5 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.5...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index afdc8248cf4..379360a9660 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -9387,9 +9387,9 @@ "devOptional": true }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", From d672b0c70512aa9c880c76f34dd448f9cffe4ae6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:32:02 +0000 Subject: [PATCH 078/134] chore(deps): bump react-toastify from 7.0.4 to 10.0.5 in /docs Bumps [react-toastify](https://github.com/fkhadra/react-toastify) from 7.0.4 to 10.0.5. - [Release notes](https://github.com/fkhadra/react-toastify/releases) - [Commits](https://github.com/fkhadra/react-toastify/compare/v7.0.4...v10.0.5) --- updated-dependencies: - dependency-name: react-toastify dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 22 +++++++--------------- docs/package.json | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 379360a9660..3c76a963b88 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -20,7 +20,7 @@ "react-async": "^10.0.1", "react-copy-to-clipboard": "^5.0.3", "react-dom": "^18.0.0", - "react-toastify": "^7.0.4", + "react-toastify": "^10.0.5", "web-tree-sitter": "^0.20.8" }, "devDependencies": { @@ -18049,23 +18049,15 @@ } }, "node_modules/react-toastify": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-7.0.4.tgz", - "integrity": "sha512-Rol7+Cn39hZp5hQ/k6CbMNE2CKYV9E5OQdC/hBLtIQU2xz7DdAm7xil4NITQTHR6zEbE5RVFbpgSwTD7xRGLeQ==", + "version": "10.0.5", + "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-10.0.5.tgz", + "integrity": "sha512-mNKt2jBXJg4O7pSdbNUfDdTsK9FIdikfsIE/yUCxbAEXl4HMyJaivrVFcn3Elvt5xvCQYhUZm+hqTIu1UXM3Pw==", "dependencies": { - "clsx": "^1.1.1" + "clsx": "^2.1.0" }, "peerDependencies": { - "react": ">=16", - "react-dom": ">=16" - } - }, - "node_modules/react-toastify/node_modules/clsx": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz", - "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==", - "engines": { - "node": ">=6" + "react": ">=18", + "react-dom": ">=18" } }, "node_modules/read-package-json-fast": { diff --git a/docs/package.json b/docs/package.json index 7f468cb53d8..a0801763030 100644 --- a/docs/package.json +++ b/docs/package.json @@ -27,7 +27,7 @@ "react-async": "^10.0.1", "react-copy-to-clipboard": "^5.0.3", "react-dom": "^18.0.0", - "react-toastify": "^7.0.4", + "react-toastify": "^10.0.5", "web-tree-sitter": "^0.20.8" }, "browserslist": { From fff1cbecdcc75302b6280a469ed31687cfc79776 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 29 Mar 2024 18:15:06 +0000 Subject: [PATCH 079/134] fix: Add wakeup-source; to kscan nodes for ZMK_SLEEP. * ZMK_SLEEP also enables PM_DEVICE, so be sure to mark kscan nodes as wakeup sources so they can wake keyboards from sleep. --- app/boards/arm/adv360pro/adv360pro_left.dts | 1 + app/boards/arm/adv360pro/adv360pro_right.dts | 1 + app/boards/arm/bt60/bt60_v1.dts | 2 ++ app/boards/arm/bt60/bt60_v1_hs.dts | 2 ++ app/boards/arm/ckp/ckp.dtsi | 2 ++ app/boards/arm/corneish_zen/corneish_zen_v1_left.dts | 1 + app/boards/arm/corneish_zen/corneish_zen_v1_right.dts | 1 + app/boards/arm/corneish_zen/corneish_zen_v2_left.dts | 1 + app/boards/arm/corneish_zen/corneish_zen_v2_right.dts | 1 + app/boards/arm/glove80/glove80.dtsi | 2 ++ app/boards/arm/nice60/nice60.dts | 1 + app/boards/arm/s40nc/s40nc.dts | 1 + app/boards/shields/a_dux/a_dux.dtsi | 2 ++ app/boards/shields/bat43/bat43.overlay | 1 + app/boards/shields/bfo9000/bfo9000.dtsi | 1 + app/boards/shields/boardsource3x4/boardsource3x4.overlay | 2 ++ app/boards/shields/boardsource5x12/boardsource5x12.overlay | 2 ++ app/boards/shields/chalice/chalice.overlay | 2 ++ app/boards/shields/clog/clog.dtsi | 1 + app/boards/shields/contra/contra.overlay | 2 ++ app/boards/shields/corne/corne.dtsi | 1 + app/boards/shields/cradio/cradio.dtsi | 2 ++ app/boards/shields/crbn/crbn.overlay | 2 ++ app/boards/shields/eek/eek.overlay | 2 ++ app/boards/shields/elephant42/elephant42.dtsi | 1 + app/boards/shields/ergodash/ergodash.dtsi | 1 + app/boards/shields/eternal_keypad/eternal_keypad.dtsi | 1 + app/boards/shields/fourier/fourier.dtsi | 1 + app/boards/shields/helix/helix.dtsi | 1 + app/boards/shields/hummingbird/hummingbird.overlay | 2 ++ app/boards/shields/iris/iris.dtsi | 1 + app/boards/shields/jian/jian.dtsi | 1 + app/boards/shields/jiran/jiran.dtsi | 1 + app/boards/shields/jorne/jorne.dtsi | 1 + app/boards/shields/knob_goblin/knob_goblin.overlay | 2 ++ app/boards/shields/kyria/kyria_common.dtsi | 1 + app/boards/shields/leeloo/leeloo_common.dtsi | 1 + app/boards/shields/leeloo_micro/leeloo_micro.dtsi | 1 + app/boards/shields/lily58/lily58.dtsi | 1 + app/boards/shields/lotus58/lotus58.dtsi | 1 + app/boards/shields/m60/m60.overlay | 1 + app/boards/shields/microdox/microdox.dtsi | 1 + app/boards/shields/microdox/microdox_v2.dtsi | 1 + app/boards/shields/murphpad/murphpad.overlay | 1 + app/boards/shields/naked60/naked60.overlay | 1 + app/boards/shields/osprette/osprette.overlay | 1 + app/boards/shields/pancake/pancake.overlay | 1 + app/boards/shields/qaz/qaz.overlay | 1 + app/boards/shields/quefrency/quefrency_left.overlay | 2 ++ app/boards/shields/quefrency/quefrency_right.overlay | 2 ++ app/boards/shields/redox/redox.dtsi | 1 + app/boards/shields/reviung34/reviung34.overlay | 2 ++ app/boards/shields/reviung41/reviung41.overlay | 2 ++ app/boards/shields/reviung5/reviung5.overlay | 1 + app/boards/shields/reviung53/reviung53.overlay | 2 ++ app/boards/shields/romac/romac.overlay | 1 + app/boards/shields/romac_plus/romac_plus.overlay | 1 + app/boards/shields/sofle/sofle.dtsi | 1 + .../splitkb_aurora_corne/splitkb_aurora_corne_left.overlay | 2 ++ .../splitkb_aurora_corne/splitkb_aurora_corne_right.overlay | 2 ++ .../splitkb_aurora_helix/splitkb_aurora_helix_left.overlay | 2 ++ .../splitkb_aurora_helix/splitkb_aurora_helix_right.overlay | 2 ++ .../splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay | 2 ++ .../splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay | 2 ++ .../splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay | 2 ++ .../splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay | 2 ++ .../splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay | 2 ++ .../splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay | 1 + app/boards/shields/splitreus62/splitreus62.dtsi | 1 + app/boards/shields/tg4x/tg4x.overlay | 1 + app/boards/shields/two_percent_milk/two_percent_milk.overlay | 1 + app/boards/shields/waterfowl/waterfowl.dtsi | 1 + app/boards/shields/zodiark/zodiark.dtsi | 1 + 73 files changed, 101 insertions(+) diff --git a/app/boards/arm/adv360pro/adv360pro_left.dts b/app/boards/arm/adv360pro/adv360pro_left.dts index 6ef5f59071b..459a2232f1e 100644 --- a/app/boards/arm/adv360pro/adv360pro_left.dts +++ b/app/boards/arm/adv360pro/adv360pro_left.dts @@ -10,6 +10,7 @@ /{ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/adv360pro/adv360pro_right.dts b/app/boards/arm/adv360pro/adv360pro_right.dts index 97d846f855c..748cc42aeb0 100644 --- a/app/boards/arm/adv360pro/adv360pro_right.dts +++ b/app/boards/arm/adv360pro/adv360pro_right.dts @@ -10,6 +10,7 @@ /{ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/bt60/bt60_v1.dts b/app/boards/arm/bt60/bt60_v1.dts index 53d4e77b41d..315d8cceb84 100644 --- a/app/boards/arm/bt60/bt60_v1.dts +++ b/app/boards/arm/bt60/bt60_v1.dts @@ -81,6 +81,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/arm/bt60/bt60_v1_hs.dts b/app/boards/arm/bt60/bt60_v1_hs.dts index 57b47554fc5..27e38286178 100644 --- a/app/boards/arm/bt60/bt60_v1_hs.dts +++ b/app/boards/arm/bt60/bt60_v1_hs.dts @@ -30,6 +30,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/arm/ckp/ckp.dtsi b/app/boards/arm/ckp/ckp.dtsi index 6bbbbdd74fb..4142622ac86 100644 --- a/app/boards/arm/ckp/ckp.dtsi +++ b/app/boards/arm/ckp/ckp.dtsi @@ -34,6 +34,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts b/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts index 6683b1b2408..2c77f01c0ba 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts b/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts index 492c79fa108..536e46eab2d 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts b/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts index dacb24c3a24..42839b61646 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts b/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts index f1baea42656..b47d122fe54 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/glove80/glove80.dtsi b/app/boards/arm/glove80/glove80.dtsi index 0078fe627fa..4803488b078 100644 --- a/app/boards/arm/glove80/glove80.dtsi +++ b/app/boards/arm/glove80/glove80.dtsi @@ -34,6 +34,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; debounce-press-ms = <4>; debounce-release-ms = <20>; diff --git a/app/boards/arm/nice60/nice60.dts b/app/boards/arm/nice60/nice60.dts index 7397cffaba3..d1b9f9927cc 100644 --- a/app/boards/arm/nice60/nice60.dts +++ b/app/boards/arm/nice60/nice60.dts @@ -42,6 +42,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,5) R kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/s40nc/s40nc.dts b/app/boards/arm/s40nc/s40nc.dts index a04f42e1ffb..a2eb89ea207 100644 --- a/app/boards/arm/s40nc/s40nc.dts +++ b/app/boards/arm/s40nc/s40nc.dts @@ -37,6 +37,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/a_dux/a_dux.dtsi b/app/boards/shields/a_dux/a_dux.dtsi index caeae8dba29..46aa8fda2c1 100644 --- a/app/boards/shields/a_dux/a_dux.dtsi +++ b/app/boards/shields/a_dux/a_dux.dtsi @@ -27,6 +27,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; + input-gpios = <&pro_micro 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, <&pro_micro 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, diff --git a/app/boards/shields/bat43/bat43.overlay b/app/boards/shields/bat43/bat43.overlay index 600dccec4ad..89c2428d1e2 100644 --- a/app/boards/shields/bat43/bat43.overlay +++ b/app/boards/shields/bat43/bat43.overlay @@ -28,6 +28,7 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(6,0) RC(6,1) RC(6,2) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/bfo9000/bfo9000.dtsi b/app/boards/shields/bfo9000/bfo9000.dtsi index ea9283ad03a..1108067196e 100644 --- a/app/boards/shields/bfo9000/bfo9000.dtsi +++ b/app/boards/shields/bfo9000/bfo9000.dtsi @@ -28,6 +28,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.overlay b/app/boards/shields/boardsource3x4/boardsource3x4.overlay index 389f5b7ab7c..0d63214dde4 100644 --- a/app/boards/shields/boardsource3x4/boardsource3x4.overlay +++ b/app/boards/shields/boardsource3x4/boardsource3x4.overlay @@ -13,6 +13,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/boardsource5x12/boardsource5x12.overlay b/app/boards/shields/boardsource5x12/boardsource5x12.overlay index 9a721d0c4aa..15ae7b68f25 100644 --- a/app/boards/shields/boardsource5x12/boardsource5x12.overlay +++ b/app/boards/shields/boardsource5x12/boardsource5x12.overlay @@ -13,6 +13,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/chalice/chalice.overlay b/app/boards/shields/chalice/chalice.overlay index 92dfe356101..8631d73572d 100644 --- a/app/boards/shields/chalice/chalice.overlay +++ b/app/boards/shields/chalice/chalice.overlay @@ -44,6 +44,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/clog/clog.dtsi b/app/boards/shields/clog/clog.dtsi index feea830c6ab..883aaa29bb3 100644 --- a/app/boards/shields/clog/clog.dtsi +++ b/app/boards/shields/clog/clog.dtsi @@ -26,6 +26,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; input-gpios = <&pro_micro 18 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/contra/contra.overlay b/app/boards/shields/contra/contra.overlay index 0ac042d6357..45cc3088f23 100644 --- a/app/boards/shields/contra/contra.overlay +++ b/app/boards/shields/contra/contra.overlay @@ -11,6 +11,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi index f6d41e3353b..e1edcce81e4 100644 --- a/app/boards/shields/corne/corne.dtsi +++ b/app/boards/shields/corne/corne.dtsi @@ -47,6 +47,7 @@ RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index 4f8a09d715c..b510c636f64 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -27,6 +27,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; + input-gpios = <&pro_micro 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro 18 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/crbn/crbn.overlay b/app/boards/shields/crbn/crbn.overlay index af5910d6993..c6a2b87c040 100644 --- a/app/boards/shields/crbn/crbn.overlay +++ b/app/boards/shields/crbn/crbn.overlay @@ -13,6 +13,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/eek/eek.overlay b/app/boards/shields/eek/eek.overlay index e9e734ac8a9..28aab7efb8c 100644 --- a/app/boards/shields/eek/eek.overlay +++ b/app/boards/shields/eek/eek.overlay @@ -26,6 +26,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/elephant42/elephant42.dtsi b/app/boards/shields/elephant42/elephant42.dtsi index 22a72708686..d72aa9a8761 100644 --- a/app/boards/shields/elephant42/elephant42.dtsi +++ b/app/boards/shields/elephant42/elephant42.dtsi @@ -26,6 +26,7 @@ RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/ergodash/ergodash.dtsi b/app/boards/shields/ergodash/ergodash.dtsi index 2e41ca3081d..b6ef7fc41c2 100644 --- a/app/boards/shields/ergodash/ergodash.dtsi +++ b/app/boards/shields/ergodash/ergodash.dtsi @@ -35,6 +35,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,13) RC(4,12 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/eternal_keypad/eternal_keypad.dtsi b/app/boards/shields/eternal_keypad/eternal_keypad.dtsi index 3144f986f61..1274e3dd958 100644 --- a/app/boards/shields/eternal_keypad/eternal_keypad.dtsi +++ b/app/boards/shields/eternal_keypad/eternal_keypad.dtsi @@ -14,6 +14,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/fourier/fourier.dtsi b/app/boards/shields/fourier/fourier.dtsi index 3b309b8dcda..f486e0a44e5 100644 --- a/app/boards/shields/fourier/fourier.dtsi +++ b/app/boards/shields/fourier/fourier.dtsi @@ -30,6 +30,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) /**/ RC(3,6) RC(3,9 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/helix/helix.dtsi b/app/boards/shields/helix/helix.dtsi index df80f4caec7..8566ffc6bf2 100644 --- a/app/boards/shields/helix/helix.dtsi +++ b/app/boards/shields/helix/helix.dtsi @@ -32,6 +32,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) RC(4,8) RC(4,9 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/hummingbird/hummingbird.overlay b/app/boards/shields/hummingbird/hummingbird.overlay index 871728a28e5..2474d089dff 100644 --- a/app/boards/shields/hummingbird/hummingbird.overlay +++ b/app/boards/shields/hummingbird/hummingbird.overlay @@ -29,6 +29,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; col-gpios diff --git a/app/boards/shields/iris/iris.dtsi b/app/boards/shields/iris/iris.dtsi index c979214c316..8ddbd359ebb 100644 --- a/app/boards/shields/iris/iris.dtsi +++ b/app/boards/shields/iris/iris.dtsi @@ -32,6 +32,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,2) RC(4,9) RC(3,6) RC(3,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/jian/jian.dtsi b/app/boards/shields/jian/jian.dtsi index c5ae1b9e444..439bf93c05c 100644 --- a/app/boards/shields/jian/jian.dtsi +++ b/app/boards/shields/jian/jian.dtsi @@ -62,6 +62,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/jiran/jiran.dtsi b/app/boards/shields/jiran/jiran.dtsi index b6633b65586..517cbe5f7c5 100644 --- a/app/boards/shields/jiran/jiran.dtsi +++ b/app/boards/shields/jiran/jiran.dtsi @@ -67,6 +67,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/jorne/jorne.dtsi b/app/boards/shields/jorne/jorne.dtsi index a2d804b9abc..e7b81e5f113 100644 --- a/app/boards/shields/jorne/jorne.dtsi +++ b/app/boards/shields/jorne/jorne.dtsi @@ -63,6 +63,7 @@ RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/knob_goblin/knob_goblin.overlay b/app/boards/shields/knob_goblin/knob_goblin.overlay index 49306ddf0ab..c42482dbf49 100644 --- a/app/boards/shields/knob_goblin/knob_goblin.overlay +++ b/app/boards/shields/knob_goblin/knob_goblin.overlay @@ -14,6 +14,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/kyria/kyria_common.dtsi b/app/boards/shields/kyria/kyria_common.dtsi index 23058f376ad..f662fa1c402 100644 --- a/app/boards/shields/kyria/kyria_common.dtsi +++ b/app/boards/shields/kyria/kyria_common.dtsi @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; }; diff --git a/app/boards/shields/leeloo/leeloo_common.dtsi b/app/boards/shields/leeloo/leeloo_common.dtsi index df4f228e9d2..8ae5b0648e0 100644 --- a/app/boards/shields/leeloo/leeloo_common.dtsi +++ b/app/boards/shields/leeloo/leeloo_common.dtsi @@ -32,6 +32,7 @@ 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) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/leeloo_micro/leeloo_micro.dtsi b/app/boards/shields/leeloo_micro/leeloo_micro.dtsi index bc314205c28..f23396533fa 100644 --- a/app/boards/shields/leeloo_micro/leeloo_micro.dtsi +++ b/app/boards/shields/leeloo_micro/leeloo_micro.dtsi @@ -31,6 +31,7 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(3,4) RC(3,5) RC(2,5) RC(2,6) RC(2,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/lily58/lily58.dtsi b/app/boards/shields/lily58/lily58.dtsi index 1a326d62e18..c82b197cc51 100644 --- a/app/boards/shields/lily58/lily58.dtsi +++ b/app/boards/shields/lily58/lily58.dtsi @@ -33,6 +33,7 @@ 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) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/lotus58/lotus58.dtsi b/app/boards/shields/lotus58/lotus58.dtsi index afa311d9a6a..e4595930cd0 100644 --- a/app/boards/shields/lotus58/lotus58.dtsi +++ b/app/boards/shields/lotus58/lotus58.dtsi @@ -33,6 +33,7 @@ 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 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/m60/m60.overlay b/app/boards/shields/m60/m60.overlay index 22eed44f35a..c479233cd52 100644 --- a/app/boards/shields/m60/m60.overlay +++ b/app/boards/shields/m60/m60.overlay @@ -14,6 +14,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/microdox/microdox.dtsi b/app/boards/shields/microdox/microdox.dtsi index 4869cfeabbd..65c670f01ef 100644 --- a/app/boards/shields/microdox/microdox.dtsi +++ b/app/boards/shields/microdox/microdox.dtsi @@ -9,6 +9,7 @@ / { kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios = <&pro_micro 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> diff --git a/app/boards/shields/microdox/microdox_v2.dtsi b/app/boards/shields/microdox/microdox_v2.dtsi index 6eb7efa58f4..95aaf79dbeb 100644 --- a/app/boards/shields/microdox/microdox_v2.dtsi +++ b/app/boards/shields/microdox/microdox_v2.dtsi @@ -9,6 +9,7 @@ / { kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; }; }; diff --git a/app/boards/shields/murphpad/murphpad.overlay b/app/boards/shields/murphpad/murphpad.overlay index a82349684ff..e2c9117f93d 100644 --- a/app/boards/shields/murphpad/murphpad.overlay +++ b/app/boards/shields/murphpad/murphpad.overlay @@ -14,6 +14,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/naked60/naked60.overlay b/app/boards/shields/naked60/naked60.overlay index 843c867f109..4e36bc762f9 100644 --- a/app/boards/shields/naked60/naked60.overlay +++ b/app/boards/shields/naked60/naked60.overlay @@ -11,6 +11,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/osprette/osprette.overlay b/app/boards/shields/osprette/osprette.overlay index af2e5625479..ed893f4737e 100644 --- a/app/boards/shields/osprette/osprette.overlay +++ b/app/boards/shields/osprette/osprette.overlay @@ -26,6 +26,7 @@ RC(0,0) RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "row2col"; col-gpios diff --git a/app/boards/shields/pancake/pancake.overlay b/app/boards/shields/pancake/pancake.overlay index 0ceb2d5c6f7..0538bf71ed9 100644 --- a/app/boards/shields/pancake/pancake.overlay +++ b/app/boards/shields/pancake/pancake.overlay @@ -11,6 +11,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/qaz/qaz.overlay b/app/boards/shields/qaz/qaz.overlay index d0ec5b3a0eb..5c76b98f873 100644 --- a/app/boards/shields/qaz/qaz.overlay +++ b/app/boards/shields/qaz/qaz.overlay @@ -27,6 +27,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/quefrency/quefrency_left.overlay b/app/boards/shields/quefrency/quefrency_left.overlay index cf7958410c6..a40d47c1bb0 100644 --- a/app/boards/shields/quefrency/quefrency_left.overlay +++ b/app/boards/shields/quefrency/quefrency_left.overlay @@ -12,6 +12,8 @@ */ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; diff --git a/app/boards/shields/quefrency/quefrency_right.overlay b/app/boards/shields/quefrency/quefrency_right.overlay index 446a614a229..ebb9f8447ac 100644 --- a/app/boards/shields/quefrency/quefrency_right.overlay +++ b/app/boards/shields/quefrency/quefrency_right.overlay @@ -17,6 +17,8 @@ */ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; diff --git a/app/boards/shields/redox/redox.dtsi b/app/boards/shields/redox/redox.dtsi index 505a5c69b0a..098be434481 100644 --- a/app/boards/shields/redox/redox.dtsi +++ b/app/boards/shields/redox/redox.dtsi @@ -32,6 +32,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) RC(4,8) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/reviung34/reviung34.overlay b/app/boards/shields/reviung34/reviung34.overlay index 6ec9813df3b..0f58b99da3a 100644 --- a/app/boards/shields/reviung34/reviung34.overlay +++ b/app/boards/shields/reviung34/reviung34.overlay @@ -38,6 +38,8 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(3,7) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/reviung41/reviung41.overlay b/app/boards/shields/reviung41/reviung41.overlay index 079fd36b96e..f8503fc35a8 100644 --- a/app/boards/shields/reviung41/reviung41.overlay +++ b/app/boards/shields/reviung41/reviung41.overlay @@ -27,6 +27,8 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(5,0) RC(5,1) RC(5,2) RC(5,3) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/reviung5/reviung5.overlay b/app/boards/shields/reviung5/reviung5.overlay index 0382145c69a..0abd3a06ecc 100644 --- a/app/boards/shields/reviung5/reviung5.overlay +++ b/app/boards/shields/reviung5/reviung5.overlay @@ -22,6 +22,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/reviung53/reviung53.overlay b/app/boards/shields/reviung53/reviung53.overlay index d6037aecdaf..fa784478bfb 100644 --- a/app/boards/shields/reviung53/reviung53.overlay +++ b/app/boards/shields/reviung53/reviung53.overlay @@ -28,6 +28,8 @@ RC(6,0) RC(6,1) RC(6,2) RC(6,3) RC(6,4) RC(6,5) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/romac/romac.overlay b/app/boards/shields/romac/romac.overlay index 3d99e51bfe9..8c11a8ac531 100644 --- a/app/boards/shields/romac/romac.overlay +++ b/app/boards/shields/romac/romac.overlay @@ -13,6 +13,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/romac_plus/romac_plus.overlay b/app/boards/shields/romac_plus/romac_plus.overlay index 229b4a2cfe8..39e123c0c21 100644 --- a/app/boards/shields/romac_plus/romac_plus.overlay +++ b/app/boards/shields/romac_plus/romac_plus.overlay @@ -13,6 +13,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/sofle/sofle.dtsi b/app/boards/shields/sofle/sofle.dtsi index f88339d7951..ef89e4a5922 100644 --- a/app/boards/shields/sofle/sofle.dtsi +++ b/app/boards/shields/sofle/sofle.dtsi @@ -33,6 +33,7 @@ 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) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay index df930cd2547..ec40a0165d3 100644 --- a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay +++ b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay index 3823cdfb76e..7341f072be5 100644 --- a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay +++ b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay index 59d825530ef..61b663e605d 100644 --- a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay +++ b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay index 95cea9ecc3c..5aee19bdbb1 100644 --- a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay +++ b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay index fc38bbcbc76..8d56890f313 100644 --- a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay index c9a96491ee9..6b719020a2b 100644 --- a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay index 024c9e75b29..2a3f485da55 100644 --- a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay +++ b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay index 58df0026f06..6eb0d113829 100644 --- a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay +++ b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay index 4a1bec902af..9c1fd975769 100644 --- a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay +++ b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay index c3655477617..b280b42d31c 100644 --- a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay +++ b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay @@ -13,6 +13,7 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitreus62/splitreus62.dtsi b/app/boards/shields/splitreus62/splitreus62.dtsi index d80f8731fbe..1a4f3af1b95 100644 --- a/app/boards/shields/splitreus62/splitreus62.dtsi +++ b/app/boards/shields/splitreus62/splitreus62.dtsi @@ -34,6 +34,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/tg4x/tg4x.overlay b/app/boards/shields/tg4x/tg4x.overlay index 07a0635d5d4..ac05e8108d7 100644 --- a/app/boards/shields/tg4x/tg4x.overlay +++ b/app/boards/shields/tg4x/tg4x.overlay @@ -9,6 +9,7 @@ / { kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/two_percent_milk/two_percent_milk.overlay b/app/boards/shields/two_percent_milk/two_percent_milk.overlay index 474150ef2fa..7647f55151d 100644 --- a/app/boards/shields/two_percent_milk/two_percent_milk.overlay +++ b/app/boards/shields/two_percent_milk/two_percent_milk.overlay @@ -11,6 +11,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; input-gpios = <&pro_micro 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/waterfowl/waterfowl.dtsi b/app/boards/shields/waterfowl/waterfowl.dtsi index d46910a3f2a..2329ca78f70 100644 --- a/app/boards/shields/waterfowl/waterfowl.dtsi +++ b/app/boards/shields/waterfowl/waterfowl.dtsi @@ -31,6 +31,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/zodiark/zodiark.dtsi b/app/boards/shields/zodiark/zodiark.dtsi index 3151f31c990..aa68e20d8cc 100644 --- a/app/boards/shields/zodiark/zodiark.dtsi +++ b/app/boards/shields/zodiark/zodiark.dtsi @@ -33,6 +33,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) R kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios From 4bef4e98f52c3ea57630a3cd1e0e2d078d67758b Mon Sep 17 00:00:00 2001 From: zhiayang <500236+zhiayang@users.noreply.github.com> Date: Sat, 30 Mar 2024 19:12:37 -0400 Subject: [PATCH 080/134] feat(boards): Support board revisions in setup scripts. * Make setup.sh/ps1 prompt for board revision for boards that have revisions --- docs/src/templates/setup.ps1.mustache | 29 ++++++++++++++++++++++ docs/src/templates/setup.sh.mustache | 35 +++++++++++++++++++++++++++ schema/hardware-metadata.schema.json | 15 +++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index 90f9cdcfaec..b8ecc2937f4 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -131,6 +131,19 @@ if ($keyboard_type -eq "shield") { {{/boards}} } + $boards_revisions = [ordered]@{ + {{#boards}} + {{id}} = @({{#revisions}} + "{{.}}"{{/revisions}}); + {{/boards}} + } + + $boards_default_revision=[ordered]@{ + {{#boards}} + {{id}} = "{{{default_revision}}}"; + {{/boards}} + } + Write-Host "$title" Write-Host "" Write-Host "MCU Board Selection:" @@ -145,6 +158,22 @@ if ($keyboard_type -eq "shield") { $shields = $keyboard_siblings $board = $($($boards.keys)[$choice]) $boards = ( $board ) + + if ($($($boards_revisions.values)[$choice]).count -gt 0) { + $valid_revisions = $($($boards_revisions.values)[$choice]) + $revision_choices = @() + $valid_revisions + + for ($i = 0; $i -lt $valid_revisions.count; $i += 1) { + if ($valid_revisions[$i] -eq $($($boards_default_revision.values)[$choice])) { + $revision_choices[$i] += " (default)" + } + } + + $revision_choice = Get-Choice-From-Options -Options $revision_choices -Prompt $prompt + $board = $board + "@" + $valid_revisions[$revision_choice] + $boards = ( $board ) + } + } else { $boards = ( $keyboard_siblings ) $shields = @( ) diff --git a/docs/src/templates/setup.sh.mustache b/docs/src/templates/setup.sh.mustache index c711dbc5b1c..dd7a7a2d2f2 100644 --- a/docs/src/templates/setup.sh.mustache +++ b/docs/src/templates/setup.sh.mustache @@ -122,6 +122,9 @@ if [ "$keyboard_shield" == "y" ]; then board_ids=({{#boards}}"{{id}}" {{/boards}}) boards_usb_only=({{#boards}}"{{#usb_only}}y{{/usb_only}}{{^usb_only}}n{{/usb_only}}" {{/boards}}) + boards_revisions=({{#boards}}"{{#revisions}}{{.}} {{/revisions}}" {{/boards}}) + boards_default_revision=({{#boards}}"{{{default_revision}}}" {{/boards}}) + echo "" echo "MCU Board Selection:" PS3="$prompt " @@ -151,6 +154,38 @@ if [ "$keyboard_shield" == "y" ]; then esac done + + if [ -n "${boards_revisions[$board_index]}" ]; then + read -a _valid_revisions <<< "${boards_revisions[$board_index]}" + + _rev_choices=("${_valid_revisions[@]}") + for (( _i=0; _i<${#_valid_revisions}; _i++ )); do + if [ "${boards_default_revision[board_index]}" = "${_valid_revisions[_i]}" ]; then + _rev_choices[_i]+=" (default)" + fi + done + + echo "" + echo "MCU Board Revision:" + select opt in "${_rev_choices[@]}" "Quit"; do + case "$REPLY" in + ''|*[!0-9]*) echo "Invalid option. Try another one."; continue;; + + $(( ${#_valid_revisions[@]}+1 )) ) echo "Goodbye!"; exit 1;; + *) + if [ $REPLY -gt $(( ${#_valid_revisions[@]}+1 )) ] || [ $REPLY -lt 0 ]; then + echo "Invalid option. Try another one." + continue + fi + + _rev_index=$(( $REPLY-1 )) + board="${board_ids[$board_index]}@${_valid_revisions[_rev_index]}" + boards=( "${board}" ) + break + ;; + esac + done + fi else board=${keyboard} boards=$keyboard_siblings diff --git a/schema/hardware-metadata.schema.json b/schema/hardware-metadata.schema.json index 4c2bdf3b730..9710c792392 100644 --- a/schema/hardware-metadata.schema.json +++ b/schema/hardware-metadata.schema.json @@ -16,7 +16,11 @@ "$defs": { "id": { "type": "string", - "pattern": "^[a-z0-9_]+$" + "pattern": "^[a-z0-9_]+(@([A-Z]|[0-9]+|([0-9]+(\\.[0-9]+){1,2})))?$" + }, + "revision": { + "type": "string", + "pattern": "[A-Z]|[0-9]+|([0-9]+(\\.[0-9]+){1,2})" }, "keyboard_siblings": { "type": "array", @@ -202,6 +206,15 @@ }, "exposes": { "$ref": "#/$defs/interconnects" + }, + "revisions": { + "type": "array", + "items": { + "$ref": "#/$defs/revision" + } + }, + "default_revision": { + "$ref": "#/$defs/revision" } } }, From e65a1227d8cddc2edc2e5da2276f992d8a91ed49 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Fri, 29 Mar 2024 14:41:18 -0700 Subject: [PATCH 081/134] fix(docs): Correct property types for behavior bindings --- docs/docs/config/behaviors.md | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/docs/config/behaviors.md b/docs/docs/config/behaviors.md index 1a5b899ab97..06e87850e38 100644 --- a/docs/docs/config/behaviors.md +++ b/docs/docs/config/behaviors.md @@ -57,18 +57,18 @@ Definition file: [zmk/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml](htt Applies to: `compatible = "zmk,behavior-hold-tap"` -| Property | Type | Description | Default | -| ----------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------- | ------------------ | -| `#binding-cells` | int | Must be `<2>` | | -| `bindings` | phandle array | A list of two behaviors (without parameters): one for hold and one for tap | | -| `flavor` | string | Adjusts how the behavior chooses between hold and tap | `"hold-preferred"` | -| `tapping-term-ms` | int | How long in milliseconds the key must be held to trigger a hold | | -| `quick-tap-ms` | int | Tap twice within this period (in milliseconds) to trigger a tap, even when held | -1 (disabled) | -| `require-prior-idle-ms` | int | Triggers a tap immediately if any non-modifier key was pressed within `require-prior-idle-ms` of the hold-tap. | -1 (disabled) | -| `retro-tap` | bool | Triggers the tap behavior on release if no other key was pressed during a hold | false | -| `hold-while-undecided` | bool | Triggers the hold behavior immediately on press and releases before a tap | false | -| `hold-while-undecided-linger` | bool | Continues to hold the hold behavior until after the tap is released | false | -| `hold-trigger-key-positions` | array | If set, pressing the hold-tap and then any key position _not_ in the list triggers a tap. | | +| Property | Type | Description | Default | +| ----------------------------- | -------- | -------------------------------------------------------------------------------------------------------------- | ------------------ | +| `#binding-cells` | int | Must be `<2>` | | +| `bindings` | phandles | A list of two behaviors (without parameters): one for hold and one for tap | | +| `flavor` | string | Adjusts how the behavior chooses between hold and tap | `"hold-preferred"` | +| `tapping-term-ms` | int | How long in milliseconds the key must be held to trigger a hold | | +| `quick-tap-ms` | int | Tap twice within this period (in milliseconds) to trigger a tap, even when held | -1 (disabled) | +| `require-prior-idle-ms` | int | Triggers a tap immediately if any non-modifier key was pressed within `require-prior-idle-ms` of the hold-tap. | -1 (disabled) | +| `retro-tap` | bool | Triggers the tap behavior on release if no other key was pressed during a hold | false | +| `hold-while-undecided` | bool | Triggers the hold behavior immediately on press and releases before a tap | false | +| `hold-while-undecided-linger` | bool | Continues to hold the hold behavior until after the tap is released | false | +| `hold-trigger-key-positions` | array | If set, pressing the hold-tap and then any key position _not_ in the list triggers a tap. | | This behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. @@ -203,12 +203,12 @@ Definition files: - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate.yaml) - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate-var.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate-var.yaml) -| Property | Type | Description | Default | -| ----------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `compatible` | string | Sensor rotation type, **must be _one_ of**:
  • `"zmk,behavior-sensor-rotate"`
  • `"zmk,behavior-sensor-rotate-var"`
| | -| `#sensor-binding-cells` | int | Must be
  • `<0>` if `compatible = "zmk,behavior-sensor-rotate"`
  • `<2>` if `compatible = "zmk,behavior-sensor-rotate-var"`
| | -| `bindings` | phandle array | A list of two behaviors to trigger for each rotation direction, must include parameters for `"zmk,behavior-sensor-rotate"` and exclude them for `"zmk,behavior-sensor-rotate-var"` | | -| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | +| Property | Type | Description | Default | +| ----------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| `compatible` | string | Sensor rotation type, **must be _one_ of**:
  • `"zmk,behavior-sensor-rotate"`
  • `"zmk,behavior-sensor-rotate-var"`
| | +| `#sensor-binding-cells` | int | Must be
  • `<0>` if `compatible = "zmk,behavior-sensor-rotate"`
  • `<2>` if `compatible = "zmk,behavior-sensor-rotate-var"`
| | +| `bindings` | phandles for `"zmk,behavior-sensor-rotate"`, phandle array for `"zmk,behavior-sensor-rotate-var"` | A list of two behaviors to trigger for each rotation direction, must include parameters for `"zmk,behavior-sensor-rotate"` and exclude them for `"zmk,behavior-sensor-rotate-var"` | | +| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | With `compatible = "zmk,behavior-sensor-rotate-var"`, this behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. @@ -224,14 +224,14 @@ Definition file: [zmk/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml](h Applies to: `compatible = "zmk,behavior-sticky-key"` -| Property | Type | Description | Default | -| ------------------ | ------------- | ------------------------------------------------------------------------ | ------- | -| `#binding-cells` | int | Must be `<1>` | | -| `bindings` | phandle array | A behavior (without parameters) to trigger | | -| `release-after-ms` | int | Releases the key after this many milliseconds if no other key is pressed | 1000 | -| `quick-release` | bool | Release the sticky key on the next key press instead of release | false | -| `lazy` | bool | Wait until the next key press to activate the sticky key behavior | false | -| `ignore-modifiers` | bool | If enabled, pressing a modifier key does not cancel the sticky key | true | +| Property | Type | Description | Default | +| ------------------ | -------- | ------------------------------------------------------------------------ | ------- | +| `#binding-cells` | int | Must be `<1>` | | +| `bindings` | phandles | A behavior (without parameters) to trigger | | +| `release-after-ms` | int | Releases the key after this many milliseconds if no other key is pressed | 1000 | +| `quick-release` | bool | Release the sticky key on the next key press instead of release | false | +| `lazy` | bool | Wait until the next key press to activate the sticky key behavior | false | +| `ignore-modifiers` | bool | If enabled, pressing a modifier key does not cancel the sticky key | true | This behavior forwards the one parameter it receives to the parameter of the behavior specified in `bindings`. From eb5a6fcfe19b32df13488d2ec751f90cb9fa3362 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Fri, 29 Mar 2024 14:44:00 -0700 Subject: [PATCH 082/134] refactor(docs): Split DT props table for sensor rotate variants --- docs/docs/config/behaviors.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/docs/config/behaviors.md b/docs/docs/config/behaviors.md index 06e87850e38..28abdf2722a 100644 --- a/docs/docs/config/behaviors.md +++ b/docs/docs/config/behaviors.md @@ -203,12 +203,21 @@ Definition files: - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate.yaml) - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate-var.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate-var.yaml) -| Property | Type | Description | Default | -| ----------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `compatible` | string | Sensor rotation type, **must be _one_ of**:
  • `"zmk,behavior-sensor-rotate"`
  • `"zmk,behavior-sensor-rotate-var"`
| | -| `#sensor-binding-cells` | int | Must be
  • `<0>` if `compatible = "zmk,behavior-sensor-rotate"`
  • `<2>` if `compatible = "zmk,behavior-sensor-rotate-var"`
| | -| `bindings` | phandles for `"zmk,behavior-sensor-rotate"`, phandle array for `"zmk,behavior-sensor-rotate-var"` | A list of two behaviors to trigger for each rotation direction, must include parameters for `"zmk,behavior-sensor-rotate"` and exclude them for `"zmk,behavior-sensor-rotate-var"` | | -| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | +Applies to: `compatible = "zmk,behavior-sensor-rotate"` + +| Property | Type | Description | Default | +| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------ | ------- | +| `#sensor-binding-cells` | int | Must be `<0>` | | +| `bindings` | phandles | A list of two behaviors to trigger for each rotation direction, must _include_ any behavior parameters | | +| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | + +Applies to: `compatible = "zmk,behavior-sensor-rotate-var"` + +| Property | Type | Description | Default | +| ----------------------- | ------------- | ------------------------------------------------------------------------------------------------------ | ------- | +| `#sensor-binding-cells` | int | Must be `<2>` | | +| `bindings` | phandle array | A list of two behaviors to trigger for each rotation direction, must _exclude_ any behavior parameters | | +| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | With `compatible = "zmk,behavior-sensor-rotate-var"`, this behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. From e7d6519534231525e6173635061ab8e8bda5a997 Mon Sep 17 00:00:00 2001 From: Tobias Arndt Date: Sat, 30 Mar 2024 18:24:11 -0700 Subject: [PATCH 083/134] fix(docs): Fix and note GPIO flags for charlieplex config --- docs/docs/config/kscan.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 3aa1b37875c..e6e8bb620be 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -187,6 +187,8 @@ Define the transform with a [matrix transform](#matrix-transform). The row is al For example, in `RC(5,0)` power flows from the 6th pin in `gpios` to the 1st pin in `gpios`. Exclude all positions where the row and column are the same as these pairs will never be triggered, since no pin can be both input and output at the same time. +The [GPIO flags](https://docs.zephyrproject.org/3.5.0/hardware/peripherals/gpio.html#api-reference) for the elements in `gpios` should be `GPIO_ACTIVE_HIGH`, and interrupt pins set in `interrupt-gpios` should have the flags `(GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)`. + ## Composite Driver Keyboard scan driver which combines multiple other keyboard scan drivers. @@ -460,11 +462,11 @@ Note that the entire addressable space does not need to be mapped. interrupt-gpios = <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) >; gpios - = <&pro_micro 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 17 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 18 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 20 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > + = <&pro_micro 16 GPIO_ACTIVE_HIGH> + , <&pro_micro 17 GPIO_ACTIVE_HIGH> + , <&pro_micro 18 GPIO_ACTIVE_HIGH> + , <&pro_micro 19 GPIO_ACTIVE_HIGH> + , <&pro_micro 20 GPIO_ACTIVE_HIGH> ; // addressable space is 5x5, (minus paired values) }; From fe509c466f818471c677b069094d1e84e33ccf2e Mon Sep 17 00:00:00 2001 From: Tobias Arndt Date: Sat, 30 Mar 2024 18:24:51 -0700 Subject: [PATCH 084/134] fix(kscan): Enable charlieplex interrupts for single compatible device Fixes #2201 --- app/module/drivers/kscan/kscan_gpio_charlieplex.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_charlieplex.c b/app/module/drivers/kscan/kscan_gpio_charlieplex.c index a4867aa3207..3ecbcd6a0e1 100644 --- a/app/module/drivers/kscan/kscan_gpio_charlieplex.c +++ b/app/module/drivers/kscan/kscan_gpio_charlieplex.c @@ -47,14 +47,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define USES_POLLING DT_INST_FOREACH_STATUS_OKAY(WITHOUT_INTR) > 0 #define USES_INTERRUPT DT_INST_FOREACH_STATUS_OKAY(WITH_INTR) > 0 -#if USES_POLLING && USES_INTERRUPT -#define USES_POLL_AND_INTR 1 -#else -#define USES_POLL_AND_INTR 0 -#endif - #define COND_ANY_POLLING(code) COND_CODE_1(USES_POLLING, code, ()) -#define COND_POLL_AND_INTR(code) COND_CODE_1(USES_POLL_AND_INTR, code, ()) #define COND_THIS_INTERRUPT(n, code) COND_CODE_1(INST_INTR_DEFINED(n), code, ()) #define KSCAN_INTR_CFG_INIT(inst_idx) GPIO_DT_SPEC_GET(DT_DRV_INST(inst_idx), interrupt_gpios) @@ -410,7 +403,7 @@ static const struct kscan_driver_api kscan_charlieplex_api = { }, \ .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ COND_ANY_POLLING((.poll_period_ms = DT_INST_PROP(n, poll_period_ms), )) \ - COND_POLL_AND_INTR((.use_interrupt = INST_INTR_DEFINED(n), )) \ + COND_THIS_INTERRUPT(n, (.use_interrupt = INST_INTR_DEFINED(n), )) \ COND_THIS_INTERRUPT(n, (.interrupt = KSCAN_INTR_CFG_INIT(n), ))}; \ \ DEVICE_DT_INST_DEFINE(n, &kscan_charlieplex_init, NULL, &kscan_charlieplex_data_##n, \ From 7d5aa0c0bf7283ce484f467338c7e04ff1f7cf25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:04:28 +0800 Subject: [PATCH 085/134] feat(docs): Update section for devicetree_generated error --- docs/docs/troubleshooting.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md index 2e9ab4dcb80..09efdecf770 100644 --- a/docs/docs/troubleshooting.md +++ b/docs/docs/troubleshooting.md @@ -48,7 +48,7 @@ If you are reviewing these errors in the GitHub Actions tab, they can be found i If you get an error stating `Keymap node not found, check a keymap is available and is has compatible = "zmk,keymap" set` this is an indication that the build process cannot find the keymap. Double check that the `.keymap` file is present and has been discovered by the build process. This can be checked by looking for a line in the build log stating `-- Using keymap file: /path/to/keymap/file/.keymap`. Inside the keymap file ensure the keymap node has `compatible = zmk,keymap` and it's not misspelled. For more information see the [Keymap](features/keymaps.mdx) and [Config](config/index.md) documentation. -#### devicetree error +#### Devicetree errors A `devicetree error` followed by a reference to the line number on `.keymap` refers to an issue at the exact line position in that file. For example, below error message indicates a missing `;` at line 109 of the `cradio.keymap` file: @@ -64,12 +64,10 @@ devicetree error: Date: Fri, 23 Feb 2024 16:59:48 -0500 Subject: [PATCH 086/134] refactor(underglow): fix uninitialized variable warning --- app/src/rgb_underglow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index a7a9b4f018f..a055a4d7d9f 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -82,7 +82,7 @@ static struct zmk_led_hsb hsb_scale_zero_max(struct zmk_led_hsb hsb) { } static struct led_rgb hsb_to_rgb(struct zmk_led_hsb hsb) { - float r, g, b; + float r = 0, g = 0, b = 0; uint8_t i = hsb.h / 60; float v = hsb.b / ((float)BRT_MAX); From 7a51a46b9fa6c97c6060b086b73d96d0c6d97b35 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Tue, 27 Feb 2024 11:41:46 -0800 Subject: [PATCH 087/134] feat(docs): Add pointer to shields folder in new shield docs --- docs/docs/development/new-shield.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index 867ccbc8cee..ecf798309e5 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -67,6 +67,10 @@ mkdir boards/shields/ ## Base Kconfig Files +:::tip[Example shields] +You can check out the [`shields` folder](https://github.com/zmkfirmware/zmk/tree/main/app/boards/shields) in the ZMK repo that houses [the in-tree supported shields](../hardware.mdx) in order to copy and modify as a starting point. +::: + There are two required Kconfig files that need to be created for your new keyboard shield to get it picked up for ZMK, `Kconfig.shield` and `Kconfig.defconfig`. From dfc6dc84b8bc06504a9542c1464c8e80f357be09 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Tue, 27 Feb 2024 11:50:54 -0800 Subject: [PATCH 088/134] fix(docs): Make clear the matrix transform example is incomplete --- docs/docs/development/new-shield.mdx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index ecf798309e5..de65f0ac765 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -348,6 +348,8 @@ Here is an example for the [nice60](https://github.com/Nicell/nice60), which use zmk,matrix-transform = &default_transform; }; + /* define kscan node with label `kscan0`... */ + default_transform: keymap_transform_0 { compatible = "zmk,matrix-transform"; columns = <8>; @@ -365,6 +367,9 @@ RC(6,0) RC(6,1) RC(6,2) RC(6,3) RC(5,3) RC(6,4) RC(5,4) RC(6,5) RC(5,5) RC RC(7,0) RC(7,1) RC(7,2) RC(7,3) RC(7,5) RC(7,6) RC(6,7) RC(7,7) >; }; + + /* potentially other overlay nodes... */ +}; ``` Some important things to note: From a9021deef6abe9c168f7cd111137f79ef8fd9655 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Tue, 9 Apr 2024 10:25:33 -0700 Subject: [PATCH 089/134] fix(docs): Add wakeup-source to split new shield example --- docs/docs/development/new-shield.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index de65f0ac765..a542fc84995 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -233,8 +233,9 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,2) RC(4,9) RC(3,6) RC(3,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; - diode-direction = "col2row"; + wakeup-source; + row-gpios = <&pro_micro 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // Row A from the schematic file , <&pro_micro 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // Row B from the schematic file From e22bc7620cef763d9ad80e9b98182273de9973db Mon Sep 17 00:00:00 2001 From: Keeley Hoek Date: Sun, 7 Apr 2024 07:05:51 -0400 Subject: [PATCH 090/134] fix(hid): Correct off-by-one buffer overflow with NKRO --- app/include/zmk/hid.h | 4 +++- app/src/hid.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index d1d3b7d47db..41f559b5189 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -6,6 +6,8 @@ #pragma once +#include + #include #include @@ -200,7 +202,7 @@ struct zmk_hid_keyboard_report_body { zmk_mod_flags_t modifiers; uint8_t _reserved; #if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO) - uint8_t keys[(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1) / 8]; + uint8_t keys[DIV_ROUND_UP(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1, 8)]; #elif IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) uint8_t keys[CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE]; #endif diff --git a/app/src/hid.c b/app/src/hid.c index 8b0c23f37ed..582db6763de 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -126,7 +126,7 @@ zmk_hid_boot_report_t *zmk_hid_get_boot_report(void) { memset(&boot_report.keys, 0, HID_BOOT_KEY_LEN); int ix = 0; uint8_t base_code = 0; - for (int i = 0; i < (ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1) / 8; ++i) { + for (int i = 0; i < sizeof(keyboard_report.body.keys); ++i) { if (ix == keys_held) { break; } From 16e92cf6652e4dbe56ba4f18f6ca6cec510b147c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 18 Apr 2024 06:38:46 +0000 Subject: [PATCH 091/134] fix(behaviors): Add multiple soft-off instances properly. * Properly pass the node id for the unique soft-off behavior instance when defining it. --- app/src/behaviors/behavior_soft_off.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 3a4ae42486d..8c6ba4225f7 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -80,7 +80,7 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = { DT_INST_PROP_OR(n, split_peripheral_off_on_press, false), \ }; \ static struct behavior_soft_off_data bso_data_##n = {}; \ - BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ + BEHAVIOR_DT_INST_DEFINE(n, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ &behavior_soft_off_driver_api); From f4a070aacf775c50b6f01a22dc3e898d49abe7b0 Mon Sep 17 00:00:00 2001 From: Sadek Baroudi Date: Sun, 21 Apr 2024 12:37:47 -0700 Subject: [PATCH 092/134] fix(boards): nrf boards missing SPI in pinctrl and dtsi, requiring users to manually define in their shield definitions if they wanted to use SPI --- .../bluemicro840/arduino_pro_micro_pins.dtsi | 2 +- .../bluemicro840/bluemicro840_v1-pinctrl.dtsi | 17 +++++++++++++++++ app/boards/arm/bluemicro840/bluemicro840_v1.dts | 7 +++++++ .../arm/mikoto/arduino_pro_micro_pins.dtsi | 2 +- app/boards/arm/mikoto/mikoto_520-pinctrl.dtsi | 17 +++++++++++++++++ app/boards/arm/mikoto/mikoto_520.dts | 7 +++++++ .../arm/nice_nano/arduino_pro_micro_pins.dtsi | 2 +- app/boards/arm/nice_nano/nice_nano-pinctrl.dtsi | 17 +++++++++++++++++ app/boards/arm/nice_nano/nice_nano.dtsi | 7 +++++++ .../arm/nrfmicro/arduino_pro_micro_pins.dtsi | 2 +- .../nrfmicro/arduino_pro_micro_pins_52833.dtsi | 2 +- .../arduino_pro_micro_pins_flipped.dtsi | 2 +- .../arm/nrfmicro/nrfmicro-flipped-pinctrl.dtsi | 17 +++++++++++++++++ app/boards/arm/nrfmicro/nrfmicro-pinctrl.dtsi | 17 +++++++++++++++++ app/boards/arm/nrfmicro/nrfmicro_11.dts | 7 +++++++ app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts | 7 +++++++ app/boards/arm/nrfmicro/nrfmicro_13.dts | 7 +++++++ app/boards/arm/nrfmicro/nrfmicro_13_52833.dts | 7 +++++++ 18 files changed, 140 insertions(+), 6 deletions(-) diff --git a/app/boards/arm/bluemicro840/arduino_pro_micro_pins.dtsi b/app/boards/arm/bluemicro840/arduino_pro_micro_pins.dtsi index cdb8fcdd3fd..b2026b6f2c0 100644 --- a/app/boards/arm/bluemicro840/arduino_pro_micro_pins.dtsi +++ b/app/boards/arm/bluemicro840/arduino_pro_micro_pins.dtsi @@ -53,5 +53,5 @@ pro_micro_d: &pro_micro {}; pro_micro_i2c: &i2c0 {}; -pro_micro_spi: &spi0 {}; +pro_micro_spi: &spi1 {}; pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1-pinctrl.dtsi b/app/boards/arm/bluemicro840/bluemicro840_v1-pinctrl.dtsi index 868d3c27ad7..046c0346f37 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1-pinctrl.dtsi +++ b/app/boards/arm/bluemicro840/bluemicro840_v1-pinctrl.dtsi @@ -36,4 +36,21 @@ low-power-enable; }; }; + + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; }; diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1.dts b/app/boards/arm/bluemicro840/bluemicro840_v1.dts index 408cca3be76..aabdf310a28 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1.dts +++ b/app/boards/arm/bluemicro840/bluemicro840_v1.dts @@ -67,6 +67,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/app/boards/arm/mikoto/arduino_pro_micro_pins.dtsi b/app/boards/arm/mikoto/arduino_pro_micro_pins.dtsi index ed6097ec6b9..b2e2d6a3cf1 100644 --- a/app/boards/arm/mikoto/arduino_pro_micro_pins.dtsi +++ b/app/boards/arm/mikoto/arduino_pro_micro_pins.dtsi @@ -55,5 +55,5 @@ pro_micro_d: &pro_micro {}; pro_micro_i2c: &i2c0 {}; -pro_micro_spi: &spi0 {}; +pro_micro_spi: &spi1 {}; pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/mikoto/mikoto_520-pinctrl.dtsi b/app/boards/arm/mikoto/mikoto_520-pinctrl.dtsi index df43c407eec..8cd1e0afc13 100644 --- a/app/boards/arm/mikoto/mikoto_520-pinctrl.dtsi +++ b/app/boards/arm/mikoto/mikoto_520-pinctrl.dtsi @@ -36,4 +36,21 @@ low-power-enable; }; }; + + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; }; diff --git a/app/boards/arm/mikoto/mikoto_520.dts b/app/boards/arm/mikoto/mikoto_520.dts index 05ec72dfcda..a6ca50812f8 100644 --- a/app/boards/arm/mikoto/mikoto_520.dts +++ b/app/boards/arm/mikoto/mikoto_520.dts @@ -66,6 +66,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/app/boards/arm/nice_nano/arduino_pro_micro_pins.dtsi b/app/boards/arm/nice_nano/arduino_pro_micro_pins.dtsi index f1b569c05db..2c257ef016f 100644 --- a/app/boards/arm/nice_nano/arduino_pro_micro_pins.dtsi +++ b/app/boards/arm/nice_nano/arduino_pro_micro_pins.dtsi @@ -53,5 +53,5 @@ pro_micro_d: &pro_micro {}; pro_micro_i2c: &i2c0 {}; -pro_micro_spi: &spi0 {}; +pro_micro_spi: &spi1 {}; pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/nice_nano/nice_nano-pinctrl.dtsi b/app/boards/arm/nice_nano/nice_nano-pinctrl.dtsi index 15c48509202..bcabf4ab376 100644 --- a/app/boards/arm/nice_nano/nice_nano-pinctrl.dtsi +++ b/app/boards/arm/nice_nano/nice_nano-pinctrl.dtsi @@ -36,4 +36,21 @@ low-power-enable; }; }; + + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; }; diff --git a/app/boards/arm/nice_nano/nice_nano.dtsi b/app/boards/arm/nice_nano/nice_nano.dtsi index 81f10906b92..41770dd310e 100644 --- a/app/boards/arm/nice_nano/nice_nano.dtsi +++ b/app/boards/arm/nice_nano/nice_nano.dtsi @@ -50,6 +50,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/app/boards/arm/nrfmicro/arduino_pro_micro_pins.dtsi b/app/boards/arm/nrfmicro/arduino_pro_micro_pins.dtsi index 01e342c0df5..1f88a4eb0e0 100644 --- a/app/boards/arm/nrfmicro/arduino_pro_micro_pins.dtsi +++ b/app/boards/arm/nrfmicro/arduino_pro_micro_pins.dtsi @@ -55,5 +55,5 @@ pro_micro_d: &pro_micro {}; pro_micro_i2c: &i2c0 {}; -pro_micro_spi: &spi0 {}; +pro_micro_spi: &spi1 {}; pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/nrfmicro/arduino_pro_micro_pins_52833.dtsi b/app/boards/arm/nrfmicro/arduino_pro_micro_pins_52833.dtsi index 76ece25f786..b16465e6aac 100644 --- a/app/boards/arm/nrfmicro/arduino_pro_micro_pins_52833.dtsi +++ b/app/boards/arm/nrfmicro/arduino_pro_micro_pins_52833.dtsi @@ -55,5 +55,5 @@ pro_micro_d: &pro_micro {}; pro_micro_i2c: &i2c0 {}; -pro_micro_spi: &spi0 {}; +pro_micro_spi: &spi1 {}; pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/nrfmicro/arduino_pro_micro_pins_flipped.dtsi b/app/boards/arm/nrfmicro/arduino_pro_micro_pins_flipped.dtsi index 923efbbf256..3ab31900b06 100644 --- a/app/boards/arm/nrfmicro/arduino_pro_micro_pins_flipped.dtsi +++ b/app/boards/arm/nrfmicro/arduino_pro_micro_pins_flipped.dtsi @@ -53,5 +53,5 @@ pro_micro_d: &pro_micro {}; pro_micro_i2c: &i2c0 {}; -pro_micro_spi: &spi0 {}; +pro_micro_spi: &spi1 {}; pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/nrfmicro/nrfmicro-flipped-pinctrl.dtsi b/app/boards/arm/nrfmicro/nrfmicro-flipped-pinctrl.dtsi index 22bc11d4013..57e868a4871 100644 --- a/app/boards/arm/nrfmicro/nrfmicro-flipped-pinctrl.dtsi +++ b/app/boards/arm/nrfmicro/nrfmicro-flipped-pinctrl.dtsi @@ -36,4 +36,21 @@ low-power-enable; }; }; + + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro-pinctrl.dtsi b/app/boards/arm/nrfmicro/nrfmicro-pinctrl.dtsi index 35a46e5ae52..c4b9f5a7c67 100644 --- a/app/boards/arm/nrfmicro/nrfmicro-pinctrl.dtsi +++ b/app/boards/arm/nrfmicro/nrfmicro-pinctrl.dtsi @@ -36,4 +36,21 @@ low-power-enable; }; }; + + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_11.dts b/app/boards/arm/nrfmicro/nrfmicro_11.dts index 652df1011a6..04368ab8741 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_11.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_11.dts @@ -54,6 +54,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts b/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts index 5095d64865d..600935aa0a6 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts @@ -54,6 +54,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13.dts b/app/boards/arm/nrfmicro/nrfmicro_13.dts index 7a6a5d4d952..716e5b181dd 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13.dts @@ -66,6 +66,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts b/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts index ff2e027fcb9..f57c413da8b 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts @@ -66,6 +66,13 @@ pinctrl-names = "default", "sleep"; }; +&spi1 { + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; From 4d566853af93860fb00d5eaf9e8cc5403d6fcf23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:55:42 +0200 Subject: [PATCH 093/134] fix(rgb): auto-off logic --- app/src/rgb_underglow.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index a055a4d7d9f..9173058f816 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -468,17 +468,31 @@ int zmk_rgb_underglow_change_spd(int direction) { #if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) || \ IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) -static int rgb_underglow_auto_state(bool *prev_state, bool new_state) { - if (state.on == new_state) { +struct rgb_underglow_sleep_state { + bool is_awake; + bool rgb_state_before_sleeping; +}; + +static int rgb_underglow_auto_state(bool target_wake_state) { + static struct rgb_underglow_sleep_state sleep_state = { + is_awake : true, + rgb_state_before_sleeping : false + }; + + // wake up event while awake, or sleep event while sleeping -> no-op + if (target_wake_state == sleep_state.is_awake) { return 0; } - if (new_state) { - state.on = *prev_state; - *prev_state = false; - return zmk_rgb_underglow_on(); + sleep_state.is_awake = target_wake_state; + + if (sleep_state.is_awake) { + if (sleep_state.rgb_state_before_sleeping) { + return zmk_rgb_underglow_on(); + } else { + return zmk_rgb_underglow_off(); + } } else { - state.on = false; - *prev_state = true; + sleep_state.rgb_state_before_sleeping = sleep_state.on; return zmk_rgb_underglow_off(); } } @@ -487,16 +501,13 @@ static int rgb_underglow_event_listener(const zmk_event_t *eh) { #if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) if (as_zmk_activity_state_changed(eh)) { - static bool prev_state = false; - return rgb_underglow_auto_state(&prev_state, - zmk_activity_get_state() == ZMK_ACTIVITY_ACTIVE); + return rgb_underglow_auto_state(zmk_activity_get_state() == ZMK_ACTIVITY_ACTIVE); } #endif #if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) if (as_zmk_usb_conn_state_changed(eh)) { - static bool prev_state = false; - return rgb_underglow_auto_state(&prev_state, zmk_usb_is_powered()); + return rgb_underglow_auto_state(zmk_usb_is_powered()); } #endif From 0d3a4b7bbb199103d151ee1cadde613101859054 Mon Sep 17 00:00:00 2001 From: Jarryd Tilbrook Date: Thu, 25 Apr 2024 22:26:26 +0800 Subject: [PATCH 094/134] fix(underglow): Correctly set underglow state This fixes a bug introduced in #2244 --- app/src/rgb_underglow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 9173058f816..5bf1ef25e8e 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -492,7 +492,7 @@ static int rgb_underglow_auto_state(bool target_wake_state) { return zmk_rgb_underglow_off(); } } else { - sleep_state.rgb_state_before_sleeping = sleep_state.on; + sleep_state.rgb_state_before_sleeping = state.on; return zmk_rgb_underglow_off(); } } From d1ad34761a0a98fd8e36edbf978ebd4938797472 Mon Sep 17 00:00:00 2001 From: German Gutierrez Date: Mon, 29 Apr 2024 18:22:40 +0200 Subject: [PATCH 095/134] fix: shortening keymap_soft_off behavior node * Shorten the soft off node in order for it to work across splits. --- app/dts/behaviors/soft_off.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index 63c04b1dd7e..a5c9d255bc1 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,7 +6,7 @@ / { behaviors { - /omit-if-no-ref/ soft_off: keymap_soft_off { + /omit-if-no-ref/ soft_off: z_so_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; split-peripheral-off-on-press; From af908826cd750f666f41fc9bb0b0a148941956c2 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 1 May 2024 11:01:32 -0700 Subject: [PATCH 096/134] fix: Initialize sideband kscan in APPLICATION. * In order to be sure the rest of the system is fully ready before intializing, because init may result in immediate events being triggered when used with toggle direct kscan inner devices. --- app/src/kscan_sideband_behaviors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index 7a9922afdae..f3992ebc512 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -173,7 +173,7 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action struct ksbb_data ksbb_data_##n = {}; \ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \ - &ksbb_config_##n, POST_KERNEL, \ + &ksbb_config_##n, APPLICATION, \ CONFIG_ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY, &ksbb_api); DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From 2423136788148158e76976223555bb017277b72a Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Fri, 3 May 2024 08:22:05 +0100 Subject: [PATCH 097/134] fix(boards): Fix pulls on ZMK uno toggle switch The devicetree pulls always add on to the extra pulls configured by toggle mode, so these should not have pulls defined in the devicetree. Saved ~200uA avg on another board with a 3t toggle switch --- app/boards/shields/zmk_uno/zmk_uno.dtsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/boards/shields/zmk_uno/zmk_uno.dtsi b/app/boards/shields/zmk_uno/zmk_uno.dtsi index e8ba79d6d09..ba1d3b5da80 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno.dtsi @@ -125,9 +125,9 @@ nice_view_spi: &arduino_spi { toggle-mode; input-gpios - = <&arduino_header 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + = <&arduino_header 4 GPIO_ACTIVE_LOW> + , <&arduino_header 3 GPIO_ACTIVE_LOW> + , <&arduino_header 2 GPIO_ACTIVE_LOW> ; }; From 4dfc45d4ab38c23cae61dae4699bd0fbef4e33eb Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Fri, 3 May 2024 19:17:09 +0100 Subject: [PATCH 098/134] feat(docs): Document example toggle-mode implementation --------- Co-authored-by: Cem Aksoylar --- docs/docs/config/kscan.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index e6e8bb620be..4fb0cf168ad 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -81,10 +81,6 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml]( | `toggle-mode` | bool | Use toggle switch mode. | n | | `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | -By default, a switch will drain current through the internal pull up/down resistor whenever it is pressed. This is not ideal for a toggle switch, where the switch may be left in the "pressed" state for a long time. Enabling `toggle-mode` will make the driver flip between pull up and down as the switch is toggled to optimize for power. - -`toggle-mode` applies to all switches handled by the instance of the driver. To use a toggle switch with other, non-toggle, direct GPIO switches, create two instances of the direct GPIO driver, one with `toggle-mode` and the other without. Then, use a [composite driver](#composite-driver) to combine them. - Assuming the switches connect each GPIO pin to the ground, the [GPIO flags](https://docs.zephyrproject.org/3.5.0/hardware/peripherals/gpio.html#api-reference) for the elements in `input-gpios` should be `(GPIO_ACTIVE_LOW | GPIO_PULL_UP)`: ```dts @@ -98,6 +94,25 @@ Assuming the switches connect each GPIO pin to the ground, the [GPIO flags](http }; ``` +By default, a switch will drain current through the internal pull up/down resistor whenever it is pressed. This is not ideal for a toggle switch, where the switch may be left in the "pressed" state for a long time. Enabling `toggle-mode` will make the driver enable and disable the internal pull up/down resistor as needed when the switch is toggled to minimise power draw. For `toggle-mode` to work correctly each pole of the switch needs a dedicated GPIO pin. + +`toggle-mode` applies to all switches handled by the instance of the driver. To use a toggle switch with other, non-toggle, direct GPIO switches, create two instances of the direct GPIO driver, one with `toggle-mode` and the other without. Then, use a [composite driver](#composite-driver) to combine them. The state of the switch is read on power on, so if the switch is moved whilst the board is off this will get correctly interpreted by the driver. + +When using `toggle-mode` the pull resistors get automatically set by the driver and should not be set in the devicetree via GPIO flags. Assuming the common pole of the switch is connected to ground with an SP3T switch: + +```dts + kscan_sp3t_toggle: kscan_sp3t_toggle { + compatible = "zmk,kscan-gpio-direct"; + toggle-mode; + + input-gpios + = <&pro_micro 4 GPIO_ACTIVE_LOW> + , <&pro_micro 3 GPIO_ACTIVE_LOW> + , <&pro_micro 2 GPIO_ACTIVE_LOW> + ; + }; +``` + ## Matrix Driver Keyboard scan driver where keys are arranged on a matrix with one GPIO per row and column. From 7d1f84e3eb889da9093841a2cd8d813eca15ded8 Mon Sep 17 00:00:00 2001 From: Horu <73709188+HigherOrderLogic@users.noreply.github.com> Date: Tue, 14 May 2024 03:47:33 +0700 Subject: [PATCH 099/134] chore: fix typos in various places --- app/Kconfig | 4 ++-- .../arm/corneish_zen/corneish_zen_v1_left.dts | 2 +- .../arm/corneish_zen/corneish_zen_v1_right.dts | 2 +- .../interconnects/seeed_xiao/seeed_xiao.zmk.yml | 2 +- app/dts/common/arduino_uno_pro_micro_map.dtsi | 2 +- app/include/zmk/display.h | 6 +++--- app/src/behaviors/behavior_hold_tap.c | 2 +- app/src/combo.c | 2 +- app/src/split/Kconfig | 2 +- app/src/split/bluetooth/central.c | 2 +- .../native_posix_64.keymap | 2 +- docs/blog/2024-01-05-zmk-tools.md | 2 +- docs/docs/config/battery.md | 2 +- docs/docs/config/bluetooth.md | 14 +++++++------- docs/docs/config/system.md | 2 +- docs/src/templates/setup.ps1.mustache | 2 +- docs/src/templates/setup.sh.mustache | 2 +- 17 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 8f2fe837317..5aedd9d9030 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -157,7 +157,7 @@ config ZMK_BLE_EXPERIMENTAL_CONN bool "Experimental BLE connection changes" help Enables a combination of settings that are planned to be default in future versions of ZMK - to improve connection stability. This includes changes to timing on BLE pairing initation, + to improve connection stability. This includes changes to timing on BLE pairing initiation, restores use of the updated/new LLCP implementation, and disables 2M PHY support. config ZMK_BLE_EXPERIMENTAL_SEC @@ -257,7 +257,7 @@ menu "Display/LED Options" rsource "src/display/Kconfig" menuconfig ZMK_RGB_UNDERGLOW - bool "RGB Adressable LED Underglow" + bool "RGB Addressable LED Underglow" select LED_STRIP select ZMK_LOW_PRIORITY_WORK_QUEUE diff --git a/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts b/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts index 2c77f01c0ba..4230147ecd9 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts @@ -88,7 +88,7 @@ fuelgauge: bq274xx@55 { compatible = "ti,bq274xx"; reg = <0x55>; - design-voltage = <3700>; //Battery Design Volatge in mV + design-voltage = <3700>; //Battery Design Voltage in mV design-capacity = <180>; //Battery Design Capacity in mAh taper-current = <2>; //Battery Taper current in mAh terminate-voltage = <2750>; //Battery Terminate Voltage in mV diff --git a/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts b/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts index 536e46eab2d..820d316378b 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts @@ -96,7 +96,7 @@ fuelgauge: bq274xx@55 { compatible = "ti,bq274xx"; reg = <0x55>; - design-voltage = <3700>; //Battery Design Volatge in mV + design-voltage = <3700>; //Battery Design Voltage in mV design-capacity = <180>; //Battery Design Capacity in mAh taper-current = <2>; //Battery Taper current in mAh 2.1 terminate-voltage = <2750>; //Battery Terminate Voltage in mV diff --git a/app/boards/interconnects/seeed_xiao/seeed_xiao.zmk.yml b/app/boards/interconnects/seeed_xiao/seeed_xiao.zmk.yml index 48080c7f2f9..e9b20507226 100644 --- a/app/boards/interconnects/seeed_xiao/seeed_xiao.zmk.yml +++ b/app/boards/interconnects/seeed_xiao/seeed_xiao.zmk.yml @@ -5,7 +5,7 @@ type: interconnect url: https://wiki.seeedstudio.com/Seeeduino-XIAO/ manufacturer: Seeed description: | - The Seeed(uino) XIAO is a popular smaller format micro-controller, that has gained popularity as an alterative + The Seeed(uino) XIAO is a popular smaller format micro-controller, that has gained popularity as an alternative to the SparkFun Pro Micro. Since its creation, several pin compatible controllers, such as the Seeeduino XIAO BLE, Adafruit QT Py and Adafruit QT Py RP2040, have become available. node_labels: diff --git a/app/dts/common/arduino_uno_pro_micro_map.dtsi b/app/dts/common/arduino_uno_pro_micro_map.dtsi index a6b8d792d1a..885661d4705 100644 --- a/app/dts/common/arduino_uno_pro_micro_map.dtsi +++ b/app/dts/common/arduino_uno_pro_micro_map.dtsi @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -/* This provies a mapping from Arduino Uno to Arduino Pro Micro pins for development */ +/* This provides a mapping from Arduino Uno to Arduino Pro Micro pins for development */ / { pro_micro_d: connector_d { diff --git a/app/include/zmk/display.h b/app/include/zmk/display.h index 1ef41f48d36..d206d357d9a 100644 --- a/app/include/zmk/display.h +++ b/app/include/zmk/display.h @@ -23,12 +23,12 @@ int zmk_display_init(void); * * @param listener THe ZMK Event manager listener name. * @param state_type The struct/enum type used to store/transfer state. - * @param cb The callback to invoke in the dispaly queue context to update the UI. Should be `void + * @param cb The callback to invoke in the display queue context to update the UI. Should be `void * func(state_type)` signature. * @param state_func The callback function to invoke to fetch the updated state from ZMK core. * Should be `state type func(const zmk_event_t *eh)` signature. - * @retval listner##_init Generates a function `listener##_init` that should be called by the widget - * once ready to be updated. + * @retval listener##_init Generates a function `listener##_init` that should be called by the + * widget once ready to be updated. **/ #define ZMK_DISPLAY_WIDGET_LISTENER(listener, state_type, cb, state_func) \ K_MUTEX_DEFINE(listener##_mutex); \ diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 204e50f478b..57263d1c85e 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -181,7 +181,7 @@ static void release_captured_events() { // // Events for different mod-tap instances are separated by a NULL pointer. // - // The first event popped will never be catched by the next active hold-tap + // The first event popped will never be caught by the next active hold-tap // because to start capturing a mod-tap-key-down event must first completely // go through the events queue. // diff --git a/app/src/combo.c b/app/src/combo.c index 61671d335f9..3f78878f01f 100644 --- a/app/src/combo.c +++ b/app/src/combo.c @@ -162,7 +162,7 @@ static int setup_candidates_for_first_keypress(int32_t position, int64_t timesta static int filter_candidates(int32_t position) { // this code iterates over candidates and the lookup together to filter in O(n) - // assuming they are both sorted on key_position_len, virtal_key_position + // assuming they are both sorted on key_position_len, virtual_key_position int matches = 0, lookup_idx = 0, candidate_idx = 0; while (lookup_idx < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY && candidate_idx < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY) { diff --git a/app/src/split/Kconfig b/app/src/split/Kconfig index 1134937056f..ce90037b1ea 100644 --- a/app/src/split/Kconfig +++ b/app/src/split/Kconfig @@ -24,7 +24,7 @@ config ZMK_SPLIT_PERIPHERAL_HID_INDICATORS bool "Peripheral HID Indicators" depends on ZMK_HID_INDICATORS help - Enable propogating the HID (LED) Indicator state to the split peripheral(s). + Enable propagating the HID (LED) Indicator state to the split peripheral(s). #ZMK_SPLIT endif diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index abb37a0b91c..ee21a12fa03 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -585,7 +585,7 @@ static bool split_central_eir_found(const bt_addr_le_t *addr) { return false; } - LOG_DBG("Initiating new connnection"); + LOG_DBG("Initiating new connection"); struct bt_le_conn_param *param = BT_LE_CONN_PARAM(CONFIG_ZMK_SPLIT_BLE_PREF_INT, CONFIG_ZMK_SPLIT_BLE_PREF_INT, CONFIG_ZMK_SPLIT_BLE_PREF_LATENCY, CONFIG_ZMK_SPLIT_BLE_PREF_TIMEOUT); diff --git a/app/tests/mod-morph/2b-masked-morph-implicit-overwrite/native_posix_64.keymap b/app/tests/mod-morph/2b-masked-morph-implicit-overwrite/native_posix_64.keymap index 8f7b2cdb02a..1a0642f127f 100644 --- a/app/tests/mod-morph/2b-masked-morph-implicit-overwrite/native_posix_64.keymap +++ b/app/tests/mod-morph/2b-masked-morph-implicit-overwrite/native_posix_64.keymap @@ -7,7 +7,7 @@ mod_morph: mod_morph { compatible = "zmk,behavior-mod-morph"; #binding-cells = <0>; - bindings = <&kp A>, <&kp LS(B)>; // implict mod overwrite + bindings = <&kp A>, <&kp LS(B)>; // implicit mod overwrite mods = <(MOD_LSFT|MOD_RSFT)>; }; }; diff --git a/docs/blog/2024-01-05-zmk-tools.md b/docs/blog/2024-01-05-zmk-tools.md index b48e57357b5..5ea3fd1394b 100755 --- a/docs/blog/2024-01-05-zmk-tools.md +++ b/docs/blog/2024-01-05-zmk-tools.md @@ -145,7 +145,7 @@ I should note that, as a native English speaker and typer, I don't use any of th ## Keyboard Latency Testing -The last project I want to mention is a tool for testing keyboard latency. It requires only a Rasbperry Pi, an optocoupler IC, a resistor, and some wire. If you've ever wondered how ZMK's latency compares to other keyboards, you can [check the results here](https://github.com/joelspadin/keyboard-latency-tester/blob/main/results/chart.ipynb)! +The last project I want to mention is a tool for testing keyboard latency. It requires only a Raspberry Pi, an optocoupler IC, a resistor, and some wire. If you've ever wondered how ZMK's latency compares to other keyboards, you can [check the results here](https://github.com/joelspadin/keyboard-latency-tester/blob/main/results/chart.ipynb)! I don't have a very large collection of keyboards though, so the data is pretty limited so far. If you want to try it on your own keyboard, see the instructions on the [keyboard latency tester README](https://github.com/joelspadin/keyboard-latency-tester), and please send me a PR with your results! diff --git a/docs/docs/config/battery.md b/docs/docs/config/battery.md index 463dc087b6e..c95e78841e8 100644 --- a/docs/docs/config/battery.md +++ b/docs/docs/config/battery.md @@ -18,7 +18,7 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ :::note[Default setting] -While `CONFIG_ZMK_BATTERY_REPORTING` is disabled by default it is implied by `CONFIG_ZMK_BLE`, thus any board with BLE enabled will have this automatically enabled unless explicitly overriden. +While `CONFIG_ZMK_BATTERY_REPORTING` is disabled by default it is implied by `CONFIG_ZMK_BLE`, thus any board with BLE enabled will have this automatically enabled unless explicitly overridden. ::: diff --git a/docs/docs/config/bluetooth.md b/docs/docs/config/bluetooth.md index 9149b36bf37..02d203510dd 100644 --- a/docs/docs/config/bluetooth.md +++ b/docs/docs/config/bluetooth.md @@ -9,10 +9,10 @@ See [Configuration Overview](index.md) for instructions on how to change these s ## Kconfig -| Option | Type | Description | Default | -| -------------------------------------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_BLE_EXPERIMENTAL_CONN` | bool | Enables a combination of settings that are planned to be default in future versions of ZMK to improve connection stability. This includes changes to timing on BLE pairing initation, restores use of the updated/new LLCP implementation, and disables 2M PHY support. | n | -| `CONFIG_ZMK_BLE_EXPERIMENTAL_SEC` | bool | Enables a combination of settings that are planned to be officially supported in the future. This includes enabling BT Secure Connection passkey entry, and allows overwrite of keys from previously paired hosts. | n | -| `CONFIG_ZMK_BLE_EXPERIMENTAL_FEATURES` | bool | Aggregate config that enables both `CONFIG_ZMK_BLE_EXPERIMENTAL_CONN` and `CONFIG_ZMK_BLE_EXPERIMENTAL_SEC`. | n | -| `CONFIG_ZMK_BLE_PASSKEY_ENTRY` | bool | Enable passkey entry during pairing for enhanced security. (Note: After enabling this, you will need to re-pair all previously paired hosts.) | n | -| `CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION` | bool | Low level setting for GATT subscriptions. Set to `n` to work around an annoying Windows bug with battery notifications. | y | +| Option | Type | Description | Default | +| -------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------- | +| `CONFIG_ZMK_BLE_EXPERIMENTAL_CONN` | bool | Enables a combination of settings that are planned to be default in future versions of ZMK to improve connection stability. This includes changes to timing on BLE pairing initiation, restores use of the updated/new LLCP implementation, and disables 2M PHY support. | n | +| `CONFIG_ZMK_BLE_EXPERIMENTAL_SEC` | bool | Enables a combination of settings that are planned to be officially supported in the future. This includes enabling BT Secure Connection passkey entry, and allows overwrite of keys from previously paired hosts. | n | +| `CONFIG_ZMK_BLE_EXPERIMENTAL_FEATURES` | bool | Aggregate config that enables both `CONFIG_ZMK_BLE_EXPERIMENTAL_CONN` and `CONFIG_ZMK_BLE_EXPERIMENTAL_SEC`. | n | +| `CONFIG_ZMK_BLE_PASSKEY_ENTRY` | bool | Enable passkey entry during pairing for enhanced security. (Note: After enabling this, you will need to re-pair all previously paired hosts.) | n | +| `CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION` | bool | Low level setting for GATT subscriptions. Set to `n` to work around an annoying Windows bug with battery notifications. | y | diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 675830e4944..27923453207 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -31,7 +31,7 @@ Making changes to any of the settings in this section modifies the HID report de | Config | Type | Description | Default | | ------------------------------------- | ---- | -------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable reciept of HID/LED indicator state from connected hosts | n | +| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | | `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | Exactly zero or one of the following options may be set to `y`. The first is used if none are set. diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index b8ecc2937f4..33a4be38845 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -308,6 +308,6 @@ if ($github_repo -ne "") { if ($github_repo -imatch "https") { $actions = "$($github_repo.substring(0, $github_repo.length - 4))/actions" - Write-Host "Your firmware should be availalbe from GitHub Actions shortly: $actions" + Write-Host "Your firmware should be available from GitHub Actions shortly: $actions" } } diff --git a/docs/src/templates/setup.sh.mustache b/docs/src/templates/setup.sh.mustache index dd7a7a2d2f2..cde3a8a17d8 100644 --- a/docs/src/templates/setup.sh.mustache +++ b/docs/src/templates/setup.sh.mustache @@ -297,7 +297,7 @@ if [ -n "$github_repo" ]; then exit 1 fi - # TODO: Support determing the actions URL when non-https:// repo URL is used. + # TODO: Support determining the actions URL when non-https:// repo URL is used. if [ "${github_repo}" != "${github_repo#https://}" ]; then echo "Your firmware should be available from GitHub Actions shortly: ${github_repo%.git}/actions" fi From 8f5c7bbfd471d6720410980d6d905673411c363c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Feb 2024 05:52:14 +0000 Subject: [PATCH 100/134] chore(deps): bump pre-commit/action from 3.0.0 to 3.0.1 Bumps [pre-commit/action](https://github.com/pre-commit/action) from 3.0.0 to 3.0.1. - [Release notes](https://github.com/pre-commit/action/releases) - [Commits](https://github.com/pre-commit/action/compare/v3.0.0...v3.0.1) --- updated-dependencies: - dependency-name: pre-commit/action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 7a4c211e37f..cc9672f40f8 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -12,4 +12,4 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.x - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 From f0b20c1c938da6dfd51f4639a2a71b587cab4205 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Fri, 13 Oct 2023 13:07:55 -0500 Subject: [PATCH 101/134] feat(boards): Add nRF52 high voltage DC/DC config Added a Kconfig option to enable SOC_DCDC_NRF52X_HV for nice_nano_v2 and mikoto. According to Nordic's documentation, the DC/DC regulator is more efficient than the LDO regulator, so this is enabled by default. The following boards do not support this mode and were not changed: - nice_nano - nice60 - nrfmicro_11, nrfmicro_13 - nrf52840_m2 - bluemicro840 I could not find schematics to confirm whether the following boards support this mode: - bt60_v1, bt60_v2 - bt65_v1 - bt75_v1 - corneish_zen_v1, corneish_zen_v2 - pillbug - puchi_ble_v1 - s40nc --- app/boards/arm/mikoto/Kconfig | 6 ++++++ app/boards/arm/nice_nano/Kconfig | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/boards/arm/mikoto/Kconfig b/app/boards/arm/mikoto/Kconfig index 71ec9411738..fab2218c049 100644 --- a/app/boards/arm/mikoto/Kconfig +++ b/app/boards/arm/mikoto/Kconfig @@ -4,6 +4,12 @@ config BOARD_ENABLE_DCDC default y depends on (BOARD_MIKOTO_520) +config BOARD_ENABLE_DCDC_HV + bool "High voltage DCDC converter" + select SOC_DCDC_NRF52X_HV + default y + depends on (BOARD_MIKOTO_520) + choice BOARD_MIKOTO_CHARGER_CURRENT prompt "Charge current to supply to attached batteries" depends on (BOARD_MIKOTO_520) diff --git a/app/boards/arm/nice_nano/Kconfig b/app/boards/arm/nice_nano/Kconfig index ac6828a4bbe..dbeb82cd126 100644 --- a/app/boards/arm/nice_nano/Kconfig +++ b/app/boards/arm/nice_nano/Kconfig @@ -5,3 +5,9 @@ config BOARD_ENABLE_DCDC select SOC_DCDC_NRF52X default y depends on (BOARD_NICE_NANO || BOARD_NICE_NANO_V2) + +config BOARD_ENABLE_DCDC_HV + bool "High voltage DCDC converter" + select SOC_DCDC_NRF52X_HV + default y + depends on (BOARD_NICE_NANO_V2) From 2ee76be6fee671042d9740ac0271eb69e2558165 Mon Sep 17 00:00:00 2001 From: German Gutierrez Date: Mon, 13 May 2024 23:43:35 +0200 Subject: [PATCH 102/134] fix(soft_off): central waits 100ms in split if hold_time enabled --- app/src/behaviors/behavior_soft_off.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 8c6ba4225f7..461ce933cf7 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -57,6 +57,9 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, uint32_t hold_time = k_uptime_get() - data->press_start; if (hold_time > config->hold_time_ms) { + if (IS_ENABLED(CONFIG_ZMK_SPLIT) && IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)) { + k_sleep(K_MSEC(100)); + } zmk_pm_soft_off(); } else { LOG_INF("Not triggering soft off: held for %d and hold time is %d", hold_time, From 2d96f469c815cb84d4cfde7c052a7ee33e2da7ae Mon Sep 17 00:00:00 2001 From: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com> Date: Sun, 26 May 2024 07:16:33 +0200 Subject: [PATCH 103/134] fix(docs): Removing to-to typos (#2310) --- docs/blog/2023-04-06-zephyr-3-2.md | 2 +- docs/docs/behaviors/caps-word.md | 2 +- docs/docs/features/backlight.mdx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/blog/2023-04-06-zephyr-3-2.md b/docs/blog/2023-04-06-zephyr-3-2.md index 4ba71cacdb2..4bb21999422 100644 --- a/docs/blog/2023-04-06-zephyr-3-2.md +++ b/docs/blog/2023-04-06-zephyr-3-2.md @@ -57,7 +57,7 @@ and then update it as appropriate to build the right shields/boards for your con ### Upgrade a manual script -If you have a custom GitHub Actions workflow you need to maintain for some reason, you can update the workflow to to use the `stable` Docker image tag for the build: +If you have a custom GitHub Actions workflow you need to maintain for some reason, you can update the workflow to use the `stable` Docker image tag for the build: - Open `.github/workflows/build.yml` in your editor/IDE - Change `zmkfirmware/zmk-build-arm:2.5` to `zmkfirmware/zmk-build-arm:stable` wherever it is found diff --git a/docs/docs/behaviors/caps-word.md b/docs/docs/behaviors/caps-word.md index 77c8fd20d2a..4551884dd50 100644 --- a/docs/docs/behaviors/caps-word.md +++ b/docs/docs/behaviors/caps-word.md @@ -7,7 +7,7 @@ sidebar_label: Caps Word The caps word behavior behaves similar to a caps lock, but will automatically deactivate when any key not in a continue list is pressed, or if the caps word key is pressed again. For smaller keyboards using [mod-taps](/docs/behaviors/mod-tap), this can help avoid repeated alternating holds when typing words in all caps. -The modifiers are applied only to to the alphabetic (`A` to `Z`) keycodes, to avoid automatically applying them to numeric values, etc. +The modifiers are applied only to the alphabetic (`A` to `Z`) keycodes, to avoid automatically applying them to numeric values, etc. ### Behavior Binding diff --git a/docs/docs/features/backlight.mdx b/docs/docs/features/backlight.mdx index 4c47305783a..674e8633014 100644 --- a/docs/docs/features/backlight.mdx +++ b/docs/docs/features/backlight.mdx @@ -58,7 +58,7 @@ config LED_PWM endif # ZMK_BACKLIGHT ``` -Create a `-pinctrl.dtsi` file if it does not already exist, and include it at the beginning of the `.dts` file. `CONFIG_PINCTRL=y` must be added to to `_defconfig` if it isn't already enabled. +Create a `-pinctrl.dtsi` file if it does not already exist, and include it at the beginning of the `.dts` file. `CONFIG_PINCTRL=y` must be added to `_defconfig` if it isn't already enabled. The pinctrl file has a `&pinctrl` node that encompasses all pinctrl settings, including I2C or SPI peripherals (e.g. WS2812 LEDs, Battery fuel gauges): From 308d6bce6eb338f387a454c7366d0bcb07463d7b Mon Sep 17 00:00:00 2001 From: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com> Date: Sun, 2 Jun 2024 06:51:08 +0200 Subject: [PATCH 104/134] feat(docs): Improve the toolchain setup page (#2272) Split the toolchain setup into separate docker and native pages and improve instructions to better refer to Zephyr docs in certain steps. Also refactor to improve consistency and add virtualenv instructions. --------- Co-authored-by: KemoNine Co-authored-by: Cem Aksoylar --- docs/blog/2020-08-12-zmk-sotf-1.md | 2 +- docs/blog/2021-07-17-zephyr-2-5.md | 2 +- docs/blog/2022-04-02-zephyr-3-0.md | 2 +- docs/blog/2022-04-10-zmk-sotf-5.md | 2 +- docs/blog/2023-04-06-zephyr-3-2.md | 2 +- docs/blog/2024-02-09-zephyr-3-5.md | 2 +- docs/docs/behaviors/index.mdx | 8 +- docs/docs/customization.md | 2 +- docs/docs/development/new-shield.mdx | 4 +- docs/docs/development/setup.mdx | 322 ---------------------- docs/docs/development/setup/docker.md | 53 ++++ docs/docs/development/setup/index.md | 20 ++ docs/docs/development/setup/native.mdx | 353 +++++++++++++++++++++++++ docs/docs/troubleshooting.md | 2 +- docs/docusaurus.config.js | 3 +- docs/sidebars.js | 11 +- docs/src/css/custom.css | 4 + 17 files changed, 456 insertions(+), 338 deletions(-) delete mode 100644 docs/docs/development/setup.mdx create mode 100644 docs/docs/development/setup/docker.md create mode 100644 docs/docs/development/setup/index.md create mode 100644 docs/docs/development/setup/native.mdx diff --git a/docs/blog/2020-08-12-zmk-sotf-1.md b/docs/blog/2020-08-12-zmk-sotf-1.md index afa03405a70..89cfffabe65 100644 --- a/docs/blog/2020-08-12-zmk-sotf-1.md +++ b/docs/blog/2020-08-12-zmk-sotf-1.md @@ -19,7 +19,7 @@ There's been lots of various activity in ZMK land! - Tons of [documentation](/docs) work. - Refactoring ([#73](https://github.com/zmkfirmware/zmk/pull/73), [#74](https://github.com/zmkfirmware/zmk/pull/74)) of [keymaps](/docs/features/keymaps) to make them simpler for users. - Mod-Tap Behavior (docs coming!) is much improved ([#69](https://github.com/zmkfirmware/zmk/pull/69)) and usable now. -- An initial [`setup.sh`](http://localhost:3000/docs/user-setup#user-config-setup-script) script was created, allowing users to quickly bootstrap a "user config" setup and push it to GitHub, where GitHub Actions will build the firmware for you. +- An initial [`setup.sh`](/docs/user-setup#user-config-setup-script) script was created, allowing users to quickly bootstrap a "user config" setup and push it to GitHub, where GitHub Actions will build the firmware for you. - Corne shield ([#80](https://github.com/zmkfirmware/zmk/pull/80)) shield definition was added. - Initial [encoder](/docs/features/encoders) support ([#61](https://github.com/zmkfirmware/zmk/pull/61)) was added. diff --git a/docs/blog/2021-07-17-zephyr-2-5.md b/docs/blog/2021-07-17-zephyr-2-5.md index 153027bb4cd..789a644caee 100644 --- a/docs/blog/2021-07-17-zephyr-2-5.md +++ b/docs/blog/2021-07-17-zephyr-2-5.md @@ -61,7 +61,7 @@ Once the container has rebuilt, VS Code will be running the 2.5 Docker image. The following steps will get you building ZMK locally against Zephyr 2.5: -- Run the updated [toolchain installation](/docs/development/setup#toolchain-installation) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) +- Run the updated [toolchain installation](/docs/development/setup) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) - pull the latest ZMK `main` with `git pull` for your ZMK checkout - run `west update` to pull the updated Zephyr version and its dependencies diff --git a/docs/blog/2022-04-02-zephyr-3-0.md b/docs/blog/2022-04-02-zephyr-3-0.md index 3b16b87ea78..92e8b33bc1c 100644 --- a/docs/blog/2022-04-02-zephyr-3-0.md +++ b/docs/blog/2022-04-02-zephyr-3-0.md @@ -62,7 +62,7 @@ Once the container has rebuilt, VS Code will be running the 3.0 Docker image. The following steps will get you building ZMK locally against Zephyr 3.0: -- Run the updated [toolchain installation](/docs/development/setup#toolchain-installation) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) +- Run the updated [toolchain installation](/docs/development/setup) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) - pull the latest ZMK `main` with `git pull` for your ZMK checkout - run `west update` to pull the updated Zephyr version and its dependencies diff --git a/docs/blog/2022-04-10-zmk-sotf-5.md b/docs/blog/2022-04-10-zmk-sotf-5.md index 43cb4e67209..1a0ea270c8d 100644 --- a/docs/blog/2022-04-10-zmk-sotf-5.md +++ b/docs/blog/2022-04-10-zmk-sotf-5.md @@ -132,7 +132,7 @@ Another persistent bug that Apple users experienced was related to crashes and p The long awaited locality enhancement was finally merged by [petejohanson] in [#547](https://github.com/zmkfirmware/zmk/pull/547), allowing more fine grained control of where certain behaviors are invoked. Some key improvements thanks to the changes: - [RGB Underglow](/docs/features/underglow) behaviors now run globally, so enabling/disabling RGB, changing the color, animation, etc. applies to both sides of a split properly. -- [Reset](/docs/behaviors/reset#reset)/[Bootloader](/docs/behaviors/reset#bootloader) behaviors now run wherever the key was pressed. For example, adding a `&bootloader` reference to the peripheral side of a split will now put that side of the split into the bootloader when pressed. +- [Reset](/docs/behaviors/reset#reset)/[Bootloader](/docs/behaviors/reset#bootloader-reset) behaviors now run wherever the key was pressed. For example, adding a `&bootloader` reference to the peripheral side of a split will now put that side of the split into the bootloader when pressed. #### Split Connections diff --git a/docs/blog/2023-04-06-zephyr-3-2.md b/docs/blog/2023-04-06-zephyr-3-2.md index 4bb21999422..21058ca9544 100644 --- a/docs/blog/2023-04-06-zephyr-3-2.md +++ b/docs/blog/2023-04-06-zephyr-3-2.md @@ -87,7 +87,7 @@ Once the container has rebuilt, VS Code will be running the 3.2 Docker image. The following steps will get you building ZMK locally against Zephyr 3.2: -- Run the updated [toolchain installation](/docs/development/setup#toolchain-installation) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) +- Run the updated [toolchain installation](/docs/development/setup) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) - Install the latest version of `west` by running `pip3 install --user --update west`. - pull the latest ZMK `main` with `git pull` for your ZMK checkout - run `west update` to pull the updated Zephyr version and its dependencies diff --git a/docs/blog/2024-02-09-zephyr-3-5.md b/docs/blog/2024-02-09-zephyr-3-5.md index b3fec6cbda2..738f22daa81 100644 --- a/docs/blog/2024-02-09-zephyr-3-5.md +++ b/docs/blog/2024-02-09-zephyr-3-5.md @@ -70,7 +70,7 @@ Once the container has rebuilt, VS Code will be running the 3.5 Docker image. The following steps will get you building ZMK locally against Zephyr 3.5: -- Run the updated [toolchain installation](/docs/development/setup#toolchain-installation) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) +- Run the updated [toolchain installation](/docs/development/setup) steps, and once completed, remove the previously installed SDK version (optional, existing SDK should still work) - Install the latest version of `west` by running `pip3 install --user --update west`. - Pull the latest ZMK `main` with `git pull` for your ZMK checkout - Run `west update` to pull the updated Zephyr version and its dependencies diff --git a/docs/docs/behaviors/index.mdx b/docs/docs/behaviors/index.mdx index 4a05f5653a0..7cd82d3e4b8 100644 --- a/docs/docs/behaviors/index.mdx +++ b/docs/docs/behaviors/index.mdx @@ -46,10 +46,10 @@ Below is a summary of pre-defined behavior bindings and user-definable behaviors ## Reset behaviors -| Binding | Behavior | Description | -| ------------- | --------------------------------- | ---------------------------------------------------------------------------------------- | -| `&sys_reset` | [Reset](reset.md#reset) | Resets the keyboard and re-runs the firmware flashed to the device | -| `&bootloader` | [Bootloader](reset.md#bootloader) | Resets the keyboard and puts it into bootloader mode, allowing you to flash new firmware | +| Binding | Behavior | Description | +| ------------- | --------------------------------------- | ---------------------------------------------------------------------------------------- | +| `&sys_reset` | [Reset](reset.md#reset) | Resets the keyboard and re-runs the firmware flashed to the device | +| `&bootloader` | [Bootloader](reset.md#bootloader-reset) | Resets the keyboard and puts it into bootloader mode, allowing you to flash new firmware | ## Output selection behaviors diff --git a/docs/docs/customization.md b/docs/docs/customization.md index 46427b9e2f9..96b5e4ea9a0 100644 --- a/docs/docs/customization.md +++ b/docs/docs/customization.md @@ -40,7 +40,7 @@ If you need to, a review of [Learn The Basics Of Git In Under 10 Minutes](https: ::: :::note -It is also possible to build firmware locally on your computer by following the [toolchain setup](development/setup.mdx) and +It is also possible to build firmware locally on your computer by following the [toolchain setup](development/setup/index.md) and [building instructions](development/build-flash.mdx), which includes pointers to [building using your `zmk-config` folder](development/build-flash.mdx#building-from-zmk-config-folder). ::: diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index a542fc84995..d48e0d1de97 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -554,7 +554,7 @@ Add additional bindings as necessary to match the default number of encoders on ### GitHub Actions -Using GitHub Actions to build your new firmware can save you from doing any local [development setup](./setup.mdx), +Using GitHub Actions to build your new firmware can save you from doing any local [development setup](./setup/index.md), at the expense of a longer feedback loop if there are issues. To push your changes and trigger a build: - Add all your pending changes with `git add .` @@ -566,7 +566,7 @@ Once pushed, click on the "Actions" tab of the repo you created in the first ste ### Local Build :::note -To build locally, be sure you've followed the [development setup](./setup.mdx) guide first. +To build locally, be sure you've followed the [development setup](./setup/index.md) guide first. ::: Once you've fully created the new keyboard shield definition, diff --git a/docs/docs/development/setup.mdx b/docs/docs/development/setup.mdx deleted file mode 100644 index bc275804cf7..00000000000 --- a/docs/docs/development/setup.mdx +++ /dev/null @@ -1,322 +0,0 @@ ---- -title: Toolchain Setup -sidebar_label: Toolchain Setup ---- - -import Tabs from "@theme/Tabs"; -import TabItem from "@theme/TabItem"; - -export const OsTabs = (props) => ( - - {/* eslint-disable-next-line */} - {props.children} - -); - -This guide will show you how to set up a development environment for building ZMK locally. - -## Install Dependencies - -Click the operating system you are using. (The VS Code & Docker option can be used on any OS.) - - - - -This option use the same [Docker image which is used by the GitHub action](https://github.com/zmkfirmware/zmk-docker) for local development. Beyond the benefits of [dev/prod parity](https://12factor.net/dev-prod-parity), this approach is also the easiest to set up. No toolchain or dependencies are necessary when using Docker; the container image you'll be using already has the toolchain installed and set up to use. - -1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop) for your operating system. -2. Install [Visual Studio Code](https://code.visualstudio.com/) -3. Install the [Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) - -:::info -The docker container already includes `west`. Skip past the following section to [Get Source Code](#get-source-code). -::: - - - - -Open Zephyr's [Getting Started Guide](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html) and follow the instructions under these sections: - -- [Select and Update OS](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#select-and-update-os) -- [Install Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-dependencies) -- [Install Zephyr SDK](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-zephyr-sdk) - -Return to this guide once you are finished with each section. - - - - -Open Zephyr's [Getting Started Guide](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html) and follow the instructions under these sections: - -- [Select and Update OS](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#select-and-update-os) -- [Install Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-dependencies) -- [Install Zephyr SDK](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-zephyr-sdk) - -Return to this guide once you are finished with each section. - -`dfu-util` is required to flash devices that use DFU, but there is currently no maintained package for it on Chocolatey. [QMK Toolbox](https://github.com/qmk/qmk_toolbox) contains a working version of it though. - - - - -Open Zephyr's [Getting Started Guide](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html) and follow the instructions under these sections: - -- [Select and Update OS](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#select-and-update-os) -- [Install Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-dependencies) -- [Install Zephyr SDK](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-zephyr-sdk) - -Return to this guide once you are finished with each section. - - - - -#### Install Base Dependencies - -Open Zephyr's [Getting Started Guide](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html) and follow the instructions for Ubuntu under these sections: - -- [Select and Update OS](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#select-and-update-os) -- [Install Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-dependencies) - -Return to this guide once you are finished with each section. - -#### Install Cross-Compile Toolchain - -Because Raspberry OS runs on the same architecture (but different ABI) as ARM keyboard MCUs, the operating system's installed [cross compilers](https://docs.zephyrproject.org/3.5.0/develop/toolchains/other_x_compilers.html) can be used to target the different ABI. Building for non-ARM MCUs has not been tested. - -First, the cross compiler should be installed: - -```sh -sudo apt install gcc-arm-none-eabi -``` - -Next, we'll configure Zephyr with some [environment variables](https://docs.zephyrproject.org/3.5.0/develop/env_vars.html#env-vars) needed to find the cross compiler. Create a file named `~/.zephyrrc` if it doesn't exist, and add these lines to it: - -```sh -export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile -export CROSS_COMPILE=/usr/bin/arm-none-eabi- -``` - - - - -Follow Zephyr's [Install Linux Host Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/installation_linux.html) documentation for Fedora. - - - - -### Install West - -`west` is the [Zephyr® Project's meta-tool](https://docs.zephyrproject.org/3.5.0/develop/west/index.html) used to configure and build Zephyr OS applications. - -West can be installed by using the `pip` python package manager. The [Zephyrâ„¢ instructions](https://docs.zephyrproject.org/3.5.0/develop/west/install.html) are summarized here: - - - - -Install west: - -```sh -pip3 install --user -U west -``` - -Verify that west is installed: - -```sh -west --version -``` - -This should print a message like "West version: v0.14.0". If it prints an error instead, make sure `~/.local/bin` is on your `PATH` environment variable. You can add it with these commands: - -```sh -echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc -source ~/.bashrc -``` - - - - -Install west: - -```sh -pip3 install -U west -``` - -Verify that west is installed: - -```sh -west --version -``` - -This should print a message like "West version: v0.14.0". If it prints an error instead, make sure that the Python scripts directory is on your `PATH` environment variable. You can add it by opening a PowerShell window and running the following commands: - -```powershell -$Scripts = python -c "import sysconfig; print(sysconfig.get_path('scripts'))" -$Path = [Environment]::GetEnvironmentVariable('PATH', 'User') -[Environment]::SetEnvironmentVariable('PATH', "$Path;$Scripts", 'User') -$env:PATH += ";$Scripts" -``` - - - - -Install west: - -```sh -pip3 install -U west -``` - - - - -## Get Source Code - -Next, you'll need to clone the ZMK source repository if you haven't already. Navigate to the folder you would like to place your `zmk` directory in and run the following command: - -``` -git clone https://github.com/zmkfirmware/zmk.git -``` - -## Initialize & Update Zephyr Workspace - -Since ZMK is built as a Zephyrâ„¢ application, the next step is -to use `west` to initialize and update your workspace. The ZMK -Zephyrâ„¢ application is in the `app/` source directory: - -### Step into the repository - - - - -```sh -cd zmk -``` - - - - -```sh -cd zmk -``` - - - - -```sh -cd zmk -``` - - - - -```sh -cd zmk -``` - - - - -```sh -cd zmk -``` - - - - - -Open the `zmk` checkout folder in VS Code. The repository includes a configuration for containerized development, so an alert will pop up: - -![VS Code Dev Container Configuration Alert](../assets/dev-setup/vscode_devcontainer.png) - -Click `Reopen in Container` in order to reopen the VS Code with the running container. - -The first time you do this on your machine, it will pull the docker image down from the registry and build the container. Subsequent launches are much faster! - -:::warning -All subsequent steps must be performed from the VS Code terminal _inside_ the container. -::: - - - - -### Initialize the Application - -```sh -west init -l app/ -``` - -### Update to Fetch Modules - -```sh -west update -``` - -:::tip -This step pulls down quite a bit of tooling. Go grab a cup of coffee, it can take 10-15 minutes even on a good internet connection! -::: - -:::info -If you're using Docker, you're done with setup! You must restart the container at this point. The easiest way to do so is to close the VS Code window, verify that the container has stopped in Docker Dashboard, and reopen the container with VS Code. - -Once your container is restarted, proceed to [Building and Flashing](development/build-flash.mdx). -::: - -### Export Zephyr CMake package - -This allows CMake to load the code needed to build ZMK. - -```sh -west zephyr-export -``` - -### Install Zephyr Python Dependencies - -Some additional Python dependencies are listed in Zephyr's `scripts/requirements.txt` file. - - - - -```sh -pip3 install --user -r zephyr/scripts/requirements.txt -``` - - - - -```sh -pip3 install -r zephyr/scripts/requirements.txt -``` - - - - -```sh -pip3 install -r zephyr/scripts/requirements.txt -``` - - - diff --git a/docs/docs/development/setup/docker.md b/docs/docs/development/setup/docker.md new file mode 100644 index 00000000000..767331e409f --- /dev/null +++ b/docs/docs/development/setup/docker.md @@ -0,0 +1,53 @@ +--- +title: Docker +sidebar_label: Docker +--- + +:::note +Currently the Docker approach is only documented for [VS Code](https://github.com/microsoft/vscode) (not [Code OSS](https://github.com/microsoft/vscode/wiki/Differences-between-the-repository-and-Visual-Studio-Code)). While it can be replicated using [devcontainers](https://containers.dev/) this is not documented yet - contributions are welcome! +::: + +### Source Code + +First, you'll need to clone the ZMK source repository if you haven't already. Open a terminal and navigate to the folder you would like to place your `zmk` directory in, then run the following command: + +```sh +git clone https://github.com/zmkfirmware/zmk.git +``` + +### Installing Development Tools + +1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop) for your operating system. +2. Install [VS Code](https://code.visualstudio.com/). +3. Install the [Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). + +### Initialize & Update Zephyr Workspace + +Open the `zmk` checkout folder in VS Code. The repository includes a configuration for containerized development, so an alert will pop up: + +![VS Code Dev Container Configuration Alert](../../assets/dev-setup/vscode_devcontainer.png) + +Click `Reopen in Container` in order to reopen the VS Code with the running container. If the alert fails to pop up or you accidentally close it, you can perform the same action by pressing `ctrl+shift+p` and selecting `Remote: Show Remote Menu`. + +The first time you do this on your machine, it will pull the docker image down from the registry and build the container. Subsequent launches are much faster! + +:::caution +The following step and any future [build commands](../build-flash.mdx) must be executed from the VS Code terminal _inside_ the container. +::: + +Initialize the application and update to fetch modules, including Zephyr: + +```sh +west init -l app/ +west update +``` + +:::tip +This step pulls down quite a bit of tooling, be patient! +::: + +:::info +You must restart the container at this point. The easiest way to do so is to close the VS Code window, verify that the container has stopped in Docker Dashboard, and reopen the container with VS Code. + +Your setup is complete once your container has restarted. +::: diff --git a/docs/docs/development/setup/index.md b/docs/docs/development/setup/index.md new file mode 100644 index 00000000000..5c795fa22c7 --- /dev/null +++ b/docs/docs/development/setup/index.md @@ -0,0 +1,20 @@ +--- +title: Getting Started +sidebar_label: Getting Started +--- + +:::tip +We recommend reading through the setup process before following it step by step, to ensure that you are happy with installing the required dependencies. +::: + +## Environment Setup + +There are two ways to set up the ZMK development environment: + +- [Docker](/docs/development/setup/docker): \ + A self-contained development environment. It uses the same [Docker image which is used by the GitHub action](https://github.com/zmkfirmware/zmk-docker) for local development. Beyond the benefits of [dev/prod parity](https://12factor.net/dev-prod-parity), this approach may be easier to set up for some operating systems. No toolchain or dependencies are necessary when using Docker; the container image has the toolchain installed and set up to use. + +- [Native](/docs/development/setup/native):\ + This uses your operating system directly. Usually runs slightly faster than the Docker approach, and can be preferable for users who already have the dependencies on their system. + +Please see the [Docker](/docs/development/setup/docker) instructions or [native](/docs/development/setup/native) instructions to continue setup. diff --git a/docs/docs/development/setup/native.mdx b/docs/docs/development/setup/native.mdx new file mode 100644 index 00000000000..d077d7d1d7d --- /dev/null +++ b/docs/docs/development/setup/native.mdx @@ -0,0 +1,353 @@ +--- +title: Native Setup +sidebar_label: Native +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +export const OsTabs = (props) => ( + + {/* eslint-disable-next-line */} + {props.children} + + +); + +export const OsNoteTabs = (props) => ( + + {/* eslint-disable-next-line */} + {props.children} + + +); + +export const EnvTabs = (props) => ( + + {/* eslint-disable-next-line */} + {props.children} + + +); + +export const WinTermTabs = (props) => ( + + {/* eslint-disable-next-line */} + {props.children} + + +); + +## 1. Install Zephyr Dependencies + +Open Zephyr's [Getting Started Guide](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html) and follow the instructions under these sections: + +- [Select and Update OS](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#select-and-update-os) +- [Install Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-dependencies) + +:::info +Zephyr's [Install Linux Host Dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/installation_linux.html) page may be of use for users of Linux distributions which are not based on Ubuntu. +::: + +## 2. Source Code + +Next, you'll need to clone the ZMK source repository if you haven't already. Open a terminal and navigate to the folder you would like to place your `zmk` directory in, then run the following command: + +```sh +git clone https://github.com/zmkfirmware/zmk.git +``` + +Then step into the repository. + +```sh +cd zmk +``` + +## 3. Get Zephyr and install Python dependencies + +:::note +These steps are very similar to Zephyr's [Get Zephyr and install Python dependencies](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#get-zephyr-and-install-python-dependencies) instructions, but specialized for ZMK. +::: + + + + + + +1. Use `apt` to install Python `venv` package: + +```sh +sudo apt install python3-venv +``` + +2. Create a new virtual environment and activate it: + +```sh +python3 -m venv .venv +source .venv/bin/activate +``` + + + + +1. Create a new virtual environment: + +```sh +python -m venv .venv +``` + +2. Activate the virtual environment: + + + + +```sh +.venv\Scripts\activate.bat +``` + + + + + +```powershell +.venv\Scripts\Activate.ps1 +``` + + + + + + + + +1. Create a new virtual environment: + +```sh +python3 -m venv .venv +``` + +2. Activate the virtual environment: + +```sh +source .venv/bin/activate +``` + + + + +Once activated your shell will be prefixed with `(.venv)`. The virtual environment can be deactivated at any time by running `deactivate`. + +:::note +Remember to activate the virtual environment every time you start working. +::: + +4. Install west: + +```sh +pip install west +``` + +5. Initialize the application and update to fetch modules, including Zephyr: + +```sh +west init -l app/ +west update +``` + +:::tip +This step pulls down quite a bit of tooling, be patient! +::: + +6. Export a [Zephyr CMake package](https://docs.zephyrproject.org/3.5.0/build/zephyr_cmake_package.html#cmake-pkg). This allows CMake to automatically load boilerplate code required for building Zephyr applications. + +```sh +west zephyr-export +``` + +7. Install the additional dependencies found in Zephyr's `requirements-base.txt`: + +```sh +pip install -r zephyr/scripts/requirements-base.txt +``` + + + + + +1. Install `west`: + +```sh +pip3 install --user -U west +``` + +:::note +You need `~/.local/bin` to be on your `PATH` environment variable; verify that it is by running + +```sh +west --version +``` + +If this prints an error rather than a `west` version number, then add `~/.local/bin` to your `PATH`: + +```sh +echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc +source ~/.bashrc +``` + +::: + + + + +1. Install `west`: + +```sh +pip install -U west +``` + +:::note +You need the Python scripts directory to be on your PATH environment variable; verify that it is by running + +```sh +west --version +``` + +If this prints an error rather than a `west` version number, then add said directory to your `PATH` with PowerShell: + +```powershell +$Scripts = python -c "import sysconfig; print(sysconfig.get_path('scripts'))" +$Path = [Environment]::GetEnvironmentVariable('PATH', 'User') +[Environment]::SetEnvironmentVariable('PATH', "$Path;$Scripts", 'User') +$env:PATH += ";$Scripts" +``` + +::: + + + + + +1. Install `west`: + +```sh +pip3 install -U west +``` + + + + +2. Initialize the application and update to fetch modules, including Zephyr: + +```sh +west init -l app/ +west update +``` + +:::tip +This step pulls down quite a bit of tooling, be patient! +::: + +3. Export a [Zephyr CMake package](https://docs.zephyrproject.org/3.5.0/build/zephyr_cmake_package.html#cmake-pkg). This allows CMake to automatically load boilerplate code required for building Zephyr applications. + +```sh +west zephyr-export +``` + + + + +4. Install the additional dependencies found in Zephyr's `requirements-base.txt`: + +```sh +pip3 install --user -r zephyr/scripts/requirements-base.txt +``` + + + + + +4. Install the additional dependencies found in Zephyr's `requirements-base.txt`: + +```sh +pip install -r zephyr/scripts/requirements-base.txt +``` + + + + +4. Install the additional dependencies found in Zephyr's `requirements-base.txt`. + +```sh +pip3 install -r zephyr/scripts/requirements-base.txt +``` + + + + + + +## 4. Install Zephyr SDK + +Return to Zephyr's Getting Started Guide and [Install Zephyr SDK](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-zephyr-sdk). + +### OS specific notes + + + + `dfu-util` is required to flash devices that use DFU, but there is currently + no maintained package for it on Chocolatey. [QMK + Toolbox](https://github.com/qmk/qmk_toolbox) contains a working version of it + though. + + + +#### Install Cross-Compile Toolchain + +Because Raspberry OS runs on the same architecture (but different ABI) as ARM keyboard MCUs, the operating system's installed [cross compilers](https://docs.zephyrproject.org/3.5.0/develop/toolchains/other_x_compilers.html) can be used to target the different ABI. Building for non-ARM MCUs has not been tested. + +First, the cross compiler should be installed: + +```sh +sudo apt install gcc-arm-none-eabi +``` + +Next, we'll configure Zephyr with some [environment variables](https://docs.zephyrproject.org/3.5.0/develop/env_vars.html#env-vars) needed to find the cross compiler. Create a file named `~/.zephyrrc` if it doesn't exist, and add these lines to it: + +```sh +export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile +export CROSS_COMPILE=/usr/bin/arm-none-eabi- +``` + + + + +Your setup is now complete. diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md index 09efdecf770..876cbb9b4d2 100644 --- a/docs/docs/troubleshooting.md +++ b/docs/docs/troubleshooting.md @@ -34,7 +34,7 @@ macOS 14.x (Sonoma) Finder may report an "Error code -36" when copying ` Date: Sun, 9 Jun 2024 21:32:26 -0700 Subject: [PATCH 105/134] refactor(docs): Split up troubleshooting page into a section --- docs/blog/2023-10-05-zmk-sotf-6.md | 2 +- docs/docs/customization.md | 2 +- docs/docs/features/bluetooth.md | 50 +----- docs/docs/troubleshooting.md | 143 ------------------ docs/docs/troubleshooting/building-issues.md | 54 +++++++ .../troubleshooting/connection-issues.mdx | 140 +++++++++++++++++ docs/docs/troubleshooting/flashing-issues.md | 29 ++++ docs/docs/troubleshooting/index.mdx | 10 ++ docs/docs/user-setup.mdx | 2 +- docs/sidebars.js | 15 +- 10 files changed, 251 insertions(+), 196 deletions(-) delete mode 100644 docs/docs/troubleshooting.md create mode 100644 docs/docs/troubleshooting/building-issues.md create mode 100644 docs/docs/troubleshooting/connection-issues.mdx create mode 100644 docs/docs/troubleshooting/flashing-issues.md create mode 100644 docs/docs/troubleshooting/index.mdx diff --git a/docs/blog/2023-10-05-zmk-sotf-6.md b/docs/blog/2023-10-05-zmk-sotf-6.md index fb8dc131d21..bd818cf67dc 100644 --- a/docs/blog/2023-10-05-zmk-sotf-6.md +++ b/docs/blog/2023-10-05-zmk-sotf-6.md @@ -105,7 +105,7 @@ Note that documentation is still lacking for utilizing more than one peripheral [petejohanson] contributed a fix to release held keys on peripheral disconnect [#1340](https://github.com/zmkfirmware/zmk/pull/1340), which makes scenarios where a split disconnects unexpectedly less painful. -[petejohanson] also improved [the `settings_reset` shield](/docs/troubleshooting#split-keyboard-halves-unable-to-pair) by making it clear bonds more reliably, and allow it to build for all boards in [#1879](https://github.com/zmkfirmware/zmk/pull/1879). +[petejohanson] also improved [the `settings_reset` shield](/docs/troubleshooting/connection-issues#split-keyboard-halves-unable-to-pair) by making it clear bonds more reliably, and allow it to build for all boards in [#1879](https://github.com/zmkfirmware/zmk/pull/1879). [petejohanson] and [xudongzheng] contributed additional split connectivity improvements, via using directed advertising in [#1913](https://github.com/zmkfirmware/zmk/pull/1913) and improving the robustness of central scanning in [#1912](https://github.com/zmkfirmware/zmk/pull/1912). diff --git a/docs/docs/customization.md b/docs/docs/customization.md index 96b5e4ea9a0..87d78a22b1c 100644 --- a/docs/docs/customization.md +++ b/docs/docs/customization.md @@ -50,7 +50,7 @@ It is also possible to build firmware locally on your computer by following the For normal keyboards, follow the same flashing instructions as before to flash your updated firmware. For split keyboards, only the central (left) side will need to be reflashed if you are just updating your keymap. -More troubleshooting information for split keyboards can be found [here](troubleshooting.md#split-keyboard-halves-unable-to-pair). +More troubleshooting information for split keyboards can be found [here](troubleshooting/connection-issues.mdx#split-keyboard-halves-unable-to-pair). ## Building Additional Keyboards diff --git a/docs/docs/features/bluetooth.md b/docs/docs/features/bluetooth.md index 28ba21367d1..d148acd82db 100644 --- a/docs/docs/features/bluetooth.md +++ b/docs/docs/features/bluetooth.md @@ -47,52 +47,4 @@ Firmware changes that would modify the descriptor include the following: While the descriptor refresh happens on boot for USB, hosts will frequently cache this descriptor for BLE devices. In order to refresh this cache, you need to remove the keyboard from the host device, clear the profile associated with the host on the keyboard, then pair again. -For Windows systems you might need to follow the instructions in [this troubleshooting section](#windows-connected-but-not-working) below. - -## Troubleshooting - -### Connectivity Issues - -Some users may experience a poor connection between the keyboard and the host. This might be due to poor quality BLE hardware, a metal enclosure on the keyboard or host, or the distance between them. Increasing the transmit power of the keyboard's BLE radio may reduce the severity of this problem. To do this, set the `CONFIG_BT_CTLR_TX_PWR_PLUS_8` configuration value in the `.conf` file of your user config directory as such: - -```ini -CONFIG_BT_CTLR_TX_PWR_PLUS_8=y -``` - -For the `nRF52840`, the value `PLUS_8` can be set to any multiple of four between `MINUS_20` and `PLUS_8`. The default value for this config is `0`, but if you are having connection issues it is recommended to set it to `PLUS_8` because the power consumption difference is negligible. For more information on changing the transmit power of your BLE device, please refer to [the Zephyr docs.](https://docs.zephyrproject.org/3.5.0/kconfig.html#CONFIG_BT_CTLR_TX_PWR) - -:::info -This setting can also improve the connection strength between the keyboard halves for split keyboards. -::: - -### Using bluetooth output with USB power - -If you want to test bluetooth output on your keyboard and are powering it through the USB connection rather than a battery, you will be able to pair with a host device but may not see keystrokes sent. In this case you need to use the [output selection behavior](../behaviors/outputs.md) to prefer sending keystrokes over bluetooth rather than USB. This might be necessary even if you are not powering from a device capable of receiving USB inputs, such as a USB charger. - -### Issues with dual boot setups - -Since ZMK associates pairing/bond keys with hardware addresses of hosts, you cannot pair to two different operating systems in a dual boot system at the same time. -While you can find [documented workarounds](https://wiki.archlinux.org/title/bluetooth#Dual_boot_pairing) that involve copying pairing keys across operating systems and use both OS with a single profile, they can be fairly involved and should be followed with caution. - -### macOS Connected But Not Working - -If you attempt to pair a ZMK keyboard from macOS in a way that causes a bonding issue, macOS may report the keyboard as connected, but fail to actually work. If this occurs: - -1. Remove the keyboard from macOS using the Bluetooth control panel. -1. Invoke `&bt BT_CLR` on the keyboard while the profile associated with the macOS device is active, by pressing the correct keys for your particular keymap. -1. Try connecting again from macOS. - -### Windows Connected But Not Working - -Occasionally pairing the keyboard to a Windows device might result in a state where the keyboard is connected but does not send any key strokes. -If this occurs: - -1. Remove the keyboard from Windows using the Bluetooth settings. -1. Invoke `&bt BT_CLR` on the keyboard while the profile associated with the Windows device is active, by pressing the correct keys for your particular keymap. -1. Turn off Bluetooth from Windows settings, then turn it back on. -1. Pair the keyboard to the Windows device. - -If this doesn't help, try following the procedure above but replace step 3 with one of the following: - -- Restart the Windows device -- Open "Device Manager," turn on "Show hidden devices" from the "View" menu, then find and delete the keyboard under the "Bluetooth" item +For Windows systems you might need to follow the additional instructions in [the section on troubleshooting connection issues](troubleshooting/connection-issues.mdx#windows-connected-but-not-working). diff --git a/docs/docs/troubleshooting.md b/docs/docs/troubleshooting.md deleted file mode 100644 index 876cbb9b4d2..00000000000 --- a/docs/docs/troubleshooting.md +++ /dev/null @@ -1,143 +0,0 @@ ---- -title: Troubleshooting -sidebar_title: Troubleshooting ---- - -The following page provides suggestions for common errors that may occur during firmware compilation or other issues with keyboard usage. If the information provided is insufficient to resolve the issue, feel free to seek out help from the [ZMK Discord](https://zmk.dev/community/discord/invite). - -Please also see [the troubleshooting section](features/bluetooth.md#troubleshooting) under the Bluetooth feature page for issues related to bluetooth. - -### File Transfer Error - -Variations of the warnings shown below occur when flashing the `.uf2` onto the microcontroller. This is because the microcontroller resets itself before the OS receives confirmation that the file transfer is complete. Errors like this are normal and can generally be ignored. Verification of a functional board can be done by attempting to pair your newly flashed keyboard to your computer via Bluetooth or plugging in a USB cable if `ZMK_USB` is enabled in your Kconfig.defconfig. - -| ![Example Error Screen](../docs/assets/troubleshooting/filetransfer/windows.png) | -| :------------------------------------------------------------------------------: | -| An example of the file transfer error on Windows 10 | - -| ![Example Error Screen](../docs/assets/troubleshooting/filetransfer/linux.png) | -| :----------------------------------------------------------------------------: | -| An example of the file transfer error on Linux | - -| ![Example Error Screen](../docs/assets/troubleshooting/filetransfer/mac.png) | -| :--------------------------------------------------------------------------: | -| An example of the file transfer error on macOS | - -### macOS Ventura error - -macOS 13.0 (Ventura) Finder may report an error code 100093 when copying `.uf2` files into microcontrollers. This bug is limited to the operating system's Finder. You can work around it by copying on Terminal command line or use a third party file manager. Issue is fixed in macOS version 13.1. - -### macOS Sonoma error - -macOS 14.x (Sonoma) Finder may report an "Error code -36" when copying `.uf2` files into microcontrollers. A similar "fcopyfile failed: Input/output error" will also be reported when copying is performed using Terminal command line. These errors can be ignored because they are reported when the bootloader disconnects automatically after the uf2 file is copied successfully. - -### CMake Error - -An error along the lines of `CMake Error at (zmk directory)/zephyr/cmake/generic_toolchain.cmake:64 (include): include could not find load file:` during firmware compilation indicates that the Zephyr Environment Variables are not properly defined. -For more information, see [Zephyr's CMake Package](https://docs.zephyrproject.org/3.5.0/build/zephyr_cmake_package.html). - -### West Build Errors - -West build errors usually indicate syntax problems in the `.keymap` file during the compilation process. The following are some examples and root causes. - -:::note -If you are reviewing these errors in the GitHub Actions tab, they can be found in the `West Build` step of the build process. -::: - -#### Keymap error - -If you get an error stating `Keymap node not found, check a keymap is available and is has compatible = "zmk,keymap" set` this is an indication that the build process cannot find the keymap. Double check that the `.keymap` file is present and has been discovered by the build process. This can be checked by looking for a line in the build log stating `-- Using keymap file: /path/to/keymap/file/.keymap`. Inside the keymap file ensure the keymap node has `compatible = zmk,keymap` and it's not misspelled. For more information see the [Keymap](features/keymaps.mdx) and [Config](config/index.md) documentation. - -#### Devicetree errors - -A `devicetree error` followed by a reference to the line number on `.keymap` refers to an issue at the exact line position in that file. For example, below error message indicates a missing `;` at line 109 of the `cradio.keymap` file: - -``` -devicetree error: /__w/zmk-config/zmk-config/config/cradio.keymap:109 (column 4): parse error: expected ';' or ',' -``` - -A `devicetree error` followed by an `empty_file.c` reference with `lacks #binding-cells` string indicates possible problems with improper parameters for specific bindings: - -``` -devicetree error: lacks #binding-cells -``` - -This error can be triggered by incorrect binding syntax such as `&kp BT_SEL 0` instead of `&bt BT_SEL 0`. - -A `devicetree_generated.h` error that follows with an "undeclared here" string indicates a problem with key bindings, like behavior nodes (e.g. `&kp` or `&mt`) with incorrect number of parameters: - -``` -/__w/zmk-config/zmk-config/build/zephyr/include/generated/devicetree_generated.h:3756:145: error: 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label' undeclared here (not in a function); did you mean 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_16_PH'? -``` - -In this example, the error string `DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label` indicates a problem with the key binding in position `12` in the `symbol_layer` of the keymap. - -:::info -Key positions are numbered starting from `0` at the top left key on the keymap, incrementing horizontally, row by row. -::: - -:::tip -A common mistake that leads to this error is to use [key press keycodes](behaviors/key-press.md) without the leading `&kp` binding. That is, having entries such as `SPACE` that should have been `&kp SPACE`. -::: - -### Split Keyboard Halves Unable to Pair - -Split keyboard halves will automatically pair with one another, but there are some cases where this breaks, and the pairing needs to be reset, for example: - -- Switching which halves are the central/peripheral. -- Replacing the controller for one of the halves. - -These issues can be resolved by flashing a settings reset firmware to both controllers. - -:::warning - -This procedure will erase all settings, such as Bluetooth profiles, output selection, RGB underglow color, etc. - -::: - -First, acquire the reset UF2 image file with one of the following options: - -#### Option 1: Build Reset UF2 in 'zmk-config' - -Find the `build.yaml` file in your `zmk-config` folder and add an additional settings reset build for the board used by your split keyboard. For example assuming that the config repo is setup for nice!nano v2 with Corne, append the `settings_reset` shield to the `build.yaml` file as follows: - -```yml -include: - - board: nice_nano_v2 - shield: corne_left - - board: nice_nano_v2 - shield: corne_right - - board: nice_nano_v2 - shield: settings_reset -``` - -Save the file, commit the changes and push them to GitHub. Download the new firmware zip file build by the latest GitHub Actions job. In it you will find an additional `settings_reset` UF2 image file. - -#### Option 2: Download Reset UF2 from ZMK's Workflow - -1. [Open the GitHub `Actions` tab and select the `Build` workflow](https://github.com/zmkfirmware/zmk/actions?query=workflow%3ABuild+branch%3Amain+event%3Apush). -1. Find one of the 'results' for which the core-coverage job was successfully run, indicated by a green checkmark in the core-coverage bubble like the image example below. -1. From the next page under "Artifacts", download and unzip the `-settings_reset-zmk` zip file for the UF2 image. - -| ![Successful core-coverage Job](../docs/assets/troubleshooting/splitpairing/corecoverage.png) | -| :-------------------------------------------------------------------------------------------: | -| An example of a successful core-coverage job which will produce a settings_reset firmware. | - -#### Reset Split Keyboard Procedure - -Perform the following steps to reset both halves of your split keyboard: - -1. Put each half of the split keyboard into bootloader mode. -1. Flash one of the halves of the split with the downloaded settings reset UF2 image. -1. Repeat step 2 with the other half of the split keyboard. -1. Flash the actual image for each half of the split keyboard (e.g `my_board_left.uf2` to the left half, `my_board_right.uf2` to the right half). - -After completing these steps, pair the halves of the split keyboard together by resetting them at the same time. Most commonly, this is done by grounding the reset pins for each of your keyboard's microcontrollers or pressing the reset buttons at the same time. - -Once this is done, you can remove/forget the keyboard on each host device and pair it again. - -:::info - -The settings reset firmware has Bluetooth disabled to prevent the two sides from automatically re-pairing until you are done resetting them both. You will not be able to pair your keyboard or see it in any Bluetooth device lists until you have flashed the normal firmware again. - -::: diff --git a/docs/docs/troubleshooting/building-issues.md b/docs/docs/troubleshooting/building-issues.md new file mode 100644 index 00000000000..e37d3934d79 --- /dev/null +++ b/docs/docs/troubleshooting/building-issues.md @@ -0,0 +1,54 @@ +--- +title: Building Issues +sidebar_label: Building Issues +description: Troubleshooting issues when compiling ZMK firmware. +--- + +## CMake Error + +An error along the lines of `CMake Error at (zmk directory)/zephyr/cmake/generic_toolchain.cmake:64 (include): include could not find load file:` during firmware compilation indicates that the Zephyr Environment Variables are not properly defined. +For more information, see [Zephyr's CMake Package](https://docs.zephyrproject.org/3.5.0/build/zephyr_cmake_package.html). + +## West Build Errors + +West build errors usually indicate syntax problems in the `.keymap` file during the compilation process. The following are some examples and root causes. + +:::note +If you are reviewing these errors in the GitHub Actions tab, they can be found in the `West Build` step of the build process. +::: + +### Keymap Error + +If you get an error stating `Keymap node not found, check a keymap is available and is has compatible = "zmk,keymap" set` this is an indication that the build process cannot find the keymap. Double check that the `.keymap` file is present and has been discovered by the build process. This can be checked by looking for a line in the build log stating `-- Using keymap file: /path/to/keymap/file/.keymap`. Inside the keymap file ensure the keymap node has `compatible = zmk,keymap` and it's not misspelled. For more information see the [Keymap](features/keymaps.mdx) and [Config](config/index.md) documentation. + +### Devicetree Errors + +A `devicetree error` followed by a reference to the line number on `.keymap` refers to an issue at the exact line position in that file. For example, below error message indicates a missing `;` at line 109 of the `cradio.keymap` file: + +``` +devicetree error: /__w/zmk-config/zmk-config/config/cradio.keymap:109 (column 4): parse error: expected ';' or ',' +``` + +A `devicetree error` followed by an `empty_file.c` reference with `lacks #binding-cells` string indicates possible problems with improper parameters for specific bindings: + +``` +devicetree error: lacks #binding-cells +``` + +This error can be triggered by incorrect binding syntax such as `&kp BT_SEL 0` instead of `&bt BT_SEL 0`. + +A `devicetree_generated.h` error that follows with an "undeclared here" string indicates a problem with key bindings, like behavior nodes (e.g. `&kp` or `&mt`) with incorrect number of parameters: + +``` +/__w/zmk-config/zmk-config/build/zephyr/include/generated/devicetree_generated.h:3756:145: error: 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label' undeclared here (not in a function); did you mean 'DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_16_PH'? +``` + +In this example, the error string `DT_N_S_keymap_S_symbol_layer_P_bindings_IDX_12_PH_P_label` indicates a problem with the key binding in position `12` in the `symbol_layer` of the keymap. + +:::info +Key positions are numbered starting from `0` at the top left key on the keymap, incrementing horizontally, row by row. +::: + +:::tip +A common mistake that leads to this error is to use [key press keycodes](behaviors/key-press.md) without the leading `&kp` binding. That is, having entries such as `SPACE` that should have been `&kp SPACE`. +::: diff --git a/docs/docs/troubleshooting/connection-issues.mdx b/docs/docs/troubleshooting/connection-issues.mdx new file mode 100644 index 00000000000..59a6a20811d --- /dev/null +++ b/docs/docs/troubleshooting/connection-issues.mdx @@ -0,0 +1,140 @@ +--- +title: Connection Issues +sidebar_label: Connection Issues +description: Troubleshooting wireless connection issues of ZMK devices. +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +export const Uf2Tabs = (props) => ( + + {/* eslint-disable-next-line */} + {props.children} + + +); + +## Split Keyboard Halves Unable to Pair + +Split keyboard halves will automatically pair with one another, but there are some cases where this breaks, and the pairing needs to be reset, for example: + +- Switching which halves are the central/peripheral. +- Replacing the controller for one of the halves. + +These issues can be resolved by flashing a settings reset firmware to both controllers. + +:::warning + +This procedure will erase all settings, such as Bluetooth profiles, output selection, RGB underglow color, etc. + +::: + +### Acquiring a Reset UF2 + +First, acquire the reset UF2 image file with one of the following options: + + + + +Find the `build.yaml` file in your `zmk-config` folder and add an additional settings reset build for the board used by your split keyboard. For example assuming that the config repo is setup for nice!nano v2 with Corne, append the `settings_reset` shield to the `build.yaml` file as follows: + +```yml +include: + - board: nice_nano_v2 + shield: corne_left + - board: nice_nano_v2 + shield: corne_right + - board: nice_nano_v2 + shield: settings_reset +``` + +Save the file, commit the changes and push them to GitHub. Download the new firmware zip file build by the latest GitHub Actions job. In it you will find an additional `settings_reset` UF2 image file. + + + + +1. [Open the GitHub `Actions` tab and select the `Build` workflow](https://github.com/zmkfirmware/zmk/actions?query=workflow%3ABuild+branch%3Amain+event%3Apush). +1. Find one of the 'results' for which the core-coverage job was successfully run, indicated by a green checkmark in the core-coverage bubble like the image example below. +1. From the next page under "Artifacts", download and unzip the `-settings_reset-zmk` zip file for the UF2 image. + +| ![Successful core-coverage Job](../../docs/assets/troubleshooting/splitpairing/corecoverage.png) | +| :----------------------------------------------------------------------------------------------: | +| An example of a successful core-coverage job which will produce a settings_reset firmware. | + + + + +### Reset Split Keyboard Procedure + +Perform the following steps to reset **_both_** halves of your split keyboard: + +1. Put each half of the split keyboard into bootloader mode. +1. Flash one of the halves of the split with the downloaded settings reset UF2 image. +1. Repeat step 2 with the other half of the split keyboard. +1. Flash the actual image for each half of the split keyboard (e.g `my_board_left.uf2` to the left half, `my_board_right.uf2` to the right half). + +After completing these steps, pair the halves of the split keyboard together by resetting them at the same time. Most commonly, this is done by grounding the reset pins for each of your keyboard's microcontrollers or pressing the reset buttons at the same time. + +Once this is done, you can remove/forget the keyboard on each host device and pair it again. + +:::info + +The settings reset firmware has Bluetooth disabled to prevent the two sides from automatically re-pairing until you are done resetting them both. You will not be able to pair your keyboard or see it in any Bluetooth device lists until you have flashed the normal firmware again. + +::: + +## Issues While Connected + +### Unreliable/Weak Connection + +Some users may experience a poor connection between the keyboard and the host. This might be due to poor quality BLE hardware, a metal enclosure on the keyboard or host, or the distance between them. Increasing the transmit power of the keyboard's BLE radio may reduce the severity of this problem. To do this, set the `CONFIG_BT_CTLR_TX_PWR_PLUS_8` configuration value in the `.conf` file of your user config directory as such: + +```ini +CONFIG_BT_CTLR_TX_PWR_PLUS_8=y +``` + +For the `nRF52840`, the value `PLUS_8` can be set to any multiple of four between `MINUS_20` and `PLUS_8`. The default value for this config is `0`, but if you are having connection issues it is recommended to set it to `PLUS_8` because the power consumption difference is negligible. For more information on changing the transmit power of your BLE device, please refer to [the Zephyr docs.](https://docs.zephyrproject.org/3.5.0/kconfig.html#CONFIG_BT_CTLR_TX_PWR) + +:::info +This setting can also improve the connection strength between the keyboard halves for split keyboards. +::: + +### Using Bluetooth Output With USB Power + +If you want to test Bluetooth output on your keyboard and are powering it through the USB connection rather than a battery, you will be able to pair with a host device but may not see keystrokes sent. In this case you need to use the [output selection behavior](../behaviors/outputs.md) to prefer sending keystrokes over Bluetooth rather than USB. This might be necessary even if you are not powering from a device capable of receiving USB inputs, such as a USB charger. + +### Issues With Dual Boot Setups + +Since ZMK associates pairing/bond keys with hardware addresses of hosts, you cannot pair to two different operating systems in a dual boot system at the same time. +While you can find [documented workarounds](https://wiki.archlinux.org/title/bluetooth#Dual_boot_pairing) that involve copying pairing keys across operating systems and use both OS with a single profile, they can be fairly involved and should be followed with caution. + +### macOS Connected but Not Working + +If you attempt to pair a ZMK keyboard from macOS in a way that causes a bonding issue, macOS may report the keyboard as connected, but fail to actually work. If this occurs: + +1. Remove the keyboard from macOS using the Bluetooth control panel. +1. Invoke `&bt BT_CLR` on the keyboard while the profile associated with the macOS device is active, by pressing the correct keys for your particular keymap. +1. Try connecting again from macOS. + +### Windows Connected but Not Working + +Occasionally pairing the keyboard to a Windows device might result in a state where the keyboard is connected but does not send any key strokes. +If this occurs: + +1. Remove the keyboard from Windows using the Bluetooth settings. +1. Invoke `&bt BT_CLR` on the keyboard while the profile associated with the Windows device is active, by pressing the correct keys for your particular keymap. +1. Turn off Bluetooth from Windows settings, then turn it back on. +1. Pair the keyboard to the Windows device. + +If this doesn't help, try following the procedure above but replace step 3 with one of the following: + +- Restart the Windows device +- Open "Device Manager," turn on "Show hidden devices" from the "View" menu, then find and delete the keyboard under the "Bluetooth" item diff --git a/docs/docs/troubleshooting/flashing-issues.md b/docs/docs/troubleshooting/flashing-issues.md new file mode 100644 index 00000000000..699555d5f92 --- /dev/null +++ b/docs/docs/troubleshooting/flashing-issues.md @@ -0,0 +1,29 @@ +--- +title: Flashing Issues +sidebar_label: Flashing Issues +description: Troubleshooting issues when flashing ZMK firmware to devices. +--- + +## File Transfer Error + +Variations of the warnings shown below occur when flashing the `.uf2` onto the microcontroller. This is because the microcontroller resets itself before the OS receives confirmation that the file transfer is complete. Errors like this are normal and can generally be ignored. Verification of a functional board can be done by attempting to pair your newly flashed keyboard to your computer via Bluetooth or plugging in a USB cable if `ZMK_USB` is enabled in your Kconfig.defconfig. + +| ![Example Error Screen](../../docs/assets/troubleshooting/filetransfer/windows.png) | +| :---------------------------------------------------------------------------------: | +| An example of the file transfer error on Windows 10 | + +| ![Example Error Screen](../../docs/assets/troubleshooting/filetransfer/linux.png) | +| :-------------------------------------------------------------------------------: | +| An example of the file transfer error on Linux | + +| ![Example Error Screen](../../docs/assets/troubleshooting/filetransfer/mac.png) | +| :-----------------------------------------------------------------------------: | +| An example of the file transfer error on macOS | + +## macOS Ventura Error + +macOS 13.0 (Ventura) Finder may report an error code 100093 when copying `.uf2` files into microcontrollers. This bug is limited to the operating system's Finder. You can work around it by copying on Terminal command line or use a third party file manager. Issue is fixed in macOS version 13.1. + +## macOS Sonoma Error + +macOS 14.x (Sonoma) Finder may report an "Error code -36" when copying `.uf2` files into microcontrollers. A similar "fcopyfile failed: Input/output error" will also be reported when copying is performed using Terminal command line. These errors can be ignored because they are reported when the bootloader disconnects automatically after the uf2 file is copied successfully. diff --git a/docs/docs/troubleshooting/index.mdx b/docs/docs/troubleshooting/index.mdx new file mode 100644 index 00000000000..45a93191b16 --- /dev/null +++ b/docs/docs/troubleshooting/index.mdx @@ -0,0 +1,10 @@ +--- +title: Troubleshooting +sidebar_label: Troubleshooting +--- + +import DocCardList from "@theme/DocCardList"; + +The following pages provide suggestions for common errors that may occur while setting up or using devices running ZMK. If the information provided is insufficient to resolve an issue, feel free to seek out additional help from the [ZMK Discord](https://zmk.dev/community/discord/invite). + + diff --git a/docs/docs/user-setup.mdx b/docs/docs/user-setup.mdx index 355fc51d5e2..78d4362857e 100644 --- a/docs/docs/user-setup.mdx +++ b/docs/docs/user-setup.mdx @@ -225,7 +225,7 @@ For split keyboards, after flashing each half individually you can connect them :::note If you have issues connecting the halves, make sure that both sides are getting powered properly through USB or batteries, then follow the -[recommended troubleshooting procedure](troubleshooting.md#split-keyboard-halves-unable-to-pair). This is typically necessary if you +[recommended troubleshooting procedure](troubleshooting/connection-issues.mdx#split-keyboard-halves-unable-to-pair). This is typically necessary if you swapped firmware sides between controllers, like flashing left side firmware to the same controller after flashing the right, or vice versa. ::: diff --git a/docs/sidebars.js b/docs/sidebars.js index a3b4ea2ce74..e8c715c8c76 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -6,7 +6,20 @@ module.exports = { "faq", "user-setup", "customization", - "troubleshooting", + { + type: "category", + label: "Troubleshooting", + link: { + type: "doc", + id: "troubleshooting/index", + }, + collapsed: true, + items: [ + "troubleshooting/building-issues", + "troubleshooting/flashing-issues", + "troubleshooting/connection-issues", + ], + }, ], Features: [ "features/keymaps", From 7c09eb217e8ef8e667db15bf71efa3748a010c16 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Sun, 9 Jun 2024 21:35:10 -0700 Subject: [PATCH 106/134] refactor(docs): Document and enforce header casing conventions --- docs/docs/behaviors/caps-word.md | 4 ++-- docs/docs/behaviors/hold-tap.mdx | 2 +- docs/docs/behaviors/index.mdx | 18 ++++++++-------- docs/docs/behaviors/key-repeat.md | 2 +- docs/docs/behaviors/layers.md | 4 ++-- docs/docs/behaviors/macros.md | 4 ++-- docs/docs/behaviors/mod-morph.md | 2 +- docs/docs/behaviors/soft-off.md | 2 +- docs/docs/behaviors/sticky-key.md | 2 +- docs/docs/behaviors/sticky-layer.md | 2 +- docs/docs/config/battery.md | 2 +- docs/docs/config/encoders.md | 4 ++-- docs/docs/development/build-flash.mdx | 2 +- docs/docs/development/documentation.md | 8 ++++++- docs/docs/development/ide-integration.mdx | 4 ++-- docs/docs/development/new-behavior.mdx | 26 +++++++++++------------ docs/docs/development/setup/native.mdx | 4 ++-- docs/docs/features/backlight.mdx | 4 ++-- docs/docs/features/beta-testing.mdx | 2 +- docs/docs/features/combos.md | 2 +- docs/docs/features/debouncing.md | 2 +- docs/docs/features/keymaps.mdx | 2 +- docs/docs/features/soft-off.md | 4 ++-- docs/docs/features/underglow.md | 6 +++--- docs/docs/intro.md | 2 +- docs/docs/user-setup.mdx | 4 ++-- 26 files changed, 63 insertions(+), 57 deletions(-) diff --git a/docs/docs/behaviors/caps-word.md b/docs/docs/behaviors/caps-word.md index 4551884dd50..c79ebae01a6 100644 --- a/docs/docs/behaviors/caps-word.md +++ b/docs/docs/behaviors/caps-word.md @@ -21,7 +21,7 @@ Example: ### Configuration -#### Continue List +#### Continue list By default, the caps word will remain active when any alphanumeric character or underscore (`UNDERSCORE`), backspace (`BACKSPACE`), or delete (`DELETE`) characters are pressed. Any other non-modifier keycode sent will turn off caps word. If you would like to override this, you can set a new array of keys in the `continue-list` property in your keymap: @@ -37,7 +37,7 @@ By default, the caps word will remain active when any alphanumeric character or }; ``` -#### Applied Modifier(s) +#### Applied modifier(s) In addition, if you would like _multiple_ modifiers, instead of just `MOD_LSFT`, you can override the `mods` property: diff --git a/docs/docs/behaviors/hold-tap.mdx b/docs/docs/behaviors/hold-tap.mdx index 5217cf79e29..20aaf810a8c 100644 --- a/docs/docs/behaviors/hold-tap.mdx +++ b/docs/docs/behaviors/hold-tap.mdx @@ -35,7 +35,7 @@ When the hold-tap key is released and the hold behavior has not been triggered, ![Hold-tap comparison](../assets/hold-tap/comparison.svg) -### Basic usage +### Basic Usage For basic usage, please see the [mod-tap](mod-tap.md) and [layer-tap](layers.md#layer-tap) pages. diff --git a/docs/docs/behaviors/index.mdx b/docs/docs/behaviors/index.mdx index 7cd82d3e4b8..bdacc209ad7 100644 --- a/docs/docs/behaviors/index.mdx +++ b/docs/docs/behaviors/index.mdx @@ -9,7 +9,7 @@ sidebar_label: Overview Below is a summary of pre-defined behavior bindings and user-definable behaviors available in ZMK, with references to documentation pages describing them. -## Key press behaviors +## Key Press Behaviors | Binding | Behavior | Description | | ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -21,14 +21,14 @@ Below is a summary of pre-defined behavior bindings and user-definable behaviors | `&caps_word` | [Caps Word](caps-word.md) | Behaves similar to caps lock, but automatically deactivates when any key not in a continue list is pressed, or if the caps word key is pressed again | | `&key_repeat` | [Key Repeat](key-repeat.md) | Sends again whatever keycode was last sent | -## Miscellaneous behaviors +## Miscellaneous Behaviors | Binding | Behavior | Description | | -------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `&trans` | [Transparent](misc.md#transparent) | Passes the key press down to the next active layer in the stack for processing | | `&none` | [None](misc.md#none) | Swallows and stops the key press, no keycode will be sent nor will the key press be passed down to the next active layer in the stack | -## Layer navigation behaviors +## Layer Navigation Behaviors | Binding | Behavior | Description | | ------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------- | @@ -38,41 +38,41 @@ Below is a summary of pre-defined behavior bindings and user-definable behaviors | `&tog` | [Toggle Layer](layers.md#toggle-layer) | Enables a layer until the layer is manually disabled | | `&sl` | [Sticky Layer](sticky-layer.md) | Activates a layer until another key is pressed, then deactivates it | -## Mouse emulation behaviors +## Mouse Emulation Behaviors | Binding | Behavior | Description | | ------- | ----------------------------------------------------------- | ------------------------------- | | `&mkp` | [Mouse Button Press](mouse-emulation.md#mouse-button-press) | Emulates pressing mouse buttons | -## Reset behaviors +## Reset Behaviors | Binding | Behavior | Description | | ------------- | --------------------------------------- | ---------------------------------------------------------------------------------------- | | `&sys_reset` | [Reset](reset.md#reset) | Resets the keyboard and re-runs the firmware flashed to the device | | `&bootloader` | [Bootloader](reset.md#bootloader-reset) | Resets the keyboard and puts it into bootloader mode, allowing you to flash new firmware | -## Output selection behaviors +## Output Selection Behaviors | Binding | Behavior | Description | | ------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | | `&bt` | [Bluetooth](bluetooth.md#bluetooth-behavior) | Completes a bluetooth action given on press, for example switching between devices | | `&out` | [Output Selection](outputs.md#output-selection-behavior) | Allows selecting whether output is sent to the USB or bluetooth connection when both are connected | -## Lighting behaviors +## Lighting Behaviors | Binding | Behavior | Description | | --------- | ---------------------------------------------- | ---------------------------------------------------------------------------- | | `&rgb_ug` | [RGB Underglow](underglow.md#behavior-binding) | Controls the RGB underglow, usually placed underneath the keyboard | | `&bl` | [Backlight](backlight.md#behavior-binding) | Controls the keyboard backlighting, usually placed through or under switches | -## Power management behaviors +## Power Management Behaviors | Binding | Behavior | Description | | ------------ | --------------------------------------------- | --------------------------------------------------------------- | | `&ext_power` | [Power management](power.md#behavior-binding) | Allows enabling or disabling the VCC power output to save power | | `&soft_off` | [Soft off](soft-off.md#behavior-binding) | Turns the keyboard off. | -## User-defined behaviors +## User-Defined Behaviors | Behavior | Description | | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | diff --git a/docs/docs/behaviors/key-repeat.md b/docs/docs/behaviors/key-repeat.md index 9772fdb4e0a..2187008417a 100644 --- a/docs/docs/behaviors/key-repeat.md +++ b/docs/docs/behaviors/key-repeat.md @@ -19,7 +19,7 @@ Example: ### Configuration -#### Usage Pages +#### Usage pages By default, the key repeat will only track the last pressed key from the HID "Key" usage page, and ignore events from other usages, e.g. Consumer page. diff --git a/docs/docs/behaviors/layers.md b/docs/docs/behaviors/layers.md index 7cfb4df7e00..511fbe08b7a 100644 --- a/docs/docs/behaviors/layers.md +++ b/docs/docs/behaviors/layers.md @@ -8,7 +8,7 @@ sidebar_label: Layers Often, you may want a certain key position to alter which layers are enabled, change the default layer, etc. Some of those behaviors are still in the works; the ones that are working now are documented here. -## Defines To Refer To Layers +## Defines to Refer to Layers When working with layers, you may have several different key positions with bindings that enable/disable those layers. To make it easier to refer to those layers in your key bindings, and to change which layers are where later, you can @@ -41,7 +41,7 @@ Example: &mo LOWER ``` -## Layer-tap +## Layer-Tap The "layer-tap" behavior enables a layer when a key is held, and outputs a [keypress](key-press.md) when the key is only tapped for a short time. diff --git a/docs/docs/behaviors/macros.md b/docs/docs/behaviors/macros.md index 37ca80ffbb5..50c8945eb80 100644 --- a/docs/docs/behaviors/macros.md +++ b/docs/docs/behaviors/macros.md @@ -223,7 +223,7 @@ Common examples are enabling one or more modifiers when the layer is active, or To achieve this, a combination of a 0ms wait time and splitting the press and release between a `¯o_pause_for_release` is used: -#### Layer + Modifier +#### Layer + modifier ```dts /** @@ -256,7 +256,7 @@ lm: lm { }; ``` -#### Layer + Underglow Color +#### Layer + underglow color To trigger a different underglow when the macro is pressed, and when it is released, we use the macro "press" activation mode whenever triggering the `&rgb_ug` behavior: diff --git a/docs/docs/behaviors/mod-morph.md b/docs/docs/behaviors/mod-morph.md index 7ecb9ab8983..8949ec2c788 100644 --- a/docs/docs/behaviors/mod-morph.md +++ b/docs/docs/behaviors/mod-morph.md @@ -65,7 +65,7 @@ Example: mods = <(MOD_LGUI|MOD_LSFT|MOD_RGUI|MOD_RSFT)>; ``` -### Advanced configuration +### Advanced Configuration `keep-mods` diff --git a/docs/docs/behaviors/soft-off.md b/docs/docs/behaviors/soft-off.md index 14b5f36aee7..086b5d75d75 100644 --- a/docs/docs/behaviors/soft-off.md +++ b/docs/docs/behaviors/soft-off.md @@ -23,7 +23,7 @@ Example: ### Configuration -#### Hold Time +#### Hold time By default, the keyboard will be turned off as soon as the key bound to the behavior is released, even if the key is only tapped briefly. If you would prefer that the key need be held a certain amount of time before releasing, you can set the `hold-time-ms` to a non-zero value in your keymap: diff --git a/docs/docs/behaviors/sticky-key.md b/docs/docs/behaviors/sticky-key.md index 8c3962f5450..30345882a66 100644 --- a/docs/docs/behaviors/sticky-key.md +++ b/docs/docs/behaviors/sticky-key.md @@ -81,7 +81,7 @@ This configuration would apply to all sticky keys. This may not be appropriate i }; ``` -### Advanced usage +### Advanced Usage Sticky keys can be combined; if you tap `&sk LCTRL` and then `&sk LSHIFT` and then `&kp A`, the output will be ctrl+shift+a. diff --git a/docs/docs/behaviors/sticky-layer.md b/docs/docs/behaviors/sticky-layer.md index 41c2ccf55d7..6a231f08995 100644 --- a/docs/docs/behaviors/sticky-layer.md +++ b/docs/docs/behaviors/sticky-layer.md @@ -36,7 +36,7 @@ You can configure a different `release-after-ms` in your keymap: }; ``` -### Advanced usage +### Advanced Usage Sticky layers behave slightly different from sticky keys. They are configured to `quick-release`. This means that the layer is released immediately when another key is pressed. "Normal" sticky keys are not `quick-release`; they are released when the next key is released. This makes it possible to combine sticky layers and sticky keys as such: tap `&sl 1`, tap `&sk LSHIFT` on layer 1, tap `&kp A` on base layer to output shift+A. diff --git a/docs/docs/config/battery.md b/docs/docs/config/battery.md index c95e78841e8..4596395b806 100644 --- a/docs/docs/config/battery.md +++ b/docs/docs/config/battery.md @@ -28,7 +28,7 @@ On macOS the BLE battery reporting packets can cause the computer to wakeup from ::: -### Peripheral battery monitoring +### Peripheral Battery Monitoring You can [configure ZMK to allow support for peripheral battery monitoring over BLE](system.md#split-keyboards) (e.g. when having a split keyboard with two independent and wirelessly connected sides). If you want to report the battery levels of both sides of a split keyboard, you should have both `CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_PROXY` and `CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING` set to `y`. diff --git a/docs/docs/config/encoders.md b/docs/docs/config/encoders.md index b242f49b5ba..c8966846efb 100644 --- a/docs/docs/config/encoders.md +++ b/docs/docs/config/encoders.md @@ -29,7 +29,7 @@ If `CONFIG_EC11` is enabled, exactly one of the following options must be set to ### Devicetree -#### Keymap Sensor Config +#### Keymap sensor config For shields/boards that export a `sensors` node configuration label, both global and per-sensor settings can be set by overriding the properties there. @@ -69,7 +69,7 @@ Definition file: [zmk/app/drivers/zephyr/dts/bindings/zmk,keymap-sensors.yaml](h | ----------------------- | ---- | --------------------------------------------------------------- | ------- | | `triggers-per-rotation` | int | Number of times to trigger the bound behavior per full rotation | | -#### EC11 Nodes +#### EC11 nodes Applies to: `compatible = "alps,ec11"` diff --git a/docs/docs/development/build-flash.mdx b/docs/docs/development/build-flash.mdx index 2cbcf5b82ef..20e9e20a34c 100644 --- a/docs/docs/development/build-flash.mdx +++ b/docs/docs/development/build-flash.mdx @@ -77,7 +77,7 @@ This produces `left` and `right` subfolders under the `build` directory and two Build times can be significantly reduced after the initial build by omitting all build arguments except the build directory, e.g. `west build -d build/left`. The additional options and intermediate build outputs from your initial build are cached and reused for unchanged files. ::: -### Building with external modules +### Building With External Modules ZMK supports loading additional boards, shields, code, etc. from [external Zephyr modules](https://docs.zephyrproject.org/3.5.0/develop/modules.html), facilitating out-of-tree management and versioning independent of the ZMK repository. To build with any additional modules, use the `ZMK_EXTRA_MODULES` define added to your `west build` command. diff --git a/docs/docs/development/documentation.md b/docs/docs/development/documentation.md index 56c4d27699b..169642ba714 100644 --- a/docs/docs/development/documentation.md +++ b/docs/docs/development/documentation.md @@ -5,7 +5,7 @@ sidebar_label: Documentation This document outlines how to test your documentation changes locally and prepare the changes for a pull request. -The documentation is written with [Docusaurus](https://docusaurus.io/). The ZMK source code has all of the necessary Docusaurus dependencies included but referencing their documentation can be helpful at times. +The documentation is written with [Docusaurus](https://docusaurus.io/). The ZMK source code has all of the necessary Docusaurus dependencies included, but referencing their documentation can be helpful at times. The general process for updating the ZMK documentation is: @@ -52,6 +52,12 @@ The check commands can be run with the following procedure in a terminal that's If any of the above steps throw an error, they need to be addressed and all of the checks re-run prior to submitting a pull request. ::: +:::note +The documentation uses American English spelling and grammar conventions. Title case is used for the first three heading levels, with sentence case used beyond that. + +Please make sure your changes conform to these conventions - prettier and lint are unfortunately unable to do this automatically. +::: + ## Submitting a Pull Request Once the above sections are complete the documentation updates are ready to submit as a pull request. diff --git a/docs/docs/development/ide-integration.mdx b/docs/docs/development/ide-integration.mdx index 87a5a4caf55..cee12f4b3bf 100644 --- a/docs/docs/development/ide-integration.mdx +++ b/docs/docs/development/ide-integration.mdx @@ -51,7 +51,7 @@ Change these options: If you are developing inside a Docker container, set the IntelliSense mode to `linux-gcc-arm` regardless of the host operating system. -#### Compiler Path +#### Compiler path Open VS Code's integrated terminal and run the following command: @@ -79,7 +79,7 @@ If you are building for an platform other than ARM, replace `/arm-zephyr-eabi/bi /home/marvin/.local/zephyr-sdk-0.15.2/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gcc ``` -#### Compiler Commands Path +#### Compiler commands path When building with all default options, the path to the compilation database file is `${workspaceFolder}/app/build/compile_commands.json` as shown in the table above, diff --git a/docs/docs/development/new-behavior.mdx b/docs/docs/development/new-behavior.mdx index 914abf52063..dca19288dc0 100644 --- a/docs/docs/development/new-behavior.mdx +++ b/docs/docs/development/new-behavior.mdx @@ -35,7 +35,7 @@ The following resources are provided for those seeking further understanding: ## Creating the Behavior -### Creating the devicetree binding (`.yaml`) +### Creating the Devicetree Binding (`.yaml`) The properties of the behavior are listed in the behavior's devicetree binding, which comes in the form of a `.yaml` file. Devicetree bindings are stored in the directory `app/dts/bindings/behaviors/` and are labelled in lowercase, beginning with the prefix `zmk,behavior-`, and ending with the behavior's name, using dashes to separate multiple words. For example, the directory for the hold-tap's devicetree binding would be located at `app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml`, which is shown below as a reference: @@ -119,7 +119,7 @@ These are additional variables required to configure a particular instance of a For more information on additional `properties`, refer to [Zephyr's documentation on Devicetree bindings](https://docs.zephyrproject.org/3.5.0/build/dts/bindings-syntax.html#properties). ::: -### Creating the driver (`.c`) +### Creating the Driver (`.c`) :::info Developing drivers for behaviors in ZMK makes extensive use of the Zephyr Devicetree API and Device Driver Model. Links to the Zephyr Project Documentation for both of these concepts can be found below: @@ -203,7 +203,7 @@ The dependencies required for any ZMK behavior are: Other common dependencies include `zmk/keymap.h`, which allows behaviors to access layer information and extract behavior bindings from keymaps, and `zmk/event_manager.h` which is detailed below. -##### ZMK Event Manager +##### ZMK event manager Including `zmk/event_manager.h` is required for the following dependencies to function properly. @@ -213,7 +213,7 @@ Including `zmk/event_manager.h` is required for the following dependencies to fu Events can be used similarly to hardware interrupts, through the use of [listeners](#listeners-and-subscriptions). -###### Listeners and Subscriptions +###### Listeners and subscriptions The condensed form of lines 192-225 of the tap-dance driver, shown below, does an excellent job of showcasing the function of listeners and subscriptions with respect to the [ZMK Event Manager](#zmk-event-manager). @@ -279,11 +279,11 @@ Note that in the hold-tap example, the instance number, `0`, has been replaced b Behaviors also require the following parameters of `BEHAVIOR_DT_INST_DEFINE` to be changed: -##### Initialization Function +##### Initialization function Comes in the form `static int _init(const struct device *dev)`. Initialization functions preconfigure any data, like resetting timers and position for hold-taps and tap-dances. All initialization functions `return 0;` once complete. -##### API Structure +##### API structure Comes in the form `static const struct behavior_driver_api _driver_api)`. Common items to include in the API Structure are: @@ -297,7 +297,7 @@ Comes in the form `static const struct behavior_driver_api _drive For unibody keyboards, all locality values perform the same as `BEHAVIOR_LOCALITY_GLOBAL`. ::: -##### Data Pointers (Optional) +##### Data pointers (optional) The data `struct` stores additional data required for **each new instance** of the behavior. Regardless of the instance number, `n`, `behavior__data_##n` is typically initialized as an empty `struct`. The data respective to each instance of the behavior can be accessed in functions like [`on__binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event)`](#dependencies) by extracting the behavior device from the keybind like so: @@ -310,7 +310,7 @@ The variables stored inside the data `struct`, `data`, can be then modified as n The fourth cell of `BEHAVIOR_DT_INST_DEFINE` can be set to `NULL` instead if instance-specific data is not required. -##### Configuration Pointers (Optional) +##### Configuration pointers (optional) The configuration `struct` stores the properties declared from the behavior's `.yaml` for **each new instance** of the behavior. As seen in the `#define KP_INST(n)` of the hold-tap example, the configuration `struct`, `behavior__config_##n`, for each instance number, `n`, can be initialized using the [Zephyr Devicetree Instance-based APIs](https://docs.zephyrproject.org/3.5.0/build/dts/api/api.html#instance-based-apis), which extract the values from the `properties` of each instance of the [devicetree binding](#creating-the-devicetree-binding-yaml) from a user's keymap or [predefined use-case `.dtsi` files](#defining-common-use-cases-for-the-behavior-dtsi-optional) stored in `app/dts/behaviors/`. We illustrate this further by comparing the [`#define KP_INST(n)` from the hold-tap driver](#behavior_dt_inst_define) and the [`properties` of the hold-tap devicetree binding.](#creating-the-devicetree-binding-yaml) @@ -320,7 +320,7 @@ The fifth cell of `BEHAVIOR_DT_INST_DEFINE` can be set to `NULL` instead if inst Remember that `.c` files should be formatted according to `clang-format` to ensure that checks run smoothly once the pull request is submitted. ::: -### Updating `app/CmakeLists.txt` to include the new driver +### Updating `app/CmakeLists.txt` to Include the New Driver Most behavior drivers' are invoked according to the central half's [locality](#api-structure), and are therefore stored after the line `if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)` in the form, `target_sources(app PRIVATE src/behaviors/.c)`, as shown below. @@ -353,7 +353,7 @@ For behaviors that do not require central locality, the following options for up - Behavior applies to _only_ peripheral half of split keyboard: place `target_sources(app PRIVATE .c)` after `if (CONFIG_ZMK_SPLIT AND (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL))` - Behavior requires certain condition in a keyboard's `.conf` file to be met: use `target_sources_ifdef(CONFIG_ app PRIVATE .c)` instead of `target_sources(.c)` -### Defining common use-cases for the behavior (`.dtsi`) (Optional) +### Defining Common Use-Cases for the Behavior (`.dtsi`) (Optional) `.dtsi` files, found in the directory `app/dts/behaviors/`, are only necessary for behaviors with more common use-cases. A common example is the mod-tap (`&mt`), which is a predefined type of hold-tap that takes a modifier key as the hold parameter and another key as the tap parameter. @@ -422,7 +422,7 @@ After creating the `.dtsi` from above, update `app/dts/behaviors.dtsi` to includ #include ``` -## Testing changes locally +## Testing Changes Locally Create a new folder in `app/tests/` to develop virtual test sets for all common use cases of the behavior. Behaviors should be tested thoroughly on both virtual testing environments using `west test` and real hardware. @@ -437,7 +437,7 @@ Zephyr currently does not support logging over Bluetooth, so any use of the seri ::: -## Documenting behavior functionality +## Documenting Behavior Functionality Consider the following prompts when writing documentation for new behaviors: @@ -453,7 +453,7 @@ Consider also including visual aids alongside written documentation if it adds c See [Documentation](documentation.md) for more information on writing, testing, and formatting ZMK documentation. ::: -## Submitting a pull request +## Submitting a Pull Request Once the above sections are complete, the behavior is almost ready to submit as a pull request. New [devicetree bindings](#creating-the-devicetree-binding-yaml), new [drivers](#creating-the-driver-c), and [predefined use-cases](#defining-common-use-cases-for-the-behavior-dtsi-optional) of the new behavior must contain the appropriate copyright headers, which can be copied and pasted from the tabs below. diff --git a/docs/docs/development/setup/native.mdx b/docs/docs/development/setup/native.mdx index d077d7d1d7d..40c1bbed6ee 100644 --- a/docs/docs/development/setup/native.mdx +++ b/docs/docs/development/setup/native.mdx @@ -319,7 +319,7 @@ pip3 install -r zephyr/scripts/requirements-base.txt Return to Zephyr's Getting Started Guide and [Install Zephyr SDK](https://docs.zephyrproject.org/3.5.0/develop/getting_started/index.html#install-zephyr-sdk). -### OS specific notes +### OS-Specific Notes @@ -330,7 +330,7 @@ Return to Zephyr's Getting Started Guide and [Install Zephyr SDK](https://docs.z -#### Install Cross-Compile Toolchain +#### Install cross-compile toolchain Because Raspberry OS runs on the same architecture (but different ABI) as ARM keyboard MCUs, the operating system's installed [cross compilers](https://docs.zephyrproject.org/3.5.0/develop/toolchains/other_x_compilers.html) can be used to target the different ABI. Building for non-ARM MCUs has not been tested. diff --git a/docs/docs/features/backlight.mdx b/docs/docs/features/backlight.mdx index 674e8633014..5debc375010 100644 --- a/docs/docs/features/backlight.mdx +++ b/docs/docs/features/backlight.mdx @@ -34,7 +34,7 @@ There are various Kconfig options used to configure the backlight feature. These | `CONFIG_ZMK_BACKLIGHT_AUTO_OFF_IDLE` | Turn off backlight when keyboard goes into idle state | n | | `CONFIG_ZMK_BACKLIGHT_AUTO_OFF_USB` | Turn off backlight when USB is disconnected | n | -## Adding Backlight to a board or a shield +## Adding Backlight to a Board or a Shield -### Multiple backlight LEDs +### Multiple Backlight LEDs It is possible to control multiple backlight LEDs at the same time. This is useful if, for example, you have a Caps Lock LED connected to a different pin and you want it to be part of the backlight. diff --git a/docs/docs/features/beta-testing.mdx b/docs/docs/features/beta-testing.mdx index 148005cea67..1a8d28633cb 100644 --- a/docs/docs/features/beta-testing.mdx +++ b/docs/docs/features/beta-testing.mdx @@ -28,7 +28,7 @@ branch and create the pull request. ![Repository URL](../assets/features/beta-testing/repo-branch.png) -## Testing features +## Testing Features Testing features will require you to modify the `west.yml` file. You will need to add a new remote for the pull request you would like to test, and change the selected remote and revision (or branch) for the `zmk` project. diff --git a/docs/docs/features/combos.md b/docs/docs/features/combos.md index 32f09c1c61e..63c57c38cc3 100644 --- a/docs/docs/features/combos.md +++ b/docs/docs/features/combos.md @@ -38,7 +38,7 @@ Key positions are numbered like the keys in your keymap, starting at 0. So, if t ::: -### Advanced usage +### Advanced Usage - Partially overlapping combos like `0 1` and `0 2` are supported. - Fully overlapping combos like `0 1` and `0 1 2` are supported. diff --git a/docs/docs/features/debouncing.md b/docs/docs/features/debouncing.md index 7d194efa061..31e00843211 100644 --- a/docs/docs/features/debouncing.md +++ b/docs/docs/features/debouncing.md @@ -40,7 +40,7 @@ CONFIG_ZMK_KSCAN_DEBOUNCE_PRESS_MS=3 CONFIG_ZMK_KSCAN_DEBOUNCE_RELEASE_MS=3 ``` -### Per-driver Options +### Per-Driver Options You can add these Devicetree properties to a kscan node to control debouncing for that instance of the driver. Values must be `<= 16383`. diff --git a/docs/docs/features/keymaps.mdx b/docs/docs/features/keymaps.mdx index 105ca794ab4..95df3e86842 100644 --- a/docs/docs/features/keymaps.mdx +++ b/docs/docs/features/keymaps.mdx @@ -96,7 +96,7 @@ The first defines the nodes for all the available behaviors in ZMK, which will b The second include brings in the defines for all the keycodes (e.g. `A`, `N1`, `C_PLAY`) and the modifiers (e.g. `LSHIFT`) used for various behavior bindings. -### Root devicetree Node +### Root Devicetree Node All the remaining keymap nodes will be nested inside of the root devicetree node, like so: diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index bd631f1b42e..7018afa08f2 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -101,7 +101,7 @@ To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, ad The kscan sideband behavior driver will be used to trigger the [soft off behavior](../behaviors/soft-off.md) "out of band" from the normal keymap processing. To do so, it will decorate/wrap an underlying kscan driver. What kscan driver will vary for simple direct pin vs. matrix-integrated hardware combo. -#### Simple Direct Pin +#### Simple direct pin With a simple direct pin setup, the The [direct kscan](../config/kscan.md) driver can be used with a GPIO key, to make a small "side matrix": @@ -148,7 +148,7 @@ Here are the properties for the node: - The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. - The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. -#### Matrix-Integrated Hardware Combo +#### Matrix-integrated hardware combo For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in the `row-gpios`/`col-gpios` for whichever pins are used to read the matrix state. For example, for an existing matrix like: diff --git a/docs/docs/features/underglow.md b/docs/docs/features/underglow.md index a32306caa0d..ba6c0092340 100644 --- a/docs/docs/features/underglow.md +++ b/docs/docs/features/underglow.md @@ -39,7 +39,7 @@ use Kconfig. If your board or shield does not have RGB underglow configured, refer to [Adding RGB Underglow to a Board](#adding-rgb-underglow-to-a-board). -### Modifying the number of LEDs +### Modifying the Number of LEDs A common issue when enabling underglow is that some of the installed LEDs do not illuminate. This can happen when a board's default underglow configuration accounts only for either the downward facing LEDs or the upward facing LEDs under each key. On a split keyboard, a good sign that this may be the problem is that the unilluminated LEDs on each half are symmetrical. @@ -64,7 +64,7 @@ If you have a shield with RGB underglow, you must add a `boards/` directory with Inside the `boards/` folder, you define a `.overlay` for each different board. For example, the Kyria shield has a `boards/nice_nano.overlay` file that defines the RGB underglow for the `nice_nano` board specifically. -### nRF52-based boards +### nRF52-Based Boards With nRF52 boards, you can just use `&spi3` and define the pins you want to use. @@ -128,7 +128,7 @@ If your board/shield uses LEDs that require the data sent in a different order, ::: -### Other boards +### Other Boards For other boards, you must select an SPI definition that has the `MOSI` pin as your data pin going to your LED strip. diff --git a/docs/docs/intro.md b/docs/docs/intro.md index da01e8297e7..e11eda71f02 100644 --- a/docs/docs/intro.md +++ b/docs/docs/intro.md @@ -46,7 +46,7 @@ ZMK is currently missing some features found in other popular firmware. This tab [^2]: Tap-Dances are limited to single and double-tap on BlueMicro [^1]: OLEDs are currently proof of concept in ZMK. -## Code Of Conduct +## Code of Conduct Please note that this project is released with a [Contributor Code of Conduct](https://www.contributor-covenant.org/version/2/0/code_of_conduct/). diff --git a/docs/docs/user-setup.mdx b/docs/docs/user-setup.mdx index 78d4362857e..f6cb5eb2717 100644 --- a/docs/docs/user-setup.mdx +++ b/docs/docs/user-setup.mdx @@ -177,9 +177,9 @@ push the initial commit. ::: -## Installing The Firmware +## Installing the Firmware -### Download The Archive +### Download the Archive Once the setup script is complete and the new user config repository has been pushed, GitHub will automatically run the action to build your keyboard firmware files. You can view the actions by clicking on the "Actions" tab on your GitHub repository. From a080b5287f9814d90166be523c3cd2969f4d69a3 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 17 Jun 2024 15:39:32 -0600 Subject: [PATCH 107/134] refactor: Remove static CDC ACM logging nodes. * To avoid spurious CDC ACM instances when usint CDC ACM for something other than logging, move to the approach used by Zephyr of using a snippet to redirect console output to a CDC ACM node added by the snippet. Remove all the existing static CDC ACM nodes. * Add new `zmk-usb-logging` snippet that mirrors the upstream `cdc-acm-logging` snippet, but still does our extra USB logging configuration. * Updated logging docs accordingly. Co-authored-by: Cem Aksoylar --- app/boards/01space_rp2040_042lcd.overlay | 2 - app/boards/adafruit_kb2040.overlay | 2 - app/boards/adafruit_qt_py_rp2040.overlay | 2 - app/boards/arm/adv360pro/adv360pro.dtsi | 6 +- app/boards/arm/bdn9/bdn9_rev2.dts | 6 +- .../arm/bluemicro840/bluemicro840_v1.dts | 6 +- app/boards/arm/bt60/bt60.dtsi | 6 +- app/boards/arm/ckp/ckp.dtsi | 2 +- app/boards/arm/corneish_zen/corneish_zen.dtsi | 6 +- app/boards/arm/dz60rgb/dz60rgb_rev1.dts | 6 +- app/boards/arm/ferris/ferris_rev02.dts | 6 +- app/boards/arm/glove80/glove80.dtsi | 6 +- .../arm/kbdfans_tofu65/kbdfans_tofu65_v2.dts | 7 +- app/boards/arm/mikoto/mikoto_520.dts | 6 +- app/boards/arm/nice60/nice60.dts | 6 +- app/boards/arm/nice_nano/nice_nano.dtsi | 6 +- app/boards/arm/nrf52840_m2/nrf52840_m2.dts | 6 +- app/boards/arm/nrfmicro/nrfmicro_11.dts | 6 +- .../arm/nrfmicro/nrfmicro_11_flipped.dts | 6 +- app/boards/arm/nrfmicro/nrfmicro_13.dts | 6 +- app/boards/arm/nrfmicro/nrfmicro_13_52833.dts | 6 +- app/boards/arm/pillbug/pillbug.dts | 6 +- app/boards/arm/planck/planck_rev6.dts | 6 +- app/boards/arm/preonic/preonic_rev3.dts | 6 +- app/boards/arm/proton_c/proton_c.dts | 6 +- app/boards/arm/puchi_ble/puchi_ble_v1.dts | 6 +- app/boards/arm/s40nc/s40nc.dts | 6 +- app/boards/boardsource_blok.overlay | 2 - app/boards/rpi_pico.overlay | 8 --- app/boards/seeeduino_xiao.overlay | 18 ----- app/boards/seeeduino_xiao_ble.overlay | 7 -- app/boards/seeeduino_xiao_rp2040.overlay | 2 - app/boards/sparkfun_pro_micro_rp2040.overlay | 2 - app/boards/usb_console.dtsi | 19 ------ docs/docs/development/usb-logging.mdx | 67 +++++++++++-------- 35 files changed, 62 insertions(+), 210 deletions(-) delete mode 100644 app/boards/rpi_pico.overlay delete mode 100644 app/boards/seeeduino_xiao.overlay delete mode 100644 app/boards/usb_console.dtsi diff --git a/app/boards/01space_rp2040_042lcd.overlay b/app/boards/01space_rp2040_042lcd.overlay index d89e53f4a8e..b5d2cdb2fd1 100644 --- a/app/boards/01space_rp2040_042lcd.overlay +++ b/app/boards/01space_rp2040_042lcd.overlay @@ -4,6 +4,4 @@ * SPDX-License-Identifier: MIT */ -#include "usb_console.dtsi" - &xiao_serial { status = "disabled"; }; diff --git a/app/boards/adafruit_kb2040.overlay b/app/boards/adafruit_kb2040.overlay index b14e0d04d47..72b3adcaf41 100644 --- a/app/boards/adafruit_kb2040.overlay +++ b/app/boards/adafruit_kb2040.overlay @@ -4,6 +4,4 @@ * SPDX-License-Identifier: MIT */ -#include "usb_console.dtsi" - &pro_micro_serial { status = "disabled"; }; diff --git a/app/boards/adafruit_qt_py_rp2040.overlay b/app/boards/adafruit_qt_py_rp2040.overlay index d89e53f4a8e..b5d2cdb2fd1 100644 --- a/app/boards/adafruit_qt_py_rp2040.overlay +++ b/app/boards/adafruit_qt_py_rp2040.overlay @@ -4,6 +4,4 @@ * SPDX-License-Identifier: MIT */ -#include "usb_console.dtsi" - &xiao_serial { status = "disabled"; }; diff --git a/app/boards/arm/adv360pro/adv360pro.dtsi b/app/boards/arm/adv360pro/adv360pro.dtsi index c64d0d3f77e..ea68624b981 100644 --- a/app/boards/arm/adv360pro/adv360pro.dtsi +++ b/app/boards/arm/adv360pro/adv360pro.dtsi @@ -21,7 +21,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,kscan = &kscan0; zmk,backlight = &backlight; zmk,battery = &vbatt; @@ -90,11 +89,8 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &flash0 { diff --git a/app/boards/arm/bdn9/bdn9_rev2.dts b/app/boards/arm/bdn9/bdn9_rev2.dts index 6e15408a2cd..2189530d4d2 100644 --- a/app/boards/arm/bdn9/bdn9_rev2.dts +++ b/app/boards/arm/bdn9/bdn9_rev2.dts @@ -16,7 +16,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,kscan = &kscan; zmk,underglow = &led_strip; }; @@ -106,13 +105,10 @@ apb1-prescaler = <1>; }; -&usb { +zephyr_udc0: &usb { status = "okay"; pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>; pinctrl-names = "default"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &rtc { diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1.dts b/app/boards/arm/bluemicro840/bluemicro840_v1.dts index aabdf310a28..84d3ebaec99 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1.dts +++ b/app/boards/arm/bluemicro840/bluemicro840_v1.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -82,11 +81,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/bt60/bt60.dtsi b/app/boards/arm/bt60/bt60.dtsi index 655d25769a7..83ff3f04aa9 100644 --- a/app/boards/arm/bt60/bt60.dtsi +++ b/app/boards/arm/bt60/bt60.dtsi @@ -16,7 +16,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; zmk,kscan = &kscan0; zmk,matrix-transform = &default_transform; @@ -70,11 +69,8 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/ckp/ckp.dtsi b/app/boards/arm/ckp/ckp.dtsi index 4142622ac86..b127cabc71a 100644 --- a/app/boards/arm/ckp/ckp.dtsi +++ b/app/boards/arm/ckp/ckp.dtsi @@ -142,7 +142,7 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; }; diff --git a/app/boards/arm/corneish_zen/corneish_zen.dtsi b/app/boards/arm/corneish_zen/corneish_zen.dtsi index 881fadb0764..dbd6f93e805 100644 --- a/app/boards/arm/corneish_zen/corneish_zen.dtsi +++ b/app/boards/arm/corneish_zen/corneish_zen.dtsi @@ -20,7 +20,6 @@ zephyr,flash = &flash0; zmk,kscan = &kscan0; zmk,display = &epd; - zephyr,console = &cdc_acm_uart; zmk,matrix-transform = &default_transform; }; @@ -76,11 +75,8 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &flash0 { diff --git a/app/boards/arm/dz60rgb/dz60rgb_rev1.dts b/app/boards/arm/dz60rgb/dz60rgb_rev1.dts index 4e1d4b66579..b8fac4e2807 100644 --- a/app/boards/arm/dz60rgb/dz60rgb_rev1.dts +++ b/app/boards/arm/dz60rgb/dz60rgb_rev1.dts @@ -16,7 +16,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,kscan = &kscan0; zmk,matrix-transform = &default_transform; }; @@ -65,11 +64,8 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,5) RC( }; -&usb { +zephyr_udc0: &usb { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &flash0 { diff --git a/app/boards/arm/ferris/ferris_rev02.dts b/app/boards/arm/ferris/ferris_rev02.dts index 4fecd280eec..a0e28f03833 100644 --- a/app/boards/arm/ferris/ferris_rev02.dts +++ b/app/boards/arm/ferris/ferris_rev02.dts @@ -17,7 +17,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,kscan = &kscan; zmk,matrix-transform = &transform; /* TODO: Enable once we support the IC for underglow @@ -110,14 +109,11 @@ }; }; -&usb { +zephyr_udc0: &usb { status = "okay"; pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>; pinctrl-names = "default"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &clk_hsi { diff --git a/app/boards/arm/glove80/glove80.dtsi b/app/boards/arm/glove80/glove80.dtsi index 4803488b078..d51a73ac066 100644 --- a/app/boards/arm/glove80/glove80.dtsi +++ b/app/boards/arm/glove80/glove80.dtsi @@ -15,7 +15,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; }; default_transform: keymap_transform_0 { @@ -59,11 +58,8 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &flash0 { diff --git a/app/boards/arm/kbdfans_tofu65/kbdfans_tofu65_v2.dts b/app/boards/arm/kbdfans_tofu65/kbdfans_tofu65_v2.dts index 18c92671d94..60ba1da0143 100644 --- a/app/boards/arm/kbdfans_tofu65/kbdfans_tofu65_v2.dts +++ b/app/boards/arm/kbdfans_tofu65/kbdfans_tofu65_v2.dts @@ -13,8 +13,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; - zephyr,shell-uart = &cdc_acm_uart; zephyr,code-partition = &code_partition; zmk,kscan = &kscan0; zmk,matrix-transform = &default_transform; @@ -108,11 +106,8 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,6) RC(4,8) RC(4,9) }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/mikoto/mikoto_520.dts b/app/boards/arm/mikoto/mikoto_520.dts index a6ca50812f8..3ea48cd9911 100644 --- a/app/boards/arm/mikoto/mikoto_520.dts +++ b/app/boards/arm/mikoto/mikoto_520.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -81,11 +80,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/nice60/nice60.dts b/app/boards/arm/nice60/nice60.dts index d1b9f9927cc..4eefbb9d8f3 100644 --- a/app/boards/arm/nice60/nice60.dts +++ b/app/boards/arm/nice60/nice60.dts @@ -20,7 +20,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; zmk,kscan = &kscan0; zmk,matrix-transform = &default_transform; @@ -129,11 +128,8 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,5) R }; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &flash0 { diff --git a/app/boards/arm/nice_nano/nice_nano.dtsi b/app/boards/arm/nice_nano/nice_nano.dtsi index 41770dd310e..839845c8e8c 100644 --- a/app/boards/arm/nice_nano/nice_nano.dtsi +++ b/app/boards/arm/nice_nano/nice_nano.dtsi @@ -16,7 +16,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; }; leds { @@ -65,11 +64,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/nrf52840_m2/nrf52840_m2.dts b/app/boards/arm/nrf52840_m2/nrf52840_m2.dts index 85e9ce2107f..39569f0b760 100644 --- a/app/boards/arm/nrf52840_m2/nrf52840_m2.dts +++ b/app/boards/arm/nrf52840_m2/nrf52840_m2.dts @@ -15,7 +15,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -57,12 +56,9 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { compatible = "nordic,nrf-usbd"; status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_11.dts b/app/boards/arm/nrfmicro/nrfmicro_11.dts index 04368ab8741..b80ed4c62c1 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_11.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_11.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; }; leds { @@ -69,11 +68,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts b/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts index 600935aa0a6..7b89b62f88a 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_11_flipped.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; }; leds { @@ -69,11 +68,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13.dts b/app/boards/arm/nrfmicro/nrfmicro_13.dts index 716e5b181dd..0cb22e63ca9 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -81,11 +80,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts b/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts index f57c413da8b..866276bbec4 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13_52833.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -81,11 +80,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/pillbug/pillbug.dts b/app/boards/arm/pillbug/pillbug.dts index c30d306e275..cf4f62fc98b 100644 --- a/app/boards/arm/pillbug/pillbug.dts +++ b/app/boards/arm/pillbug/pillbug.dts @@ -18,7 +18,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -83,11 +82,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/planck/planck_rev6.dts b/app/boards/arm/planck/planck_rev6.dts index 5b8e16b2efe..85b751400a1 100644 --- a/app/boards/arm/planck/planck_rev6.dts +++ b/app/boards/arm/planck/planck_rev6.dts @@ -16,7 +16,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,kscan = &kscan0; zmk,matrix-transform = &layout_grid_transform; }; @@ -96,13 +95,10 @@ layout_2x2u_transform: }; }; -&usb { +zephyr_udc0: &usb { pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>; pinctrl-names = "default"; status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &clk_hse { diff --git a/app/boards/arm/preonic/preonic_rev3.dts b/app/boards/arm/preonic/preonic_rev3.dts index d14355dac93..79f88c33b0a 100644 --- a/app/boards/arm/preonic/preonic_rev3.dts +++ b/app/boards/arm/preonic/preonic_rev3.dts @@ -17,7 +17,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,kscan = &kscan0; zmk,matrix-transform = &layout_grid_transform; }; @@ -90,13 +89,10 @@ }; }; -&usb { +zephyr_udc0: &usb { pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>; pinctrl-names = "default"; status = "okay"; -cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &clk_hse { diff --git a/app/boards/arm/proton_c/proton_c.dts b/app/boards/arm/proton_c/proton_c.dts index 3aad62c8f30..05872b25dde 100644 --- a/app/boards/arm/proton_c/proton_c.dts +++ b/app/boards/arm/proton_c/proton_c.dts @@ -16,7 +16,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart0; }; aliases { @@ -66,13 +65,10 @@ apb2-prescaler = <1>; }; -&usb { +zephyr_udc0: &usb { pinctrl-0 = <&usb_dm_pa11 &usb_dp_pa12>; pinctrl-names = "default"; status = "okay"; - cdc_acm_uart0: cdc_acm_uart0 { - compatible = "zephyr,cdc-acm-uart"; - }; }; &rtc { diff --git a/app/boards/arm/puchi_ble/puchi_ble_v1.dts b/app/boards/arm/puchi_ble/puchi_ble_v1.dts index 05aba8d3780..9f3194e036f 100644 --- a/app/boards/arm/puchi_ble/puchi_ble_v1.dts +++ b/app/boards/arm/puchi_ble/puchi_ble_v1.dts @@ -17,7 +17,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -72,11 +71,8 @@ pinctrl-names = "default", "sleep"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; diff --git a/app/boards/arm/s40nc/s40nc.dts b/app/boards/arm/s40nc/s40nc.dts index a2eb89ea207..4c37030db33 100644 --- a/app/boards/arm/s40nc/s40nc.dts +++ b/app/boards/arm/s40nc/s40nc.dts @@ -16,7 +16,6 @@ zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; zmk,kscan = &kscan0; zmk,matrix-transform = &default_transform; @@ -93,11 +92,8 @@ status = "okay"; }; -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; &flash0 { diff --git a/app/boards/boardsource_blok.overlay b/app/boards/boardsource_blok.overlay index b14e0d04d47..72b3adcaf41 100644 --- a/app/boards/boardsource_blok.overlay +++ b/app/boards/boardsource_blok.overlay @@ -4,6 +4,4 @@ * SPDX-License-Identifier: MIT */ -#include "usb_console.dtsi" - &pro_micro_serial { status = "disabled"; }; diff --git a/app/boards/rpi_pico.overlay b/app/boards/rpi_pico.overlay deleted file mode 100644 index efc8e080f15..00000000000 --- a/app/boards/rpi_pico.overlay +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#include "usb_console.dtsi" - diff --git a/app/boards/seeeduino_xiao.overlay b/app/boards/seeeduino_xiao.overlay deleted file mode 100644 index 285ee4de332..00000000000 --- a/app/boards/seeeduino_xiao.overlay +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2022 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -/ { - chosen { - zephyr,console = &cdc_acm_uart; - }; -}; - -&usb0 { - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; -}; - diff --git a/app/boards/seeeduino_xiao_ble.overlay b/app/boards/seeeduino_xiao_ble.overlay index e0934691d84..f6a608582e6 100644 --- a/app/boards/seeeduino_xiao_ble.overlay +++ b/app/boards/seeeduino_xiao_ble.overlay @@ -7,7 +7,6 @@ / { chosen { - zephyr,console = &cdc_acm_uart; zmk,battery = &vbatt; }; @@ -24,12 +23,6 @@ status = "okay"; }; -&usbd { - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; -}; - &qspi { status = "okay"; pinctrl-0 = <&qspi_default>; diff --git a/app/boards/seeeduino_xiao_rp2040.overlay b/app/boards/seeeduino_xiao_rp2040.overlay index d89e53f4a8e..b5d2cdb2fd1 100644 --- a/app/boards/seeeduino_xiao_rp2040.overlay +++ b/app/boards/seeeduino_xiao_rp2040.overlay @@ -4,6 +4,4 @@ * SPDX-License-Identifier: MIT */ -#include "usb_console.dtsi" - &xiao_serial { status = "disabled"; }; diff --git a/app/boards/sparkfun_pro_micro_rp2040.overlay b/app/boards/sparkfun_pro_micro_rp2040.overlay index b14e0d04d47..72b3adcaf41 100644 --- a/app/boards/sparkfun_pro_micro_rp2040.overlay +++ b/app/boards/sparkfun_pro_micro_rp2040.overlay @@ -4,6 +4,4 @@ * SPDX-License-Identifier: MIT */ -#include "usb_console.dtsi" - &pro_micro_serial { status = "disabled"; }; diff --git a/app/boards/usb_console.dtsi b/app/boards/usb_console.dtsi deleted file mode 100644 index adf3bd19bf1..00000000000 --- a/app/boards/usb_console.dtsi +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - - -/ { - chosen { - zephyr,console = &cdc_acm_uart; - }; -}; - -&usbd { - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; -}; - diff --git a/docs/docs/development/usb-logging.mdx b/docs/docs/development/usb-logging.mdx index cb9508a2be0..b7c3d233820 100644 --- a/docs/docs/development/usb-logging.mdx +++ b/docs/docs/development/usb-logging.mdx @@ -18,26 +18,33 @@ It is recommended to only enable logging when needed, and not leaving it on by d ::: -## Kconfig +## USB Logging Snippet -The `CONFIG_ZMK_USB_LOGGING` Kconfig enables USB logging. This can be set at the keyboard level, typically in the `config/.conf` -file if you are using a [user config repository](user-setup.mdx). It can also be enabled at the ZMK level using the `app/prj.conf` file, or other -search locations described in the [configuration overview](config/index.md#config-file-locations). +The `zmk-usb-logging` snippet is used to enable logging. -Logging can be further configured using Kconfig described in [the Zephyr documentation](https://docs.zephyrproject.org/3.5.0/services/logging/index.html). -For instance, setting `CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS` to a large value such as `8000` might help catch issues that happen near keyboard -boot, before you can connect to view the logs. +If using GitHub Actions to build your firmware, enabling logging +requires adding a `snippet: zmk-usb-logging` to your `build.yaml` file for any build you want logging enabled, e.g. -:::note -In Github Actions, you can check the ` Kconfig file` step output to verify the options above have been enabled -for you successfully. -::: +```yaml +--- +include: + - board: nice_nano_v2 + shield: corne_left + snippet: zmk-usb-logging +``` -```ini -# Turn on logging, and set ZMK logging to debug output -CONFIG_ZMK_USB_LOGGING=y +When building locally, the `-S`/`--snippet` flag can be passed to `west build` to enable the snippet, e.g. + +```sh +west build -b nice_nano_v2 -S zmk-usb-logging -- -DSHIELD="corne_left" ``` +### Additional Config + +Logging can be further configured using Kconfig described in [the Zephyr documentation](https://docs.zephyrproject.org/3.5.0/services/logging/index.html). +For instance, setting `CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS` to a large value such as `8000` might help catch issues that happen near keyboard +boot, before you can connect to view the logs. + ## Viewing Logs After flashing the updated ZMK image, the board should expose a USB CDC ACM device that you can connect to and view the logs. @@ -89,27 +96,29 @@ From there, you should see the various log messages from ZMK and Zephyr, dependi Standard boards such as the nice!nano and Seeeduino XIAO family have the necessary configuration for logging already added, however if you are developing your own standalone board you may wish to add the ability to use USB logging in the future. -To add USB logging to a board you need to define the USB CDC ACM device that the serial output gets piped to, as well as adding the console in the `chosen` node inside `.dts`. +To do so, you need to follow the upstream Zephyr [`cdc-acm-console` snippet requirements](https://docs.zephyrproject.org/3.5.0/snippets/cdc-acm-console/README.html#requirements) steps. -Inside the USB device (`&usbd`), add the CDC ACM node: +Usually, this just requires ensuring that the USB node has been tagged with the `zephyr_udc0` label, e.g. ```dts -&usbd { +zephyr_udc0: &usbd { status = "okay"; - cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - }; }; ``` -Then you can add the `zephyr,console` binding in the `chosen` node: +## Enabling Logging on Older Boards -```dts -/ { - chosen { - ... - zephyr,console = &cdc_acm_uart; - }; - ... -}; +Previously, enabling logging required setting the `CONFIG_ZMK_USB_LOGGING` Kconfig symbol. If for whatever reason +a custom board definition does not support the new `zmk-usb-logging` snippet, you can try setting this symbol at the keyboard level, typically in the `config/.conf` +file if you are using a [user config repository](user-setup.mdx). It can also be enabled at the ZMK level using the `app/prj.conf` file, or other +search locations described in the [configuration overview](config/index.md#config-file-locations). + +:::note +In Github Actions, you can check the ` Kconfig file` step output to verify the options above have been enabled +for you successfully. +::: + +```ini +# Turn on logging, and set ZMK logging to debug output +CONFIG_ZMK_USB_LOGGING=y ``` From 7be955ff7285a1003455b4d573e843ef713ac584 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 21 Jun 2024 13:12:13 -0600 Subject: [PATCH 108/134] fix(usb): Ensure USB init is last * To avoid USB init issues due to other initialization disrupting USB setup, move USB setup to a lower priority. --- app/Kconfig | 6 +++++- app/src/usb_hid.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 5aedd9d9030..8f690175ddc 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -490,7 +490,11 @@ if USB_DEVICE_STACK config ZMK_USB_INIT_PRIORITY int "USB Init Priority" - default 50 + default 94 + +config ZMK_USB_HID_INIT_PRIORITY + int "USB HID Init Priority" + default 95 #USB endif diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index cd3ef920391..9db10952c95 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -195,4 +195,4 @@ static int zmk_usb_hid_init(void) { return 0; } -SYS_INIT(zmk_usb_hid_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); +SYS_INIT(zmk_usb_hid_init, APPLICATION, CONFIG_ZMK_USB_HID_INIT_PRIORITY); From 7cdf1e42ea1ef7e1f90b44096145f9bc7a95b66d Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 24 Jun 2024 10:48:21 -0600 Subject: [PATCH 109/134] fix: Actually add the `zmk-usb-logging` snippet. * D'oh. --- app/snippets/zmk-usb-logging/snippet.yml | 4 ++++ .../zmk-usb-logging/zmk-usb-logging.conf | 2 ++ .../zmk-usb-logging/zmk-usb-logging.overlay | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 app/snippets/zmk-usb-logging/snippet.yml create mode 100644 app/snippets/zmk-usb-logging/zmk-usb-logging.conf create mode 100644 app/snippets/zmk-usb-logging/zmk-usb-logging.overlay diff --git a/app/snippets/zmk-usb-logging/snippet.yml b/app/snippets/zmk-usb-logging/snippet.yml new file mode 100644 index 00000000000..8f218085008 --- /dev/null +++ b/app/snippets/zmk-usb-logging/snippet.yml @@ -0,0 +1,4 @@ +name: zmk-usb-logging +append: + EXTRA_CONF_FILE: zmk-usb-logging.conf + EXTRA_DTC_OVERLAY_FILE: zmk-usb-logging.overlay diff --git a/app/snippets/zmk-usb-logging/zmk-usb-logging.conf b/app/snippets/zmk-usb-logging/zmk-usb-logging.conf new file mode 100644 index 00000000000..57893df5f9d --- /dev/null +++ b/app/snippets/zmk-usb-logging/zmk-usb-logging.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_USB_LOGGING=y + diff --git a/app/snippets/zmk-usb-logging/zmk-usb-logging.overlay b/app/snippets/zmk-usb-logging/zmk-usb-logging.overlay new file mode 100644 index 00000000000..5ceda583f49 --- /dev/null +++ b/app/snippets/zmk-usb-logging/zmk-usb-logging.overlay @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/ { + chosen { + zephyr,console = &snippet_zmk_usb_logging_uart; + zephyr,shell-uart = &snippet_zmk_usb_logging_uart; + }; +}; + +&zephyr_udc0 { + snippet_zmk_usb_logging_uart: snippet_zmk_usb_logging_uart { + compatible = "zephyr,cdc-acm-uart"; + }; +}; From 03099b04b68bf65bc455b3b7ae921261ed47f3a7 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 27 Mar 2024 12:27:49 -0700 Subject: [PATCH 110/134] feat(behaviors): Add behavior metadata information. * For upcoming ZMK studio work, make a set of rich metadata available to provide a friendly name for a behavior, and allow super flexible descriptions of the parameters the behaviors take. * Add ability to validate a zmk_behavior_binding against the behavior metadata available. --- app/Kconfig.behaviors | 8 +- app/dts/behaviors/backlight.dtsi | 1 + app/dts/behaviors/bluetooth.dtsi | 1 + app/dts/behaviors/caps_word.dtsi | 1 + app/dts/behaviors/ext_power.dtsi | 1 + app/dts/behaviors/gresc.dtsi | 1 + app/dts/behaviors/key_press.dtsi | 1 + app/dts/behaviors/key_repeat.dtsi | 1 + app/dts/behaviors/key_toggle.dtsi | 1 + app/dts/behaviors/layer_tap.dtsi | 1 + app/dts/behaviors/mod_tap.dtsi | 1 + app/dts/behaviors/momentary_layer.dtsi | 1 + app/dts/behaviors/none.dtsi | 1 + app/dts/behaviors/outputs.dtsi | 1 + app/dts/behaviors/reset.dtsi | 2 + app/dts/behaviors/rgb_underglow.dtsi | 1 + app/dts/behaviors/sticky_key.dtsi | 2 + app/dts/behaviors/to_layer.dtsi | 1 + app/dts/behaviors/toggle_layer.dtsi | 1 + app/dts/behaviors/transparent.dtsi | 1 + .../bindings/behaviors/behavior-metadata.yaml | 6 + app/dts/bindings/behaviors/one_param.yaml | 2 + app/dts/bindings/behaviors/two_param.yaml | 2 + app/dts/bindings/behaviors/zero_param.yaml | 2 + app/include/drivers/behavior.h | 158 +++++++++++++++++- app/include/zmk/behavior.h | 2 +- app/src/behavior.c | 146 ++++++++++++++++ app/src/behaviors/behavior_backlight.c | 79 +++++++++ app/src/behaviors/behavior_bt.c | 71 ++++++++ app/src/behaviors/behavior_hold_tap.c | 58 ++++++- app/src/behaviors/behavior_key_press.c | 28 +++- app/src/behaviors/behavior_key_toggle.c | 25 +++ app/src/behaviors/behavior_macro.c | 95 +++++++++++ app/src/behaviors/behavior_momentary_layer.c | 28 +++- app/src/behaviors/behavior_none.c | 3 + app/src/behaviors/behavior_outputs.c | 39 +++++ app/src/behaviors/behavior_rgb_underglow.c | 116 +++++++++++++ app/src/behaviors/behavior_soft_off.c | 3 + app/src/behaviors/behavior_sticky_key.c | 34 +++- app/src/behaviors/behavior_tap_dance.c | 3 + app/src/behaviors/behavior_to_layer.c | 25 +++ app/src/behaviors/behavior_toggle_layer.c | 25 +++ 42 files changed, 965 insertions(+), 14 deletions(-) create mode 100644 app/dts/bindings/behaviors/behavior-metadata.yaml diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index c9754bf7d83..c6cc45f3b87 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,6 +1,12 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT +config ZMK_BEHAVIOR_METADATA + bool "Metadata" + help + Enabling this option adds APIs for documenting and fetching + metadata describing a behaviors name, and supported parameters. + config ZMK_BEHAVIOR_KEY_TOGGLE bool default y @@ -35,4 +41,4 @@ config ZMK_BEHAVIOR_SENSOR_ROTATE_VAR config ZMK_BEHAVIOR_MACRO bool default y - depends on DT_HAS_ZMK_BEHAVIOR_MACRO_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_ONE_PARAM_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_TWO_PARAM_ENABLED \ No newline at end of file + depends on DT_HAS_ZMK_BEHAVIOR_MACRO_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_ONE_PARAM_ENABLED || DT_HAS_ZMK_BEHAVIOR_MACRO_TWO_PARAM_ENABLED diff --git a/app/dts/behaviors/backlight.dtsi b/app/dts/behaviors/backlight.dtsi index 54c83ff44c1..dd045effed3 100644 --- a/app/dts/behaviors/backlight.dtsi +++ b/app/dts/behaviors/backlight.dtsi @@ -10,6 +10,7 @@ /omit-if-no-ref/ bl: bcklight { compatible = "zmk,behavior-backlight"; #binding-cells = <2>; + display-name = "Backlight"; }; }; }; diff --git a/app/dts/behaviors/bluetooth.dtsi b/app/dts/behaviors/bluetooth.dtsi index 40557b7a28c..bece156f8fb 100644 --- a/app/dts/behaviors/bluetooth.dtsi +++ b/app/dts/behaviors/bluetooth.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ bt: bluetooth { compatible = "zmk,behavior-bluetooth"; #binding-cells = <2>; + display-name = "Bluetooth"; }; }; }; diff --git a/app/dts/behaviors/caps_word.dtsi b/app/dts/behaviors/caps_word.dtsi index 795fbc08439..05431bd8db2 100644 --- a/app/dts/behaviors/caps_word.dtsi +++ b/app/dts/behaviors/caps_word.dtsi @@ -12,6 +12,7 @@ compatible = "zmk,behavior-caps-word"; #binding-cells = <0>; continue-list = ; + display-name = "Caps Word"; }; }; }; diff --git a/app/dts/behaviors/ext_power.dtsi b/app/dts/behaviors/ext_power.dtsi index 2ae1daf84a8..08113f94bbe 100644 --- a/app/dts/behaviors/ext_power.dtsi +++ b/app/dts/behaviors/ext_power.dtsi @@ -10,6 +10,7 @@ ext_power: extpower { compatible = "zmk,behavior-ext-power"; #binding-cells = <1>; + display-name = "External Power"; }; }; }; diff --git a/app/dts/behaviors/gresc.dtsi b/app/dts/behaviors/gresc.dtsi index 59a7329178f..2643a383d81 100644 --- a/app/dts/behaviors/gresc.dtsi +++ b/app/dts/behaviors/gresc.dtsi @@ -13,6 +13,7 @@ #binding-cells = <0>; bindings = <&kp ESC>, <&kp GRAVE>; mods = <(MOD_LGUI|MOD_LSFT|MOD_RGUI|MOD_RSFT)>; + display-name = "Grave/Escape"; }; }; }; diff --git a/app/dts/behaviors/key_press.dtsi b/app/dts/behaviors/key_press.dtsi index ddaf7eed374..2435699b6ab 100644 --- a/app/dts/behaviors/key_press.dtsi +++ b/app/dts/behaviors/key_press.dtsi @@ -10,6 +10,7 @@ /omit-if-no-ref/ cp: kp: key_press { compatible = "zmk,behavior-key-press"; #binding-cells = <1>; + display-name = "Key Press"; }; }; }; diff --git a/app/dts/behaviors/key_repeat.dtsi b/app/dts/behaviors/key_repeat.dtsi index 88910f6271c..cd5d3771dcb 100644 --- a/app/dts/behaviors/key_repeat.dtsi +++ b/app/dts/behaviors/key_repeat.dtsi @@ -12,6 +12,7 @@ compatible = "zmk,behavior-key-repeat"; #binding-cells = <0>; usage-pages = ; + display-name = "Key Repeat"; }; }; }; diff --git a/app/dts/behaviors/key_toggle.dtsi b/app/dts/behaviors/key_toggle.dtsi index a3e3f36f270..a7b66aab1af 100644 --- a/app/dts/behaviors/key_toggle.dtsi +++ b/app/dts/behaviors/key_toggle.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ kt: key_toggle { compatible = "zmk,behavior-key-toggle"; #binding-cells = <1>; + display-name = "Key Toggle"; }; }; }; diff --git a/app/dts/behaviors/layer_tap.dtsi b/app/dts/behaviors/layer_tap.dtsi index dc953e9358b..2858bf17bc5 100644 --- a/app/dts/behaviors/layer_tap.dtsi +++ b/app/dts/behaviors/layer_tap.dtsi @@ -12,6 +12,7 @@ flavor = "tap-preferred"; tapping-term-ms = <200>; bindings = <&mo>, <&kp>; + display-name = "Layer-Tap"; }; }; }; diff --git a/app/dts/behaviors/mod_tap.dtsi b/app/dts/behaviors/mod_tap.dtsi index 38bb34fe5c4..0b46f77e739 100644 --- a/app/dts/behaviors/mod_tap.dtsi +++ b/app/dts/behaviors/mod_tap.dtsi @@ -12,6 +12,7 @@ flavor = "hold-preferred"; tapping-term-ms = <200>; bindings = <&kp>, <&kp>; + display-name = "Mod-Tap"; }; }; }; diff --git a/app/dts/behaviors/momentary_layer.dtsi b/app/dts/behaviors/momentary_layer.dtsi index 6d85165dbb3..cae08d5f101 100644 --- a/app/dts/behaviors/momentary_layer.dtsi +++ b/app/dts/behaviors/momentary_layer.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ mo: momentary_layer { compatible = "zmk,behavior-momentary-layer"; #binding-cells = <1>; + display-name = "Momentary Layer"; }; }; }; diff --git a/app/dts/behaviors/none.dtsi b/app/dts/behaviors/none.dtsi index 13d056f0cf2..a9a820c30b5 100644 --- a/app/dts/behaviors/none.dtsi +++ b/app/dts/behaviors/none.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ none: none { compatible = "zmk,behavior-none"; #binding-cells = <0>; + display-name = "None"; }; }; }; diff --git a/app/dts/behaviors/outputs.dtsi b/app/dts/behaviors/outputs.dtsi index f7737196719..3047852adce 100644 --- a/app/dts/behaviors/outputs.dtsi +++ b/app/dts/behaviors/outputs.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ out: outputs { compatible = "zmk,behavior-outputs"; #binding-cells = <1>; + display-name = "Output Selection"; }; }; }; diff --git a/app/dts/behaviors/reset.dtsi b/app/dts/behaviors/reset.dtsi index e407b107b90..2aa41d7d6e8 100644 --- a/app/dts/behaviors/reset.dtsi +++ b/app/dts/behaviors/reset.dtsi @@ -12,6 +12,7 @@ sys_reset: sysreset { compatible = "zmk,behavior-reset"; #binding-cells = <0>; + display-name = "Reset"; }; // Behavior can be invoked on peripherals, so name must be <= 8 characters. @@ -19,6 +20,7 @@ compatible = "zmk,behavior-reset"; type = ; #binding-cells = <0>; + display-name = "Bootloader"; }; }; }; diff --git a/app/dts/behaviors/rgb_underglow.dtsi b/app/dts/behaviors/rgb_underglow.dtsi index 969518a6ff3..0764005872d 100644 --- a/app/dts/behaviors/rgb_underglow.dtsi +++ b/app/dts/behaviors/rgb_underglow.dtsi @@ -10,6 +10,7 @@ rgb_ug: rgb_ug { compatible = "zmk,behavior-rgb-underglow"; #binding-cells = <2>; + display-name = "Underglow"; }; }; }; diff --git a/app/dts/behaviors/sticky_key.dtsi b/app/dts/behaviors/sticky_key.dtsi index c8973d4df2c..382a7254e7b 100644 --- a/app/dts/behaviors/sticky_key.dtsi +++ b/app/dts/behaviors/sticky_key.dtsi @@ -12,6 +12,7 @@ release-after-ms = <1000>; bindings = <&kp>; ignore-modifiers; + display-name = "Sticky Key"; }; /omit-if-no-ref/ sl: sticky_layer { compatible = "zmk,behavior-sticky-key"; @@ -19,6 +20,7 @@ release-after-ms = <1000>; bindings = <&mo>; quick-release; + display-name = "Sticky Layer"; }; }; diff --git a/app/dts/behaviors/to_layer.dtsi b/app/dts/behaviors/to_layer.dtsi index 904f023da53..3c740209cb1 100644 --- a/app/dts/behaviors/to_layer.dtsi +++ b/app/dts/behaviors/to_layer.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ to: to_layer { compatible = "zmk,behavior-to-layer"; #binding-cells = <1>; + display-name = "To Layer"; }; }; }; diff --git a/app/dts/behaviors/toggle_layer.dtsi b/app/dts/behaviors/toggle_layer.dtsi index 05f2988e08c..ea9b25b7c1d 100644 --- a/app/dts/behaviors/toggle_layer.dtsi +++ b/app/dts/behaviors/toggle_layer.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ tog: toggle_layer { compatible = "zmk,behavior-toggle-layer"; #binding-cells = <1>; + display-name = "Toggle Layer"; }; }; }; diff --git a/app/dts/behaviors/transparent.dtsi b/app/dts/behaviors/transparent.dtsi index 3586f02afab..03ec36a64e8 100644 --- a/app/dts/behaviors/transparent.dtsi +++ b/app/dts/behaviors/transparent.dtsi @@ -9,6 +9,7 @@ /omit-if-no-ref/ trans: transparent { compatible = "zmk,behavior-transparent"; #binding-cells = <0>; + display-name = "Transparent"; }; }; }; diff --git a/app/dts/bindings/behaviors/behavior-metadata.yaml b/app/dts/bindings/behaviors/behavior-metadata.yaml new file mode 100644 index 00000000000..3a758ba3e22 --- /dev/null +++ b/app/dts/bindings/behaviors/behavior-metadata.yaml @@ -0,0 +1,6 @@ +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT + +properties: + display-name: + type: string diff --git a/app/dts/bindings/behaviors/one_param.yaml b/app/dts/bindings/behaviors/one_param.yaml index 9a503e8a815..fa4c2dc0b44 100644 --- a/app/dts/bindings/behaviors/one_param.yaml +++ b/app/dts/bindings/behaviors/one_param.yaml @@ -1,6 +1,8 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT +include: behavior-metadata.yaml + properties: label: type: string diff --git a/app/dts/bindings/behaviors/two_param.yaml b/app/dts/bindings/behaviors/two_param.yaml index 4f342301bb3..af9618e1624 100644 --- a/app/dts/bindings/behaviors/two_param.yaml +++ b/app/dts/bindings/behaviors/two_param.yaml @@ -1,6 +1,8 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT +include: behavior-metadata.yaml + properties: label: type: string diff --git a/app/dts/bindings/behaviors/zero_param.yaml b/app/dts/bindings/behaviors/zero_param.yaml index 79d0dcaed3f..deed5a1218b 100644 --- a/app/dts/bindings/behaviors/zero_param.yaml +++ b/app/dts/bindings/behaviors/zero_param.yaml @@ -1,6 +1,8 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT +include: behavior-metadata.yaml + properties: label: type: string diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h index 3936da5e4be..3dd6e0623f7 100644 --- a/app/include/drivers/behavior.h +++ b/app/include/drivers/behavior.h @@ -23,6 +23,39 @@ * (Internal use only.) */ +struct behavior_parameter_value_metadata { + char *display_name; + + union { + uint32_t value; + struct { + int32_t min; + int32_t max; + } range; + }; + + enum { + BEHAVIOR_PARAMETER_VALUE_TYPE_NIL = 0, + BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE = 1, + BEHAVIOR_PARAMETER_VALUE_TYPE_RANGE = 2, + BEHAVIOR_PARAMETER_VALUE_TYPE_HID_USAGE = 3, + BEHAVIOR_PARAMETER_VALUE_TYPE_LAYER_INDEX = 4, + } type; +}; + +struct behavior_parameter_metadata_set { + size_t param1_values_len; + const struct behavior_parameter_value_metadata *param1_values; + + size_t param2_values_len; + const struct behavior_parameter_value_metadata *param2_values; +}; + +struct behavior_parameter_metadata { + size_t sets_len; + const struct behavior_parameter_metadata_set *sets; +}; + enum behavior_sensor_binding_process_mode { BEHAVIOR_SENSOR_BINDING_PROCESS_MODE_TRIGGER, BEHAVIOR_SENSOR_BINDING_PROCESS_MODE_DISCARD, @@ -37,6 +70,10 @@ typedef int (*behavior_sensor_keymap_binding_accept_data_callback_t)( struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event, const struct zmk_sensor_config *sensor_config, size_t channel_data_size, const struct zmk_sensor_channel_data channel_data[channel_data_size]); +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +typedef int (*behavior_get_parameter_metadata_t)( + const struct device *behavior, struct behavior_parameter_metadata *param_metadata); +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) enum behavior_locality { BEHAVIOR_LOCALITY_CENTRAL, @@ -51,23 +88,54 @@ __subsystem struct behavior_driver_api { behavior_keymap_binding_callback_t binding_released; behavior_sensor_keymap_binding_accept_data_callback_t sensor_binding_accept_data; behavior_sensor_keymap_binding_process_callback_t sensor_binding_process; +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + behavior_get_parameter_metadata_t get_parameter_metadata; + const struct behavior_parameter_metadata *parameter_metadata; +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; /** * @endcond */ +struct zmk_behavior_metadata { +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + const char *display_name; +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +}; + struct zmk_behavior_ref { const struct device *device; + const struct zmk_behavior_metadata metadata; }; +#define ZMK_BEHAVIOR_REF_DT_NAME(node_id) _CONCAT(zmk_behavior_, DEVICE_DT_NAME_GET(node_id)) + +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +#define ZMK_BEHAVIOR_METADATA_INITIALIZER(node_id) \ + { .display_name = DT_PROP_OR(node_id, display_name, DEVICE_DT_NAME(node_id)), } + +#else + +#define ZMK_BEHAVIOR_METADATA_INITIALIZER(node_id) \ + {} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +#define ZMK_BEHAVIOR_REF_INITIALIZER(node_id, _dev) \ + { .device = _dev, .metadata = ZMK_BEHAVIOR_METADATA_INITIALIZER(node_id), } + +#define ZMK_BEHAVIOR_REF_DEFINE(name, node_id, _dev) \ + static const STRUCT_SECTION_ITERABLE(zmk_behavior_ref, name) = \ + ZMK_BEHAVIOR_REF_INITIALIZER(node_id, _dev) + +#define ZMK_BEHAVIOR_REF_DT_DEFINE(node_id) \ + ZMK_BEHAVIOR_REF_DEFINE(ZMK_BEHAVIOR_REF_DT_NAME(node_id), node_id, DEVICE_DT_GET(node_id)) + /** * Registers @p node_id as a behavior. */ -#define BEHAVIOR_DEFINE(node_id) \ - static const STRUCT_SECTION_ITERABLE(zmk_behavior_ref, \ - _CONCAT(zmk_behavior_, DEVICE_DT_NAME_GET(node_id))) = { \ - .device = DEVICE_DT_GET(node_id), \ - } +#define BEHAVIOR_DEFINE(node_id) ZMK_BEHAVIOR_REF_DT_DEFINE(node_id) /** * @brief Like DEVICE_DT_DEFINE(), but also registers the device as a behavior. @@ -89,6 +157,52 @@ struct zmk_behavior_ref { DEVICE_DT_INST_DEFINE(inst, __VA_ARGS__); \ BEHAVIOR_DEFINE(DT_DRV_INST(inst)) +/** + * @brief Validate a given behavior binding is valid, including parameter validation + * if the metadata feature is enablued. + * + * @param binding The behavior binding to validate. + * + * @retval 0 if the passed in binding is valid. + * @retval -ENODEV if the binding references a non-existant behavior. + * @retval -EINVAL if parameters are not valid for the behavior metadata. + */ +int zmk_behavior_validate_binding(const struct zmk_behavior_binding *binding); + +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +int zmk_behavior_get_empty_param_metadata(const struct device *dev, + struct behavior_parameter_metadata *metadata); + +/** + * @brief Validate a given behavior parameters match the behavior metadata. + * + * @param metadata The behavior metadata to validate against + * @param param1 The first parameter value + * @param param2 The second parameter value + * + * @retval 0 if the passed in parameters are valid. + * @retval -ENODEV if metadata is NULL. + * @retval -EINVAL if parameters are not valid for the metadata. + */ +int zmk_behavior_check_params_match_metadata(const struct behavior_parameter_metadata *metadata, + uint32_t param1, uint32_t param2); +/** + * @brief Validate a given behavior parameter matches the behavior metadata parameter values. + * + * @param values The values to validate against + * @param values_len How many values to check + * @param param The value to check. + * + * @retval 0 if the passed in parameter is valid. + * @retval -ENODEV if values is NULL. + * @retval -EINVAL if parameter is not valid for the value metadata. + */ +int zmk_behavior_validate_param_values(const struct behavior_parameter_value_metadata *values, + size_t values_len, uint32_t param); + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + /** * Syscall wrapper for zmk_behavior_get_binding(). * @@ -120,6 +234,40 @@ static inline int z_impl_behavior_keymap_binding_convert_central_state_dependent return api->binding_convert_central_state_dependent_params(binding, event); } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +/** + * @brief Determine where the behavior should be run + * @param behavior Pointer to the device structure for the driver instance. + * + * @retval Zero if successful. + * @retval Negative errno code if failure. + */ +__syscall int behavior_get_parameter_metadata(const struct device *behavior, + struct behavior_parameter_metadata *param_metadata); + +static inline int +z_impl_behavior_get_parameter_metadata(const struct device *behavior, + struct behavior_parameter_metadata *param_metadata) { + if (behavior == NULL || param_metadata == NULL) { + return -EINVAL; + } + + const struct behavior_driver_api *api = (const struct behavior_driver_api *)behavior->api; + + if (api->get_parameter_metadata) { + return api->get_parameter_metadata(behavior, param_metadata); + } else if (api->parameter_metadata) { + *param_metadata = *api->parameter_metadata; + } else { + return -ENODEV; + } + + return 0; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + /** * @brief Determine where the behavior should be run * @param behavior Pointer to the device structure for the driver instance. diff --git a/app/include/zmk/behavior.h b/app/include/zmk/behavior.h index ab95fd8e728..016fa3bc063 100644 --- a/app/include/zmk/behavior.h +++ b/app/include/zmk/behavior.h @@ -12,7 +12,7 @@ #define ZMK_BEHAVIOR_TRANSPARENT 1 struct zmk_behavior_binding { - char *behavior_dev; + const char *behavior_dev; uint32_t param1; uint32_t param2; }; diff --git a/app/src/behavior.c b/app/src/behavior.c index fa2005ff1af..7777155f404 100644 --- a/app/src/behavior.c +++ b/app/src/behavior.c @@ -11,6 +11,8 @@ #include #include +#include +#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -39,6 +41,150 @@ const struct device *z_impl_behavior_get_binding(const char *name) { return NULL; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +int zmk_behavior_get_empty_param_metadata(const struct device *dev, + struct behavior_parameter_metadata *metadata) { + metadata->sets_len = 0; + return 0; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +static int validate_hid_usage(uint16_t usage_page, uint16_t usage_id) { + LOG_DBG("Validate usage %d in page %d", usage_id, usage_page); + switch (usage_page) { + case HID_USAGE_KEY: + if (usage_id == 0 || (usage_id > ZMK_HID_KEYBOARD_NKRO_MAX_USAGE && + usage_id < LEFT_CONTROL && usage_id > RIGHT_GUI)) { + return -EINVAL; + } + break; + case HID_USAGE_CONSUMER: + if (usage_id > + COND_CODE_1(IS_ENABLED(CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC), (0xFF), (0xFFF))) { + return -EINVAL; + } + break; + default: + LOG_WRN("Unsupported HID usage page %d", usage_page); + return -EINVAL; + } + + return 0; +} + +#define PARAM_MATCHES 0 + +static int check_param_matches_value(const struct behavior_parameter_value_metadata *value_meta, + uint32_t param) { + switch (value_meta->type) { + case BEHAVIOR_PARAMETER_VALUE_TYPE_NIL: + if (param == 0) { + return PARAM_MATCHES; + } + break; + case BEHAVIOR_PARAMETER_VALUE_TYPE_HID_USAGE: + if (validate_hid_usage(ZMK_HID_USAGE_PAGE(param), ZMK_HID_USAGE_ID(param)) >= 0) { + return PARAM_MATCHES; + } + + break; + case BEHAVIOR_PARAMETER_VALUE_TYPE_LAYER_INDEX: + if (param >= 0 && param < ZMK_KEYMAP_LEN) { + return PARAM_MATCHES; + } + break; + /* TODO: Restore with HSV -> RGB refactor + case BEHAVIOR_PARAMETER_STANDARD_DOMAIN_HSV: + // TODO: No real way to validate? Maybe max brightness? + break; + */ + case BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE: + if (param == value_meta->value) { + return PARAM_MATCHES; + } + break; + case BEHAVIOR_PARAMETER_VALUE_TYPE_RANGE: + if (param >= value_meta->range.min && param <= value_meta->range.max) { + return PARAM_MATCHES; + } + break; + default: + LOG_WRN("Unknown type %d", value_meta->type); + break; + } + + return -ENOTSUP; +} + +int zmk_behavior_validate_param_values(const struct behavior_parameter_value_metadata *values, + size_t values_len, uint32_t param) { + if (values_len == 0) { + return -ENODEV; + } + + for (int v = 0; v < values_len; v++) { + int ret = check_param_matches_value(&values[v], param); + if (ret >= 0) { + return ret; + } + } + + return -EINVAL; +} + +int zmk_behavior_check_params_match_metadata(const struct behavior_parameter_metadata *metadata, + uint32_t param1, uint32_t param2) { + if (!metadata || metadata->sets_len == 0) { + if (!metadata) { + LOG_ERR("No metadata to check against"); + } + + return (param1 == 0 && param2 == 0) ? 0 : -ENODEV; + } + + for (int s = 0; s < metadata->sets_len; s++) { + const struct behavior_parameter_metadata_set *set = &metadata->sets[s]; + int param1_ret = + zmk_behavior_validate_param_values(set->param1_values, set->param1_values_len, param1); + int param2_ret = + zmk_behavior_validate_param_values(set->param2_values, set->param2_values_len, param2); + + if ((param1_ret >= 0 || (param1_ret == -ENODEV && param1 == 0)) && + (param2_ret >= 0 || (param2_ret == -ENODEV && param2 == 0))) { + return 0; + } + } + + return -EINVAL; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +int zmk_behavior_validate_binding(const struct zmk_behavior_binding *binding) { +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + const struct device *behavior = zmk_behavior_get_binding(binding->behavior_dev); + + if (!behavior) { + return -ENODEV; + } + + struct behavior_parameter_metadata metadata; + int ret = behavior_get_parameter_metadata(behavior, &metadata); + + if (ret < 0) { + LOG_WRN("Failed getting metadata for %s: %d", binding->behavior_dev, ret); + return ret; + } + + return zmk_behavior_check_params_match_metadata(&metadata, binding->param1, binding->param2); +#else + return 0; +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +} + #if IS_ENABLED(CONFIG_LOG) static int check_behavior_names(void) { // Behavior names must be unique, but we don't have a good way to enforce this diff --git a/app/src/behaviors/behavior_backlight.c b/app/src/behaviors/behavior_backlight.c index 3f836b73d76..d67ce2e7a8a 100644 --- a/app/src/behaviors/behavior_backlight.c +++ b/app/src/behaviors/behavior_backlight.c @@ -18,6 +18,82 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata no_arg_values[] = { + { + .display_name = "Toggle On/Off", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_TOG_CMD, + }, + { + .display_name = "Turn On", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_ON_CMD, + }, + { + .display_name = "Turn OFF", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_OFF_CMD, + }, + { + .display_name = "Increase Brightness", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_INC_CMD, + }, + { + .display_name = "Decrease Brightness", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_DEC_CMD, + }, + { + .display_name = "Cycle Brightness", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_CYCLE_CMD, + }, +}; + +static const struct behavior_parameter_value_metadata one_arg_p1_values[] = { + { + .display_name = "Set Brightness", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BL_SET_CMD, + }, +}; + +static const struct behavior_parameter_value_metadata one_arg_p2_values[] = { + { + .display_name = "Brightness", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_RANGE, + .range = + { + .min = 0, + .max = 255, + }, + }, +}; + +static const struct behavior_parameter_metadata_set no_args_set = { + .param1_values = no_arg_values, + .param1_values_len = ARRAY_SIZE(no_arg_values), +}; + +static const struct behavior_parameter_metadata_set one_args_set = { + .param1_values = one_arg_p1_values, + .param1_values_len = ARRAY_SIZE(one_arg_p1_values), + .param2_values = one_arg_p2_values, + .param2_values_len = ARRAY_SIZE(one_arg_p2_values), +}; + +static const struct behavior_parameter_metadata_set sets[] = {no_args_set, one_args_set}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(sets), + .sets = sets, +}; + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static int behavior_backlight_init(const struct device *dev) { return 0; } static int @@ -89,6 +165,9 @@ static const struct behavior_driver_api behavior_backlight_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, .locality = BEHAVIOR_LOCALITY_GLOBAL, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif }; BEHAVIOR_DT_INST_DEFINE(0, behavior_backlight_init, NULL, NULL, NULL, POST_KERNEL, diff --git a/app/src/behaviors/behavior_bt.c b/app/src/behaviors/behavior_bt.c index 03bb7d8c898..f439e49b1cf 100644 --- a/app/src/behaviors/behavior_bt.c +++ b/app/src/behaviors/behavior_bt.c @@ -20,6 +20,74 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata no_arg_values[] = { + { + .display_name = "Next Profile", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BT_NXT_CMD, + }, + { + .display_name = "Previous Profile", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BT_PRV_CMD, + }, + { + .display_name = "Clear All Profiles", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BT_CLR_ALL_CMD, + }, + { + .display_name = "Clear Selected Profile", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BT_CLR_CMD, + }, +}; + +static const struct behavior_parameter_metadata_set no_args_set = { + .param1_values = no_arg_values, + .param1_values_len = ARRAY_SIZE(no_arg_values), +}; + +static const struct behavior_parameter_value_metadata prof_index_param1_values[] = { + { + .display_name = "Select Profile", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BT_SEL_CMD, + }, + { + .display_name = "Disconnect Profile", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = BT_DISC_CMD, + }, +}; + +static const struct behavior_parameter_value_metadata prof_index_param2_values[] = { + { + .display_name = "Profile", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_RANGE, + .range = {.min = 0, .max = ZMK_BLE_PROFILE_COUNT}, + }, +}; + +static const struct behavior_parameter_metadata_set profile_index_metadata_set = { + .param1_values = prof_index_param1_values, + .param1_values_len = ARRAY_SIZE(prof_index_param1_values), + .param2_values = prof_index_param2_values, + .param2_values_len = ARRAY_SIZE(prof_index_param2_values), +}; + +static const struct behavior_parameter_metadata_set metadata_sets[] = {no_args_set, + profile_index_metadata_set}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(metadata_sets), + .sets = metadata_sets, +}; + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { switch (binding->param1) { @@ -54,6 +122,9 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_bt_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; BEHAVIOR_DT_INST_DEFINE(0, behavior_bt_init, NULL, NULL, NULL, POST_KERNEL, diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 57263d1c85e..1c050c44fe5 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -68,6 +68,12 @@ struct behavior_hold_tap_config { int32_t hold_trigger_key_positions[]; }; +struct behavior_hold_tap_data { +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + struct behavior_parameter_metadata_set set; +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +}; + // this data is specific for each hold-tap struct active_hold_tap { int32_t position; @@ -652,9 +658,52 @@ static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding, return ZMK_BEHAVIOR_OPAQUE; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +static int hold_tap_parameter_metadata(const struct device *hold_tap, + struct behavior_parameter_metadata *param_metadata) { + const struct behavior_hold_tap_config *cfg = hold_tap->config; + struct behavior_hold_tap_data *data = hold_tap->data; + int err; + struct behavior_parameter_metadata child_meta; + + err = behavior_get_parameter_metadata(zmk_behavior_get_binding(cfg->hold_behavior_dev), + &child_meta); + if (err < 0) { + LOG_WRN("Failed to get the hold behavior parameter: %d", err); + return err; + } + + if (child_meta.sets_len > 0) { + data->set.param1_values = child_meta.sets[0].param1_values; + data->set.param1_values_len = child_meta.sets[0].param1_values_len; + } + + err = behavior_get_parameter_metadata(zmk_behavior_get_binding(cfg->tap_behavior_dev), + &child_meta); + if (err < 0) { + LOG_WRN("Failed to get the tap behavior parameter: %d", err); + return err; + } + + if (child_meta.sets_len > 0) { + data->set.param2_values = child_meta.sets[0].param1_values; + data->set.param2_values_len = child_meta.sets[0].param1_values_len; + } + + param_metadata->sets = &data->set; + param_metadata->sets_len = 1; + + return 0; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static const struct behavior_driver_api behavior_hold_tap_driver_api = { .binding_pressed = on_hold_tap_binding_pressed, .binding_released = on_hold_tap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = hold_tap_parameter_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static int position_state_changed_listener(const zmk_event_t *eh) { @@ -791,7 +840,7 @@ static int behavior_hold_tap_init(const struct device *dev) { } #define KP_INST(n) \ - static struct behavior_hold_tap_config behavior_hold_tap_config_##n = { \ + static const struct behavior_hold_tap_config behavior_hold_tap_config_##n = { \ .tapping_term_ms = DT_INST_PROP(n, tapping_term_ms), \ .hold_behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(n, bindings, 0)), \ .tap_behavior_dev = DEVICE_DT_NAME(DT_INST_PHANDLE_BY_IDX(n, bindings, 1)), \ @@ -807,9 +856,10 @@ static int behavior_hold_tap_init(const struct device *dev) { .hold_trigger_key_positions = DT_INST_PROP(n, hold_trigger_key_positions), \ .hold_trigger_key_positions_len = DT_INST_PROP_LEN(n, hold_trigger_key_positions), \ }; \ - BEHAVIOR_DT_INST_DEFINE(n, behavior_hold_tap_init, NULL, NULL, &behavior_hold_tap_config_##n, \ - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - &behavior_hold_tap_driver_api); + static struct behavior_hold_tap_data behavior_hold_tap_data_##n = {}; \ + BEHAVIOR_DT_INST_DEFINE(n, behavior_hold_tap_init, NULL, &behavior_hold_tap_data_##n, \ + &behavior_hold_tap_config_##n, POST_KERNEL, \ + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_hold_tap_driver_api); DT_INST_FOREACH_STATUS_OKAY(KP_INST) diff --git a/app/src/behaviors/behavior_key_press.c b/app/src/behaviors/behavior_key_press.c index 566cfcfba77..b090401ec50 100644 --- a/app/src/behaviors/behavior_key_press.c +++ b/app/src/behaviors/behavior_key_press.c @@ -16,6 +16,27 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata param_values[] = { + { + .display_name = "Key", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_HID_USAGE, + }, +}; + +static const struct behavior_parameter_metadata_set param_metadata_set[] = {{ + .param1_values = param_values, + .param1_values_len = ARRAY_SIZE(param_values), +}}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(param_metadata_set), + .sets = param_metadata_set, +}; + +#endif + static int behavior_key_press_init(const struct device *dev) { return 0; }; static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, @@ -31,7 +52,12 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, } static const struct behavior_driver_api behavior_key_press_driver_api = { - .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released}; + .binding_pressed = on_keymap_binding_pressed, + .binding_released = on_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +}; #define KP_INST(n) \ BEHAVIOR_DT_INST_DEFINE(n, behavior_key_press_init, NULL, NULL, NULL, POST_KERNEL, \ diff --git a/app/src/behaviors/behavior_key_toggle.c b/app/src/behaviors/behavior_key_toggle.c index 0dc0f5abfdc..d967af0146b 100644 --- a/app/src/behaviors/behavior_key_toggle.c +++ b/app/src/behaviors/behavior_key_toggle.c @@ -31,9 +31,34 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, return 0; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata param_values[] = { + { + .display_name = "Key", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_STANDARD, + .standard = BEHAVIOR_PARAMETER_STANDARD_DOMAIN_HID_USAGE, + }, +}; + +static const struct behavior_parameter_metadata_set param_metadata_set[] = {{ + .param1_values = param_values, + .param1_values_len = ARRAY_SIZE(param_values), +}}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(param_metadata_set), + .sets = param_metadata_set, +}; + +#endif + static const struct behavior_driver_api behavior_key_toggle_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; #define KT_INST(n) \ diff --git a/app/src/behaviors/behavior_macro.c b/app/src/behaviors/behavior_macro.c index acffe3d8857..b535ed8be07 100644 --- a/app/src/behaviors/behavior_macro.c +++ b/app/src/behaviors/behavior_macro.c @@ -34,6 +34,10 @@ struct behavior_macro_trigger_state { struct behavior_macro_state { struct behavior_macro_trigger_state release_state; +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + struct behavior_parameter_metadata_set set; +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + uint32_t press_bindings_count; }; @@ -209,9 +213,100 @@ static int on_macro_binding_released(struct zmk_behavior_binding *binding, return ZMK_BEHAVIOR_OPAQUE; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static void assign_values_to_set(enum param_source param_source, + struct behavior_parameter_metadata_set *set, + const struct behavior_parameter_value_metadata *values, + size_t values_len) { + if (param_source == PARAM_SOURCE_MACRO_1ST) { + set->param1_values = values; + set->param1_values_len = values_len; + } else { + set->param2_values = values; + set->param2_values_len = values_len; + } +} + +// This function will dynamically determine the parameter metadata for a particular macro by +// inspecting the macro *bindings* to see what behaviors in that list receive the macro parameters, +// and then using the metadata from those behaviors for the macro itself. +// +// Care need be taken, where a behavior in the list takes two parameters, and the macro passes along +// a value for the *second* parameter, we need to make sure we find the right metadata set for the +// referenced behavior that matches the first parameter. +static int get_macro_parameter_metadata(const struct device *macro, + struct behavior_parameter_metadata *param_metadata) { + const struct behavior_macro_config *cfg = macro->config; + struct behavior_macro_state *data = macro->data; + struct behavior_macro_trigger_state state = {0}; + + for (int i = 0; (i < cfg->count) && (!data->set.param1_values || !data->set.param2_values); + i++) { + if (handle_control_binding(&state, &cfg->bindings[i]) || + (state.param1_source == PARAM_SOURCE_BINDING && + state.param2_source == PARAM_SOURCE_BINDING)) { + continue; + } + + LOG_DBG("checking %d for the given state", i); + + struct behavior_parameter_metadata binding_meta; + int err = behavior_get_parameter_metadata( + zmk_behavior_get_binding(cfg->bindings[i].behavior_dev), &binding_meta); + if (err < 0 || binding_meta.sets_len == 0) { + LOG_WRN("Failed to fetch macro binding parameter details %d", err); + return -ENOTSUP; + } + + // If both macro parameters get passed to this one entry, use + // the metadata for this behavior verbatim. + if (state.param1_source != PARAM_SOURCE_BINDING && + state.param2_source != PARAM_SOURCE_BINDING) { + param_metadata->sets_len = binding_meta.sets_len; + param_metadata->sets = binding_meta.sets; + return 0; + } + + if (state.param1_source != PARAM_SOURCE_BINDING) { + assign_values_to_set(state.param1_source, &data->set, + binding_meta.sets[0].param1_values, + binding_meta.sets[0].param1_values_len); + } + + if (state.param2_source != PARAM_SOURCE_BINDING) { + // For the param2 metadata, we need to find a set that matches fully bound first + // parameter of our macro entry, and use the metadata from that set. + for (int s = 0; s < binding_meta.sets_len; s++) { + if (zmk_behavior_validate_param_values(binding_meta.sets[s].param1_values, + binding_meta.sets[s].param1_values_len, + cfg->bindings[i].param1) >= 0) { + assign_values_to_set(state.param2_source, &data->set, + binding_meta.sets[s].param2_values, + binding_meta.sets[s].param2_values_len); + break; + } + } + } + + state.param1_source = PARAM_SOURCE_BINDING; + state.param2_source = PARAM_SOURCE_BINDING; + } + + param_metadata->sets_len = 1; + param_metadata->sets = &data->set; + + return 0; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static const struct behavior_driver_api behavior_macro_driver_api = { .binding_pressed = on_macro_binding_pressed, .binding_released = on_macro_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = get_macro_parameter_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; #define TRANSFORMED_BEHAVIORS(n) \ diff --git a/app/src/behaviors/behavior_momentary_layer.c b/app/src/behaviors/behavior_momentary_layer.c index 0c86e605b55..e27889df96f 100644 --- a/app/src/behaviors/behavior_momentary_layer.c +++ b/app/src/behaviors/behavior_momentary_layer.c @@ -15,6 +15,27 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata param_values[] = { + { + .display_name = "Layer", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_LAYER_INDEX, + }, +}; + +static const struct behavior_parameter_metadata_set param_metadata_set[] = {{ + .param1_values = param_values, + .param1_values_len = ARRAY_SIZE(param_values), +}}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(param_metadata_set), + .sets = param_metadata_set, +}; + +#endif + struct behavior_mo_config {}; struct behavior_mo_data {}; @@ -33,7 +54,12 @@ static int mo_keymap_binding_released(struct zmk_behavior_binding *binding, } static const struct behavior_driver_api behavior_mo_driver_api = { - .binding_pressed = mo_keymap_binding_pressed, .binding_released = mo_keymap_binding_released}; + .binding_pressed = mo_keymap_binding_pressed, + .binding_released = mo_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) +}; static const struct behavior_mo_config behavior_mo_config = {}; diff --git a/app/src/behaviors/behavior_none.c b/app/src/behaviors/behavior_none.c index 0137622aceb..b1dc4ad3327 100644 --- a/app/src/behaviors/behavior_none.c +++ b/app/src/behaviors/behavior_none.c @@ -31,6 +31,9 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_none_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; BEHAVIOR_DT_INST_DEFINE(0, behavior_none_init, NULL, NULL, NULL, POST_KERNEL, diff --git a/app/src/behaviors/behavior_outputs.c b/app/src/behaviors/behavior_outputs.c index d172c3a11b8..ffa57d16357 100644 --- a/app/src/behaviors/behavior_outputs.c +++ b/app/src/behaviors/behavior_outputs.c @@ -20,6 +20,42 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata std_values[] = { + { + .value = OUT_TOG, + .display_name = "Toggle Outputs", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + }, +#if IS_ENABLED(CONFIG_ZMK_USB) + { + .value = OUT_USB, + .display_name = "USB Output", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + }, +#endif // IS_ENABLED(CONFIG_ZMK_USB) +#if IS_ENABLED(CONFIG_ZMK_BLE) + { + .value = OUT_BLE, + .display_name = "BLE Output", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + }, +#endif // IS_ENABLED(CONFIG_ZMK_BLE) +}; + +static const struct behavior_parameter_metadata_set std_set = { + .param1_values = std_values, + .param1_values_len = ARRAY_SIZE(std_values), +}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = 1, + .sets = &std_set, +}; + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { switch (binding->param1) { @@ -40,6 +76,9 @@ static int behavior_out_init(const struct device *dev) { return 0; } static const struct behavior_driver_api behavior_outputs_driver_api = { .binding_pressed = on_keymap_binding_pressed, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; BEHAVIOR_DT_INST_DEFINE(0, behavior_out_init, NULL, NULL, NULL, POST_KERNEL, diff --git a/app/src/behaviors/behavior_rgb_underglow.c b/app/src/behaviors/behavior_rgb_underglow.c index a16ee591ed4..c37e5217c73 100644 --- a/app/src/behaviors/behavior_rgb_underglow.c +++ b/app/src/behaviors/behavior_rgb_underglow.c @@ -18,6 +18,119 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata no_arg_values[] = { + { + .display_name = "Toggle On/Off", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_TOG_CMD, + }, + { + .display_name = "Turn On", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_ON_CMD, + }, + { + .display_name = "Turn OFF", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_OFF_CMD, + }, + { + .display_name = "Hue Up", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_HUI_CMD, + }, + { + .display_name = "Hue Down", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_HUD_CMD, + }, + { + .display_name = "Saturation Up", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_SAI_CMD, + }, + { + .display_name = "Saturation Down", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_SAD_CMD, + }, + { + .display_name = "Brightness Up", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_BRI_CMD, + }, + { + .display_name = "Brightness Down", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_BRD_CMD, + }, + { + .display_name = "Speed Up", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_SPI_CMD, + }, + { + .display_name = "Speed Down", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_SPD_CMD, + }, + { + .display_name = "Next Effect", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_EFF_CMD, + }, + { + .display_name = "Previous Effect", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_EFR_CMD, + }, +}; + +static const struct behavior_parameter_metadata_set no_args_set = { + .param1_values = no_arg_values, + .param1_values_len = ARRAY_SIZE(no_arg_values), +}; + +/* +static const struct behavior_parameter_value_metadata hsv_p1_value_metadata_values[] = { + { + .display_name = "Set Color", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE, + .value = RGB_COLOR_HSB_CMD, + }, +}; + +static const struct behavior_parameter_value_metadata hsv_p2_value_metadata_values[] = { + { + .display_name = "Color", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_STANDARD, + .standard = BEHAVIOR_PARAMETER_STANDARD_DOMAIN_HSV, + }, +}; + +static const struct behavior_parameter_metadata_set hsv_value_metadata_set = { + .param1_values = hsv_p1_value_metadata_values, + .param1_values_len = ARRAY_SIZE(hsv_p1_value_metadata_values), + .param_values = hsv_p2_value_metadata_values, + .param_values_len = ARRAY_SIZE(hsv_p2_value_metadata_values), +}; + +*/ + +static const struct behavior_parameter_metadata_set sets[] = { + no_args_set, + // hsv_value_metadata_set, +}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(sets), + .sets = sets, +}; + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static int behavior_rgb_underglow_init(const struct device *dev) { return 0; } static int @@ -147,6 +260,9 @@ static const struct behavior_driver_api behavior_rgb_underglow_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, .locality = BEHAVIOR_LOCALITY_GLOBAL, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif }; BEHAVIOR_DT_INST_DEFINE(0, behavior_rgb_underglow_init, NULL, NULL, NULL, POST_KERNEL, diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 461ce933cf7..fcffd09ae5e 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -74,6 +74,9 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, .locality = BEHAVIOR_LOCALITY_GLOBAL, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; #define BSO_INST(n) \ diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index b0e9f3ed0c0..d1299c78d7f 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -188,9 +188,41 @@ static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding, return ZMK_BEHAVIOR_OPAQUE; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static int sticky_key_parameter_domains(const struct device *sk, + struct behavior_parameter_metadata *param_metadata) { + const struct behavior_sticky_key_config *cfg = sk->config; + + struct behavior_parameter_metadata child_metadata; + + int err = behavior_get_parameter_metadata(zmk_behavior_get_binding(cfg->behavior.behavior_dev), + &child_metadata); + if (err < 0) { + LOG_WRN("Failed to get the sticky key bound behavior parameter: %d", err); + } + + for (int s = 0; s < child_metadata.sets_len; s++) { + const struct behavior_parameter_metadata_set *set = &child_metadata.sets[s]; + + if (set->param2_values_len > 0) { + return -ENOTSUP; + } + } + + *param_metadata = child_metadata; + + return 0; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + static const struct behavior_driver_api behavior_sticky_key_driver_api = { .binding_pressed = on_sticky_key_binding_pressed, .binding_released = on_sticky_key_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = sticky_key_parameter_domains, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh); @@ -337,7 +369,7 @@ struct behavior_sticky_key_data {}; static struct behavior_sticky_key_data behavior_sticky_key_data; #define KP_INST(n) \ - static struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \ + static const struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \ .behavior = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ .release_after_ms = DT_INST_PROP(n, release_after_ms), \ .quick_release = DT_INST_PROP(n, quick_release), \ diff --git a/app/src/behaviors/behavior_tap_dance.c b/app/src/behaviors/behavior_tap_dance.c index 4f6fa1a134e..ce57b70fc4b 100644 --- a/app/src/behaviors/behavior_tap_dance.c +++ b/app/src/behaviors/behavior_tap_dance.c @@ -189,6 +189,9 @@ void behavior_tap_dance_timer_handler(struct k_work *item) { static const struct behavior_driver_api behavior_tap_dance_driver_api = { .binding_pressed = on_tap_dance_binding_pressed, .binding_released = on_tap_dance_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static int tap_dance_position_state_changed_listener(const zmk_event_t *eh); diff --git a/app/src/behaviors/behavior_to_layer.c b/app/src/behaviors/behavior_to_layer.c index 1c87a925905..d260087efce 100644 --- a/app/src/behaviors/behavior_to_layer.c +++ b/app/src/behaviors/behavior_to_layer.c @@ -32,9 +32,34 @@ static int to_keymap_binding_released(struct zmk_behavior_binding *binding, return ZMK_BEHAVIOR_OPAQUE; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata param_values[] = { + { + .display_name = "Layer", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_STANDARD, + .standard = BEHAVIOR_PARAMETER_STANDARD_DOMAIN_LAYER_INDEX, + }, +}; + +static const struct behavior_parameter_metadata_set param_metadata_set[] = {{ + .param1_values = param_values, + .param1_values_len = ARRAY_SIZE(param_values), +}}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(param_metadata_set), + .sets = param_metadata_set, +}; + +#endif + static const struct behavior_driver_api behavior_to_driver_api = { .binding_pressed = to_keymap_binding_pressed, .binding_released = to_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; BEHAVIOR_DT_INST_DEFINE(0, behavior_to_init, NULL, NULL, NULL, POST_KERNEL, diff --git a/app/src/behaviors/behavior_toggle_layer.c b/app/src/behaviors/behavior_toggle_layer.c index 817462df5aa..df261ed3a34 100644 --- a/app/src/behaviors/behavior_toggle_layer.c +++ b/app/src/behaviors/behavior_toggle_layer.c @@ -34,9 +34,34 @@ static int tog_keymap_binding_released(struct zmk_behavior_binding *binding, return ZMK_BEHAVIOR_OPAQUE; } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata param_values[] = { + { + .display_name = "Layer", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_STANDARD, + .standard = BEHAVIOR_PARAMETER_STANDARD_DOMAIN_LAYER_INDEX, + }, +}; + +static const struct behavior_parameter_metadata_set param_metadata_set[] = {{ + .param1_values = param_values, + .param1_values_len = ARRAY_SIZE(param_values), +}}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(param_metadata_set), + .sets = param_metadata_set, +}; + +#endif + static const struct behavior_driver_api behavior_tog_driver_api = { .binding_pressed = tog_keymap_binding_pressed, .binding_released = tog_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static const struct behavior_tog_config behavior_tog_config = {}; From 3e2c428fca717d9e699dda371311b28e7791204c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 24 Jun 2024 10:58:34 -0600 Subject: [PATCH 111/134] chore: Add rp2040/USB logging core coverage. * Include an rp2040 core build target, and include USB logging snippet for completeness. --- app/core-coverage.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/core-coverage.yml b/app/core-coverage.yml index 4a60aad9caf..7eef35cf70f 100644 --- a/app/core-coverage.yml +++ b/app/core-coverage.yml @@ -22,6 +22,9 @@ include: shield: kyria_left cmake-args: "-DCONFIG_ZMK_DISPLAY=y" nickname: "display" + - board: sparkfun_pro_micro_rp2040 + shield: reviung41 + cmake-args: "-DSNIPPET='zmk-usb-logging'" - board: nice_nano_v2 shield: kyria_right cmake-args: "-DCONFIG_ZMK_DISPLAY=y" From 0bea7832e99a2c7cc0c33c68de8abbd2e52c844c Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:08:19 -0400 Subject: [PATCH 112/134] ci(build): amend changed-files invocation --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c2d1992dc43..804c35f1eb2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -413,7 +413,9 @@ jobs: board-changes: ${{ steps.board-changes.outputs.result }} core-changes: ${{ steps.core-changes.outputs.result }} steps: - - uses: tj-actions/changed-files@v42 + - name: Checkout + uses: actions/checkout@v4 + - uses: tj-actions/changed-files@v44 id: changed-files with: json: true From 7c9477be6ed3b2b05b96cb0210f9ec2724f09ad5 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:26:35 -0400 Subject: [PATCH 113/134] ci(build): improve security posture * Limit unnecessary permissions. * Avoid storing credentials. --- .github/workflows/build.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 804c35f1eb2..b54c9eefa9c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,8 @@ on: schedule: - cron: "22 4 * * *" +permissions: {} + jobs: build: if: ${{ always() }} @@ -25,6 +27,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + persist-credentials: false - name: Cache west modules uses: actions/cache@v4 env: @@ -179,6 +183,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + persist-credentials: false - name: Use Node.js uses: actions/setup-node@v4 with: @@ -335,6 +341,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + persist-credentials: false - name: Use Node.js uses: actions/setup-node@v4 with: @@ -415,6 +423,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + persist-credentials: false - uses: tj-actions/changed-files@v44 id: changed-files with: From 9c6d1af102bd5986b254fc8def72cc3c80c74785 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:43:54 -0400 Subject: [PATCH 114/134] ci(build): limit run scope * Cancel redundant non-nightly runs and jobs dependent on canceled jobs. * Limit scheduled runs to zmkfirmware-owned repos. --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b54c9eefa9c..9e09dc21074 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,10 @@ on: schedule: - cron: "22 4 * * *" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'schedule' }} + cancel-in-progress: true + permissions: {} jobs: @@ -135,7 +139,7 @@ jobs: throw new Error('Failed to build one or more configurations'); } compile-matrix: - if: ${{ always() }} + if: ${{ !cancelled() }} runs-on: ubuntu-latest needs: [core-coverage, board-changes, nightly] outputs: @@ -290,7 +294,7 @@ jobs: }); }))).flat(); nightly: - if: ${{ github.event_name == 'schedule' }} + if: ${{ github.event_name == 'schedule' && github.repository_owner == 'zmkfirmware' }} runs-on: ubuntu-latest needs: get-grouped-hardware outputs: From 4dce0961611a2297959ab27579f145a4fb9b097e Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:13:35 -0400 Subject: [PATCH 115/134] docs: improve settings_reset link --- docs/docs/troubleshooting/connection-issues.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/troubleshooting/connection-issues.mdx b/docs/docs/troubleshooting/connection-issues.mdx index 59a6a20811d..5fdd1c836a0 100644 --- a/docs/docs/troubleshooting/connection-issues.mdx +++ b/docs/docs/troubleshooting/connection-issues.mdx @@ -61,8 +61,8 @@ Save the file, commit the changes and push them to GitHub. Download the new firm -1. [Open the GitHub `Actions` tab and select the `Build` workflow](https://github.com/zmkfirmware/zmk/actions?query=workflow%3ABuild+branch%3Amain+event%3Apush). -1. Find one of the 'results' for which the core-coverage job was successfully run, indicated by a green checkmark in the core-coverage bubble like the image example below. +1. [Open the `Build` workflow](https://github.com/zmkfirmware/zmk/actions/workflows/build.yml?query=event%3Apush+branch%3Amain+is%3Asuccess) from the `Actions` tab of the ZMK GitHub repository. +1. Find one of the results for which the `core-coverage` job ran successfully, indicated by a green checkmark in the "core-coverage" bubble like the image example below. 1. From the next page under "Artifacts", download and unzip the `-settings_reset-zmk` zip file for the UF2 image. | ![Successful core-coverage Job](../../docs/assets/troubleshooting/splitpairing/corecoverage.png) | From 10d03ca46c84a2530701ef82e28ec018d34df905 Mon Sep 17 00:00:00 2001 From: Timoyoungster Date: Fri, 14 Jun 2024 02:28:49 +0200 Subject: [PATCH 116/134] fix: adding option to separate implicit mod release from key release This adds a new config value `ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` where, if enabled, the report for a key release is sent separately to the accompanying modifier release signals, which are then sent in a second report. This fixes an issue where certain applications are unable to work with implicitly modified keys (e.g. colon) due to them registering the modifier release prior to the actual key release. Have tested this on my personal keyboard and `wev` now shows the signals in the correct order. => **Previously:** ```LSHIFT (pressed) -> colon (pressed) -> LSHIFT (released) -> **semi**colon (released)``` => **Now:** ```LSHIFT (pressed) -> colon (pressed) -> colon (released) -> LSHIFT (released)``` (This time without accidental files) --- app/Kconfig | 6 ++++++ app/src/hid_listener.c | 13 ++++++++++++- docs/docs/config/system.md | 9 +++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 8f690175ddc..a45f2dc23f0 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -113,6 +113,12 @@ config ZMK_HID_INDICATORS Enable HID indicators, used for detecting state of Caps/Scroll/Num Lock, Kata, and Compose. +config ZMK_HID_SEPARATE_MOD_RELEASE_REPORT + bool "Release Modifiers Separately" + help + Send a separate release event for the modifiers, to make sure the release + of the modifier doesn't get recognized before the actual key's release event. + menu "Output Types" config ZMK_USB diff --git a/app/src/hid_listener.c b/app/src/hid_listener.c index 2b8470820a1..2d17a395407 100644 --- a/app/src/hid_listener.c +++ b/app/src/hid_listener.c @@ -66,6 +66,17 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed return err; } +#if IS_ENABLED(CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT) + + // send report of normal key release early to fix the issue + // of some programs recognizing the implicit_mod release before the actual key release + err = zmk_endpoints_send_report(ev->usage_page); + if (err < 0) { + LOG_ERR("Failed to send key report for the released keycode (%d)", err); + } + +#endif // IS_ENABLED(CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT) + explicit_mods_changed = zmk_hid_unregister_mods(ev->explicit_modifiers); // 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 @@ -73,7 +84,7 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed // Solving this would require keeping track of which key's implicit modifiers are currently // active and only releasing modifiers at that time. implicit_mods_changed = zmk_hid_implicit_modifiers_release(); - ; + if (ev->usage_page != HID_USAGE_KEY && (explicit_mods_changed > 0 || implicit_mods_changed > 0)) { err = zmk_endpoints_send_report(HID_USAGE_KEY); diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 27923453207..cc34219543d 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -29,10 +29,11 @@ Making changes to any of the settings in this section modifies the HID report de ::: -| Config | Type | Description | Default | -| ------------------------------------- | ---- | -------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | -| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| Config | Type | Description | Default | +| -------------------------------------------- | ---- | -------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | +| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Release the Modifiers separate from and after the modified key | n | Exactly zero or one of the following options may be set to `y`. The first is used if none are set. From 29599e8b0acbe425d190f17da9bf6569abbda9f1 Mon Sep 17 00:00:00 2001 From: Timoyoungster Date: Fri, 14 Jun 2024 15:23:37 +0200 Subject: [PATCH 117/134] docs: hopefully more clear description of the new setting --- docs/docs/config/system.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index cc34219543d..5d63ca529f4 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -29,11 +29,11 @@ Making changes to any of the settings in this section modifies the HID report de ::: -| Config | Type | Description | Default | -| -------------------------------------------- | ---- | -------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | -| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | -| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Release the Modifiers separate from and after the modified key | n | +| Config | Type | Description | Default | +| -------------------------------------------- | ---- | ---------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | +| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Send modifier release event **after** non-modifier release event | n | Exactly zero or one of the following options may be set to `y`. The first is used if none are set. From 49f7275bebc73a49065f419c6d05eac1c398596c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 25 Jun 2024 11:57:54 -0600 Subject: [PATCH 118/134] fix: Add metadata to missed behaviors. --- app/src/behaviors/behavior_caps_word.c | 3 +++ app/src/behaviors/behavior_key_repeat.c | 24 ++++++++++++++++++++++++ app/src/behaviors/behavior_mod_morph.c | 3 +++ app/src/behaviors/behavior_reset.c | 3 +++ app/src/behaviors/behavior_transparent.c | 3 +++ 5 files changed, 36 insertions(+) diff --git a/app/src/behaviors/behavior_caps_word.c b/app/src/behaviors/behavior_caps_word.c index d9b3f24ec7d..bf74a4b3dd3 100644 --- a/app/src/behaviors/behavior_caps_word.c +++ b/app/src/behaviors/behavior_caps_word.c @@ -75,6 +75,9 @@ static int on_caps_word_binding_released(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_caps_word_driver_api = { .binding_pressed = on_caps_word_binding_pressed, .binding_released = on_caps_word_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh); diff --git a/app/src/behaviors/behavior_key_repeat.c b/app/src/behaviors/behavior_key_repeat.c index c93fa722734..f2cd569f635 100644 --- a/app/src/behaviors/behavior_key_repeat.c +++ b/app/src/behaviors/behavior_key_repeat.c @@ -19,6 +19,27 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + +static const struct behavior_parameter_value_metadata param_values[] = { + { + .display_name = "Key", + .type = BEHAVIOR_PARAMETER_VALUE_TYPE_HID_USAGE, + }, +}; + +static const struct behavior_parameter_metadata_set param_metadata_set[] = {{ + .param1_values = param_values, + .param1_values_len = ARRAY_SIZE(param_values), +}}; + +static const struct behavior_parameter_metadata metadata = { + .sets_len = ARRAY_SIZE(param_metadata_set), + .sets = param_metadata_set, +}; + +#endif + struct behavior_key_repeat_config { uint8_t index; uint8_t usage_pages_count; @@ -67,6 +88,9 @@ static int on_key_repeat_binding_released(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_key_repeat_driver_api = { .binding_pressed = on_key_repeat_binding_pressed, .binding_released = on_key_repeat_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .parameter_metadata = &metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static int key_repeat_keycode_state_changed_listener(const zmk_event_t *eh); diff --git a/app/src/behaviors/behavior_mod_morph.c b/app/src/behaviors/behavior_mod_morph.c index 3a8bf08c198..303f96a7d05 100644 --- a/app/src/behaviors/behavior_mod_morph.c +++ b/app/src/behaviors/behavior_mod_morph.c @@ -75,6 +75,9 @@ static int on_mod_morph_binding_released(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_mod_morph_driver_api = { .binding_pressed = on_mod_morph_binding_pressed, .binding_released = on_mod_morph_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; static int behavior_mod_morph_init(const struct device *dev) { return 0; } diff --git a/app/src/behaviors/behavior_reset.c b/app/src/behaviors/behavior_reset.c index c559f17fd6f..554132f4a1e 100644 --- a/app/src/behaviors/behavior_reset.c +++ b/app/src/behaviors/behavior_reset.c @@ -38,6 +38,9 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_reset_driver_api = { .binding_pressed = on_keymap_binding_pressed, .locality = BEHAVIOR_LOCALITY_EVENT_SOURCE, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; #define RST_INST(n) \ diff --git a/app/src/behaviors/behavior_transparent.c b/app/src/behaviors/behavior_transparent.c index c7bf802b9fc..32357046724 100644 --- a/app/src/behaviors/behavior_transparent.c +++ b/app/src/behaviors/behavior_transparent.c @@ -31,6 +31,9 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, static const struct behavior_driver_api behavior_transparent_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) + .get_parameter_metadata = zmk_behavior_get_empty_param_metadata, +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) }; BEHAVIOR_DT_INST_DEFINE(0, behavior_transparent_init, NULL, NULL, NULL, POST_KERNEL, From b576d52d58eade3d909e536acffac282d71651c8 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 27 Mar 2024 22:17:32 +0000 Subject: [PATCH 119/134] feat(core): Support adding subs to other listeners. * Used for ZMK Studio event remappers to be sure the one RPC event listener subscribes to their mapped events. --- app/include/zmk/event_manager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/app/include/zmk/event_manager.h b/app/include/zmk/event_manager.h index e44207152d3..0eb63ad73d5 100644 --- a/app/include/zmk/event_manager.h +++ b/app/include/zmk/event_manager.h @@ -64,6 +64,7 @@ struct zmk_event_subscription { #define ZMK_LISTENER(mod, cb) const struct zmk_listener zmk_listener_##mod = {.callback = cb}; #define ZMK_SUBSCRIPTION(mod, ev_type) \ + extern const struct zmk_listener zmk_listener_##mod; \ const Z_DECL_ALIGN(struct zmk_event_subscription) \ _CONCAT(_CONCAT(zmk_event_sub_, mod), ev_type) __used \ __attribute__((__section__(".event_subscription"))) = { \ From f7c34c70bad6d09dbdb4bfdfad5a196179dbb8c8 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 5 Apr 2024 16:44:42 +0000 Subject: [PATCH 120/134] refactor(ble): Extract API to get active profile connection. * Add `struct bt_conn *zmk_ble_active_profile_conn(void)` function for fetching a connection for the current profile. --- app/include/zmk/ble.h | 3 +++ app/src/ble.c | 15 +++++++++++++++ app/src/hog.c | 19 ++----------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/include/zmk/ble.h b/app/include/zmk/ble.h index 773323c1cf9..cc55a6ce142 100644 --- a/app/include/zmk/ble.h +++ b/app/include/zmk/ble.h @@ -29,7 +29,10 @@ int zmk_ble_prof_disconnect(uint8_t index); int zmk_ble_active_profile_index(void); int zmk_ble_profile_index(const bt_addr_le_t *addr); + bt_addr_le_t *zmk_ble_active_profile_addr(void); +struct bt_conn *zmk_ble_active_profile_conn(void); + bool zmk_ble_active_profile_is_open(void); bool zmk_ble_active_profile_is_connected(void); char *zmk_ble_active_profile_name(void); diff --git a/app/src/ble.c b/app/src/ble.c index 7e1ae7d4949..b2dfbfa1eac 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -318,6 +318,21 @@ int zmk_ble_prof_disconnect(uint8_t index) { bt_addr_le_t *zmk_ble_active_profile_addr(void) { return &profiles[active_profile].peer; } +struct bt_conn *zmk_ble_active_profile_conn(void) { + struct bt_conn *conn; + bt_addr_le_t *addr = zmk_ble_active_profile_addr(); + + if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) { + LOG_WRN("Not sending, no active address for current profile"); + return NULL; + } else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) { + LOG_WRN("Not sending, not connected to active profile"); + return NULL; + } + + return conn; +} + char *zmk_ble_active_profile_name(void) { return profiles[active_profile].name; } #if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) diff --git a/app/src/hog.c b/app/src/hog.c index f17f759c908..77dde989e3a 100644 --- a/app/src/hog.c +++ b/app/src/hog.c @@ -220,21 +220,6 @@ BT_GATT_SERVICE_DEFINE( BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_CTRL_POINT, BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE, NULL, write_ctrl_point, &ctrl_point)); -struct bt_conn *destination_connection(void) { - struct bt_conn *conn; - bt_addr_le_t *addr = zmk_ble_active_profile_addr(); - LOG_DBG("Address pointer %p", addr); - if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) { - LOG_WRN("Not sending, no active address for current profile"); - return NULL; - } else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) { - LOG_WRN("Not sending, not connected to active profile"); - return NULL; - } - - return conn; -} - K_THREAD_STACK_DEFINE(hog_q_stack, CONFIG_ZMK_BLE_THREAD_STACK_SIZE); struct k_work_q hog_work_q; @@ -246,7 +231,7 @@ void send_keyboard_report_callback(struct k_work *work) { struct zmk_hid_keyboard_report_body report; while (k_msgq_get(&zmk_hog_keyboard_msgq, &report, K_NO_WAIT) == 0) { - struct bt_conn *conn = destination_connection(); + struct bt_conn *conn = zmk_ble_active_profile_conn(); if (conn == NULL) { return; } @@ -298,7 +283,7 @@ void send_consumer_report_callback(struct k_work *work) { struct zmk_hid_consumer_report_body report; while (k_msgq_get(&zmk_hog_consumer_msgq, &report, K_NO_WAIT) == 0) { - struct bt_conn *conn = destination_connection(); + struct bt_conn *conn = zmk_ble_active_profile_conn(); if (conn == NULL) { return; } From 483a4930e992a219d9fe941d1e7369194d34b15f Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 17 Apr 2024 16:44:22 -0700 Subject: [PATCH 121/134] feat(behaviors): Add local ID system for behaviors * Add a new feature for tracking a given behavior by a new concept of a "behavior local ID" which is a stable 16-bit identifier for a given behavior, that is resilient to new behaviors being added and requires no additional work on the part of the behavior authors. * Add implementations for either settings lookup table, or CRC16 hashing of behavior device names for generating behavior local IDs. --- app/CMakeLists.txt | 4 + app/Kconfig.behaviors | 29 ++++ app/include/drivers/behavior.h | 19 ++- .../linker/zmk-behavior-local-id-map.ld | 9 ++ app/include/zmk/behavior.h | 22 +++ app/src/behavior.c | 135 ++++++++++++++++++ 6 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 app/include/linker/zmk-behavior-local-id-map.ld diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 0b681ea9531..2818e932256 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -11,6 +11,10 @@ project(zmk) zephyr_linker_sources(SECTIONS include/linker/zmk-behaviors.ld) zephyr_linker_sources(RODATA include/linker/zmk-events.ld) +if(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS) + zephyr_linker_sources(DATA_SECTIONS include/linker/zmk-behavior-local-id-map.ld) +endif() + zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/behavior.h) zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/ext_power.h) diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index c6cc45f3b87..0fa345462dc 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -7,6 +7,35 @@ config ZMK_BEHAVIOR_METADATA Enabling this option adds APIs for documenting and fetching metadata describing a behaviors name, and supported parameters. +config ZMK_BEHAVIOR_LOCAL_IDS + bool "Local IDs" + +if ZMK_BEHAVIOR_LOCAL_IDS + +choice ZMK_BEHAVIOR_LOCAL_ID_TYPE + prompt "Local ID Type" + +config ZMK_BEHAVIOR_LOCAL_ID_TYPE_SETTINGS_TABLE + bool "Settings Table" + depends on SETTINGS + help + Use persistent entries in the settings subsystem to identify + behaviors by local ID, which uses the device name to generate + a new settings entry tying a presistant local ID to that name. + This guarantees stable, colllision-free local IDs at the expense + of settings storage used. + +config ZMK_BEHAVIOR_LOCAL_ID_TYPE_CRC16 + bool "CRC16 Hash" + help + Use the CRC16-ANSI hash of behavior device names to generate + stable behavior local IDs. This saves on settings storage at + the expense of (highly unlikely) risk of collisions. + +endchoice + +endif + config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/include/drivers/behavior.h b/app/include/drivers/behavior.h index 3dd6e0623f7..0b814ff2828 100644 --- a/app/include/drivers/behavior.h +++ b/app/include/drivers/behavior.h @@ -108,6 +108,15 @@ struct zmk_behavior_ref { const struct zmk_behavior_metadata metadata; }; +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS) + +struct zmk_behavior_local_id_map { + const struct device *device; + zmk_behavior_local_id_t local_id; +}; + +#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS) + #define ZMK_BEHAVIOR_REF_DT_NAME(node_id) _CONCAT(zmk_behavior_, DEVICE_DT_NAME_GET(node_id)) #if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) @@ -125,9 +134,17 @@ struct zmk_behavior_ref { #define ZMK_BEHAVIOR_REF_INITIALIZER(node_id, _dev) \ { .device = _dev, .metadata = ZMK_BEHAVIOR_METADATA_INITIALIZER(node_id), } +#define ZMK_BEHAVIOR_LOCAL_ID_MAP_INITIALIZER(node_id, _dev) \ + { .device = _dev, } + #define ZMK_BEHAVIOR_REF_DEFINE(name, node_id, _dev) \ static const STRUCT_SECTION_ITERABLE(zmk_behavior_ref, name) = \ - ZMK_BEHAVIOR_REF_INITIALIZER(node_id, _dev) + ZMK_BEHAVIOR_REF_INITIALIZER(node_id, _dev); \ + COND_CODE_1(IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS), \ + (static const STRUCT_SECTION_ITERABLE(zmk_behavior_local_id_map, \ + _CONCAT(_zmk_behavior_local_id_map, name)) = \ + ZMK_BEHAVIOR_LOCAL_ID_MAP_INITIALIZER(node_id, _dev)), \ + ()); #define ZMK_BEHAVIOR_REF_DT_DEFINE(node_id) \ ZMK_BEHAVIOR_REF_DEFINE(ZMK_BEHAVIOR_REF_DT_NAME(node_id), node_id, DEVICE_DT_GET(node_id)) diff --git a/app/include/linker/zmk-behavior-local-id-map.ld b/app/include/linker/zmk-behavior-local-id-map.ld new file mode 100644 index 00000000000..c91e64c43b1 --- /dev/null +++ b/app/include/linker/zmk-behavior-local-id-map.ld @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +ITERABLE_SECTION_RAM(zmk_behavior_local_id_map, 4) diff --git a/app/include/zmk/behavior.h b/app/include/zmk/behavior.h index 016fa3bc063..34a415ca06e 100644 --- a/app/include/zmk/behavior.h +++ b/app/include/zmk/behavior.h @@ -23,6 +23,8 @@ struct zmk_behavior_binding_event { int64_t timestamp; }; +typedef uint16_t zmk_behavior_local_id_t; + /** * @brief Get a const struct device* for a behavior from its @p name field. * @@ -36,3 +38,23 @@ struct zmk_behavior_binding_event { * unrelated node which shares the same name as a behavior. */ const struct device *zmk_behavior_get_binding(const char *name); + +/** + * @brief Get a local ID for a behavior from its @p name field. + * + * @param name Behavior name to search for. + * + * @retval The local ID value that can be used to reference the behavior later, across reboots. + * @retval UINT16_MAX if the behavior is not found or its initialization function failed. + */ +zmk_behavior_local_id_t zmk_behavior_get_local_id(const char *name); + +/** + * @brief Get a behavior name for a behavior from its @p local_id . + * + * @param local_id Behavior local ID used to search for the behavior + * + * @retval The name of the behavior that is associated with that local ID. + * @retval NULL if the behavior is not found or its initialization function failed. + */ +const char *zmk_behavior_find_behavior_name_from_local_id(zmk_behavior_local_id_t local_id); diff --git a/app/src/behavior.c b/app/src/behavior.c index 7777155f404..7505aa7f1c1 100644 --- a/app/src/behavior.c +++ b/app/src/behavior.c @@ -6,9 +6,17 @@ #include #include +#include #include #include +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS) && \ + IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_ID_TYPE_SETTINGS_TABLE) + +#include + +#endif + #include #include #include @@ -185,6 +193,133 @@ int zmk_behavior_validate_binding(const struct zmk_behavior_binding *binding) { #endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) } +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS) + +zmk_behavior_local_id_t zmk_behavior_get_local_id(const char *name) { + if (!name) { + return UINT16_MAX; + } + + STRUCT_SECTION_FOREACH(zmk_behavior_local_id_map, item) { + if (z_device_is_ready(item->device) && strcmp(item->device->name, name) == 0) { + return item->local_id; + } + } + + return UINT16_MAX; +} + +const char *zmk_behavior_find_behavior_name_from_local_id(zmk_behavior_local_id_t local_id) { + STRUCT_SECTION_FOREACH(zmk_behavior_local_id_map, item) { + if (z_device_is_ready(item->device) && item->local_id == local_id) { + return item->device->name; + } + } + + return NULL; +} + +#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_ID_TYPE_CRC16) + +static int behavior_local_id_init(void) { + STRUCT_SECTION_FOREACH(zmk_behavior_local_id_map, item) { + item->local_id = crc16_ansi(item->device->name, strlen(item->device->name)); + } + + return 0; +} + +#elif IS_ENABLED(CONFIG_ZMK_BEHAVIOR_LOCAL_ID_TYPE_SETTINGS_TABLE) + +static zmk_behavior_local_id_t largest_local_id = 0; + +static int behavior_handle_set(const char *name, size_t len, settings_read_cb read_cb, + void *cb_arg) { + const char *next; + + if (settings_name_steq(name, "local_id", &next) && next) { + char *endptr; + uint8_t local_id = strtoul(next, &endptr, 10); + if (*endptr != '\0') { + LOG_WRN("Invalid behavior local ID: %s with endptr %s", next, endptr); + return -EINVAL; + } + + if (len >= 64) { + LOG_ERR("Too large binding setting size (got %d expected less than %d)", len, 64); + return -EINVAL; + } + + char name[len + 1]; + + int err = read_cb(cb_arg, name, len); + if (err <= 0) { + LOG_ERR("Failed to handle keymap binding from settings (err %d)", err); + return err; + } + + name[len] = '\0'; + STRUCT_SECTION_FOREACH(zmk_behavior_local_id_map, item) { + if (strcmp(name, item->device->name) == 0) { + item->local_id = local_id; + largest_local_id = MAX(largest_local_id, local_id); + return 0; + } + } + + return -EINVAL; + } + + return 0; +} + +static int behavior_handle_commit(void) { + STRUCT_SECTION_FOREACH(zmk_behavior_local_id_map, item) { + if (item->local_id != 0) { + continue; + } + + if (!item->device || !item->device->name || !device_is_ready(item->device)) { + LOG_WRN("Skipping ID for device that doesn't exist or isn't ready"); + continue; + } + + item->local_id = ++largest_local_id; + char setting_name[32]; + sprintf(setting_name, "behavior/local_id/%d", item->local_id); + + // If the `device->name` is readonly in flash, settings save can fail to copy/read it while + // persisting to flash, so copy the device name into memory first before saving. + char device_name[32]; + snprintf(device_name, ARRAY_SIZE(device_name), "%s", item->device->name); + + settings_save_one(setting_name, device_name, strlen(device_name)); + } + + return 0; +} + +SETTINGS_STATIC_HANDLER_DEFINE(behavior, "behavior", NULL, behavior_handle_set, + behavior_handle_commit, NULL); + +static int behavior_local_id_init(void) { + settings_subsys_init(); + + settings_load_subtree("behavior"); + + return 0; +} + +#else + +#error "A behavior local ID mechanism must be selected" + +#endif + +SYS_INIT(behavior_local_id_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); + +#endif + #if IS_ENABLED(CONFIG_LOG) static int check_behavior_names(void) { // Behavior names must be unique, but we don't have a good way to enforce this From 96e55c8be61e9a12cf06147ece38dd7596023bc6 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 28 Jun 2024 17:40:49 -0600 Subject: [PATCH 122/134] fix: BLE refactor mouse keys fix. --- app/core-coverage.yml | 4 ++++ app/src/hog.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/core-coverage.yml b/app/core-coverage.yml index 7eef35cf70f..1350044cffb 100644 --- a/app/core-coverage.yml +++ b/app/core-coverage.yml @@ -22,6 +22,10 @@ include: shield: kyria_left cmake-args: "-DCONFIG_ZMK_DISPLAY=y" nickname: "display" + - board: nice_nano_v2 + shield: kyria_left + cmake-args: "-DCONFIG_ZMK_MOUSE=y" + nickname: "mouse" - board: sparkfun_pro_micro_rp2040 shield: reviung41 cmake-args: "-DSNIPPET='zmk-usb-logging'" diff --git a/app/src/hog.c b/app/src/hog.c index 77dde989e3a..82fafc29cd7 100644 --- a/app/src/hog.c +++ b/app/src/hog.c @@ -336,7 +336,7 @@ K_MSGQ_DEFINE(zmk_hog_mouse_msgq, sizeof(struct zmk_hid_mouse_report_body), void send_mouse_report_callback(struct k_work *work) { struct zmk_hid_mouse_report_body report; while (k_msgq_get(&zmk_hog_mouse_msgq, &report, K_NO_WAIT) == 0) { - struct bt_conn *conn = destination_connection(); + struct bt_conn *conn = zmk_ble_active_profile_conn(); if (conn == NULL) { return; } From f2ea1da036f7c54199c3bcb79fcbda9753f91028 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Sun, 30 Jun 2024 17:59:46 +0100 Subject: [PATCH 123/134] fix(boards): Suppress devicetree warning nRF5x boards throw a spurious warning for duplicate unit-address when the devicetree gets processed Upstream issue: https://github.com/zephyrproject-rtos/zephyr/issues/29713 Warning suppressed as per: https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html --- app/boards/arm/adv360pro/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/bluemicro840/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/bt60/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/ckp/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/corneish_zen/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/glove80/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/mikoto/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/nice60/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/nice_nano/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/nrf52840_m2/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/nrfmicro/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/pillbug/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/puchi_ble/pre_dt_board.cmake | 9 +++++++++ app/boards/arm/s40nc/pre_dt_board.cmake | 9 +++++++++ 14 files changed, 126 insertions(+) create mode 100644 app/boards/arm/adv360pro/pre_dt_board.cmake create mode 100644 app/boards/arm/bluemicro840/pre_dt_board.cmake create mode 100644 app/boards/arm/bt60/pre_dt_board.cmake create mode 100644 app/boards/arm/ckp/pre_dt_board.cmake create mode 100644 app/boards/arm/corneish_zen/pre_dt_board.cmake create mode 100644 app/boards/arm/glove80/pre_dt_board.cmake create mode 100644 app/boards/arm/mikoto/pre_dt_board.cmake create mode 100644 app/boards/arm/nice60/pre_dt_board.cmake create mode 100644 app/boards/arm/nice_nano/pre_dt_board.cmake create mode 100644 app/boards/arm/nrf52840_m2/pre_dt_board.cmake create mode 100644 app/boards/arm/nrfmicro/pre_dt_board.cmake create mode 100644 app/boards/arm/pillbug/pre_dt_board.cmake create mode 100644 app/boards/arm/puchi_ble/pre_dt_board.cmake create mode 100644 app/boards/arm/s40nc/pre_dt_board.cmake diff --git a/app/boards/arm/adv360pro/pre_dt_board.cmake b/app/boards/arm/adv360pro/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/adv360pro/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/bluemicro840/pre_dt_board.cmake b/app/boards/arm/bluemicro840/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/bluemicro840/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/bt60/pre_dt_board.cmake b/app/boards/arm/bt60/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/bt60/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/ckp/pre_dt_board.cmake b/app/boards/arm/ckp/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/ckp/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/corneish_zen/pre_dt_board.cmake b/app/boards/arm/corneish_zen/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/corneish_zen/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/glove80/pre_dt_board.cmake b/app/boards/arm/glove80/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/glove80/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/mikoto/pre_dt_board.cmake b/app/boards/arm/mikoto/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/mikoto/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/nice60/pre_dt_board.cmake b/app/boards/arm/nice60/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/nice60/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/nice_nano/pre_dt_board.cmake b/app/boards/arm/nice_nano/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/nice_nano/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/nrf52840_m2/pre_dt_board.cmake b/app/boards/arm/nrf52840_m2/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/nrf52840_m2/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/nrfmicro/pre_dt_board.cmake b/app/boards/arm/nrfmicro/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/nrfmicro/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/pillbug/pre_dt_board.cmake b/app/boards/arm/pillbug/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/pillbug/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/puchi_ble/pre_dt_board.cmake b/app/boards/arm/puchi_ble/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/puchi_ble/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file diff --git a/app/boards/arm/s40nc/pre_dt_board.cmake b/app/boards/arm/s40nc/pre_dt_board.cmake new file mode 100644 index 00000000000..05b0efe5f04 --- /dev/null +++ b/app/boards/arm/s40nc/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +# Suppresses duplicate unit-address warning at build time for power, clock, acl and flash-controller +# https://docs.zephyrproject.org/latest/build/dts/intro-input-output.html + +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") \ No newline at end of file From f18974e8c401b139058549dcd95ab7a4cdc7a6e9 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 1 Jul 2024 18:26:43 +0000 Subject: [PATCH 124/134] fix: Adjust hid indicator listeners for event refactor * Avoid static listener to prevent subscription issue. --- app/src/hid_indicators.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/hid_indicators.c b/app/src/hid_indicators.c index 1b489068956..a2220b1bead 100644 --- a/app/src/hid_indicators.c +++ b/app/src/hid_indicators.c @@ -64,5 +64,5 @@ static int profile_listener(const zmk_event_t *eh) { return 0; } -static ZMK_LISTENER(profile_listener, profile_listener); -static ZMK_SUBSCRIPTION(profile_listener, zmk_endpoint_changed); +ZMK_LISTENER(profile_listener, profile_listener); +ZMK_SUBSCRIPTION(profile_listener, zmk_endpoint_changed); From 9ef2e8eb0e8a47ff31943f9a3ca1e779b4da4d9a Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Sat, 28 May 2022 20:15:51 +0900 Subject: [PATCH 125/134] rgb_underglow: refresh more frequently for smoother RGB underglow --- app/src/rgb_underglow.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 5bf1ef25e8e..3dd85051096 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -280,7 +280,7 @@ static int zmk_rgb_underglow_init(void) { #endif if (state.on) { - k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); + k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(25)); } return 0; @@ -318,7 +318,7 @@ int zmk_rgb_underglow_on(void) { state.on = true; state.animation_step = 0; - k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); + k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(25)); return zmk_rgb_underglow_save_state(); } From e71732cf07258e8652c6d77db0bf8149ac858d3c Mon Sep 17 00:00:00 2001 From: Donald Gordon Date: Wed, 13 Jul 2022 22:39:44 +1200 Subject: [PATCH 126/134] RGB underglow status support Adds Glove80's status indicator using RGB underglow support. Requires ZMK PR#999 and PR#1243. The underglow status is able to show layer state, battery levels, caps/num/scroll-lock, BLE and USB state. The underglow positions selected for each of these indicators is configured using the new devicetree node zmk,underglow-indicators, which takes an array of integer LED positions for each feature. --- .../bindings/zmk,underglow-indicators.yaml | 35 +++ app/include/dt-bindings/zmk/rgb.h | 2 + app/include/zmk/ble.h | 1 + app/include/zmk/endpoints.h | 2 + app/include/zmk/rgb_underglow.h | 1 + app/src/behaviors/behavior_rgb_underglow.c | 2 + app/src/ble.c | 17 + app/src/endpoints.c | 4 + app/src/rgb_underglow.c | 296 ++++++++++++++++-- 9 files changed, 340 insertions(+), 20 deletions(-) create mode 100644 app/dts/bindings/zmk,underglow-indicators.yaml diff --git a/app/dts/bindings/zmk,underglow-indicators.yaml b/app/dts/bindings/zmk,underglow-indicators.yaml new file mode 100644 index 00000000000..d5cdde80a9a --- /dev/null +++ b/app/dts/bindings/zmk,underglow-indicators.yaml @@ -0,0 +1,35 @@ +# Copyright (c) 2020, The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Underglow indicators + +compatible: "zmk,underglow-indicators" + +properties: + bat-lhs: + type: array + required: true + bat-rhs: + type: array + required: true + capslock: + type: int + required: true + numlock: + type: int + required: true + scrolllock: + type: int + required: true + layer-state: + type: array + required: true + ble-state: + type: array + required: true + usb-state: + type: int + required: true + output-fallback: + type: int + required: true diff --git a/app/include/dt-bindings/zmk/rgb.h b/app/include/dt-bindings/zmk/rgb.h index c1a8008273c..657ac2fd528 100644 --- a/app/include/dt-bindings/zmk/rgb.h +++ b/app/include/dt-bindings/zmk/rgb.h @@ -19,6 +19,7 @@ #define RGB_EFR_CMD 12 #define RGB_EFS_CMD 13 #define RGB_COLOR_HSB_CMD 14 +#define RGB_STATUS_CMD 15 #define RGB_TOG RGB_TOG_CMD 0 #define RGB_ON RGB_ON_CMD 0 @@ -33,6 +34,7 @@ #define RGB_SPD RGB_SPD_CMD 0 #define RGB_EFF RGB_EFF_CMD 0 #define RGB_EFR RGB_EFR_CMD 0 +#define RGB_STATUS RGB_STATUS_CMD 0 #define RGB_COLOR_HSB_VAL(h, s, v) (((h) << 16) + ((s) << 8) + (v)) #define RGB_COLOR_HSB(h, s, v) RGB_COLOR_HSB_CMD##(RGB_COLOR_HSB_VAL(h, s, v)) #define RGB_COLOR_HSV RGB_COLOR_HSB \ No newline at end of file diff --git a/app/include/zmk/ble.h b/app/include/zmk/ble.h index cc55a6ce142..098a7c0b9dc 100644 --- a/app/include/zmk/ble.h +++ b/app/include/zmk/ble.h @@ -36,6 +36,7 @@ struct bt_conn *zmk_ble_active_profile_conn(void); bool zmk_ble_active_profile_is_open(void); bool zmk_ble_active_profile_is_connected(void); char *zmk_ble_active_profile_name(void); +int8_t zmk_ble_profile_status(uint8_t index); int zmk_ble_unpair_all(void); diff --git a/app/include/zmk/endpoints.h b/app/include/zmk/endpoints.h index f2aff2bcc2d..766a3b74946 100644 --- a/app/include/zmk/endpoints.h +++ b/app/include/zmk/endpoints.h @@ -68,6 +68,8 @@ int zmk_endpoints_toggle_transport(void); */ struct zmk_endpoint_instance zmk_endpoints_selected(void); +bool zmk_endpoints_preferred_transport_is_active(); + int zmk_endpoints_send_report(uint16_t usage_page); #if IS_ENABLED(CONFIG_ZMK_MOUSE) diff --git a/app/include/zmk/rgb_underglow.h b/app/include/zmk/rgb_underglow.h index be0ef252290..0c45e1c68f7 100644 --- a/app/include/zmk/rgb_underglow.h +++ b/app/include/zmk/rgb_underglow.h @@ -27,3 +27,4 @@ int zmk_rgb_underglow_change_sat(int direction); int zmk_rgb_underglow_change_brt(int direction); int zmk_rgb_underglow_change_spd(int direction); int zmk_rgb_underglow_set_hsb(struct zmk_led_hsb color); +int zmk_rgb_underglow_status(void); diff --git a/app/src/behaviors/behavior_rgb_underglow.c b/app/src/behaviors/behavior_rgb_underglow.c index c37e5217c73..88df9518c36 100644 --- a/app/src/behaviors/behavior_rgb_underglow.c +++ b/app/src/behaviors/behavior_rgb_underglow.c @@ -244,6 +244,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, return zmk_rgb_underglow_set_hsb((struct zmk_led_hsb){.h = (binding->param2 >> 16) & 0xFFFF, .s = (binding->param2 >> 8) & 0xFF, .b = binding->param2 & 0xFF}); + case RGB_STATUS_CMD: + return zmk_rgb_underglow_status(); } return -ENOTSUP; diff --git a/app/src/ble.c b/app/src/ble.c index b2dfbfa1eac..1966151d705 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -129,6 +129,23 @@ bool zmk_ble_active_profile_is_connected(void) { return info.state == BT_CONN_STATE_CONNECTED; } +int8_t zmk_ble_profile_status(uint8_t index) { + if (index >= ZMK_BLE_PROFILE_COUNT) + return -1; + bt_addr_le_t *addr = &profiles[index].peer; + struct bt_conn *conn; + int result; + if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) { + result = 0; // disconnected + } else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) { + result = 1; // paired + } else { + result = 2; // connected + bt_conn_unref(conn); + } + return result; +} + #define CHECKED_ADV_STOP() \ err = bt_le_adv_stop(); \ advertising_status = ZMK_ADV_NONE; \ diff --git a/app/src/endpoints.c b/app/src/endpoints.c index 7c9d15a31fe..bf9f8cb4559 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -320,6 +320,10 @@ static struct zmk_endpoint_instance get_selected_instance(void) { return instance; } +bool zmk_endpoints_preferred_transport_is_active(void) { + return preferred_transport == get_selected_transport(); +} + static int zmk_endpoints_init(void) { #if IS_ENABLED(CONFIG_SETTINGS) settings_subsys_init(); diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 3dd85051096..34ea46895be 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -12,6 +12,13 @@ #include #include +#include +#include +#include +#include +#include +#include + #include #include @@ -20,12 +27,15 @@ #include #include -#include #include #include #include #include +#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING) +#include +#endif + LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #if !DT_HAS_CHOSEN(zmk_underglow) @@ -58,11 +68,14 @@ struct rgb_underglow_state { uint8_t current_effect; uint16_t animation_step; bool on; + bool status_active; + uint16_t status_animation_step; }; static const struct device *led_strip; static struct led_rgb pixels[STRIP_NUM_PIXELS]; +static struct led_rgb status_pixels[STRIP_NUM_PIXELS]; static struct rgb_underglow_state state; @@ -70,6 +83,8 @@ static struct rgb_underglow_state state; static const struct device *const ext_power = DEVICE_DT_GET(DT_INST(0, zmk_ext_power_generic)); #endif +void zmk_rgb_set_ext_power(void); + static struct zmk_led_hsb hsb_scale_min_max(struct zmk_led_hsb hsb) { hsb.b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN + (CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX - CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) * hsb.b / BRT_MAX; @@ -175,6 +190,199 @@ static void zmk_rgb_underglow_effect_swirl(void) { state.animation_step = state.animation_step % HUE_MAX; } +static int zmk_led_generate_status(void); + +static void zmk_led_write_pixels(void) { + static struct led_rgb led_buffer[STRIP_NUM_PIXELS]; + int bat0 = zmk_battery_state_of_charge(); + int blend = 0; + if (state.status_active) { + blend = zmk_led_generate_status(); + } + + // fast path: no status indicators, battery level OK + if (blend == 0 && bat0 >= 20) { + led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); + return; + } + + if (blend == 0) { + for (int i = 0; i < STRIP_NUM_PIXELS; i++) { + led_buffer[i] = pixels[i]; + } + } else if (blend >= 256) { + for (int i = 0; i < STRIP_NUM_PIXELS; i++) { + led_buffer[i] = status_pixels[i]; + } + } else if (blend < 256) { + uint16_t blend_l = blend; + uint16_t blend_r = 256 - blend; + for (int i = 0; i < STRIP_NUM_PIXELS; i++) { + led_buffer[i].r = + ((status_pixels[i].r * blend_l) >> 8) + ((pixels[i].r * blend_r) >> 8); + led_buffer[i].g = + ((status_pixels[i].g * blend_l) >> 8) + ((pixels[i].g * blend_r) >> 8); + led_buffer[i].b = + ((status_pixels[i].b * blend_l) >> 8) + ((pixels[i].b * blend_r) >> 8); + } + } + + int err = led_strip_update_rgb(led_strip, led_buffer, STRIP_NUM_PIXELS); + if (err < 0) { + LOG_ERR("Failed to update the RGB strip (%d)", err); + } +} + +#define UNDERGLOW_INDICATORS DT_PATH(underglow_indicators) + +#if defined(DT_N_S_underglow_indicators_EXISTS) +#define UNDERGLOW_INDICATORS_ENABLED 1 +#else +#define UNDERGLOW_INDICATORS_ENABLED 0 +#endif + +#if !UNDERGLOW_INDICATORS_ENABLED +static int zmk_led_generate_status(void) { return 0; } +#else + +const uint8_t underglow_layer_state[] = DT_PROP(UNDERGLOW_INDICATORS, layer_state); +const uint8_t underglow_ble_state[] = DT_PROP(UNDERGLOW_INDICATORS, ble_state); +const uint8_t underglow_bat_lhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_lhs); +const uint8_t underglow_bat_rhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_rhs); + +#define HEXRGB(R, G, B) \ + ((struct led_rgb){ \ + r : (CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX * (R)) / 0xff, \ + g : (CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX * (G)) / 0xff, \ + b : (CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX * (B)) / 0xff \ + }) +const struct led_rgb red = HEXRGB(0xff, 0x00, 0x00); +const struct led_rgb yellow = HEXRGB(0xff, 0xff, 0x00); +const struct led_rgb green = HEXRGB(0x00, 0xff, 0x00); +const struct led_rgb dull_green = HEXRGB(0x00, 0xff, 0x68); +const struct led_rgb magenta = HEXRGB(0xff, 0x00, 0xff); +const struct led_rgb white = HEXRGB(0xff, 0xff, 0xff); +const struct led_rgb lilac = HEXRGB(0x6b, 0x1f, 0xce); + +static void zmk_led_battery_level(int bat_level, const uint8_t *addresses, size_t addresses_len) { + struct led_rgb bat_colour; + + if (bat_level > 40) { + bat_colour = green; + } else if (bat_level > 20) { + bat_colour = yellow; + } else { + bat_colour = red; + } + + // originally, six levels, 0 .. 100 + + for (int i = 0; i < addresses_len; i++) { + int min_level = (i * 100) / (addresses_len - 1); + if (bat_level >= min_level) { + status_pixels[addresses[i]] = bat_colour; + } + } +} + +static void zmk_led_fill(struct led_rgb color, const uint8_t *addresses, size_t addresses_len) { + for (int i = 0; i < addresses_len; i++) { + status_pixels[addresses[i]] = color; + } +} + +#define ZMK_LED_NUMLOCK_BIT BIT(0) +#define ZMK_LED_CAPSLOCK_BIT BIT(1) +#define ZMK_LED_SCROLLLOCK_BIT BIT(2) + +static int zmk_led_generate_status(void) { + for (int i = 0; i < STRIP_NUM_PIXELS; i++) { + status_pixels[i] = (struct led_rgb){r : 0, g : 0, b : 0}; + } + + // BATTERY STATUS + zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_lhs, + DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_lhs)); + +#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING) + uint8_t peripheral_level = 0; + int rc = zmk_split_get_peripheral_battery_level(0, &peripheral_level); + + if (rc == 0) { + zmk_led_battery_level(peripheral_level, underglow_bat_rhs, + DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs)); + } else if (rc == -ENOTCONN) { + zmk_led_fill(red, underglow_bat_rhs, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs)); + } else if (rc == -EINVAL) { + LOG_ERR("Invalid peripheral index requested for battery level read: 0"); + } +#endif + + // CAPSLOCK/NUMLOCK/SCROLLOCK STATUS + zmk_hid_indicators_t led_flags = zmk_hid_indicators_get_current_profile(); + + if (led_flags & ZMK_LED_CAPSLOCK_BIT) + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, capslock)] = red; + if (led_flags & ZMK_LED_NUMLOCK_BIT) + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, numlock)] = red; + if (led_flags & ZMK_LED_SCROLLLOCK_BIT) + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, scrolllock)] = red; + + // LAYER STATUS + for (uint8_t i = 0; i < DT_PROP_LEN(UNDERGLOW_INDICATORS, layer_state); i++) { + if (zmk_keymap_layer_active(i)) + status_pixels[underglow_layer_state[i]] = magenta; + } + + struct zmk_endpoint_instance active_endpoint = zmk_endpoints_selected(); + + if (!zmk_endpoints_preferred_transport_is_active()) + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, output_fallback)] = red; + + int active_ble_profile_index = zmk_ble_active_profile_index(); + for (uint8_t i = 0; + i < MIN(ZMK_BLE_PROFILE_COUNT, DT_PROP_LEN(UNDERGLOW_INDICATORS, ble_state)); i++) { + int8_t status = zmk_ble_profile_status(i); + int ble_pixel = underglow_ble_state[i]; + if (status == 2 && active_endpoint.transport == ZMK_TRANSPORT_BLE && + active_ble_profile_index == i) { // connected AND active + status_pixels[ble_pixel] = white; + } else if (status == 2) { // connected + status_pixels[ble_pixel] = dull_green; + } else if (status == 1) { // paired + status_pixels[ble_pixel] = red; + } else if (status == 0) { // unused + status_pixels[ble_pixel] = lilac; + } + } + + enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state(); + if (usb_state == ZMK_USB_CONN_HID && + active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white; + } else if (usb_state == ZMK_USB_CONN_HID) { // connected + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green; + } else if (usb_state == ZMK_USB_CONN_POWERED) { // powered + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red; + } else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac; + } + + int16_t blend = 256; + if (state.status_animation_step < (500 / 25)) { + blend = ((state.status_animation_step * 256) / (500 / 25)); + } else if (state.status_animation_step > (8000 / 25)) { + blend = 256 - (((state.status_animation_step - (8000 / 25)) * 256) / (2000 / 25)); + } + if (blend < 0) + blend = 0; + if (blend > 256) + blend = 256; + + return blend; +} +#endif // underglow_indicators exists + static void zmk_rgb_underglow_tick(struct k_work *work) { switch (state.current_effect) { case UNDERGLOW_EFFECT_SOLID: @@ -191,10 +399,7 @@ static void zmk_rgb_underglow_tick(struct k_work *work) { break; } - int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); - if (err < 0) { - LOG_ERR("Failed to update the RGB strip (%d)", err); - } + zmk_led_write_pixels(); } K_WORK_DEFINE(underglow_tick_work, zmk_rgb_underglow_tick); @@ -303,20 +508,37 @@ int zmk_rgb_underglow_get_state(bool *on_off) { return 0; } -int zmk_rgb_underglow_on(void) { - if (!led_strip) - return -ENODEV; - +void zmk_rgb_set_ext_power(void) { #if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER) - if (ext_power != NULL) { + if (ext_power == NULL) + return; + int c_power = ext_power_get(ext_power); + if (c_power < 0) { + LOG_ERR("Unable to examine EXT_POWER: %d", c_power); + c_power = 0; + } + int desired_state = state.on || state.status_active; + if (desired_state && !c_power) { int rc = ext_power_enable(ext_power); if (rc != 0) { LOG_ERR("Unable to enable EXT_POWER: %d", rc); } + } else if (!desired_state && c_power) { + int rc = ext_power_disable(ext_power); + if (rc != 0) { + LOG_ERR("Unable to disable EXT_POWER: %d", rc); + } } #endif +} + +int zmk_rgb_underglow_on(void) { + if (!led_strip) + return -ENODEV; state.on = true; + zmk_rgb_set_ext_power(); + state.animation_step = 0; k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(25)); @@ -328,7 +550,7 @@ static void zmk_rgb_underglow_off_handler(struct k_work *work) { pixels[i] = (struct led_rgb){r : 0, g : 0, b : 0}; } - led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); + zmk_led_write_pixels(); } K_WORK_DEFINE(underglow_off_work, zmk_rgb_underglow_off_handler); @@ -337,19 +559,11 @@ int zmk_rgb_underglow_off(void) { if (!led_strip) return -ENODEV; -#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER) - if (ext_power != NULL) { - int rc = ext_power_disable(ext_power); - if (rc != 0) { - LOG_ERR("Unable to disable EXT_POWER: %d", rc); - } - } -#endif - k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &underglow_off_work); k_timer_stop(&underglow_tick); state.on = false; + zmk_rgb_set_ext_power(); return zmk_rgb_underglow_save_state(); } @@ -380,6 +594,48 @@ int zmk_rgb_underglow_toggle(void) { return state.on ? zmk_rgb_underglow_off() : zmk_rgb_underglow_on(); } +static void zmk_led_write_pixels_work(struct k_work *work); +static void zmk_rgb_underglow_status_update(struct k_timer *timer); + +K_WORK_DEFINE(underglow_write_work, zmk_led_write_pixels_work); +K_TIMER_DEFINE(underglow_status_update_timer, zmk_rgb_underglow_status_update, NULL); + +static void zmk_rgb_underglow_status_update(struct k_timer *timer) { + if (!state.status_active) + return; + state.status_animation_step++; + if (state.status_animation_step > (10000 / 25)) { + state.status_active = false; + k_timer_stop(&underglow_status_update_timer); + } + if (!k_work_is_pending(&underglow_write_work)) + k_work_submit(&underglow_write_work); +} + +static void zmk_led_write_pixels_work(struct k_work *work) { + zmk_led_write_pixels(); + if (!state.status_active) { + zmk_rgb_set_ext_power(); + } +} + +int zmk_rgb_underglow_status(void) { + if (!state.status_active) { + state.status_animation_step = 0; + } else { + if (state.status_animation_step > (500 / 25)) { + state.status_animation_step = 500 / 25; + } + } + state.status_active = true; + zmk_led_write_pixels(); + zmk_rgb_set_ext_power(); + + k_timer_start(&underglow_status_update_timer, K_NO_WAIT, K_MSEC(25)); + + return 0; +} + int zmk_rgb_underglow_set_hsb(struct zmk_led_hsb color) { if (color.h > HUE_MAX || color.s > SAT_MAX || color.b > BRT_MAX) { return -ENOTSUP; From 6ce3a79dd4e3f06b2e889c766a5fb74a13121f02 Mon Sep 17 00:00:00 2001 From: Donald Gordon Date: Wed, 28 Sep 2022 21:11:04 +0900 Subject: [PATCH 127/134] RGB underglow: dim or disable when battery low Disable underglow when battery below 10%, halve brightness when battery below 20% --- app/src/rgb_underglow.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 34ea46895be..273223171a1 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -196,6 +196,7 @@ static void zmk_led_write_pixels(void) { static struct led_rgb led_buffer[STRIP_NUM_PIXELS]; int bat0 = zmk_battery_state_of_charge(); int blend = 0; + int reset_ext_power = 0; if (state.status_active) { blend = zmk_led_generate_status(); } @@ -205,6 +206,18 @@ static void zmk_led_write_pixels(void) { led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); return; } + // battery below minimum charge + if (bat0 < 10) { + memset(pixels, 0, sizeof(struct led_rgb) * STRIP_NUM_PIXELS); + if (state.on) { + int c_power = ext_power_get(ext_power); + if (c_power && !state.status_active) { + // power is on, RGB underglow is on, but battery is too low + state.on = false; + reset_ext_power = true; + } + } + } if (blend == 0) { for (int i = 0; i < STRIP_NUM_PIXELS; i++) { @@ -227,10 +240,23 @@ static void zmk_led_write_pixels(void) { } } + // battery below 20%, reduce LED brightness + if (bat0 < 20) { + for (int i = 0; i < STRIP_NUM_PIXELS; i++) { + led_buffer[i].r = led_buffer[i].r >> 1; + led_buffer[i].g = led_buffer[i].g >> 1; + led_buffer[i].b = led_buffer[i].b >> 1; + } + } + int err = led_strip_update_rgb(led_strip, led_buffer, STRIP_NUM_PIXELS); if (err < 0) { LOG_ERR("Failed to update the RGB strip (%d)", err); } + + if (reset_ext_power) { + zmk_rgb_set_ext_power(); + } } #define UNDERGLOW_INDICATORS DT_PATH(underglow_indicators) @@ -518,6 +544,12 @@ void zmk_rgb_set_ext_power(void) { c_power = 0; } int desired_state = state.on || state.status_active; + // force power off, when battery low (<10%) + if (state.on && !state.status_active) { + if (zmk_battery_state_of_charge() < 10) { + desired_state = false; + } + } if (desired_state && !c_power) { int rc = ext_power_enable(ext_power); if (rc != 0) { From a9d480590025f6faf7aca355e825a865c57e2cfa Mon Sep 17 00:00:00 2001 From: Donald Gordon Date: Sat, 21 Jan 2023 15:33:21 +1300 Subject: [PATCH 128/134] ext_power: add Kconfig for initial ext_power state Adds a Kconfig setting for the default EXT_POWER status at initialization time. Previously it was always initialized to on if no saved value was present. --- app/Kconfig | 9 +++++++++ app/src/ext_power_generic.c | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index a45f2dc23f0..84a2aeb08aa 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -450,6 +450,15 @@ config ZMK_GPIO_KEY_WAKEUP_TRIGGER default y depends on DT_HAS_ZMK_GPIO_KEY_WAKEUP_TRIGGER_ENABLED && ZMK_PM_SOFT_OFF +if ZMK_EXT_POWER + +config ZMK_EXT_POWER_START + bool "Enable external power output by default" + default y + +#ZMK_EXT_POWER +endif + #Power Management endmenu diff --git a/app/src/ext_power_generic.c b/app/src/ext_power_generic.c index 2586f436852..9b179fcbb0a 100644 --- a/app/src/ext_power_generic.c +++ b/app/src/ext_power_generic.c @@ -145,18 +145,26 @@ static int ext_power_generic_init(const struct device *dev) { k_work_init_delayable(&ext_power_save_work, ext_power_save_state_work); - // Set default value (on) if settings isn't set + // Set default value if settings isn't set settings_load_subtree("ext_power"); if (!data->settings_init) { - data->status = true; + data->status = IS_ENABLED(CONFIG_ZMK_EXT_POWER_START); k_work_schedule(&ext_power_save_work, K_NO_WAIT); - ext_power_enable(dev); + if (data->status) { + ext_power_enable(dev); + } else { + ext_power_disable(dev); + } } #else - // Default to the ext_power being open when no settings - ext_power_enable(dev); + // If no settings, set ext_power on/off + if (IS_ENABLED(CONFIG_ZMK_EXT_POWER_START)) { + ext_power_enable(dev); + } else { + ext_power_disable(dev); + } #endif if (config->init_delay_ms) { From ddad581dd4db728db4563c59e472a9c8746f176e Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Wed, 15 Feb 2023 14:10:21 +0900 Subject: [PATCH 129/134] Include the serial number in the Bluetooth device name --- app/Kconfig | 10 +++++++ app/boards/arm/glove80/glove80_lh_defconfig | 2 ++ app/boards/arm/glove80/usb_serial_number.c | 31 +++++++++++++------- app/src/ble.c | 32 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 84a2aeb08aa..8e300a8c21b 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -222,6 +222,16 @@ config ZMK_BLE_MOUSE_REPORT_QUEUE_SIZE config ZMK_BLE_CLEAR_BONDS_ON_START bool "Configuration that clears all bond information from the keyboard on startup." +config ZMK_BLE_DEVICE_NAME_APPEND_SN + bool "Append the device serial number to the Bluetooth device name" + default n + select BT_DEVICE_NAME_DYNAMIC + +config ZMK_BLE_DEVICE_NAME_SN_CHARS + int "Number of hexadecimal digits of serial number to append to the BT device name" + default 6 + depends on ZMK_BLE_DEVICE_NAME_APPEND_SN + # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. config BT_GATT_NOTIFY_MULTIPLE default n diff --git a/app/boards/arm/glove80/glove80_lh_defconfig b/app/boards/arm/glove80/glove80_lh_defconfig index a93f27cd8f2..b454e8be1bf 100644 --- a/app/boards/arm/glove80/glove80_lh_defconfig +++ b/app/boards/arm/glove80/glove80_lh_defconfig @@ -16,6 +16,8 @@ CONFIG_USB_DEVICE_VID=0x16c0 CONFIG_USB_DEVICE_MANUFACTURER="MoErgo" CONFIG_USB_DEVICE_SN="moergo.com:GLV80-0123456789ABCDEF" +CONFIG_BT_DEVICE_NAME="Glove80" + CONFIG_BT_DIS_PNP_PID=0x27db CONFIG_BT_DIS_PNP_VID=0x16c0 CONFIG_BT_DIS_MANUF="MoErgo" diff --git a/app/boards/arm/glove80/usb_serial_number.c b/app/boards/arm/glove80/usb_serial_number.c index 44d7ee20363..6254cdc4d73 100644 --- a/app/boards/arm/glove80/usb_serial_number.c +++ b/app/boards/arm/glove80/usb_serial_number.c @@ -14,14 +14,15 @@ LOG_MODULE_DECLARE(usb_descriptor); int base16_encode(const uint8_t *data, int length, uint8_t *result, int bufSize); +void fill_serial_number(char *buf, int length); +/** + * nrf52840 hwinfo returns a 64-bit hardware id. Glove80 uses this as a + * serial number, encoded as base16 into the last 16 characters of the + * CONFIG_USB_DEVICE_SN template. If insufficient template space is + * available, instead return the static serial number string. + */ uint8_t *usb_update_sn_string_descriptor(void) { - /* - * nrf52840 hwinfo returns a 64-bit hardware id. Glove80 uses this as a - * serial number, encoded as base16 into the last 16 characters of the - * CONFIG_USB_DEVICE_SN template. If insufficient template space is - * available, instead return the static serial number string. - */ const uint8_t template_len = sizeof(CONFIG_USB_DEVICE_SN); const uint8_t sn_len = 16; @@ -33,17 +34,25 @@ uint8_t *usb_update_sn_string_descriptor(void) { static uint8_t serial[sizeof(CONFIG_USB_DEVICE_SN)]; strncpy(serial, CONFIG_USB_DEVICE_SN, template_len); + const uint8_t offset = template_len - sn_len - 1; + fill_serial_number(serial + offset, sn_len); + serial[template_len - 1] = '\0'; + + return serial; +} + +/** + * Writes the first `length` bytes of the device serial number into buf + */ +void fill_serial_number(char *buf, int length) { uint8_t hwid[8]; memset(hwid, 0, sizeof(hwid)); uint8_t hwlen = hwinfo_get_device_id(hwid, sizeof(hwid)); if (hwlen > 0) { - const uint8_t offset = template_len - sn_len - 1; - LOG_HEXDUMP_DBG(&hwid, sn_len, "Serial Number"); - base16_encode(hwid, hwlen, serial + offset, sn_len + 1); + LOG_HEXDUMP_DBG(&hwid, 16, "Serial Number"); + base16_encode(hwid, hwlen, buf, length); } - - return serial; } int base16_encode(const uint8_t *data, int length, uint8_t *result, int bufSize) { diff --git a/app/src/ble.c b/app/src/ble.c index 1966151d705..d5633864821 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -62,9 +62,32 @@ enum advertising_type { static struct zmk_ble_profile profiles[ZMK_BLE_PROFILE_COUNT]; static uint8_t active_profile; +#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN) + +static char bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) + CONFIG_ZMK_BLE_DEVICE_NAME_SN_CHARS + 1]; + +void fill_serial_number(char *buf, int length); + +// configure the BT device name by appending a serial number prefix to +// CONFIG_BT_DEVICE_NAME +void init_bt_device_name(void) { + strncpy(bt_device_name, CONFIG_BT_DEVICE_NAME, sizeof(bt_device_name)); + bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME) - 1] = ' '; + fill_serial_number(&bt_device_name[sizeof(CONFIG_BT_DEVICE_NAME)], + CONFIG_ZMK_BLE_DEVICE_NAME_SN_CHARS); + bt_device_name[sizeof(bt_device_name) - 1] = '\0'; +} + +#define DEVICE_NAME bt_device_name +#define DEVICE_NAME_LEN (sizeof(bt_device_name) - 1) + +#else + #define DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) +#endif + BUILD_ASSERT(DEVICE_NAME_LEN <= 16, "ERROR: BLE device name is too long. Max length: 16"); static const struct bt_data zmk_ble_ad[] = { @@ -662,6 +685,10 @@ static void zmk_ble_ready(int err) { } static int zmk_ble_init(void) { +#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN) + init_bt_device_name(); +#endif + int err = bt_enable(NULL); if (err) { @@ -682,7 +709,12 @@ static int zmk_ble_init(void) { settings_load_subtree("ble"); settings_load_subtree("bt"); +#endif +#if IS_ENABLED(CONFIG_ZMK_BLE_DEVICE_NAME_APPEND_SN) + if (strcmp(bt_get_name(), bt_device_name) != 0) { + bt_set_name(bt_device_name); + } #endif #if IS_ENABLED(CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START) From 476550b876efd32cbe7417a550759934610caf5d Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Sat, 18 Sep 2021 20:38:30 +0900 Subject: [PATCH 130/134] Add build environment using Nix --- .gitattributes | 1 + README-NIX.md | 39 +++ default.nix | 51 ++++ nix/cmake-shell.nix | 17 ++ nix/generate-pin.rb | 34 +++ nix/manifest.json | 343 +++++++++++++++++++++++++ nix/pinned-nixpkgs.json | 4 + nix/pinned-nixpkgs.nix | 17 ++ nix/update-manifest/default.nix | 11 + nix/update-manifest/update-manifest.sh | 39 +++ nix/west-manifest.patch | 17 ++ nix/west-shell.nix | 50 ++++ nix/zephyr.nix | 52 ++++ nix/zmk.nix | 112 ++++++++ 14 files changed, 787 insertions(+) create mode 100644 README-NIX.md create mode 100644 default.nix create mode 100644 nix/cmake-shell.nix create mode 100755 nix/generate-pin.rb create mode 100644 nix/manifest.json create mode 100644 nix/pinned-nixpkgs.json create mode 100644 nix/pinned-nixpkgs.nix create mode 100644 nix/update-manifest/default.nix create mode 100755 nix/update-manifest/update-manifest.sh create mode 100644 nix/west-manifest.patch create mode 100644 nix/west-shell.nix create mode 100644 nix/zephyr.nix create mode 100644 nix/zmk.nix diff --git a/.gitattributes b/.gitattributes index 3d05d86d31a..af12493a041 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,4 @@ # Docker on Windows. .bashrc text eol=lf *.sh text eol=lf +*.nix text eol=lf diff --git a/README-NIX.md b/README-NIX.md new file mode 100644 index 00000000000..a65c376a4a2 --- /dev/null +++ b/README-NIX.md @@ -0,0 +1,39 @@ +# Building Zephyrâ„¢ Mechanical Keyboard (ZMK) Firmware with Nix + +This extension is added by MoErgo for the Glove80 keyboard. + +Nix makes setup significantly easier. With this approach `west` is not needed. +You can however still choose to build using the standard Zephyr `west` toolchain +if you wish. + +# To build a target + +In ZMK root directory, + + nix-build -A *target* [-o *output_directory*] + +For example, + + nix-build -A glove80_left -o left + +The `output_directory` nix creates is a symlink. If you prefer not to rely on +symlink (perhaps because you are using WSL on Windows), you can make a copy of +the resulting `uf2` file using: + + cp -f $(nix-build -A *target* --no-out-link)/zmk.uf2 . + +# To build Glove80 + +In ZMK root directory, + + cp -f $(nix-build -A glove80_combined --no-out-link)/glove80.uf2 . + +# Adding new targets + +Edit default.nix and add an target based on zmk + +An example is: + + glove80_left = zmk.override { + board = "glove80_lh"; + }; diff --git a/default.nix b/default.nix new file mode 100644 index 00000000000..2a9f766e226 --- /dev/null +++ b/default.nix @@ -0,0 +1,51 @@ +{ pkgs ? (import ./nix/pinned-nixpkgs.nix {}) }: +let + inherit (pkgs) newScope; + inherit (pkgs.lib) makeScope; +in + +makeScope newScope (self: with self; { + west = pkgs.python3Packages.west.overrideAttrs(attrs: { + patches = (attrs.patches or []) ++ [./nix/west-manifest.patch]; + }); + + # To update the pinned Zephyr dependecies using west and update-manifest: + # nix shell -f . west -c west init -l app + # nix shell -f . west -c west update + # nix shell -f . update-manifest -c update-manifest > nix/manifest.json + # Note that any `group-filter` groups in west.yml need to be temporarily + # removed, as `west update-manifest` requires all dependencies to be fetched. + update-manifest = callPackage ./nix/update-manifest { inherit west; }; + + combine_uf2 = a: b: pkgs.runCommandNoCC "combined_${a.name}_${b.name}" {} + '' + mkdir -p $out + cat ${a}/zmk.uf2 ${b}/zmk.uf2 > $out/glove80.uf2 + ''; + + zephyr = callPackage ./nix/zephyr.nix { }; + + zmk = callPackage ./nix/zmk.nix { }; + + zmk_settings_reset = zmk.override { + shield = "settings_reset"; + }; + + glove80_left = zmk.override { + board = "glove80_lh"; + }; + + glove80_right = zmk.override { + board = "glove80_rh"; + }; + + glove80_combined = combine_uf2 glove80_left glove80_right; + + glove80_v0_left = zmk.override { + board = "glove80_v0_lh"; + }; + + glove80_v0_right = zmk.override { + board = "glove80_v0_rh"; + }; +}) diff --git a/nix/cmake-shell.nix b/nix/cmake-shell.nix new file mode 100644 index 00000000000..de68e6cf502 --- /dev/null +++ b/nix/cmake-shell.nix @@ -0,0 +1,17 @@ +{ pkgs ? (import ./pinned-nixpkgs.nix {}) }: + +let + zmkPkgs = (import ../default.nix { inherit pkgs; }); + inherit (zmkPkgs) zmk zephyr; + + zmkCmake = pkgs.writeShellScriptBin "zmk-cmake" '' + export PATH=${pkgs.lib.makeBinPath zmk.nativeBuildInputs}:$PATH + export CMAKE_PREFIX_PATH=${zephyr} + + cmake -G Ninja ${pkgs.lib.escapeShellArgs zmk.cmakeFlags} "-DUSER_CACHE_DIR=/tmp/.cache" "$@" + ''; +in +pkgs.stdenv.mkDerivation { + name = "zmk-cmake-shell"; + nativeBuildInputs = zmk.nativeBuildInputs ++ [zmkCmake]; +} diff --git a/nix/generate-pin.rb b/nix/generate-pin.rb new file mode 100755 index 00000000000..b6bf682dff2 --- /dev/null +++ b/nix/generate-pin.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'json' +require 'net/http' +require 'shellwords' + +def get_channel_url(channel) + uri = URI("https://channels.nixos.org/#{channel}") + res = Net::HTTP.get_response(uri) + raise 'Not a redirect' unless res.is_a?(Net::HTTPRedirection) + res['location'] +end + +def fetch_tarball(url) + hash = `nix-prefetch-url --unpack #{Shellwords.escape(url)}` + raise 'Prefetch failed' unless $?.success? + hash.chomp +end + +def generate_pin(channel) + channel_url = get_channel_url(channel) + nixexprs = "#{channel_url}/nixexprs.tar.xz" + hash = fetch_tarball(nixexprs) + { url: nixexprs, sha256: hash } +end + +def main + channel = ENV.fetch('CHANNEL', 'nixpkgs-unstable') + pin = generate_pin(channel) + puts JSON.pretty_generate(pin) +end + +main diff --git a/nix/manifest.json b/nix/manifest.json new file mode 100644 index 00000000000..4a942ef6589 --- /dev/null +++ b/nix/manifest.json @@ -0,0 +1,343 @@ +[ + { + "name": "zephyr", + "url": "https://github.com/petejohanson/zephyr", + "revision": "339570e2393b108bf8f9241018ecaf5615c25469", + "clone-depth": 1, + "west-commands": "scripts/west-commands.yml", + "sha256": "0m4hcp2017zg8c637siv941976lc377hp4z5kkijxznlb4c3xi8s" + }, + { + "name": "chre", + "url": "https://github.com/zephyrproject-rtos/chre", + "revision": "ef76d3456db07e4959df555047d6962279528c8d", + "path": "modules/lib/chre", + "groups": ["optional"], + "sha256": "00jnv58slzgp4srmsamd7x34yf0hj1c6agmws4csv7w28013bwfm" + }, + { + "name": "lz4", + "url": "https://github.com/zephyrproject-rtos/lz4", + "revision": "8e303c264fc21c2116dc612658003a22e933124d", + "path": "modules/lib/lz4", + "groups": ["optional"], + "sha256": "1kqs7gxg17gvws01rir8p6gmzp54y12s1898lflhsb418122v8nf" + }, + { + "name": "nanopb", + "url": "https://github.com/zephyrproject-rtos/nanopb", + "revision": "dc4deed54fd4c7e1935e3b6387eedf21bb45dc38", + "path": "modules/lib/nanopb", + "groups": ["optional"], + "sha256": "0kmzh65hyhnl88w9x0rcdypj4nl1brbxrnzhy3flgxmhr564y05s" + }, + { + "name": "psa-arch-tests", + "url": "https://github.com/zephyrproject-rtos/psa-arch-tests", + "revision": "f4fc2442b8e29e2a03d9899e46e5a3ea3df8c2c9", + "path": "modules/tee/tf-m/psa-arch-tests", + "groups": ["optional"], + "sha256": "015qan6qfqyfc1lwpqb29zk1wxx02b6ng5wc1nfpfvknvhiwifay" + }, + { + "name": "sof", + "url": "https://github.com/zephyrproject-rtos/sof", + "revision": "c0f20b69daa44e3563f970b366e49ccfcfa1b71c", + "path": "modules/audio/sof", + "groups": ["optional"], + "sha256": "1ijad7xp9a5j5fc0sdmdrf0l2k3fc4dnw8ka3glp4ay52dhy04zx" + }, + { + "name": "tf-m-tests", + "url": "https://github.com/zephyrproject-rtos/tf-m-tests", + "revision": "c99a86b295c4887520da9d8402566d7f225c974e", + "path": "modules/tee/tf-m/tf-m-tests", + "groups": ["optional"], + "sha256": "0cc4029i9qfzq4vply9l2yjigaf9rq1zc6a44b8dc779kx31qx36" + }, + { + "name": "tflite-micro", + "url": "https://github.com/zephyrproject-rtos/tflite-micro", + "revision": "1a34dcab41e7e0e667db72d6a40999c1ec9c510c", + "path": "optional/modules/lib/tflite-micro", + "groups": ["optional"], + "sha256": "194k1wh4fx49vymc3dhmmsg8wfq4jjhsp00rsrmax5vfhy7fjsi6" + }, + { + "name": "thrift", + "url": "https://github.com/zephyrproject-rtos/thrift", + "revision": "10023645a0e6cb7ce23fcd7fd3dbac9f18df6234", + "path": "optional/modules/lib/thrift", + "groups": ["optional"], + "sha256": "1bpi64lk7sdidjqsq7rspbqk9k7z8s26mgg17c8sv6cr4h007raq" + }, + { + "name": "zscilib", + "url": "https://github.com/zephyrproject-rtos/zscilib", + "revision": "ca070ddabdaf67175a2da901d0bd62e8899371c5", + "path": "modules/lib/zscilib", + "groups": ["optional"], + "sha256": "1ss33lfz2xzz8b3fcnibz109x09lj9ajw3na8lsmhvn7mhg6zh3v" + }, + { + "name": "acpica", + "url": "https://github.com/zephyrproject-rtos/acpica", + "revision": "0333c2af13179f9b33d495cf7cb9a509f751cbb1", + "path": "modules/lib/acpica", + "sha256": "04864is6iisjfasvlwgfsmgnlihdg43cfcc3hpqkzb446x2ix4iw" + }, + { + "name": "canopennode", + "url": "https://github.com/zephyrproject-rtos/canopennode", + "revision": "dec12fa3f0d790cafa8414a4c2930ea71ab72ffd", + "path": "modules/lib/canopennode", + "sha256": "0x6l56q5zdrz78iarfwxiwc05wwq4krg9xhx1z8kjarkwf6q9f85" + }, + { + "name": "cmsis", + "url": "https://github.com/zephyrproject-rtos/cmsis", + "revision": "5a00331455dd74e31e80efa383a489faea0590e3", + "path": "modules/hal/cmsis", + "groups": ["hal"], + "sha256": "00zqyin7bn6jwp7kq51dfs7sinwj5dhx4s981gdm171mmx7rx06n" + }, + { + "name": "cmsis-dsp", + "url": "https://github.com/zephyrproject-rtos/cmsis-dsp", + "revision": "ff7b5fd1ea5f094665c090c343ec44e74dc0b193", + "path": "modules/lib/cmsis-dsp", + "sha256": "0ycznb30fmh35sz3gsg3gzdh9shk8ad90k4849lmx21jzxr6jrai" + }, + { + "name": "cmsis-nn", + "url": "https://github.com/zephyrproject-rtos/cmsis-nn", + "revision": "0c8669d81381ccf3b1a01d699f3b68b50134a99f", + "path": "modules/lib/cmsis-nn", + "sha256": "1bnlyklzlhjrx8b66y6fy9im9wipx4shkq3mla5k7iw7kn3kqs7z" + }, + { + "name": "fatfs", + "url": "https://github.com/zephyrproject-rtos/fatfs", + "revision": "427159bf95ea49b7680facffaa29ad506b42709b", + "path": "modules/fs/fatfs", + "groups": ["fs"], + "sha256": "1pj6ik1bdyn07zsm0006n818mjzpbhhpsca4cw5imw66mhjy2pg6" + }, + { + "name": "hal_ambiq", + "url": "https://github.com/zephyrproject-rtos/hal_ambiq", + "revision": "0a7c99325aa73a1ef777501da91c2c6608661e56", + "path": "modules/hal/ambiq", + "groups": ["hal"], + "sha256": "1s1xv746p7c1ccyp2j1b36hrm9pp7dlpb8v4fclpd6wl3jcdjj74" + }, + { + "name": "hal_atmel", + "url": "https://github.com/zephyrproject-rtos/hal_atmel", + "revision": "5ab43007eda3f380c125f957f03638d2e8d1144d", + "path": "modules/hal/atmel", + "groups": ["hal"], + "sha256": "0csnr0npgfraf4g11dn4f77ywm2qd80y65a12kx68f7bfm8flf9j" + }, + { + "name": "hal_ethos_u", + "url": "https://github.com/zephyrproject-rtos/hal_ethos_u", + "revision": "90ada2ea5681b2a2722a10d2898eac34c2510791", + "path": "modules/hal/ethos_u", + "groups": ["hal"], + "sha256": "12nv46xhi8v6k36l7qgmlsp58vc1d0zw5wqizv30acj5si2bz3y3" + }, + { + "name": "hal_gigadevice", + "url": "https://github.com/zephyrproject-rtos/hal_gigadevice", + "revision": "2994b7dde8b0b0fa9b9c0ccb13474b6a486cddc3", + "path": "modules/hal/gigadevice", + "groups": ["hal"], + "sha256": "16h3l09ikbb4sqql7nlnfdxqvsgcdywrwckf83r4mjs9pgxiq1qa" + }, + { + "name": "hal_intel", + "url": "https://github.com/zephyrproject-rtos/hal_intel", + "revision": "b3b43d4e3da7ba483611bbbea7ef8af92c69df31", + "path": "modules/hal/intel", + "groups": ["hal"], + "sha256": "1m2d0vwa2iip80rfzip8av41lga2p8zm0gzxhd6x11b3lq05vkb2" + }, + { + "name": "hal_nordic", + "url": "https://github.com/zephyrproject-rtos/hal_nordic", + "revision": "d054a315eb888ba70e09e5f6decd4097b0276d1f", + "path": "modules/hal/nordic", + "groups": ["hal"], + "sha256": "0ypny416ylb2w5jg4bg55xvfg0yhqlbrakzvm0w23lnamg49kd6j" + }, + { + "name": "hal_nuvoton", + "url": "https://github.com/zephyrproject-rtos/hal_nuvoton", + "revision": "3e0a4c4d3328b2f72b164219add19d5308b53cb5", + "path": "modules/hal/nuvoton", + "groups": ["hal"], + "sha256": "1xc1cr4c0d0zzmbdrfb7xr8zzq0aifki1l50wcrn9dsi9c1ww12g" + }, + { + "name": "hal_quicklogic", + "url": "https://github.com/zephyrproject-rtos/hal_quicklogic", + "revision": "b3a66fe6d04d87fd1533a5c8de51d0599fcd08d0", + "path": "modules/hal/quicklogic", + "groups": ["hal"], + "sha256": "0hk1x72kibaw3xkspy9822vh28ax3bk11b80qn8l4dwrm0wx34sy" + }, + { + "name": "hal_renesas", + "url": "https://github.com/zephyrproject-rtos/hal_renesas", + "revision": "a6cf2af9140e014fbbc48d2b6deb802231dd369f", + "path": "modules/hal/renesas", + "groups": ["hal"], + "sha256": "000dmd1z72n9blw1pdjskkpz978k3pa6fzg60lhcaj9y24kl9y6z" + }, + { + "name": "hal_rpi_pico", + "url": "https://github.com/zephyrproject-rtos/hal_rpi_pico", + "revision": "fba7162cc7bee06d0149622bbcaac4e41062d368", + "path": "modules/hal/rpi_pico", + "groups": ["hal"], + "sha256": "01q3rf427vvfl0hn3af84hmb3g78dnd8n6saddy7mljha0z0dzda" + }, + { + "name": "hal_stm32", + "url": "https://github.com/zephyrproject-rtos/hal_stm32", + "revision": "89ef0a3383edebf661073073bcdf6e2836fe90ee", + "path": "modules/hal/stm32", + "groups": ["hal"], + "sha256": "0z7q5xg1rn9c3anjvi2kl0hgik3y3r25svwf97w1cjhjx1rhqmpv" + }, + { + "name": "hal_telink", + "url": "https://github.com/zephyrproject-rtos/hal_telink", + "revision": "38573af589173259801ae6c2b34b7d4c9e626746", + "path": "modules/hal/telink", + "groups": ["hal"], + "sha256": "16lzqnzwl2ij0jvbg9x1cgh54kv76dbmpcn4xhd5m4wph3yix78z" + }, + { + "name": "hal_wurthelektronik", + "url": "https://github.com/zephyrproject-rtos/hal_wurthelektronik", + "revision": "24ca9873c3d608fad1fea0431836bc8f144c132e", + "path": "modules/hal/wurthelektronik", + "groups": ["hal"], + "sha256": "0s2b3j40b7qd85np46n4vh0zjmwymnpxd8r42nhss6xznn11g2h8" + }, + { + "name": "libmetal", + "url": "https://github.com/zephyrproject-rtos/libmetal", + "revision": "b91611a6f47dd29fb24c46e5621e797557f80ec6", + "path": "modules/hal/libmetal", + "groups": ["hal"], + "sha256": "0pj0g6zaxiylpdiizf03jil4q2sq1z9px7cfxlv95ddnbv6rjjcz" + }, + { + "name": "liblc3", + "url": "https://github.com/zephyrproject-rtos/liblc3", + "revision": "448f3de31f49a838988a162ef1e23a89ddf2d2ed", + "path": "modules/lib/liblc3", + "sha256": "07r923k1y05sq1sl9740z33cz64pqm2n7x8rr2ws460fij64aixp" + }, + { + "name": "littlefs", + "url": "https://github.com/zephyrproject-rtos/littlefs", + "revision": "ca583fd297ceb48bced3c2548600dc615d67af24", + "path": "modules/fs/littlefs", + "groups": ["fs"], + "sha256": "10xpjrnp5n1j1xbay2qwmg2w314fw9pgzv3kz1mn3pgadhckfgdn" + }, + { + "name": "lvgl", + "url": "https://github.com/zephyrproject-rtos/lvgl", + "revision": "8a6a2d1d29d17d1e4bdc94c243c146a39d635fdd", + "path": "modules/lib/gui/lvgl", + "sha256": "0rsmlh358f4g2yidak916pxhkgckfrnck2a5hcsh9larsdnsnf24" + }, + { + "name": "mbedtls", + "url": "https://github.com/zephyrproject-rtos/mbedtls", + "revision": "c38dc78d9a8dcbe43b898cc1171ab33ba3e6fc26", + "path": "modules/crypto/mbedtls", + "groups": ["crypto"], + "sha256": "0661myy0wjz38nypbyfw51x10mzg57syb5c28irblgjm2w25wbi7" + }, + { + "name": "mipi-sys-t", + "url": "https://github.com/zephyrproject-rtos/mipi-sys-t", + "revision": "a819419603a2dfcb47f7f39092e1bc112e45d1ef", + "path": "modules/debug/mipi-sys-t", + "groups": ["debug"], + "sha256": "1ba0h4p3n0ldk5pjilj7z2i62b09vjq6ma668rqpr3w2hrg6941v" + }, + { + "name": "nrf_hw_models", + "url": "https://github.com/zephyrproject-rtos/nrf_hw_models", + "revision": "f4595802d32d103718bf50b3d390b7a450895843", + "path": "modules/bsim_hw_models/nrf_hw_models", + "sha256": "04p6nfyrv38vq0dhdz0g11zqlrqhw43lydyyr06vlrijm0zja8p5" + }, + { + "name": "open-amp", + "url": "https://github.com/zephyrproject-rtos/open-amp", + "revision": "42b7c577714b8f22ce82a901e19c1814af4609a8", + "path": "modules/lib/open-amp", + "sha256": "0ch1iv4c3v3zx1l2clm4mawyd83kvxl3b5sd6m7r2sn6wpr456w9" + }, + { + "name": "percepio", + "url": "https://github.com/zephyrproject-rtos/percepio", + "revision": "a3728efccc47dd372f40e6313589ca4c5cc7d5e9", + "path": "modules/debug/percepio", + "groups": ["debug"], + "sha256": "0fhz6jwsni7s79p5pwmynxn4yzrr40yd8m51y20d8jf1ka6dh4gw" + }, + { + "name": "picolibc", + "url": "https://github.com/zephyrproject-rtos/picolibc", + "revision": "d07c38ff051386f8e09a143ea0a6c1d6d66dd1d8", + "path": "modules/lib/picolibc", + "sha256": "1pb4piwyib1mmqjyycq8xanvx9aps6mz4w2ijgrn1fjgfh5f7zpq" + }, + { + "name": "segger", + "url": "https://github.com/zephyrproject-rtos/segger", + "revision": "9d0191285956cef43daf411edc2f1a7788346def", + "path": "modules/debug/segger", + "groups": ["debug"], + "sha256": "11wbzyd2n006ygh72ixhqcmgn1yrzk3kq3c0piqvrfgqmv7p8yzn" + }, + { + "name": "tinycrypt", + "url": "https://github.com/zephyrproject-rtos/tinycrypt", + "revision": "3e9a49d2672ec01435ffbf0d788db6d95ef28de0", + "path": "modules/crypto/tinycrypt", + "groups": ["crypto"], + "sha256": "19d2q9y23yzz9i383q3cldjl3k5mryx9762cab23zy3ijdnmj2z6" + }, + { + "name": "trusted-firmware-a", + "url": "https://github.com/zephyrproject-rtos/trusted-firmware-a", + "revision": "421dc050278287839f5c70019bd6aec617f2bbdb", + "path": "modules/tee/tf-a/trusted-firmware-a", + "groups": ["tee"], + "sha256": "029sha3dpagbvfnk5h6ad69pvs5ahwps3cxkzbfrdbq2xm8x3j2y" + }, + { + "name": "uoscore-uedhoc", + "url": "https://github.com/zephyrproject-rtos/uoscore-uedhoc", + "revision": "5fe2cb613bd7e4590bd1b00c2adf181ac0229379", + "path": "modules/lib/uoscore-uedhoc", + "sha256": "0z31lbibkvhw5dfps4l7049gggfczh5qqfjb4s3csnr447m81gdd" + }, + { + "name": "zcbor", + "url": "https://github.com/zephyrproject-rtos/zcbor", + "revision": "67fd8bb88d3136738661fa8bb5f9989103f4599e", + "path": "modules/lib/zcbor", + "sha256": "16138k7xlahf63dfvplm8c2m0kxs1g17gcx1fa31y4gcfbi3b0k7" + } +] diff --git a/nix/pinned-nixpkgs.json b/nix/pinned-nixpkgs.json new file mode 100644 index 00000000000..d50315b0deb --- /dev/null +++ b/nix/pinned-nixpkgs.json @@ -0,0 +1,4 @@ +{ + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre640317.38d3352a65ac/nixexprs.tar.xz", + "sha256": "056jn02xbwdds0gwvnba6fq2lba7g5aa70qgc4by0fh4cyfa4phy" +} diff --git a/nix/pinned-nixpkgs.nix b/nix/pinned-nixpkgs.nix new file mode 100644 index 00000000000..c62cf91d1f9 --- /dev/null +++ b/nix/pinned-nixpkgs.nix @@ -0,0 +1,17 @@ +{ system ? builtins.currentSystem }: + +let + pin = builtins.fromJSON (builtins.readFile ./pinned-nixpkgs.json); + + nixpkgsSrc = builtins.fetchTarball { + inherit (pin) url sha256; + }; +in + +import nixpkgsSrc { + inherit system; + config = { + allowUnfree = true; + }; + overlays = []; # prevent impure overlays +} diff --git a/nix/update-manifest/default.nix b/nix/update-manifest/default.nix new file mode 100644 index 00000000000..eb858c16dbb --- /dev/null +++ b/nix/update-manifest/default.nix @@ -0,0 +1,11 @@ +{ runCommand, lib, makeWrapper, west, remarshal, nix-prefetch-git, jq, git }: + +runCommand "update-manifest" { + nativeBuildInputs = [ makeWrapper ]; +} '' + mkdir -p $out/bin $out/libexec + cp ${./update-manifest.sh} $out/libexec/update-manifest.sh + makeWrapper $out/libexec/update-manifest.sh $out/bin/update-manifest \ + --set PATH ${lib.makeBinPath [ west remarshal nix-prefetch-git jq git ]} + patchShebangs $out +'' diff --git a/nix/update-manifest/update-manifest.sh b/nix/update-manifest/update-manifest.sh new file mode 100755 index 00000000000..1f717a5a2b6 --- /dev/null +++ b/nix/update-manifest/update-manifest.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ignored_modules=(hal_espressif sof tflite-micro thrift bsim babblesim babblesim_base \ + babblesim_ext_2G4_libPhyComv1 babblesim_ext_2G4_channel_NtNcable \ + babblesim_ext_2G4_channel_multiatt babblesim_ext_2G4_modem_magic \ + babblesim_ext_2G4_modem_BLE_simple babblesim_ext_2G4_device_burst_interferer \ + babblesim_ext_2G4_device_WLAN_actmod babblesim_ext_2G4_phy_v1 \ + babblesim_ext_2G4_device_playback babblesim_ext_libCryptov1) + +prefetch_project() { + local p=$1 + local name + name="$(jq -r .name <<< "$p")" + + if [[ " ${ignored_modules[*]} " =~ " ${name} " ]]; then + echo "Skipping: $name" >&2 + return + fi + + echo "Prefetching: $name" >&2 + + sha256=$(nix-prefetch-git \ + --quiet \ + --fetch-submodules \ + --url "$(jq -r .url <<< "$p")" \ + --rev "$(jq -r .revision <<< "$p")" \ + | jq -r .sha256) + + jq --arg sha256 "$sha256" '. + $ARGS.named' <<< "$p" +} + + +west manifest --freeze | \ + yaml2json | \ + jq -c '.manifest.projects[]' | \ + while read -r p; do prefetch_project "$p"; done | \ + jq --slurp diff --git a/nix/west-manifest.patch b/nix/west-manifest.patch new file mode 100644 index 00000000000..f6f82b75735 --- /dev/null +++ b/nix/west-manifest.patch @@ -0,0 +1,17 @@ +diff --git a/src/west/manifest.py b/src/west/manifest.py +index e28fade..f3d3784 100644 +--- a/src/west/manifest.py ++++ b/src/west/manifest.py +@@ -1618,8 +1618,10 @@ class Manifest: + ''' + def pdict(p): + if not p.is_cloned(): +- raise RuntimeError(f'cannot freeze; project {p.name} ' +- 'is uncloned') ++ # For the purposes of exporting a frozen manifest for Nix, this ++ # is sufficient, as a package whose revision is not represented ++ # as a SHA will fail the prefetch. ++ return Project.as_dict(p) + try: + sha = p.sha(QUAL_MANIFEST_REV_BRANCH) + except subprocess.CalledProcessError as e: diff --git a/nix/west-shell.nix b/nix/west-shell.nix new file mode 100644 index 00000000000..a9be5f8db62 --- /dev/null +++ b/nix/west-shell.nix @@ -0,0 +1,50 @@ +{ pkgs ? (import ./pinned-nixpkgs.nix {}) }: + +let + # from zephyr/scripts/requirements-base.txt + pythonDependencies = ps: with ps; [ + pyelftools + pyyaml + packaging + progress + anytree + intelhex + west + ]; + + requiredStdenv = + if pkgs.stdenv.hostPlatform.isLinux + then pkgs.multiStdenv + else pkgs.stdenv; +in +with pkgs; +# requires multiStdenv to build 32-bit test binaries +requiredStdenv.mkDerivation { + name = "zmk-shell"; + + buildInputs = [ + # ZMK dependencies + gitFull + wget + autoconf + automake + bzip2 + ccache + dtc # devicetree compiler + dfu-util + gcc + libtool + ninja + cmake + xz + (python3.withPackages(pythonDependencies)) + + # ARM toolchain + gcc-arm-embedded + ]; + + ZEPHYR_TOOLCHAIN_VARIANT = "gnuarmemb"; + GNUARMEMB_TOOLCHAIN_PATH = gcc-arm-embedded; + + shellHook = "if [ ! -d \"zephyr\" ]; then west init -l app/ ; west update; west zephyr-export; fi; source zephyr/zephyr-env.sh"; +} diff --git a/nix/zephyr.nix b/nix/zephyr.nix new file mode 100644 index 00000000000..d7c1bd05624 --- /dev/null +++ b/nix/zephyr.nix @@ -0,0 +1,52 @@ +{ stdenvNoCC, lib, fetchgit, runCommand }: +let + manifestJSON = builtins.fromJSON (builtins.readFile ./manifest.json); + + mkModule = { name, revision, url, sha256, ... }: + stdenvNoCC.mkDerivation (finalAttrs: { + name = "zmk-module-${name}"; + + src = fetchgit { + inherit name url sha256; + rev = revision; + }; + + dontUnpack = true; + dontBuild = true; + + installPhase = '' + mkdir $out + ln -s ${finalAttrs.src} $out/${name} + ''; + + passthru = { + modulePath = "${finalAttrs.finalPackage}/${name}"; + }; + }); + + modules = lib.listToAttrs (lib.forEach manifestJSON ({ name, ... }@args: + lib.nameValuePair name (mkModule args))); +in + + +# Zephyr with no modules, from the frozen manifest. +# For now the modules are passed through as passthru +stdenvNoCC.mkDerivation { + name = "zephyr"; + src = modules.zephyr.src; + + dontBuild = true; + + # This awkward structure is required by + # COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/../tools/uf2/utils/uf2conv.py + installPhase = '' + mkdir -p $out/zephyr + mv * $out/zephyr + + # uf2 is gone, not sure what replaced it + ''; + + passthru = { + modules = removeAttrs modules ["zephyr"]; + }; +} diff --git a/nix/zmk.nix b/nix/zmk.nix new file mode 100644 index 00000000000..c467f60fa2c --- /dev/null +++ b/nix/zmk.nix @@ -0,0 +1,112 @@ +{ stdenvNoCC, lib, buildPackages +, cmake, ninja, dtc, gcc-arm-embedded +, zephyr +, board ? "glove80_lh" +, shield ? null +, keymap ? null +, kconfig ? null +}: + + +let + # from zephyr/scripts/requirements-base.txt + packageOverrides = pyself: pysuper: { + can = pysuper.can.overrideAttrs (_: { + # horribly flaky test suite full of assertions about timing. + # > assert 0.1 <= took < inc(0.3) + # E assert 0.31151700019836426 < 0.3 + # E + where 0.3 = inc(0.3) + doCheck = false; + doInstallCheck = false; + }); + + canopen = pysuper.can.overrideAttrs (_: { + # Also has timing sensitive tests + # task = self.network.send_periodic(0x123, [1, 2, 3], 0.01) + # time.sleep(0.1) + # > self.assertTrue(9 <= bus.queue.qsize() <= 11) + # E AssertionError: False is not true + doCheck = false; + doInstallCheck = false; + }); + }; + + python = (buildPackages.python3.override { inherit packageOverrides; }).withPackages (ps: with ps; [ + pyelftools + pyyaml + canopen + packaging + progress + anytree + intelhex + + # TODO: this was required but not in shell.nix + pykwalify + ]); + + requiredZephyrModules = [ + "cmsis" "hal_nordic" "tinycrypt" "picolibc" "lvgl" "picolibc" "segger" + ]; + + zephyrModuleDeps = + let modules = lib.attrVals requiredZephyrModules zephyr.modules; + in map (x: x.modulePath) modules; +in + +stdenvNoCC.mkDerivation { + name = "zmk_${board}"; + + sourceRoot = "source/app"; + + src = builtins.path { + name = "source"; + path = ./..; + filter = path: type: + let relPath = lib.removePrefix (toString ./.. + "/") (toString path); + in (lib.cleanSourceFilter path type) && ! ( + # Meta files + relPath == "nix" || lib.hasSuffix ".nix" path || + # Transient state + relPath == "build" || relPath == ".west" || + # Fetched by west + relPath == "modules" || relPath == "tools" || relPath == "zephyr" || + # Not part of ZMK + relPath == "lambda" || relPath == ".github" + ); + }; + + preConfigure = '' + cmakeFlagsArray+=("-DUSER_CACHE_DIR=$TEMPDIR/.cache") + ''; + + cmakeFlags = [ + # "-DZephyrBuildConfiguration_ROOT=${zephyr}/zephyr" + # TODO: is this required? if not, why not? + "-DZEPHYR_BASE=${zephyr}/zephyr" + "-DBOARD_ROOT=." + "-DBOARD=${board}" + "-DZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb" + "-DGNUARMEMB_TOOLCHAIN_PATH=${gcc-arm-embedded}" + # TODO: maybe just use a cross environment for this gcc + "-DCMAKE_C_COMPILER=${gcc-arm-embedded}/bin/arm-none-eabi-gcc" + "-DCMAKE_CXX_COMPILER=${gcc-arm-embedded}/bin/arm-none-eabi-g++" + "-DCMAKE_AR=${gcc-arm-embedded}/bin/arm-none-eabi-ar" + "-DCMAKE_RANLIB=${gcc-arm-embedded}/bin/arm-none-eabi-ranlib" + "-DZEPHYR_MODULES=${lib.concatStringsSep ";" zephyrModuleDeps}" + ] ++ + (lib.optional (shield != null) "-DSHIELD=${shield}") ++ + (lib.optional (keymap != null) "-DKEYMAP_FILE=${keymap}") ++ + (lib.optional (kconfig != null) "-DEXTRA_CONF_FILE=${kconfig}"); + + nativeBuildInputs = [ cmake ninja python dtc gcc-arm-embedded ]; + buildInputs = [ zephyr ]; + + installPhase = '' + mkdir $out + cp zephyr/zmk.{uf2,hex,bin,elf} $out + cp zephyr/.config $out/zmk.kconfig + cp zephyr/zephyr.dts $out/zmk.dts + ''; + + passthru = { inherit zephyrModuleDeps; }; +} From 28cc218d2fe075513e745e36a253d1f5976e1d9e Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Sun, 18 Sep 2022 17:07:01 +0900 Subject: [PATCH 131/134] Github build action: build Glove80 combined firmware using Nix --- .github/workflows/build.yml | 13 +++---- .github/workflows/nix-build.yml | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/nix-build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9e09dc21074..49db100ef11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ permissions: {} jobs: build: - if: ${{ always() }} + if: ${{ false }} runs-on: ubuntu-latest container: image: docker.io/zmkfirmware/zmk-build-arm:3.5 @@ -139,7 +139,7 @@ jobs: throw new Error('Failed to build one or more configurations'); } compile-matrix: - if: ${{ !cancelled() }} + if: ${{ false && !cancelled() }} runs-on: ubuntu-latest needs: [core-coverage, board-changes, nightly] outputs: @@ -179,7 +179,7 @@ jobs: shieldArgs: JSON.stringify(shieldArgs), })); core-coverage: - if: ${{ needs.get-changed-files.outputs.core-changes == 'true' }} + if: ${{ false && needs.get-changed-files.outputs.core-changes == 'true' }} runs-on: ubuntu-latest needs: get-changed-files outputs: @@ -210,7 +210,7 @@ jobs: return [...include, ...coreCoverage.include]; board-changes: - if: ${{ needs.get-changed-files.outputs.board-changes == 'true' }} + if: ${{ false && needs.get-changed-files.outputs.board-changes == 'true' }} runs-on: ubuntu-latest needs: [get-grouped-hardware, get-changed-files] outputs: @@ -294,7 +294,7 @@ jobs: }); }))).flat(); nightly: - if: ${{ github.event_name == 'schedule' && github.repository_owner == 'zmkfirmware' }} + if: ${{ false && github.event_name == 'schedule' && github.repository_owner == 'zmkfirmware' }} runs-on: ubuntu-latest needs: get-grouped-hardware outputs: @@ -339,6 +339,7 @@ jobs: return [...includeOnboard, ...includeInterconnect]; get-grouped-hardware: + if: ${{ false }} runs-on: ubuntu-latest outputs: organized-metadata: ${{ steps.organize-metadata.outputs.result }} @@ -418,7 +419,7 @@ jobs: return JSON.stringify(grouped).replace(/\\/g,"\\\\").replace(/`/g,"\\`"); result-encoding: string get-changed-files: - if: ${{ github.event_name != 'schedule' }} + if: ${{ false && github.event_name != 'schedule' }} runs-on: ubuntu-latest outputs: changed-files: ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml new file mode 100644 index 00000000000..6f6b0bbf866 --- /dev/null +++ b/.github/workflows/nix-build.yml @@ -0,0 +1,62 @@ +name: Build + +on: + push: + paths: + - ".github/workflows/nix-build.yml" + - "default.nix" + - "app/**" + - "nix/**" + branches: + - "**" + tags: + - "**" + pull_request: + paths: + - ".github/workflows/nix-build.yml" + - "default.nix" + - "app/**" + - "nix/**" + +jobs: + build: + name: Build Glove80 Firmware + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-22.05 + - uses: cachix/cachix-action@v15 + with: + name: moergo-glove80-zmk-dev + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" + skipPush: "${{ github.repository != 'moergo-sc/zmk' }}" + - name: Build Glove80 combined firmware + run: nix-build -A glove80_combined -o combined + - name: Copy result out of nix store + run: cp combined/glove80.uf2 glove80.uf2 + - name: Upload result + uses: actions/upload-artifact@v4 + with: + name: glove80.uf2 + path: glove80.uf2 + release: + name: Create Release for Tag + if: >- + github.repository == 'moergo-sc/zmk' + && github.event_name == 'push' + && contains(github.ref, 'refs/tags/v') + needs: build + runs-on: ubuntu-latest + steps: + - name: Download compiled firmware artifact + uses: actions/download-artifact@v4 + with: + name: glove80.uf2 + - name: Create Release for Tag + uses: ncipollo/release-action@v1 + with: + artifacts: "glove80.uf2" + artifactErrorsFailBuild: true + generateReleaseNotes: true From a75d6aa10698ebcee7171f6693f43c7f4420df64 Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Mon, 11 Oct 2021 16:49:33 +0900 Subject: [PATCH 132/134] Docker container and lambda function for performing firmware builds Provides an entry point that builds and returns a combined LH + RH keyboard firmware when provided a keymap via a POST body. Wraps compilation with ccache, and includes a pre-warmed cache of the build in /tmp/ccache. To maximize chance of a direct cache hit, changes the lambda driver to always build in /tmp/build. some back of the envelope measurements (2012 xeon e3-1230v2, nixos) clean build, no cache -> 21.308 clean build, cache -> 7.145 modified keymap, clean build, cache -> 12.127 --- .github/workflows/build-container.yml | 110 +++++++++++++ .github/workflows/cleanup-container.yml | 43 +++++ .github/workflows/nix-build.yml | 2 +- lambda/Gemfile | 3 + lambda/Gemfile.lock | 13 ++ lambda/api_version.txt | 1 + lambda/app.rb | 68 ++++++++ lambda/compiler.rb | 131 +++++++++++++++ lambda/default.nix | 26 +++ lambda/gemset.nix | 12 ++ lambda/shell.nix | 9 + nix/ccache.nix | 43 +++++ release.nix | 208 ++++++++++++++++++++++++ 13 files changed, 668 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-container.yml create mode 100644 .github/workflows/cleanup-container.yml create mode 100644 lambda/Gemfile create mode 100644 lambda/Gemfile.lock create mode 100644 lambda/api_version.txt create mode 100644 lambda/app.rb create mode 100644 lambda/compiler.rb create mode 100644 lambda/default.nix create mode 100644 lambda/gemset.nix create mode 100644 lambda/shell.nix create mode 100644 nix/ccache.nix create mode 100644 release.nix diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml new file mode 100644 index 00000000000..320409f7bcd --- /dev/null +++ b/.github/workflows/build-container.yml @@ -0,0 +1,110 @@ +name: Build Compiler Service Container + +on: + push: + tags: + - "*" + pull_request_target: + branches: + - main + +jobs: + build: + # This job must never be run on a PR from outside the same repository + if: github.repository == 'moergo-sc/zmk' && (github.event.pull_request == null || github.event.pull_request.head.repo.full_name == github.repository) + runs-on: ubuntu-latest + # These permissions are needed to interact with GitHub's OIDC Token endpoint. + permissions: + id-token: write + contents: read + env: + ECR_REPOSITORY: zmk-builder-lambda + VERSIONS_BUCKET: glove80firmwarepipelines-compilerversionsbucket44-zubaquiyjdam + UPDATE_COMPILER_VERSIONS_FUNCTION: arn:aws:lambda:us-east-1:431227615537:function:Glove80FirmwarePipelineSt-UpdateCompilerVersions2A-CNxPOHb4VSuV + REVISION_TAG: ${{ github.event.pull_request && github.event.pull_request.head.sha || github.sha }} + PR_NUMBER: ${{ github.event.number }} + steps: + - uses: actions/checkout@v4 + with: + repository: moergo-sc/zmk + ref: ${{ github.event.pull_request && github.event.pull_request.head.sha || github.sha }} + fetch-depth: 0 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::431227615537:role/GithubCompilerLambdaBuilder + aws-region: us-east-1 + - name: Extract container name from branch name + shell: bash + run: | + if [ "$GITHUB_HEAD_REF" ]; then + branch_ref="$GITHUB_HEAD_REF" + type="pr" + tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}" + elif [[ "$GITHUB_REF" == refs/tags/* ]]; then + branch_ref="$GITHUB_REF" + type="tag" + tag="${GITHUB_REF#refs/tags/}" + else + echo "Not a pull request or release tag" >&2 + exit 1 + fi + # Replace / with . in container tag names + tag="${tag//\//.}" + echo "VERSION_BRANCH=${branch_ref}" >> $GITHUB_ENV + echo "VERSION_TYPE=${type}" >> $GITHUB_ENV + echo "VERSION_NAME=${tag}" >> $GITHUB_ENV + id: extract_name + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-22.05 + - uses: cachix/cachix-action@v15 + with: + name: moergo-glove80-zmk-dev + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" + - name: Build lambda image + run: nix-build release.nix --arg revision "\"${REVISION_TAG}\"" -A lambdaImage -o lambdaImage + - name: Import OCI image into docker-daemon + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: nix shell -f nix/pinned-nixpkgs.nix skopeo -c skopeo --insecure-policy copy oci:lambdaImage docker-daemon:$REGISTRY/$ECR_REPOSITORY:$REVISION_TAG + - name: Push container image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: docker push $REGISTRY/$ECR_REPOSITORY:$REVISION_TAG + - name: Create JSON metadata to represent the built container + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + shell: bash + run: | + digest="$(docker inspect --format='{{index .RepoDigests 0}}' $REGISTRY/$ECR_REPOSITORY:$REVISION_TAG)" + digest="${digest##*@}" + api_version="$(cat lambda/api_version.txt)" + timestamp="$(date -u +"%Y%m%d.%H%M%S")" + + if [ "$VERSION_TYPE" = "pr" ]; then + release_name="$VERSION_NAME.$timestamp" + else + release_name="$VERSION_NAME" + fi + + jq -n '$ARGS.named' \ + --arg name "$release_name" \ + --arg version_name "$VERSION_NAME" \ + --arg revision "$REVISION_TAG" \ + --arg release_time "$timestamp" \ + --arg branch "$VERSION_BRANCH" \ + --arg digest "$digest" \ + --arg api_version "$api_version" \ + > "/tmp/$VERSION_NAME.json" + - name: Upload image metadata file to versions bucket + run: aws s3 cp "/tmp/$VERSION_NAME.json" "s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json" + - name: Notify the build pipeline that the compile containers have updated + run: >- + aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION + --invocation-type Event + --cli-binary-format raw-in-base64-out + /dev/null diff --git a/.github/workflows/cleanup-container.yml b/.github/workflows/cleanup-container.yml new file mode 100644 index 00000000000..886c4106d35 --- /dev/null +++ b/.github/workflows/cleanup-container.yml @@ -0,0 +1,43 @@ +name: Clean up PR Compiler Service Container + +on: + pull_request: + types: [closed] + branches: + - main + +jobs: + build: + if: github.repository == 'moergo-sc/zmk' + runs-on: ubuntu-latest + # These permissions are needed to interact with GitHub's OIDC Token endpoint. + permissions: + id-token: write + contents: read + env: + ECR_REPOSITORY: zmk-builder-lambda + VERSIONS_BUCKET: glove80firmwarepipelines-compilerversionsbucket44-zubaquiyjdam + UPDATE_COMPILER_VERSIONS_FUNCTION: arn:aws:lambda:us-east-1:431227615537:function:Glove80FirmwarePipelineSt-UpdateCompilerVersions2A-CNxPOHb4VSuV + PR_NUMBER: ${{ github.event.number }} + steps: + - name: Extract image tag name + shell: bash + run: | + tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}" + # Replace / with . in container tag names + tag="${tag//\//.}" + echo "VERSION_NAME=${tag}" >> $GITHUB_ENV + id: extract_name + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::431227615537:role/GithubCompilerLambdaBuilder + aws-region: us-east-1 + - name: Delete the image metadata file from the versions s3 bucket + run: aws s3 rm s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json + - name: Notify the build pipeline that the compile containers have updated + run: >- + aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION + --invocation-type Event + --cli-binary-format raw-in-base64-out + /dev/null diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 6f6b0bbf866..345a6bdcf3d 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -1,4 +1,4 @@ -name: Build +name: Build Glove80 Firmware on: push: diff --git a/lambda/Gemfile b/lambda/Gemfile new file mode 100644 index 00000000000..6b6bbf753ec --- /dev/null +++ b/lambda/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' +gem 'aws_lambda_ric' + diff --git a/lambda/Gemfile.lock b/lambda/Gemfile.lock new file mode 100644 index 00000000000..8b6c1f95c58 --- /dev/null +++ b/lambda/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + aws_lambda_ric (2.0.0) + +PLATFORMS + ruby + +DEPENDENCIES + aws_lambda_ric + +BUNDLED WITH + 2.1.4 diff --git a/lambda/api_version.txt b/lambda/api_version.txt new file mode 100644 index 00000000000..0cfbf08886f --- /dev/null +++ b/lambda/api_version.txt @@ -0,0 +1 @@ +2 diff --git a/lambda/app.rb b/lambda/app.rb new file mode 100644 index 00000000000..8c3eb554cca --- /dev/null +++ b/lambda/app.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'stringio' +require 'digest' +require 'json' +require './compiler' + +module LambdaFunction + # Handle a non-HTTP compile request, returning a JSON body of either the + # compiled result or an error. + class Handler + REVISION = ENV.fetch('REVISION', 'unknown') + + def self.process(event:, context:) + return { type: 'keep_alive' } if event.has_key?('keep_alive') + + parse_base64_param = ->(param, required: true) do + if event.include?(param) + Base64.strict_decode64(event.fetch(param)) + elsif required + return error(status: 400, message: "Missing required argument: #{param}") + end + rescue ArgumentError + return error(status: 400, message: "Invalid Base64 in #{param} input") + end + + keymap_data = parse_base64_param.('keymap') + kconfig_data = parse_base64_param.('kconfig', required: false) + + # Including kconfig settings that affect the RHS require building both + # firmware images, doubling compile time. Clients should omit rhs_kconfig + # where possible. + rhs_kconfig_data = parse_base64_param.('rhs_kconfig', required: false) + + result, log = + begin + log_compile(keymap_data, kconfig_data, rhs_kconfig_data) + + Compiler.new.compile(keymap_data, kconfig_data, rhs_kconfig_data) + rescue Compiler::CompileError => e + return error(status: e.status, message: e.message, detail: e.log) + end + + result = Base64.strict_encode64(result) + + { type: 'result', result: result, log: log, revision: REVISION } + rescue StandardError => e + error(status: 500, message: "Unexpected error: #{e.class}", detail: [e.message], exception: e) + end + + def self.log_compile(keymap_data, kconfig_data, rhs_kconfig_data) + keymap = Digest::SHA1.base64digest(keymap_data) + kconfig = kconfig_data ? Digest::SHA1.base64digest(kconfig_data) : 'nil' + rhs_kconfig = rhs_kconfig_data ? Digest::SHA1.base64digest(rhs_kconfig_data) : 'nil' + puts("Compiling with keymap: #{keymap}; kconfig: #{kconfig}; rhs_kconfig: #{rhs_kconfig}") + end + + def self.error(status:, message:, detail: nil, exception: nil) + reported_error = { type: 'error', status:, message:, detail:, revision: REVISION } + + exception_detail = { class: exception.class, backtrace: exception.backtrace } if exception + logged_error = reported_error.merge(exception: exception_detail) + puts(JSON.dump(logged_error)) + + reported_error + end + end +end diff --git a/lambda/compiler.rb b/lambda/compiler.rb new file mode 100644 index 00000000000..58ab0eaef8d --- /dev/null +++ b/lambda/compiler.rb @@ -0,0 +1,131 @@ +# frozen_string_literal: true + +require 'tmpdir' +require 'base64' +require 'json' +require 'open3' +require 'yaml' + +class Compiler + class CompileError < RuntimeError + attr_reader :status, :log + + def initialize(message, status: 400, log:) + super(message) + @status = status + @log = log + end + end + + def compile(keymap_data, lhs_kconfig_data, rhs_kconfig_data) + if rhs_kconfig_data && !rhs_kconfig_data.empty? + lhs_result, lhs_output = compile_board('glove80_lh', keymap_data:, kconfig_data: lhs_kconfig_data, include_static_rhs: false) + rhs_result, rhs_output = compile_board('glove80_rh', keymap_data: nil, kconfig_data: rhs_kconfig_data, include_static_rhs: false) + [ + lhs_result.concat(rhs_result), + ["LHS Output:", *lhs_output, "RHS Output:", *rhs_output], + ] + else + compile_board('glove80_lh', keymap_data:, kconfig_data: lhs_kconfig_data, include_static_rhs: true) + end + end + + def compile_board(board, keymap_data:, kconfig_data:, include_static_rhs: false) + in_build_dir do + compile_command = ['compileZmk', '-b', board] + + if keymap_data + dts_parse_errors = validate_devicetree!(keymap_data) + File.open('build.keymap', 'w') { |io| io.write(keymap_data) } + compile_command << '-k' << './build.keymap' + end + + if kconfig_data + File.open('build.conf', 'w') { |io| io.write(kconfig_data) } + compile_command << '-c' << './build.conf' + end + + if include_static_rhs + # Concatenate the pre-compiled glove80_rh image to the resulting uf2 + compile_command << '-m' + end + + compile_output = nil + + IO.popen(compile_command, 'rb', err: [:child, :out]) do |io| + compile_output = io.read + end + + compile_output = compile_output.split("\n") + + unless $?.success? + status = $?.exitstatus + raise CompileError.new("Compile failed with exit status #{status}", log: compile_output) + end + + unless File.exist?('zmk.uf2') + raise CompileError.new('Compile failed to produce result binary', status: 500, log: compile_output) + end + + if dts_parse_errors + # DTS validation failed to parse the DTS, yet the Zephyr build + # nonetheless succeeded. We can't allow returning the result, since we + # were unable to check it for unsafe dts sections. + raise CompileError.new('Syntax error validating device-tree input', log: dts_parse_errors) + end + + result = File.read('zmk.uf2') + + [result, compile_output] + end + end + + PERMITTED_DTS_SECTIONS = %w[ + behaviors macros combos conditional_layers keymap underglow-indicators + ].freeze + + def validate_devicetree!(dtsi) + dts = "/dts-v1/;\n" + dtsi + + stdout, stderr, status = + Open3.capture3({}, 'dts2yml', unsetenv_others: true, stdin_data: dts) + + unless status.success? + # The error output from dtc is much harder to understand than Zephyr's + # errors, and the line numbers don't match up due to preprocessing. Rather + # than raising these now, return the error output in order that it's only + # used in the case that the Zephyr build doesn't itself error. + return stderr.split("\n") + end + + data = + begin + YAML.safe_load(stdout) + rescue Psych::Exception => e + raise CompileError.new('Error parsing translated device-tree', status: 500, log: [e.message]) + end + + sections = data.flat_map(&:keys) + invalid_sections = sections - PERMITTED_DTS_SECTIONS + + unless invalid_sections.empty? + raise CompileError.new( + "Device-tree included the non-permitted root sections: #{invalid_sections.inspect}", log: []) + end + + nil + end + + # Lambda is single-process per container, and we get substantial speedups + # from ccache by always building in the same path + BUILD_DIR = '/tmp/build' + + def in_build_dir + FileUtils.remove_entry(BUILD_DIR, true) + Dir.mkdir(BUILD_DIR) + Dir.chdir(BUILD_DIR) + yield + ensure + FileUtils.remove_entry(BUILD_DIR, true) rescue nil + end +end diff --git a/lambda/default.nix b/lambda/default.nix new file mode 100644 index 00000000000..6a34b0d1122 --- /dev/null +++ b/lambda/default.nix @@ -0,0 +1,26 @@ +{ pkgs ? import {} }: + +with pkgs; + +let + bundleEnv = bundlerEnv { + name = "lambda-bundler-env"; + ruby = ruby_3_1; + gemfile = ./Gemfile; + lockfile = ./Gemfile.lock; + gemset = ./gemset.nix; + }; + + source = stdenv.mkDerivation { + name = "lambda-builder"; + version = "0.0.1"; + src = ./.; + installPhase = '' + cp -r ./ $out + ''; + }; + +in +{ + inherit bundleEnv source; +} diff --git a/lambda/gemset.nix b/lambda/gemset.nix new file mode 100644 index 00000000000..6b2fd1a0207 --- /dev/null +++ b/lambda/gemset.nix @@ -0,0 +1,12 @@ +{ + aws_lambda_ric = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "19c4xlgnhgwf3n3z57z16nmr76jd2vihhshknm5zqip2g00awhi1"; + type = "gem"; + }; + version = "2.0.0"; + }; +} diff --git a/lambda/shell.nix b/lambda/shell.nix new file mode 100644 index 00000000000..2f1eca8bb75 --- /dev/null +++ b/lambda/shell.nix @@ -0,0 +1,9 @@ +{ pkgs ? (import {})}: + +let + lambda = import ./default.nix { inherit pkgs; }; +in +pkgs.stdenv.mkDerivation { + name = "lambda-shell"; + buildInputs = [lambda.bundleEnv.wrappedRuby]; +} diff --git a/nix/ccache.nix b/nix/ccache.nix new file mode 100644 index 00000000000..030153140e2 --- /dev/null +++ b/nix/ccache.nix @@ -0,0 +1,43 @@ +{ stdenv, lib, makeWrapper, ccache +, unwrappedCC ? stdenv.cc.cc, extraConfig ? "" }: + +# copied from ccache in nixpkgs, modified to glob over prefixes. Also doesn't +# pass lib. Why was it passing lib? +stdenv.mkDerivation { + name = "ccache-links"; + passthru = { + isClang = unwrappedCC.isClang or false; + isGNU = unwrappedCC.isGNU or false; + }; + nativeBuildInputs = [ makeWrapper ]; + buildCommand = '' + mkdir -p $out/bin + + wrap() { + local cname="$(basename $1)" + if [ -x "${unwrappedCC}/bin/$cname" ]; then + echo "Wrapping $1" + makeWrapper ${ccache}/bin/ccache $out/bin/$cname \ + --run ${lib.escapeShellArg extraConfig} \ + --add-flags ${unwrappedCC}/bin/$cname + fi + } + + wrapAll() { + for prog in "$@"; do + wrap "$prog" + done + } + + wrapAll ${unwrappedCC}/bin/{*cc,*c++,*gcc,*g++,*clang,*clang++} + + for executable in $(ls ${unwrappedCC}/bin); do + if [ ! -x "$out/bin/$executable" ]; then + ln -s ${unwrappedCC}/bin/$executable $out/bin/$executable + fi + done + for file in $(ls ${unwrappedCC} | grep -vw bin); do + ln -s ${unwrappedCC}/$file $out/$file + done + ''; +} diff --git a/release.nix b/release.nix new file mode 100644 index 00000000000..f4137e4e5cb --- /dev/null +++ b/release.nix @@ -0,0 +1,208 @@ +{ pkgs ? (import ./nix/pinned-nixpkgs.nix {}), revision ? "HEAD" }: + +let + lib = pkgs.lib; + zmkPkgs = (import ./default.nix { inherit pkgs; }); + lambda = (import ./lambda { inherit pkgs; }); + ccacheWrapper = pkgs.callPackage ./nix/ccache.nix {}; + + nix-utils = pkgs.fetchFromGitHub { + owner = "iknow"; + repo = "nix-utils"; + rev = "c13c7a23836c8705452f051d19fc4dff05533b53"; + sha256 = "0ax7hld5jf132ksdasp80z34dlv75ir0ringzjs15mimrkw8zcac"; + }; + + ociTools = pkgs.callPackage "${nix-utils}/oci" {}; + + inherit (zmkPkgs) zmk zephyr; + + accounts = { + users.deploy = { + uid = 999; + group = "deploy"; + home = "/home/deploy"; + shell = "/bin/sh"; + }; + groups.deploy.gid = 999; + }; + + baseLayer = { + name = "base-layer"; + path = [ pkgs.busybox ]; + entries = ociTools.makeFilesystem { + inherit accounts; + tmp = true; + usrBinEnv = "${pkgs.busybox}/bin/env"; + binSh = "${pkgs.busybox}/bin/sh"; + }; + }; + + depsLayer = { + name = "deps-layer"; + path = [ pkgs.ccache ]; + includes = zmk.buildInputs ++ zmk.nativeBuildInputs ++ zmk.zephyrModuleDeps; + }; + + dts2yml = pkgs.writeShellScriptBin "dts2yml" '' + set -eo pipefail + + ${pkgs.gcc-arm-embedded}/bin/arm-none-eabi-cpp -P -D__DTS__ -E -nostdinc \ + -I "${zmk.src}/app/dts" -I "${zmk.src}/app/include" \ + -I "${zephyr}/zephyr/dts" -I "${zephyr}/zephyr/dts/common" -I "${zephyr}/zephyr/dts/arm" \ + -I "${zephyr}/zephyr/include" -I "${zephyr}/zephyr/include/zephyr"\ + -undef -x assembler-with-cpp - |\ + ${pkgs.dtc}/bin/dtc -I dts -O yaml + ''; + + zmkCompileScript = let + zmk' = zmk.override { + gcc-arm-embedded = ccacheWrapper.override { + unwrappedCC = pkgs.gcc-arm-embedded; + }; + }; + zmk_glove80_rh = zmk.override { board = "glove80_rh"; }; + realpath_coreutils = if pkgs.stdenv.isDarwin then pkgs.coreutils else pkgs.busybox; + in pkgs.writeShellScriptBin "compileZmk" '' + set -eo pipefail + + function usage() { + echo "Usage: compileZmk [-m] [-k keymap_file] [-c kconfig_file] [-b board]" + } + + function checkPath() { + if [ -z "$1" ]; then + return 0 + elif [ ! -f "$1" ]; then + echo "Error: Missing $2 file" >&2 + usage >&2 + exit 1 + fi + + ${realpath_coreutils}/bin/realpath "$1" + } + + keymap="${zmk.src}/app/boards/arm/glove80/glove80.keymap" + kconfig="" + board="glove80_lh" + merge_rhs="" + + while getopts "hk:c:d:b:m" opt; do + case "$opt" in + h|\?) + usage >&2 + exit 1 + ;; + k) + keymap="$OPTARG" + ;; + c) + kconfig="$OPTARG" + ;; + b) + board="$OPTARG" + ;; + m) + merge_rhs=t + ;; + esac + done + + if [ "$board" = "glove80_rh" -a -n "$merge_rhs" ]; then + echo "Cannot merge static RHS with built RHS" >&2 + exit 2 + fi + + keymap="$(checkPath "$keymap" keymap)" + kconfig="$(checkPath "$kconfig" Kconfig)" + + export PATH=${lib.makeBinPath (with pkgs; zmk'.nativeBuildInputs ++ [ ccache ])}:$PATH + export CMAKE_PREFIX_PATH=${zephyr} + + export CCACHE_BASEDIR=$PWD + export CCACHE_NOHASHDIR=t + export CCACHE_COMPILERCHECK=none + + if [ -n "$DEBUG" ]; then ccache -z; fi + + cmake -G Ninja -S ${zmk'.src}/app ${lib.escapeShellArgs zmk'.cmakeFlags} "-DUSER_CACHE_DIR=/tmp/.cache" "-DKEYMAP_FILE=$keymap" "-DBOARD=$board" "-DEXTRA_CONF_FILE=$kconfig" "-DBUILD_VERSION=${revision}" + + ninja + + if [ -n "$DEBUG" ]; then ccache -s; fi + + if [ -n "$merge_rhs" ]; then + cat zephyr/zmk.uf2 ${zmk_glove80_rh}/zmk.uf2 > zmk.uf2 + else + mv zephyr/zmk.uf2 zmk.uf2 + fi + ''; + + ccacheCache = pkgs.runCommandNoCC "ccache-cache" { + nativeBuildInputs = [ zmkCompileScript ]; + } '' + export CCACHE_DIR=$out + + mkdir /tmp/build + cd /tmp/build + + compileZmk -b glove80_lh -k ${zmk.src}/app/boards/arm/glove80/glove80.keymap + + rm -fr /tmp/build + mkdir /tmp/build + cd /tmp/build + + compileZmk -b glove80_rh -k ${zmk.src}/app/boards/arm/glove80/glove80.keymap + ''; + + entrypoint = pkgs.writeShellScriptBin "entrypoint" '' + set -euo pipefail + + if [ ! -d "$CCACHE_DIR" ]; then + cp -r ${ccacheCache} "$CCACHE_DIR" + chmod -R u=rwX,go=u-w "$CCACHE_DIR" + fi + + if [ ! -d /tmp/build ]; then + mkdir /tmp/build + fi + + exec "$@" + ''; + + startLambda = pkgs.writeShellScriptBin "startLambda" '' + set -euo pipefail + export PATH=${lib.makeBinPath [ zmkCompileScript dts2yml ]}:$PATH + cd ${lambda.source} + ${lambda.bundleEnv}/bin/bundle exec aws_lambda_ric "app.LambdaFunction::Handler.process" + ''; + + simulateLambda = pkgs.writeShellScriptBin "simulateLambda" '' + ${pkgs.aws-lambda-rie}/bin/aws-lambda-rie ${startLambda}/bin/startLambda + ''; + + lambdaImage = + let + appLayer = { + name = "app-layer"; + path = [ startLambda zmkCompileScript ]; + }; + in + ociTools.makeSimpleImage { + name = "zmk-builder-lambda"; + layers = [ baseLayer depsLayer appLayer ]; + config = { + User = "deploy"; + WorkingDir = "/tmp"; + Entrypoint = [ "${entrypoint}/bin/entrypoint" ]; + Cmd = [ "startLambda" ]; + Env = [ "CCACHE_DIR=/tmp/ccache" "REVISION=${revision}" ]; + }; + }; +in { + inherit lambdaImage zmkCompileScript dts2yml ccacheCache; + directLambdaImage = lambdaImage; + + # nix shell -f release.nix simulateLambda -c simulateLambda + inherit simulateLambda; +} From e4f167f01dd83a3e454ed5e79efa4d8b08ea12a4 Mon Sep 17 00:00:00 2001 From: moergo-sc Date: Sun, 19 Sep 2021 13:05:21 +1200 Subject: [PATCH 133/134] Configure Glove80 board definitions for custom features Additionally adds a board definition for Glove80-v0, an early version of Glove80. --- app/boards/arm/glove80/glove80.keymap | 35 ++++- app/boards/arm/glove80/glove80_lh.dts | 27 ++++ app/boards/arm/glove80/glove80_lh_defconfig | 21 +++ app/boards/arm/glove80/glove80_rh_defconfig | 10 +- app/boards/arm/glove80_v0/Kconfig | 7 + app/boards/arm/glove80_v0/Kconfig.board | 12 ++ app/boards/arm/glove80_v0/Kconfig.defconfig | 66 +++++++++ app/boards/arm/glove80_v0/board.cmake | 5 + app/boards/arm/glove80_v0/glove80_v0.dtsi | 100 +++++++++++++ app/boards/arm/glove80_v0/glove80_v0.keymap | 56 ++++++++ .../arm/glove80_v0/glove80_v0_lh-pinctrl.dtsi | 47 ++++++ app/boards/arm/glove80_v0/glove80_v0_lh.dts | 135 ++++++++++++++++++ .../arm/glove80_v0/glove80_v0_lh.keymap | 1 + app/boards/arm/glove80_v0/glove80_v0_lh.yaml | 15 ++ app/boards/arm/glove80_v0/glove80_v0_lh.yml | 10 ++ .../arm/glove80_v0/glove80_v0_lh_defconfig | 50 +++++++ .../arm/glove80_v0/glove80_v0_rh-pinctrl.dtsi | 47 ++++++ app/boards/arm/glove80_v0/glove80_v0_rh.dts | 118 +++++++++++++++ .../arm/glove80_v0/glove80_v0_rh.keymap | 1 + app/boards/arm/glove80_v0/glove80_v0_rh.yaml | 15 ++ app/boards/arm/glove80_v0/glove80_v0_rh.yml | 10 ++ .../arm/glove80_v0/glove80_v0_rh_defconfig | 50 +++++++ 22 files changed, 833 insertions(+), 5 deletions(-) create mode 100644 app/boards/arm/glove80_v0/Kconfig create mode 100644 app/boards/arm/glove80_v0/Kconfig.board create mode 100644 app/boards/arm/glove80_v0/Kconfig.defconfig create mode 100644 app/boards/arm/glove80_v0/board.cmake create mode 100644 app/boards/arm/glove80_v0/glove80_v0.dtsi create mode 100644 app/boards/arm/glove80_v0/glove80_v0.keymap create mode 100644 app/boards/arm/glove80_v0/glove80_v0_lh-pinctrl.dtsi create mode 100644 app/boards/arm/glove80_v0/glove80_v0_lh.dts create mode 100644 app/boards/arm/glove80_v0/glove80_v0_lh.keymap create mode 100644 app/boards/arm/glove80_v0/glove80_v0_lh.yaml create mode 100644 app/boards/arm/glove80_v0/glove80_v0_lh.yml create mode 100644 app/boards/arm/glove80_v0/glove80_v0_lh_defconfig create mode 100644 app/boards/arm/glove80_v0/glove80_v0_rh-pinctrl.dtsi create mode 100644 app/boards/arm/glove80_v0/glove80_v0_rh.dts create mode 100644 app/boards/arm/glove80_v0/glove80_v0_rh.keymap create mode 100644 app/boards/arm/glove80_v0/glove80_v0_rh.yaml create mode 100644 app/boards/arm/glove80_v0/glove80_v0_rh.yml create mode 100644 app/boards/arm/glove80_v0/glove80_v0_rh_defconfig diff --git a/app/boards/arm/glove80/glove80.keymap b/app/boards/arm/glove80/glove80.keymap index 60129bd94e9..6806be79f97 100644 --- a/app/boards/arm/glove80/glove80.keymap +++ b/app/boards/arm/glove80/glove80.keymap @@ -11,10 +11,13 @@ #include #include +#define HYPER LC(LS(LG(LALT))) + // layers #define DEFAULT 0 #define LOWER 1 #define MAGIC 2 +#define FACTORY_TEST 3 / { behaviors { @@ -26,9 +29,24 @@ tapping-term-ms = <200>; bindings = <&mo LOWER>, <&to LOWER>; }; + + magic: magic_hold_tap { + compatible = "zmk,behavior-hold-tap"; + #binding-cells = <2>; + flavor = "tap-preferred"; + tapping-term-ms = <200>; + bindings = <&mo>, <&rgb_ug_status_macro>; + }; }; macros { + rgb_ug_status_macro: rgb_ug_status_macro_0 { + compatible = "zmk,behavior-macro"; + #binding-cells = <0>; + bindings + = <&rgb_ug RGB_STATUS>; + }; + bt_0: bt_profile_macro_0 { compatible = "zmk,behavior-macro"; #binding-cells = <0>; @@ -80,7 +98,7 @@ &kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSLH &kp ESC &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp GRAVE &kp Z &kp X &kp C &kp V &kp B &kp LSHFT &kp LCTRL &layer_td &kp LGUI &kp RCTRL &kp RSHFT &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp PG_UP - &mo MAGIC &kp HOME &kp END &kp LEFT &kp RIGHT &kp BSPC &kp DEL &kp LALT &kp RALT &kp RET &kp SPACE &kp UP &kp DOWN &kp LBKT &kp RBKT &kp PG_DN + &magic MAGIC 0 &kp HOME &kp END &kp LEFT &kp RIGHT &kp BSPC &kp DEL &kp LALT &kp RALT &kp RET &kp SPACE &kp UP &kp DOWN &kp LBKT &kp RBKT &kp PG_DN >; }; @@ -97,12 +115,23 @@ magic_layer { bindings = < - &bt BT_CLR &none &none &none &none &none &none &none &none &none + &bt BT_CLR &none &none &none &none &none &none &none &none &bt BT_CLR_ALL &none &none &none &none &none &none &none &none &none &none &none &none &none &rgb_ug RGB_SPI &rgb_ug RGB_SAI &rgb_ug RGB_HUI &rgb_ug RGB_BRI &rgb_ug RGB_TOG &none &none &none &none &none &none &bootloader &rgb_ug RGB_SPD &rgb_ug RGB_SAD &rgb_ug RGB_HUD &rgb_ug RGB_BRD &rgb_ug RGB_EFF &none &none &none &none &none &bootloader &sys_reset &none &none &none &none &none &bt_2 &bt_3 &none &none &none &none &none &none &none &none &none &sys_reset - &none &none &none &none &none &bt_0 &bt_1 &out OUT_USB &none &none &none &none &none &none &none &none + &none &none &none &none &none &bt_0 &bt_1 &out OUT_USB &none &none &none &none &none &none &none &to FACTORY_TEST + >; + }; + + factory_test_layer { + bindings = < + &kp N0 &kp N6 &kp N2 &kp N8 &kp N4 &kp N4 &kp N8 &kp N2 &kp N6 &kp N0 + &kp N1 &kp N7 &kp N3 &kp N9 &kp N5 &kp N0 &kp N0 &kp N5 &kp N9 &kp N3 &kp N7 &kp N1 + &kp N2 &kp N8 &kp N4 &kp N0 &kp N6 &kp N1 &kp N1 &kp N6 &kp N0 &kp N4 &kp N8 &kp N2 + &kp N3 &kp N9 &kp N5 &kp N1 &kp N7 &kp N2 &kp N2 &kp N7 &kp N1 &kp N5 &kp N9 &kp N3 + &kp N4 &kp N0 &kp N6 &kp N2 &kp N8 &kp N3 &kp N4 &kp N5 &kp N6 &kp N6 &kp N5 &kp N4 &kp N3 &kp N8 &kp N2 &kp N6 &kp N0 &kp N4 + &kp N5 &kp N1 &kp N7 &kp N3 &kp N9 &kp N7 &kp N8 &kp N9 &kp N9 &kp N8 &kp N7 &kp N9 &kp N3 &kp N7 &kp N1 &kp N5 >; }; }; diff --git a/app/boards/arm/glove80/glove80_lh.dts b/app/boards/arm/glove80/glove80_lh.dts index 5ef54207127..43b620a3cbc 100644 --- a/app/boards/arm/glove80/glove80_lh.dts +++ b/app/boards/arm/glove80/glove80_lh.dts @@ -17,6 +17,7 @@ zmk,underglow = &led_strip; zmk,backlight = &back_led_backlight; zmk,battery = &vbatt; + zmk,underglow-indicators = &underglow_indicators; }; back_led_backlight: pwmleds { @@ -36,6 +37,32 @@ vbatt: vbatt { compatible = "zmk,battery-nrf-vddh"; }; + +/* + MoErgo 40 LEDs + + 34 28 22 16 10 + 35 29 23 17 11 6 + 36 30 24 18 12 7 + 37 31 25 19 13 8 + 38 32 26 20 14 9 + 39 33 27 21 15 + 0 1 2 + 3 4 5 +*/ + + underglow_indicators: underglow-indicators { + compatible = "zmk,underglow-indicators"; + layer-state = <35 29 23 17 11 6>; + bat-lhs = <36 30 24 18 12 7>; + bat-rhs = <37 31 25 19 13 8>; + capslock = <22>; + numlock = <16>; + scrolllock = <10>; + ble-state = <3 4 0 1>; + usb-state = <5>; + output-fallback = <15>; + }; }; &spi3 { diff --git a/app/boards/arm/glove80/glove80_lh_defconfig b/app/boards/arm/glove80/glove80_lh_defconfig index b454e8be1bf..57c72c8be9d 100644 --- a/app/boards/arm/glove80/glove80_lh_defconfig +++ b/app/boards/arm/glove80/glove80_lh_defconfig @@ -23,11 +23,25 @@ CONFIG_BT_DIS_PNP_VID=0x16c0 CONFIG_BT_DIS_MANUF="MoErgo" CONFIG_BT_DIS_MODEL="Glove80" +### Bluetooth configuration workarounds + +# Use higher radio transmit power CONFIG_BT_CTLR_TX_PWR_PLUS_8=y # Work-around for Windows bug with battery notifications CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=n +# Allow unauthenticated re-pairing for already paired hosts. This would permit +# an attacker that can spoof the host's peer address to "steal" the keyboard +# pairing by overwriting it, but without access to the previous keys it can't +# establish a MITM, and the sudden loss of the keyboard would be very obvious to +# the previously-connected host. +CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y +CONFIG_ZMK_BLE_PASSKEY_ENTRY=n + +# Fetch peripheral battery level for status display reporting +CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING=y + # Enable MPU CONFIG_ARM_MPU=y @@ -53,6 +67,9 @@ CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y # Enable RGB underglow CONFIG_ZMK_RGB_UNDERGLOW=y +# disable EXT_POWER until underglow gets turned on +CONFIG_ZMK_EXT_POWER_START=n + CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y CONFIG_ZMK_RGB_UNDERGLOW_ON_START=n CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP=4 @@ -81,6 +98,10 @@ CONFIG_ZMK_BACKLIGHT_AUTO_OFF_USB=y # space. CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_BASIC=y +# Enable USB boot protocol support +CONFIG_ZMK_USB_BOOT=y +CONFIG_ZMK_HID_INDICATORS=y + # Turn on debugging to disable optimization. Debug messages can result in larger # stacks, so enable stack protection and particularly a larger BLE peripheral stack. # CONFIG_DEBUG=y diff --git a/app/boards/arm/glove80/glove80_rh_defconfig b/app/boards/arm/glove80/glove80_rh_defconfig index ef29d682a54..4394bee2ad2 100644 --- a/app/boards/arm/glove80/glove80_rh_defconfig +++ b/app/boards/arm/glove80/glove80_rh_defconfig @@ -5,8 +5,8 @@ CONFIG_SOC_SERIES_NRF52X=y CONFIG_SOC_NRF52840_QIAA=y CONFIG_BOARD_GLOVE80_RH=y -# Enable both USB and BLE -CONFIG_ZMK_USB=y +# Enable BLE for split peripheral +CONFIG_ZMK_USB=n CONFIG_ZMK_BLE=y # Keyboard IDs @@ -21,6 +21,9 @@ CONFIG_BT_DIS_PNP_VID=0x16c0 CONFIG_BT_DIS_MANUF="MoErgo" CONFIG_BT_DIS_MODEL="Glove80 Right" +### Bluetooth configuration workarounds + +# Use higher radio transmit power CONFIG_BT_CTLR_TX_PWR_PLUS_8=y # Enable MPU @@ -48,6 +51,9 @@ CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y # Enable RGB underglow CONFIG_ZMK_RGB_UNDERGLOW=y +# disable EXT_POWER until underglow gets turned on +CONFIG_ZMK_EXT_POWER_START=n + CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y CONFIG_ZMK_RGB_UNDERGLOW_ON_START=n CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP=4 diff --git a/app/boards/arm/glove80_v0/Kconfig b/app/boards/arm/glove80_v0/Kconfig new file mode 100644 index 00000000000..f971e6c81da --- /dev/null +++ b/app/boards/arm/glove80_v0/Kconfig @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT + +config BOARD_ENABLE_DCDC + bool "Enable DCDC mode" + select SOC_DCDC_NRF52X + default y + depends on (BOARD_GLOVE80_V0_LH || BOARD_GLOVE80_V0_RH) diff --git a/app/boards/arm/glove80_v0/Kconfig.board b/app/boards/arm/glove80_v0/Kconfig.board new file mode 100644 index 00000000000..ce97e890fbc --- /dev/null +++ b/app/boards/arm/glove80_v0/Kconfig.board @@ -0,0 +1,12 @@ +# nice!nano board configuration + +# Copyright (c) 2020 Pete Johanson +# SPDX-License-Identifier: MIT + +config BOARD_GLOVE80_V0_LH + bool "Glove80 v0 LH" + depends on SOC_NRF52840_QIAA + +config BOARD_GLOVE80_V0_RH + bool "Glove80 v0 RH" + depends on SOC_NRF52840_QIAA diff --git a/app/boards/arm/glove80_v0/Kconfig.defconfig b/app/boards/arm/glove80_v0/Kconfig.defconfig new file mode 100644 index 00000000000..9e68b18dc89 --- /dev/null +++ b/app/boards/arm/glove80_v0/Kconfig.defconfig @@ -0,0 +1,66 @@ +# Copyright (c) 2021 The ZMK Contributors +# SPDX-License-Identifier: MIT + +if BOARD_GLOVE80_V0_LH +config BOARD + default "glove80 v0 lh" + +config ZMK_SPLIT_BLE_ROLE_CENTRAL + default y + +config ZMK_KEYBOARD_NAME + default "Glove80 V0 Left" +endif # BOARD_GLOVE80_V0_LH + +if BOARD_GLOVE80_V0_RH +config BOARD + default "glove80 v0 rh" + +config ZMK_KEYBOARD_NAME + default "Glove80 V0 Right" +endif # BOARD_GLOVE80_V0_RH + +if BOARD_GLOVE80_V0_LH || BOARD_GLOVE80_V0_RH + +config ZMK_SPLIT + default y + +config BT_CTLR + default BT + +config ZMK_BLE + default y + +config ZMK_USB + default y + +config ZMK_BATTERY_VOLTAGE_DIVIDER + default y + +config ZMK_BATTERY_NRF_VDDH + default y + +config PINCTRL + default y + +if USB + +config USB_NRFX + default y + +config USB_DEVICE_STACK + default y + +endif # USB + +if ZMK_BACKLIGHT + +config PWM + default y + +config LED_PWM + default y + +endif # ZMK_BACKLIGHT + +endif # BOARD_GLOVE80_V0_LH || BOARD_GLOVE80_V0_RH diff --git a/app/boards/arm/glove80_v0/board.cmake b/app/boards/arm/glove80_v0/board.cmake new file mode 100644 index 00000000000..fa847d50595 --- /dev/null +++ b/app/boards/arm/glove80_v0/board.cmake @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT + +board_runner_args(nrfjprog "--nrf-family=NRF52" "--softreset") +include(${ZEPHYR_BASE}/boards/common/blackmagicprobe.board.cmake) +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) diff --git a/app/boards/arm/glove80_v0/glove80_v0.dtsi b/app/boards/arm/glove80_v0/glove80_v0.dtsi new file mode 100644 index 00000000000..dafa089dbd8 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0.dtsi @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix-transform = &default_transform; + zephyr,code-partition = &code_partition; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,console = &cdc_acm_uart; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <14>; + rows = <6>; + map = < +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) +RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) +RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,12) RC(2,13) +RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) RC(3,13) +RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(0,6) RC(1,6) RC(2,6) RC(2,7) RC(1,7) RC(0,7) RC(4,8) RC(4,9) RC(4,10) RC(4,11) RC(4,12) RC(4,13) +RC(5,0) RC(5,1) RC(5,2) RC(5,3) RC(5,4) RC(3,6) RC(4,6) RC(5,6) RC(5,7) RC(4,7) RC(3,7) RC(5,9) RC(5,10) RC(5,11) RC(5,12) RC(5,13) + >; + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-matrix"; + + diode-direction = "row2col"; + debounce-press-ms = <1>; + debounce-release-ms = <25>; + }; + +}; + +&adc { + status = "okay"; +}; + +&gpiote { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +&usbd { + status = "okay"; + cdc_acm_uart: cdc_acm_uart { + compatible = "zephyr,cdc-acm-uart"; + }; +}; + +&flash0 { + /* + * For more information, see: + * http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html + */ + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + sd_partition: partition@0 { + reg = <0x00000000 0x00026000>; + }; + code_partition: partition@26000 { + reg = <0x00026000 0x000c6000>; + }; + + /* + * The flash starting at 0x000ec000 and ending at + * 0x000f3fff is reserved for use by the application. + */ + + /* + * Storage partition will be used by FCB/LittleFS/NVS + * if enabled. + */ + storage_partition: partition@ec000 { + reg = <0x000ec000 0x00008000>; + }; + + boot_partition: partition@f4000 { + reg = <0x000f4000 0x0000c000>; + }; + }; +}; diff --git a/app/boards/arm/glove80_v0/glove80_v0.keymap b/app/boards/arm/glove80_v0/glove80_v0.keymap new file mode 100644 index 00000000000..52a88125275 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0.keymap @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include + +#define HYPER LC(LS(LG(LALT))) + +// layers +#define DEFAULT 0 +#define LOWER 1 + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + // --------------------------------------------------------------------------------------------------------------------------------- + // | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 | + // | = | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | - | + // | TAB | Q | W | E | R | T | | Y | U | I | O | P | \ | + // | ESC | A | S | D | F | G | | H | J | K | L | ; | ' | + // | ` | Z | X | C | V | B | LSHFT | LCTRL | LOWER | | LGUI | RCTRL | RSHFT | N | M | , | . | / | PGUP | + // | MAGIC | HOME| END | LEFT | RIGHT| | BSPC | DEL | LALT | | RALT | RET | SPACE | | UP | DOWN | [ | ] | PGDN | + + + // MAGIC is currently bound to the same as LAYER - these will be fixed later + bindings = < + &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 + &kp EQUAL &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp MINUS + &kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSLH + &kp ESC &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT + &kp GRAVE &kp Z &kp X &kp C &kp V &kp B &kp LSHFT &kp LCTRL &mo LOWER &kp LGUI &kp RCTRL &kp RSHFT &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp PG_UP + &mo LOWER &kp HOME &kp END &kp LEFT &kp RIGHT &kp BSPC &kp DEL &kp LALT &kp RALT &kp RET &kp SPACE &kp UP &kp DOWN &kp LBKT &kp RBKT &kp PG_DN + >; + }; + + lower_layer { + bindings = < + &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &none &none &none &kp F11 &kp F12 + &bt BT_CLR &bt BT_CLR &out OUT_USB &out OUT_BLE &out OUT_TOG &none &none &none &none &none &none &none + &bootloader &rgb_ug RGB_TOG &rgb_ug RGB_EFF &rgb_ug RGB_BRI &rgb_ug RGB_BRD &kp K_VOL_UP &none &none &none &none &none &bootloader + &sys_reset &none &none &none &none &kp K_VOL_DN &none &none &none &none &none &sys_reset + &ext_power EP_ON &ext_power EP_OFF &none &none &none &kp K_MUTE &none &kp HYPER &none &none &none &none &none &none &none &none &none &none + &none &kp CAPS &kp INS &none &none &none &none &none &none &none &none &none &none &none &none &none + >; + }; + }; +}; diff --git a/app/boards/arm/glove80_v0/glove80_v0_lh-pinctrl.dtsi b/app/boards/arm/glove80_v0/glove80_v0_lh-pinctrl.dtsi new file mode 100644 index 00000000000..f4437b601d2 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_lh-pinctrl.dtsi @@ -0,0 +1,47 @@ +&pinctrl { + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; + + pwm0_default: pwm0_default { + group1 { + psels = ; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = ; + low-power-enable; + }; + }; + + uart0_default: uart0_default { + group1 { + psels = , + ; + }; + }; + + uart0_sleep: uart0_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + +}; diff --git a/app/boards/arm/glove80_v0/glove80_v0_lh.dts b/app/boards/arm/glove80_v0/glove80_v0_lh.dts new file mode 100644 index 00000000000..db8ae5a3334 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_lh.dts @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/dts-v1/; +#include +#include +#include "glove80_v0.dtsi" +#include "glove80_v0_lh-pinctrl.dtsi" + +/ { + model = "glove80_v0_lh"; + compatible = "glove80_v0_lh"; + + chosen { + zmk,underglow = &led_strip; + zmk,backlight = &power_led_backlight; + zmk,battery = &vbatt; + zmk,underglow-indicators = &underglow_indicators; + }; + + power_led_backlight: pwmleds { + compatible = "pwm-leds"; + pwm_led_0 { + pwms = <&pwm0 0 PWM_USEC(20) PWM_POLARITY_NORMAL>; + }; + }; + + // Node name must match original "EXT_POWER" label to preserve user settings. + EXT_POWER { + compatible = "zmk,ext-power-generic"; + control-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; /**[SC] WS2812_CE */ + init-delay-ms = <10>; + }; + + vbatt: vbatt-divider { + compatible = "zmk,battery-voltage-divider"; + io-channels = <&adc 5>; + output-ohms = <820000>; /** Double check that this is right */ + full-ohms = <(1500000 + 820000)>; + }; + + vbatt-vddh { + compatible = "zmk,battery-nrf-vddh"; + }; + +/* + MoErgo 40 LEDs + + 34 28 22 16 10 + 35 29 23 17 11 6 + 36 30 24 18 12 7 + 37 31 25 19 13 8 + 38 32 26 20 14 9 + 39 33 27 21 15 + 0 1 2 + 3 4 5 +*/ + + underglow_indicators: underglow-indicators { + compatible = "zmk,underglow-indicators"; + layer-state = <35 29 23 17 11 6>; + bat-lhs = <36 30 24 18 12 7>; + bat-rhs = <37 31 25 19 13 8>; + capslock = <22>; + numlock = <16>; + scrolllock = <10>; + ble-state = <3 4 0 1>; + usb-state = <5>; + output-fallback = <15>; + }; +}; + +&spi1 { + compatible = "nordic,nrf-spim"; + /* Cannot be used together with i2c0. */ + status = "okay"; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + + /* SPI */ + reg = <0>; /* ignored, but necessary for SPI bindings */ + spi-max-frequency = <2000000>; + + /* WS2812 */ + chain-length = <40>; /* 18 keys have underglow at the moment */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + + color-mapping = ; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + + +// [SC] Not sure if this section is necessary +&uart0 { + compatible = "nordic,nrf-uarte"; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&kscan0 { + row-gpios + = <&gpio0 26 GPIO_ACTIVE_HIGH> // LH ROW1 + , <&gpio0 5 GPIO_ACTIVE_HIGH> // LH ROW2 + , <&gpio0 7 GPIO_ACTIVE_HIGH> // LH ROW3 + , <&gpio1 8 GPIO_ACTIVE_HIGH> // LH ROW4 + , <&gpio0 11 GPIO_ACTIVE_HIGH> // LH ROW5 + , <&gpio0 12 GPIO_ACTIVE_HIGH> // LH ROW6 + ; + col-gpios + = <&gpio1 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH COL6 + , <&gpio1 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH COL5 + , <&gpio1 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH COL4 + , <&gpio1 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH COL3 + , <&gpio1 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH COL2 + , <&gpio1 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH COL1 + , <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // LH Thumb + ; +}; diff --git a/app/boards/arm/glove80_v0/glove80_v0_lh.keymap b/app/boards/arm/glove80_v0/glove80_v0_lh.keymap new file mode 100644 index 00000000000..1a5a04b3937 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_lh.keymap @@ -0,0 +1 @@ +#include "glove80_v0.keymap" \ No newline at end of file diff --git a/app/boards/arm/glove80_v0/glove80_v0_lh.yaml b/app/boards/arm/glove80_v0/glove80_v0_lh.yaml new file mode 100644 index 00000000000..56b575ac27e --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_lh.yaml @@ -0,0 +1,15 @@ +identifier: glove80_v0_lh +name: Glove80_V0_LH +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - adc + - usb_device + - ble + - ieee802154 + - pwm + - watchdog diff --git a/app/boards/arm/glove80_v0/glove80_v0_lh.yml b/app/boards/arm/glove80_v0/glove80_v0_lh.yml new file mode 100644 index 00000000000..407021c51df --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_lh.yml @@ -0,0 +1,10 @@ +file_format: "1" +id: glove80_v0_lh +name: Glove80_V0_LH +type: board +arch: arm +outputs: + - usb + - ble +url: https://www.moergo.com +exposes: diff --git a/app/boards/arm/glove80_v0/glove80_v0_lh_defconfig b/app/boards/arm/glove80_v0/glove80_v0_lh_defconfig new file mode 100644 index 00000000000..4d5676a1231 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_lh_defconfig @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: MIT + +CONFIG_SOC_SERIES_NRF52X=y +CONFIG_SOC_NRF52840_QIAA=y +CONFIG_BOARD_GLOVE80_V0_LH=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# enable GPIO +CONFIG_GPIO=y + +CONFIG_BUILD_OUTPUT_UF2=y + +CONFIG_USE_DT_CODE_PARTITION=y + +CONFIG_MPU_ALLOW_FLASH_WRITE=y +CONFIG_NVS=y +CONFIG_SETTINGS_NVS=y +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_MAP=y + +# Enable RGB underglow +CONFIG_ZMK_RGB_UNDERGLOW=y +CONFIG_WS2812_STRIP=y +CONFIG_SPI=y + +CONFIG_ZMK_RGB_UNDERGLOW_ON_START=n +CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y +CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP=4 + +CONFIG_ZMK_RGB_UNDERGLOW_EFF_START=3 +CONFIG_ZMK_RGB_UNDERGLOW_HUE_START=285 +CONFIG_ZMK_RGB_UNDERGLOW_SAT_START=75 +CONFIG_ZMK_RGB_UNDERGLOW_BRT_START=20 + +# The power LED is implemented as a backlight +CONFIG_ZMK_BACKLIGHT=y +CONFIG_ZMK_BACKLIGHT_ON_START=y +CONFIG_ZMK_BACKLIGHT_BRT_START=5 +CONFIG_ZMK_BACKLIGHT_AUTO_OFF_IDLE=y +CONFIG_ZMK_BACKLIGHT_AUTO_OFF_USB=y + +# Turn on logging, and set ZMK logging to debug output +# Only for debugging +CONFIG_ZMK_USB_LOGGING=n + +# Turn on debugging to disable optimization +CONFIG_DEBUG=n diff --git a/app/boards/arm/glove80_v0/glove80_v0_rh-pinctrl.dtsi b/app/boards/arm/glove80_v0/glove80_v0_rh-pinctrl.dtsi new file mode 100644 index 00000000000..08f649f759f --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_rh-pinctrl.dtsi @@ -0,0 +1,47 @@ +&pinctrl { + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; + + pwm0_default: pwm0_default { + group1 { + psels = ; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = ; + low-power-enable; + }; + }; + + uart0_default: uart0_default { + group1 { + psels = , + ; + }; + }; + + uart0_sleep: uart0_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + +}; diff --git a/app/boards/arm/glove80_v0/glove80_v0_rh.dts b/app/boards/arm/glove80_v0/glove80_v0_rh.dts new file mode 100644 index 00000000000..c2185da7817 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_rh.dts @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/dts-v1/; +#include +#include +#include "glove80_v0.dtsi" +#include "glove80_v0_rh-pinctrl.dtsi" + +/ { + model = "glove80_v0_rh"; + compatible = "glove80_v0_rh"; + + chosen { + zmk,underglow = &led_strip; + zmk,backlight = &power_led_backlight; + zmk,battery = &vbatt; + }; + + leds { + compatible = "gpio-leds"; + red_led: led_0 { + gpios = <&gpio0 20 GPIO_ACTIVE_HIGH>; + }; + }; + + power_led_backlight: pwmleds { + compatible = "pwm-leds"; + pwm_led_0 { + pwms = <&pwm0 0 PWM_USEC(20) PWM_POLARITY_NORMAL>; + }; + }; + + // Node name must match original "EXT_POWER" label to preserve user settings. + EXT_POWER { + compatible = "zmk,ext-power-generic"; + control-gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>; /**[SC] WS2812_CE */ + init-delay-ms = <10>; + }; + + vbatt: vbatt-divider { + compatible = "zmk,battery-voltage-divider"; + io-channels = <&adc 5>; + output-ohms = <820000>; /** Double check that this is right */ + full-ohms = <(1500000 + 820000)>; + }; + + vbatt-vddh { + compatible = "zmk,battery-nrf-vddh"; + }; +}; + +&spi1 { + compatible = "nordic,nrf-spim"; + /* Cannot be used together with i2c0. */ + status = "okay"; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + + /* SPI */ + reg = <0>; /* ignored, but necessary for SPI bindings */ + spi-max-frequency = <2000000>; + + /* WS2812 */ + chain-length = <40>; + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + + color-mapping = ; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +// [SC] Not sure if this section is necessary +&uart0 { + compatible = "nordic,nrf-uarte"; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&default_transform { + col-offset = <7>; +}; + +&kscan0 { + row-gpios + = <&gpio0 26 GPIO_ACTIVE_HIGH> // RH ROW1 + , <&gpio0 5 GPIO_ACTIVE_HIGH> // RH ROW2 + , <&gpio0 7 GPIO_ACTIVE_HIGH> // RH ROW3 + , <&gpio1 8 GPIO_ACTIVE_HIGH> // RH ROW4 + , <&gpio0 11 GPIO_ACTIVE_HIGH> // RH ROW5 + , <&gpio0 12 GPIO_ACTIVE_HIGH> // RH ROW6 + ; + col-gpios + = <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH Thumb + , <&gpio1 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH COL1 + , <&gpio1 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH COL2 + , <&gpio1 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH COL3 + , <&gpio1 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH COL4 + , <&gpio1 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH COL5 + , <&gpio1 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> // RH COL6 + ; +}; diff --git a/app/boards/arm/glove80_v0/glove80_v0_rh.keymap b/app/boards/arm/glove80_v0/glove80_v0_rh.keymap new file mode 100644 index 00000000000..1a5a04b3937 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_rh.keymap @@ -0,0 +1 @@ +#include "glove80_v0.keymap" \ No newline at end of file diff --git a/app/boards/arm/glove80_v0/glove80_v0_rh.yaml b/app/boards/arm/glove80_v0/glove80_v0_rh.yaml new file mode 100644 index 00000000000..222ae1770e2 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_rh.yaml @@ -0,0 +1,15 @@ +identifier: glove80_v0_rh +name: Glove80_V0_RH +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - adc + - usb_device + - ble + - ieee802154 + - pwm + - watchdog diff --git a/app/boards/arm/glove80_v0/glove80_v0_rh.yml b/app/boards/arm/glove80_v0/glove80_v0_rh.yml new file mode 100644 index 00000000000..41333f08662 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_rh.yml @@ -0,0 +1,10 @@ +file_format: "1" +id: glove80_v0_rh +name: Glove80_V0_RH +type: board +arch: arm +outputs: + - usb + - ble +url: https://www.moergo.com +exposes: diff --git a/app/boards/arm/glove80_v0/glove80_v0_rh_defconfig b/app/boards/arm/glove80_v0/glove80_v0_rh_defconfig new file mode 100644 index 00000000000..71b5f2f6215 --- /dev/null +++ b/app/boards/arm/glove80_v0/glove80_v0_rh_defconfig @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: MIT + +CONFIG_SOC_SERIES_NRF52X=y +CONFIG_SOC_NRF52840_QIAA=y +CONFIG_BOARD_GLOVE80_V0_RH=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# enable GPIO +CONFIG_GPIO=y + +CONFIG_BUILD_OUTPUT_UF2=y + +CONFIG_USE_DT_CODE_PARTITION=y + +CONFIG_MPU_ALLOW_FLASH_WRITE=y +CONFIG_NVS=y +CONFIG_SETTINGS_NVS=y +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_MAP=y + +# Disable RGB underglow for now in RH +CONFIG_ZMK_RGB_UNDERGLOW=y +CONFIG_WS2812_STRIP=y +CONFIG_SPI=y + +CONFIG_ZMK_RGB_UNDERGLOW_ON_START=y +CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y +CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP=4 + +CONFIG_ZMK_RGB_UNDERGLOW_EFF_START=3 +CONFIG_ZMK_RGB_UNDERGLOW_HUE_START=285 +CONFIG_ZMK_RGB_UNDERGLOW_SAT_START=75 +CONFIG_ZMK_RGB_UNDERGLOW_BRT_START=20 + +# The power LED is implemented as a backlight +CONFIG_ZMK_BACKLIGHT=y +CONFIG_ZMK_BACKLIGHT_ON_START=y +CONFIG_ZMK_BACKLIGHT_BRT_START=5 +CONFIG_ZMK_BACKLIGHT_AUTO_OFF_IDLE=y +CONFIG_ZMK_BACKLIGHT_AUTO_OFF_USB=y + +# Turn on logging, and set ZMK logging to debug output +# Only for debugging +CONFIG_ZMK_USB_LOGGING=n + +# Turn on debugging to disable optimization +CONFIG_DEBUG=n From 3fc2867c2141e7d3a87e3e577e413fa0c15ded60 Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Fri, 13 Sep 2024 15:55:08 +0900 Subject: [PATCH 134/134] lambda-compiler DTS validation: extend stub to define &underglow_indicators --- lambda/compiler.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lambda/compiler.rb b/lambda/compiler.rb index 58ab0eaef8d..611bb9edb82 100644 --- a/lambda/compiler.rb +++ b/lambda/compiler.rb @@ -84,8 +84,15 @@ def compile_board(board, keymap_data:, kconfig_data:, include_static_rhs: false) behaviors macros combos conditional_layers keymap underglow-indicators ].freeze + DTS_STUB = <<~EOF + /dts-v1/; + / { + underglow_indicators: underglow-indicators {}; + }; + EOF + def validate_devicetree!(dtsi) - dts = "/dts-v1/;\n" + dtsi + dts = DTS_STUB + dtsi stdout, stderr, status = Open3.capture3({}, 'dts2yml', unsetenv_others: true, stdin_data: dts)