From 9dd8217cd4c5ae434bde6bd5eb4dca2274ce9cec Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 15 Aug 2020 15:32:36 -0400 Subject: [PATCH 01/38] Add bluemicro support --- .../arm/bluemicro52840_v1/CMakeLists.txt | 8 ++ .../arm/bluemicro52840_v1/Kconfig.board | 8 ++ .../arm/bluemicro52840_v1/Kconfig.defconfig | 30 +++++ .../arduino_pro_micro_pins.dtsi | 52 +++++++++ .../bluemicro52840_v1/bluemicro52840_v1.dts | 103 ++++++++++++++++++ .../bluemicro52840_v1/bluemicro52840_v1.yaml | 15 +++ .../bluemicro52840_v1_defconfig | 20 ++++ app/boards/arm/bluemicro52840_v1/board.cmake | 5 + 8 files changed, 241 insertions(+) create mode 100644 app/boards/arm/bluemicro52840_v1/CMakeLists.txt create mode 100644 app/boards/arm/bluemicro52840_v1/Kconfig.board create mode 100644 app/boards/arm/bluemicro52840_v1/Kconfig.defconfig create mode 100644 app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi create mode 100644 app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts create mode 100644 app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.yaml create mode 100644 app/boards/arm/bluemicro52840_v1/bluemicro52840_v1_defconfig create mode 100644 app/boards/arm/bluemicro52840_v1/board.cmake diff --git a/app/boards/arm/bluemicro52840_v1/CMakeLists.txt b/app/boards/arm/bluemicro52840_v1/CMakeLists.txt new file mode 100644 index 00000000..00952c30 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/CMakeLists.txt @@ -0,0 +1,8 @@ +set_property(GLOBAL APPEND PROPERTY extra_post_build_commands + COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/../tools/uf2/utils/uf2conv.py + -c + -b 0x26000 + -f 0xADA52840 + -o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.uf2 + ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin +) diff --git a/app/boards/arm/bluemicro52840_v1/Kconfig.board b/app/boards/arm/bluemicro52840_v1/Kconfig.board new file mode 100644 index 00000000..dea05550 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/Kconfig.board @@ -0,0 +1,8 @@ +# BlueMicro52840_V1 board configuration + +# Copyright (c) 2020 Pete Johanson, Derek Schmell +# SPDX-License-Identifier: MIT + +config BOARD_BLUEMICRO52840_V1 + bool "BlueMicro52840_V1" + depends on SOC_NRF52840_QIAA diff --git a/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig b/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig new file mode 100644 index 00000000..e33a6556 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig @@ -0,0 +1,30 @@ +# Electronut Labs Papyr board configuration + +# Copyright (c) 2020 Pete Johanson, Derek Schmell +# SPDX-License-Identifier: MIT + +if BOARD_BLUEMICRO52840_V1 + +config BOARD + default "bluemicro52840_v1" + +if USB + +config USB_NRFX + default y + +config USB_DEVICE_STACK + default y + +endif # USB + +config BT_CTLR + default BT + +config ZMK_BLE + default y + +config ZMK_USB + default y + +endif # BOARD_BLUEMICRO52840_V1 diff --git a/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi b/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi new file mode 100644 index 00000000..eb0afe88 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + +/ { + pro_micro_d: connector_d { + compatible = "arduino-pro-micro"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map + = <0 0 &gpio0 8 0> /* D0 D2 */ + , <1 0 &gpio0 6 0> /* D1 D3*/ + , <2 0 &gpio0 15 0> /* D2 D1*/ + , <3 0 &gpio0 17 0> /* D3 D0*/ + , <4 0 &gpio0 20 0> /* D4/A6 D4*/ + , <5 0 &gpio0 13 0> /* D5 C6*/ + , <6 0 &gpio0 24 0> /* D6/A7 D7*/ + , <7 0 &gpio0 9 0> /* D7 E6*/ + , <8 0 &gpio0 10 0> /* D8/A8 B4*/ + , <9 0 &gpio1 6 0> /* D9/A9 B5*/ + , <10 0 &gpio1 11 0> /* D10/A10 B6*/ + , <16 0 &gpio0 28 0> /* D16 B2*/ + , <14 0 &gpio0 3 0> /* D14 B3*/ + , <15 0 &gpio1 13 0> /* D15 B1*/ + ; + }; + + pro_micro_a: connector_a { + compatible = "arduino-pro-micro"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map + = <0 0 &gpio0 2 0> /* A0 F7*/ + , <1 0 &gpio0 29 0> /* A1 F6*/ + , <2 0 &gpio0 26 0> /* A2 F5*/ + , <3 0 &gpio0 30 0> /* A3 F4*/ + , <6 0 &gpio0 20 0> /* D4/A6 D4*/ + , <7 0 &gpio0 24 0> /* D6/A7 D7*/ + , <8 0 &gpio0 10 0> /* D8/A8 B4*/ + , <9 0 &gpio1 6 0> /* D9/A9 B5*/ + , <10 0 &gpio1 13 0> /* D10/A10 B6*/ + ; + }; +}; + +pro_micro_i2c: &i2c0 {}; +pro_micro_spi: &spi0 {}; +pro_micro_serial: &uart0 {}; diff --git a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts new file mode 100644 index 00000000..a1f95e38 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2020 Pete Johanson, Derek Schmell + * + * SPDX-License-Identifier: MIT + */ + +/dts-v1/; +#include +#include "arduino_pro_micro_pins.dtsi" + +/ { + model = "BlueMicro52840_V1"; + compatible = "bluemicro52840,v1"; + + chosen { + zephyr,code-partition = &code_partition; + // zephyr,console = &uart0; + //zephyr,bt-mon-uart = &uart0; + //zephyr,bt-c2h-uart = &uart0; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + }; + + leds { + compatible = "gpio-leds"; + blue_led: led_0 { + gpios = <&gpio0 42 GPIO_ACTIVE_LOW>; + label = "Blue LED"; + }; + }; + +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +&uart0 { + compatible = "nordic,nrf-uart"; + current-speed = <115200>; + tx-pin = <6>; + rx-pin = <8>; +}; + +&i2c0 { + compatible = "nordic,nrf-twi"; + sda-pin = <25>; + scl-pin = <26>; +}; + +&uart0 { + compatible = "nordic,nrf-uarte"; + status = "okay"; + current-speed = <115200>; + tx-pin = <39>; + rx-pin = <34>; + rts-pin = <33>; + cts-pin = <12>; +}; + +&usbd { + status = "okay"; +}; + + +&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>; + + boot_partition: partition@0 { + label = "adafruit_boot"; + reg = <0x000000000 0x0000C000>; + }; + code_partition: partition@26000 { + label = "code_partition"; + reg = <0x00026000 0x000d2000>; + }; + + /* + * The flash starting at 0x000f8000 and ending at + * 0x000fffff is reserved for use by the application. + */ + + /* + * Storage partition will be used by FCB/LittleFS/NVS + * if enabled. + */ + storage_partition: partition@f8000 { + label = "storage"; + reg = <0x000f8000 0x00008000>; + }; + }; +}; diff --git a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.yaml b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.yaml new file mode 100644 index 00000000..fca969d3 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.yaml @@ -0,0 +1,15 @@ +identifier: bluemicro52840_v1 +name: BlueMicro52840_V1 +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - adc + - usb_device + - ble + - ieee802154 + - pwm + - watchdog diff --git a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1_defconfig b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1_defconfig new file mode 100644 index 00000000..f87e69d7 --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1_defconfig @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT + +CONFIG_SOC_SERIES_NRF52X=y +CONFIG_SOC_NRF52840_QIAA=y +CONFIG_BOARD_BLUEMICRO52840_V1=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# enable GPIO +CONFIG_GPIO=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 \ No newline at end of file diff --git a/app/boards/arm/bluemicro52840_v1/board.cmake b/app/boards/arm/bluemicro52840_v1/board.cmake new file mode 100644 index 00000000..12a1d93b --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/board.cmake @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(nrfjprog "--nrf-family=NRF52" "--softreset") +include(${ZEPHYR_BASE}/boards/common/blackmagicprobe.board.cmake) +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) From dd165c68296a9ddf915a1f1681dc15995282ccea Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 15 Aug 2020 15:53:31 -0400 Subject: [PATCH 02/38] Corrected pins for scl-pin and sda-pin --- app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts index a1f95e38..257a0069 100644 --- a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts +++ b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts @@ -48,8 +48,8 @@ &i2c0 { compatible = "nordic,nrf-twi"; - sda-pin = <25>; - scl-pin = <26>; + sda-pin = <15>; + scl-pin = <17>; }; &uart0 { From c44693cd4822c4a90b828aad3619987af2e94447 Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 15 Aug 2020 16:57:06 -0400 Subject: [PATCH 03/38] Update build.yml Updated workflow to include new board and shield --- .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 5eb79716..3fa91e56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: name: Build Test strategy: matrix: - board: [proton_c, nice_nano] + board: [proton_c, nice_nano, bluemicro52840_v1] shield: - corne_left - corne_right @@ -16,6 +16,8 @@ jobs: - kyria_right - lily58_left - lily58_right + - splitreus62_left + - splitreus62_right include: - board: proton_c shield: clueboard_california From 0a23d98962e5aa43d8c90670841cccf368660b58 Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 15 Aug 2020 17:09:44 -0400 Subject: [PATCH 04/38] Update build.yml Fails without splitreus62 shield and without itself added? --- .github/workflows/build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3fa91e56..5eb79716 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: name: Build Test strategy: matrix: - board: [proton_c, nice_nano, bluemicro52840_v1] + board: [proton_c, nice_nano] shield: - corne_left - corne_right @@ -16,8 +16,6 @@ jobs: - kyria_right - lily58_left - lily58_right - - splitreus62_left - - splitreus62_right include: - board: proton_c shield: clueboard_california From 23b188330f53c3907802efb091614002ee4237b7 Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 15 Aug 2020 19:30:35 -0400 Subject: [PATCH 05/38] Update setup.sh Updated setup.sh --- docs/static/setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/static/setup.sh b/docs/static/setup.sh index 27dcb0b3..71692ef1 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -11,7 +11,7 @@ title="ZMK Config Setup:" # TODO: Check for user.name and user.email git configs being set prompt="Pick an MCU board:" -options=("nice!nano" "QMK Proton-C") +options=("nice!nano" "QMK Proton-C" "bluemicro52840_v1") echo "$title" echo "" @@ -37,7 +37,7 @@ echo "" echo "Keyboard Shield Selection:" prompt="Pick an keyboard:" -options=("Kyria" "Lily58" "Corne") +options=("Kyria" "Lily58" "Corne" "splitreus62") PS3="$prompt " # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. From ba1cde94a80e7ecaf8e2a8373b08eb65ef820285 Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 16 Aug 2020 08:43:09 -0400 Subject: [PATCH 06/38] Update docs/static/setup.sh Co-authored-by: Pete Johanson --- docs/static/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/static/setup.sh b/docs/static/setup.sh index 71692ef1..07178890 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -11,7 +11,7 @@ title="ZMK Config Setup:" # TODO: Check for user.name and user.email git configs being set prompt="Pick an MCU board:" -options=("nice!nano" "QMK Proton-C" "bluemicro52840_v1") +options=("nice!nano" "QMK Proton-C" "BlueMicro52840 (v1)") echo "$title" echo "" From 68da92f4ddb9fab9bc5cc92c96b50578f7b66266 Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 16 Aug 2020 08:45:03 -0400 Subject: [PATCH 07/38] Update setup.sh --- docs/static/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/static/setup.sh b/docs/static/setup.sh index 71692ef1..ca223a8f 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -37,7 +37,7 @@ echo "" echo "Keyboard Shield Selection:" prompt="Pick an keyboard:" -options=("Kyria" "Lily58" "Corne" "splitreus62") +options=("Kyria" "Lily58" "Corne") PS3="$prompt " # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. From 75f4adb101850ae5a2d619cbeff1c5b19af7b846 Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 16 Aug 2020 08:46:16 -0400 Subject: [PATCH 08/38] Update arduino_pro_micro_pins.dtsi --- app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi b/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi index eb0afe88..940d8913 100644 --- a/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi +++ b/app/boards/arm/bluemicro52840_v1/arduino_pro_micro_pins.dtsi @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Pete Johanson + * Copyright (c) 2020 Derek Schmell * * SPDX-License-Identifier: MIT */ From 6ef2102af989afd87a28615292f9f39f40e41aa0 Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 16 Aug 2020 08:48:34 -0400 Subject: [PATCH 09/38] Update board.cmake --- app/boards/arm/bluemicro52840_v1/board.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/boards/arm/bluemicro52840_v1/board.cmake b/app/boards/arm/bluemicro52840_v1/board.cmake index 12a1d93b..c0eed657 100644 --- a/app/boards/arm/bluemicro52840_v1/board.cmake +++ b/app/boards/arm/bluemicro52840_v1/board.cmake @@ -1,5 +1,5 @@ -# SPDX-License-Identifier: Apache-2.0 - + #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) From 17c43881b8441e3e5c2fe9b5d25cb5ee9536a26a Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 16 Aug 2020 13:43:59 -0400 Subject: [PATCH 10/38] Updated select block --- docs/static/setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/static/setup.sh b/docs/static/setup.sh index c4a4f612..72eee0b4 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -23,6 +23,7 @@ select opt in "${options[@]}" "Quit"; do 1 ) board="nice_nano"; break;; 2 ) board="proton_c"; break;; + 3 ) board="BlueMicro52840 (v1)"; break;; $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit;; *) echo "Invalid option. Try another one.";continue;; From 25c8a269982ae7414ef0e407900c0f793971e625 Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Sun, 16 Aug 2020 12:49:08 -0700 Subject: [PATCH 11/38] wait before sending HID report --- app/src/usb_hid.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 4c6dd4b2..07c3d5f7 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -1,4 +1,5 @@ +#include #include #include @@ -15,6 +16,18 @@ static enum usb_dc_status_code usb_status; static struct device *hid_dev; +static K_SEM_DEFINE(hid_sem, 1, 1); + +static void in_ready_cb(void) +{ + k_sem_give(&hid_sem); +} + +static const struct hid_ops ops = +{ + .int_in_ready = in_ready_cb, +}; + int zmk_usb_hid_send_report(const u8_t *report, size_t len) { if (usb_status == USB_DC_SUSPEND) @@ -22,6 +35,7 @@ int zmk_usb_hid_send_report(const u8_t *report, size_t len) return usb_wakeup_request(); } + k_sem_take(&hid_sem, K_FOREVER); return hid_int_ep_write(hid_dev, report, len, NULL); } @@ -43,7 +57,7 @@ static int zmk_usb_hid_init(struct device *_arg) usb_hid_register_device(hid_dev, zmk_hid_report_desc, sizeof(zmk_hid_report_desc), - NULL); + &ops); usb_hid_init(hid_dev); From 5b4e5a30c41ea6edfa592735fcf607c44b0b3243 Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Sun, 16 Aug 2020 12:51:06 -0700 Subject: [PATCH 12/38] remove unnecessary include --- app/src/usb_hid.c | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 07c3d5f7..40511b08 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -1,5 +1,4 @@ -#include #include #include From 087574f607b4a500738b8155281cf24388ba4400 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Aug 2020 15:36:43 -0500 Subject: [PATCH 13/38] Create proper fix for split default conn bug --- app/Kconfig | 3 +++ app/src/ble.c | 19 ------------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index be5a1e4a..b26be487 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -124,6 +124,9 @@ config ZMK_USB config BT_MAX_CONN default 5 +config BT_GAP_AUTO_UPDATE_CONN_PARAMS + default n + endif endchoice diff --git a/app/src/ble.c b/app/src/ble.c index 488491c2..6d2903fa 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -76,29 +76,10 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, } } -#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) -static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { - static struct bt_conn_info info; - - bt_conn_get_info(conn, &info); - - /* This captures a param change from central half of a split board connection - to stop default params from getting set over the top of our preferred ones */ - if (info.role == BT_CONN_ROLE_MASTER && (param->interval_min != 6 || param->latency != 30)) { - return false; - } - - return true; -} -#endif - static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, .security_changed = security_changed, -#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) - .le_param_req = le_param_req, -#endif }; static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) From 47b219cca55e053509f373cc4f4812d55afb1451 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 16 Aug 2020 21:27:37 -0400 Subject: [PATCH 14/38] Remove duplicate uart0 node. --- app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts index 257a0069..c56ca189 100644 --- a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts +++ b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts @@ -39,13 +39,6 @@ status = "okay"; }; -&uart0 { - compatible = "nordic,nrf-uart"; - current-speed = <115200>; - tx-pin = <6>; - rx-pin = <8>; -}; - &i2c0 { compatible = "nordic,nrf-twi"; sda-pin = <15>; From abe40f8ef52265f9d807775a82f40ca783622018 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 16 Aug 2020 21:30:45 -0400 Subject: [PATCH 15/38] Various fixes. --- app/boards/arm/bluemicro52840_v1/Kconfig.defconfig | 2 +- app/boards/arm/bluemicro52840_v1/board.cmake | 4 ++-- docs/static/setup.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig b/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig index e33a6556..90a5ed9a 100644 --- a/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig +++ b/app/boards/arm/bluemicro52840_v1/Kconfig.defconfig @@ -1,4 +1,4 @@ -# Electronut Labs Papyr board configuration +# BlueMicro52840 board configuration # Copyright (c) 2020 Pete Johanson, Derek Schmell # SPDX-License-Identifier: MIT diff --git a/app/boards/arm/bluemicro52840_v1/board.cmake b/app/boards/arm/bluemicro52840_v1/board.cmake index c0eed657..fa847d50 100644 --- a/app/boards/arm/bluemicro52840_v1/board.cmake +++ b/app/boards/arm/bluemicro52840_v1/board.cmake @@ -1,5 +1,5 @@ - #SPDX-License-Identifier: MIT - +# 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/docs/static/setup.sh b/docs/static/setup.sh index 72eee0b4..55c96ff9 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -23,7 +23,7 @@ select opt in "${options[@]}" "Quit"; do 1 ) board="nice_nano"; break;; 2 ) board="proton_c"; break;; - 3 ) board="BlueMicro52840 (v1)"; break;; + 3 ) board="bluemicro52840_v1"; break;; $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit;; *) echo "Invalid option. Try another one.";continue;; From 8b4d2b6093dcdf22348e8f5b76f1d389328fad1e Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 16 Aug 2020 21:33:01 -0400 Subject: [PATCH 16/38] Add DCDC mode config. --- app/boards/arm/bluemicro52840_v1/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/boards/arm/bluemicro52840_v1/Kconfig diff --git a/app/boards/arm/bluemicro52840_v1/Kconfig b/app/boards/arm/bluemicro52840_v1/Kconfig new file mode 100644 index 00000000..67751a0f --- /dev/null +++ b/app/boards/arm/bluemicro52840_v1/Kconfig @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT + +config BOARD_ENABLE_DCDC + bool "Enable DCDC mode" + select SOC_DCDC_NRF52X + default y + depends on BOARD_BLUEMICRO52840_V1 + From 15405f351ac8446bbadd2d46e65f6c90dd7c4c6d Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 16 Aug 2020 21:34:48 -0400 Subject: [PATCH 17/38] Add BlueMicro52840 to build matrix. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5eb79716..a87ce5f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: name: Build Test strategy: matrix: - board: [proton_c, nice_nano] + board: [proton_c, nice_nano, bluemicro52840_v1] shield: - corne_left - corne_right From 1607656c531f315f7d9209f576a2e0784b8e0d75 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 16 Aug 2020 23:16:50 -0400 Subject: [PATCH 18/38] Note the fixed showstoppers. --- docs/blog/2020-08-12-zmk-sotf-1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/blog/2020-08-12-zmk-sotf-1.md b/docs/blog/2020-08-12-zmk-sotf-1.md index 2b695350..8a3ca7c6 100644 --- a/docs/blog/2020-08-12-zmk-sotf-1.md +++ b/docs/blog/2020-08-12-zmk-sotf-1.md @@ -28,10 +28,10 @@ There's been lots of various activity in ZMK land! Despite the flurry of activity, there are still some serious bugs and show stoppers that potential ZMK users should be aware of: - [Bluetooth Related](https://github.com/zmkfirmware/zmk/issues/58) - There are several key bugs and fixes needed, including one complete show stopper: - - Fully working split wireless is not working. In particular, both split halves can properly pair, but once they do so, pairing with the _central_ host will not work. Workaround: You can currently have both halves pair, and use USB on the central side (Left side right now for Kyria, Corne, Lily58) and receive HID events over USB. + - Fully working split wireless is not working. In particular, both split halves can properly pair, but once they do so, pairing with the _central_ host will not work. Workaround: You can currently have both halves pair, and use USB on the central side (Left side right now for Kyria, Corne, Lily58) and receive HID events over USB. - Fixed in 8b61beb. - BT bond information is not currently stored to the devices, so after powering off or restarting your device, users need to re-pair - USB - There is one important USB related bug which is a showstopper: - - The Zephyr USB stack does not have a built in queue for endpoint data being written. As a result, HID events sent by ZMK are sometimes [dropped, or lost](https://github.com/zmkfirmware/zmk/issues/84). + - The Zephyr USB stack does not have a built in queue for endpoint data being written. As a result, HID events sent by ZMK are sometimes dropped, or lost. - Fixed by careyk007 in #93. ## Next Steps From 064323b667e33b3f68e56165e9add66b7482ed68 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 17 Aug 2020 22:34:06 -0400 Subject: [PATCH 19/38] fix(build): Remove more unused west modules. --- .github/workflows/build.yml | 8 ++++---- app/west.yml | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a87ce5f1..98ca44d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,11 +34,11 @@ jobs: tools/ zephyr/ bootloader/ - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('app/west.yml') }} + key: 2-${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('app/west.yml') }} restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- + 2-${{ runner.os }}-build-${{ env.cache-name }}- + 2-${{ runner.os }}-build- + 2-${{ runner.os }}- - name: West Init uses: "docker://zmkfirmware/zephyr-west-action-arm:latest" id: west-init diff --git a/app/west.yml b/app/west.yml index 3784d97b..cba53ab0 100644 --- a/app/west.yml +++ b/app/west.yml @@ -21,6 +21,18 @@ manifest: - hal_microchip - hal_nxp - hal_openisa + - hal_silabs + - hal_xtensa + - hal_st + - hal_ti + - loramac-node + - mcuboot + - mcumgr + - net-tools + - segger + - openthread + - edtt + - trusted-firmware-m - name: uf2 remote: microsoft path: tools/uf2 From e5ba03f0881658514c24b1227c514ed57c0c7937 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 17 Aug 2020 23:23:30 -0400 Subject: [PATCH 20/38] Revert "Merge pull request #93 from careyk007/main" This reverts commit 8cd8933c87aadd2ce7b31c1367bfaad81fc2a36b, reversing changes made to 3f1dfbaad1a867f59c13814a517e03dfce4d4223. --- app/src/usb_hid.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 40511b08..4c6dd4b2 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -15,18 +15,6 @@ static enum usb_dc_status_code usb_status; static struct device *hid_dev; -static K_SEM_DEFINE(hid_sem, 1, 1); - -static void in_ready_cb(void) -{ - k_sem_give(&hid_sem); -} - -static const struct hid_ops ops = -{ - .int_in_ready = in_ready_cb, -}; - int zmk_usb_hid_send_report(const u8_t *report, size_t len) { if (usb_status == USB_DC_SUSPEND) @@ -34,7 +22,6 @@ int zmk_usb_hid_send_report(const u8_t *report, size_t len) return usb_wakeup_request(); } - k_sem_take(&hid_sem, K_FOREVER); return hid_int_ep_write(hid_dev, report, len, NULL); } @@ -56,7 +43,7 @@ static int zmk_usb_hid_init(struct device *_arg) usb_hid_register_device(hid_dev, zmk_hid_report_desc, sizeof(zmk_hid_report_desc), - &ops); + NULL); usb_hid_init(hid_dev); From d7dee20e8d9b0b566859304063df2176aef8c057 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 09:56:25 -0400 Subject: [PATCH 21/38] Add missing license header. --- app/src/ble.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/ble.c b/app/src/ble.c index 6d2903fa..71bbccdd 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ #include #include From 4402e4fbc7bc79206589d3006fde802c4ba70ec7 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 11:20:15 -0400 Subject: [PATCH 22/38] feeature(bt): Add "unpair combo" on startup. * Especially for splits, we need the ability to unpair all paired devices as sledgehammer if we need to "reset things", and doing so via keymaps isn't suitable. * Allows shields to define a collection of key positions that if all held 2 seconds after startup, will unpair all existing pairs for the device. --- app/CMakeLists.txt | 1 + app/Kconfig | 10 ++- app/boards/shields/corne/corne.dtsi | 4 + app/boards/shields/corne/corne_left.conf | 3 +- app/boards/shields/corne/corne_left.overlay | 4 + app/boards/shields/corne/corne_right.conf | 3 +- app/boards/shields/corne/corne_right.overlay | 3 + app/boards/shields/kyria/kyria.dtsi | 4 + app/boards/shields/kyria/kyria_left.conf | 3 +- app/boards/shields/kyria/kyria_left.overlay | 4 + app/boards/shields/kyria/kyria_right.conf | 3 +- app/boards/shields/kyria/kyria_right.overlay | 4 + app/boards/shields/lily58/lily58.dtsi | 4 + app/boards/shields/lily58/lily58_left.conf | 3 +- app/boards/shields/lily58/lily58_left.overlay | 3 + app/boards/shields/lily58/lily58_right.conf | 1 + .../shields/lily58/lily58_right.overlay | 3 + app/drivers/zephyr/kscan_gpio_matrix.c | 10 ++- app/dts/bindings/zmk,bt-unpair-combo.yaml | 12 +++ app/include/zmk/ble.h | 2 +- app/src/ble.c | 6 ++ app/src/ble_unpair_combo.c | 80 +++++++++++++++++++ 22 files changed, 160 insertions(+), 10 deletions(-) create mode 100644 app/dts/bindings/zmk,bt-unpair-combo.yaml create mode 100644 app/src/ble_unpair_combo.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index d0d343b7..1f6de5de 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -42,6 +42,7 @@ target_sources(app PRIVATE src/behaviors/behavior_transparent.c) target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/ble.c) +target_sources_ifdef(CONFIG_ZMK_BLE_UNPAIR_COMBO app PRIVATE src/ble_unpair_combo.c) target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL app PRIVATE src/split_listener.c) target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL app PRIVATE src/split/bluetooth/service.c) target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL app PRIVATE src/split/bluetooth/central.c) diff --git a/app/Kconfig b/app/Kconfig index b26be487..416c9852 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -40,11 +40,17 @@ menuconfig ZMK_BLE select BT_PERIPHERAL select BT_GATT_DIS select BT_GATT_BAS - # select SETTINGS - # select BT_SETTINGS + select SETTINGS + select BT_SETTINGS if ZMK_BLE +config ZMK_BLE_UNPAIR_COMBO + bool "Enable BT unpair combo" + help + Adds a magic key combo that can be held on startup to remove all paired devices + default n + config ZMK_BLE_INIT_PRIORITY int "Init Priority" default 50 diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi index 70d6495b..3df055cd 100644 --- a/app/boards/shields/corne/corne.dtsi +++ b/app/boards/shields/corne/corne.dtsi @@ -58,6 +58,10 @@ 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 }; + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; + }; + // TODO: per-key RGB node(s)? }; diff --git a/app/boards/shields/corne/corne_left.conf b/app/boards/shields/corne/corne_left.conf index e51dee44..338fa59c 100644 --- a/app/boards/shields/corne/corne_left.conf +++ b/app/boards/shields/corne/corne_left.conf @@ -1,2 +1,3 @@ CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y \ No newline at end of file +CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y +CONFIG_ZMK_BLE_UNPAIR_COMBO=y \ No newline at end of file diff --git a/app/boards/shields/corne/corne_left.overlay b/app/boards/shields/corne/corne_left.overlay index 399bddd1..f12c417d 100644 --- a/app/boards/shields/corne/corne_left.overlay +++ b/app/boards/shields/corne/corne_left.overlay @@ -16,3 +16,7 @@ , <&pro_micro_d 14 GPIO_ACTIVE_HIGH> ; }; + +&bt_unpair_combo { + key-positions = <0 38>; +}; diff --git a/app/boards/shields/corne/corne_right.conf b/app/boards/shields/corne/corne_right.conf index a835adc1..be344c41 100644 --- a/app/boards/shields/corne/corne_right.conf +++ b/app/boards/shields/corne/corne_right.conf @@ -1,2 +1,3 @@ CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y \ No newline at end of file +CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y +CONFIG_ZMK_BLE_UNPAIR_COMBO=y \ No newline at end of file diff --git a/app/boards/shields/corne/corne_right.overlay b/app/boards/shields/corne/corne_right.overlay index 652d5edd..9d97d853 100644 --- a/app/boards/shields/corne/corne_right.overlay +++ b/app/boards/shields/corne/corne_right.overlay @@ -21,3 +21,6 @@ ; }; +&bt_unpair_combo { + key-positions = <11 39>; +}; diff --git a/app/boards/shields/kyria/kyria.dtsi b/app/boards/shields/kyria/kyria.dtsi index bbead846..a13f7f08 100644 --- a/app/boards/shields/kyria/kyria.dtsi +++ b/app/boards/shields/kyria/kyria.dtsi @@ -81,6 +81,10 @@ 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(2,9) sensors = <&left_encoder &right_encoder>; }; + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; + }; + // TODO: RGB node(s) }; diff --git a/app/boards/shields/kyria/kyria_left.conf b/app/boards/shields/kyria/kyria_left.conf index e51dee44..338fa59c 100644 --- a/app/boards/shields/kyria/kyria_left.conf +++ b/app/boards/shields/kyria/kyria_left.conf @@ -1,2 +1,3 @@ CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y \ No newline at end of file +CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y +CONFIG_ZMK_BLE_UNPAIR_COMBO=y \ No newline at end of file diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index c8b5be27..441c1a69 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -22,3 +22,7 @@ &left_encoder { status = "okay"; }; + +&bt_unpair_combo { + key-positions = <0 44>; +}; \ No newline at end of file diff --git a/app/boards/shields/kyria/kyria_right.conf b/app/boards/shields/kyria/kyria_right.conf index a835adc1..be344c41 100644 --- a/app/boards/shields/kyria/kyria_right.conf +++ b/app/boards/shields/kyria/kyria_right.conf @@ -1,2 +1,3 @@ CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y \ No newline at end of file +CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y +CONFIG_ZMK_BLE_UNPAIR_COMBO=y \ No newline at end of file diff --git a/app/boards/shields/kyria/kyria_right.overlay b/app/boards/shields/kyria/kyria_right.overlay index 8163c95e..8ee0fcbc 100644 --- a/app/boards/shields/kyria/kyria_right.overlay +++ b/app/boards/shields/kyria/kyria_right.overlay @@ -27,3 +27,7 @@ &right_encoder { status = "okay"; }; + +&bt_unpair_combo { + key-positions = <11 45>; +}; \ No newline at end of file diff --git a/app/boards/shields/lily58/lily58.dtsi b/app/boards/shields/lily58/lily58.dtsi index 8655d8c0..cbda5237 100644 --- a/app/boards/shields/lily58/lily58.dtsi +++ b/app/boards/shields/lily58/lily58.dtsi @@ -44,6 +44,10 @@ 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) ; }; + + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; + }; }; &pro_micro_i2c { diff --git a/app/boards/shields/lily58/lily58_left.conf b/app/boards/shields/lily58/lily58_left.conf index e51dee44..338fa59c 100644 --- a/app/boards/shields/lily58/lily58_left.conf +++ b/app/boards/shields/lily58/lily58_left.conf @@ -1,2 +1,3 @@ CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y \ No newline at end of file +CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y +CONFIG_ZMK_BLE_UNPAIR_COMBO=y \ No newline at end of file diff --git a/app/boards/shields/lily58/lily58_left.overlay b/app/boards/shields/lily58/lily58_left.overlay index c8e22130..c6f630f8 100644 --- a/app/boards/shields/lily58/lily58_left.overlay +++ b/app/boards/shields/lily58/lily58_left.overlay @@ -17,3 +17,6 @@ ; }; +&bt_unpair_combo { + key-positions = <0 42>; +}; diff --git a/app/boards/shields/lily58/lily58_right.conf b/app/boards/shields/lily58/lily58_right.conf index 990cf7c0..cf16779e 100644 --- a/app/boards/shields/lily58/lily58_right.conf +++ b/app/boards/shields/lily58/lily58_right.conf @@ -1,2 +1,3 @@ CONFIG_ZMK_SPLIT=y CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y +CONFIG_ZMK_BLE_UNPAIR_COMBO=y diff --git a/app/boards/shields/lily58/lily58_right.overlay b/app/boards/shields/lily58/lily58_right.overlay index 748be145..84f0b06b 100644 --- a/app/boards/shields/lily58/lily58_right.overlay +++ b/app/boards/shields/lily58/lily58_right.overlay @@ -21,3 +21,6 @@ ; }; +&bt_unpair_combo { + key-positions = <11 43>; +}; diff --git a/app/drivers/zephyr/kscan_gpio_matrix.c b/app/drivers/zephyr/kscan_gpio_matrix.c index baaca309..b19c4922 100644 --- a/app/drivers/zephyr/kscan_gpio_matrix.c +++ b/app/drivers/zephyr/kscan_gpio_matrix.c @@ -205,7 +205,13 @@ static int kscan_gpio_config_interrupts(struct device **devices, } \ data->callback = callback; \ return 0; \ - } \ + }; \ + static int kscan_gpio_enable_##n(struct device *dev) \ + { \ + int err = kscan_gpio_enable_interrupts_##n(dev); \ + if (err) { return err; } \ + return kscan_gpio_read_##n(dev); \ + }; \ static int kscan_gpio_init_##n(struct device *dev) \ { \ struct kscan_gpio_data_##n *data = dev->driver_data; \ @@ -258,7 +264,7 @@ static int kscan_gpio_config_interrupts(struct device **devices, } \ static const struct kscan_driver_api gpio_driver_api_##n = { \ .config = kscan_gpio_configure_##n, \ - .enable_callback = kscan_gpio_enable_interrupts_##n, \ + .enable_callback = kscan_gpio_enable_##n, \ .disable_callback = kscan_gpio_disable_interrupts_##n, \ }; \ static const struct kscan_gpio_config_##n kscan_gpio_config_##n = { \ diff --git a/app/dts/bindings/zmk,bt-unpair-combo.yaml b/app/dts/bindings/zmk,bt-unpair-combo.yaml new file mode 100644 index 00000000..d781347a --- /dev/null +++ b/app/dts/bindings/zmk,bt-unpair-combo.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2020, Pete Johanson +# SPDX-License-Identifier: MIT + +description: | + Defines a set of key positions that will unpair all BT devices if held on startup. + +compatible: "zmk,bt-unpair-combo" + +properties: + key-positions: + type: array + required: true diff --git a/app/include/zmk/ble.h b/app/include/zmk/ble.h index a77237d8..e760ed70 100644 --- a/app/include/zmk/ble.h +++ b/app/include/zmk/ble.h @@ -3,5 +3,5 @@ #include -int zmk_ble_init(); +int zmk_ble_unpair_all(); bool zmk_ble_handle_key_user(struct zmk_key_event *key_event); diff --git a/app/src/ble.c b/app/src/ble.c index 71bbccdd..686a5362 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -190,6 +190,12 @@ static int zmk_ble_init(struct device *_arg) return 0; } +int zmk_ble_unpair_all() +{ + LOG_DBG(""); + return bt_unpair(BT_ID_DEFAULT, NULL); +}; + bool zmk_ble_handle_key_user(struct zmk_key_event *key_event) { zmk_key key = key_event->key; diff --git a/app/src/ble_unpair_combo.c b/app/src/ble_unpair_combo.c new file mode 100644 index 00000000..a33a8e22 --- /dev/null +++ b/app/src/ble_unpair_combo.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include + +#define DT_DRV_COMPAT zmk_bt_unpair_combo + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include +#include +#include + + +static u8_t combo_state; + +const u32_t key_positions[] = DT_INST_PROP(0, key_positions); +#define KP_LEN DT_INST_PROP_LEN(0, key_positions) + +int index_for_key_position(u32_t kp) +{ + for (int i = 0; i < KP_LEN; i++) { + if (key_positions[i] == kp) { + return i; + } + } + + return -1; +} + +int unpair_combo_listener(const struct zmk_event_header *eh) +{ + if (is_position_state_changed(eh)) { + const struct position_state_changed *psc = cast_position_state_changed(eh); + + int kp_index = index_for_key_position(psc->position); + if (kp_index < 0) { + return 0; + } + + WRITE_BIT(combo_state, kp_index, psc->state); + } + + return 0; +}; + +void unpair_combo_work_handler(struct k_work *work) +{ + for (int i = 0; i < KP_LEN; i++) { + if (!(combo_state & BIT(i))) { + LOG_DBG("Key position %d not held, skipping unpair combo", key_positions[i]); + return; + } + } + + zmk_ble_unpair_all(); +}; + +struct k_delayed_work unpair_combo_work; + +int zmk_ble_unpair_combo_init(struct device *_unused) +{ + k_delayed_work_init(&unpair_combo_work, unpair_combo_work_handler); + k_delayed_work_submit(&unpair_combo_work, K_SECONDS(2)); + + return 0; +}; + +ZMK_LISTENER(zmk_ble_unpair_combo, unpair_combo_listener); +ZMK_SUBSCRIPTION(zmk_ble_unpair_combo, position_state_changed); + +SYS_INIT(zmk_ble_unpair_combo_init, + APPLICATION, + CONFIG_APPLICATION_INIT_PRIORITY); From a82f990d4c518165fc745ce2b5fb5cf2dd6b2727 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Tue, 18 Aug 2020 14:02:24 -0400 Subject: [PATCH 23/38] feat(keymap): allow users to toggle layers --- app/CMakeLists.txt | 1 + app/dts/behaviors.dtsi | 1 + app/dts/behaviors/toggle_layer.dtsi | 9 ++++ .../behaviors/zmk,behavior-toggle-layer.yaml | 8 +++ app/include/zmk/keymap.h | 1 + app/src/behaviors/behavior_toggle_layer.c | 54 +++++++++++++++++++ app/src/keymap.c | 5 ++ 7 files changed, 79 insertions(+) create mode 100644 app/dts/behaviors/toggle_layer.dtsi create mode 100644 app/dts/bindings/behaviors/zmk,behavior-toggle-layer.yaml create mode 100644 app/src/behaviors/behavior_toggle_layer.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index d0d343b7..e0b9aeac 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -38,6 +38,7 @@ target_sources(app PRIVATE src/behaviors/behavior_key_press.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources(app PRIVATE src/behaviors/behavior_mod_tap.c) target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c) +target_sources(app PRIVATE src/behaviors/behavior_toggle_layer.c) target_sources(app PRIVATE src/behaviors/behavior_transparent.c) target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c) diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 04e42b63..a47a8b85 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include \ No newline at end of file diff --git a/app/dts/behaviors/toggle_layer.dtsi b/app/dts/behaviors/toggle_layer.dtsi new file mode 100644 index 00000000..df6fd231 --- /dev/null +++ b/app/dts/behaviors/toggle_layer.dtsi @@ -0,0 +1,9 @@ +/ { + behaviors { + tog: behavior_toggle_layer { + compatible = "zmk,behavior-toggle-layer"; + label = "TOGGLE_LAYER"; + #binding-cells = <1>; + }; + }; +}; diff --git a/app/dts/bindings/behaviors/zmk,behavior-toggle-layer.yaml b/app/dts/bindings/behaviors/zmk,behavior-toggle-layer.yaml new file mode 100644 index 00000000..065949fe --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-toggle-layer.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2020, Cody McGinnis +# SPDX-License-Identifier: MIT + +description: Toggle Layer + +compatible: "zmk,behavior-toggle-layer" + +include: one_param.yaml diff --git a/app/include/zmk/keymap.h b/app/include/zmk/keymap.h index 4a6bb37d..c55207f5 100644 --- a/app/include/zmk/keymap.h +++ b/app/include/zmk/keymap.h @@ -1,5 +1,6 @@ #pragma once +bool zmk_keymap_layer_active(u8_t layer); int zmk_keymap_layer_activate(u8_t layer); int zmk_keymap_layer_deactivate(u8_t layer); diff --git a/app/src/behaviors/behavior_toggle_layer.c b/app/src/behaviors/behavior_toggle_layer.c new file mode 100644 index 00000000..ff0fe6ab --- /dev/null +++ b/app/src/behaviors/behavior_toggle_layer.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 Cody McGinnis + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_toggle_layer + +#include +#include +#include + +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_tog_config { }; +struct behavior_tog_data { }; + +static int behavior_tog_init(struct device *dev) +{ + return 0; +}; + + +static int tog_keymap_binding_pressed(struct device *dev, u32_t position, u32_t layer, u32_t _) +{ + LOG_DBG("position %d layer %d current %d", position, layer, zmk_keymap_layer_active(layer)); + + if (zmk_keymap_layer_active(layer)) + return zmk_keymap_layer_deactivate(layer); + + return zmk_keymap_layer_activate(layer); +} + +static int tog_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _) +{ + return 0; +} + +static const struct behavior_driver_api behavior_tog_driver_api = { + .binding_pressed = tog_keymap_binding_pressed, + .binding_released = tog_keymap_binding_released, +}; + +static const struct behavior_tog_config behavior_tog_config = {}; + +static struct behavior_tog_data behavior_tog_data; + +DEVICE_AND_API_INIT(behavior_tog, DT_INST_LABEL(0), behavior_tog_init, + &behavior_tog_data, + &behavior_tog_config, + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &behavior_tog_driver_api); diff --git a/app/src/keymap.c b/app/src/keymap.c index ff494f76..ebb42eff 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -76,6 +76,11 @@ static struct zmk_behavior_binding zmk_sensor_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_ WRITE_BIT(zmk_keymap_layer_state, layer, state); \ return 0; +bool zmk_keymap_layer_active(u8_t layer) +{ + return (zmk_keymap_layer_state & (BIT(layer))) == (BIT(layer)); +}; + int zmk_keymap_layer_activate(u8_t layer) { SET_LAYER_STATE(layer, true); From ae104374c0af0c2cbf9d246f980ccce56e60c105 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Tue, 18 Aug 2020 14:02:24 -0400 Subject: [PATCH 24/38] feat(docs): document the toggle layer behavior --- docs/docs/behavior/layers.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/docs/behavior/layers.md b/docs/docs/behavior/layers.md index 2388cafe..09defadc 100644 --- a/docs/docs/behavior/layers.md +++ b/docs/docs/behavior/layers.md @@ -39,3 +39,18 @@ Example: ``` &mo LOWER ``` + +## Toggle Layer + +The "toggle layer" behavior allows you to enable a layer until the layer is manually disabled. + +### Behavior Binding + +- Reference: `&tog` +- Parameter: The layer number to enable/disable, e.g. `1` + +Example: + +``` +&tog LOWER +``` \ No newline at end of file From 7facb6eee8c5864c86b0a69213db4aabf6f24585 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Tue, 18 Aug 2020 14:02:25 -0400 Subject: [PATCH 25/38] fix(keymap): move the toggle layer logic to keymap.c --- app/dts/behaviors/toggle_layer.dtsi | 8 +++++++- app/include/zmk/keymap.h | 1 + app/src/behaviors/behavior_toggle_layer.c | 7 +------ app/src/keymap.c | 8 ++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/dts/behaviors/toggle_layer.dtsi b/app/dts/behaviors/toggle_layer.dtsi index df6fd231..86a050d9 100644 --- a/app/dts/behaviors/toggle_layer.dtsi +++ b/app/dts/behaviors/toggle_layer.dtsi @@ -1,4 +1,10 @@ -/ { +/* + * Copyright (c) 2020 Cody McGinnis + * + * SPDX-License-Identifier: MIT + */ + + / { behaviors { tog: behavior_toggle_layer { compatible = "zmk,behavior-toggle-layer"; diff --git a/app/include/zmk/keymap.h b/app/include/zmk/keymap.h index c55207f5..c1f63932 100644 --- a/app/include/zmk/keymap.h +++ b/app/include/zmk/keymap.h @@ -3,5 +3,6 @@ bool zmk_keymap_layer_active(u8_t layer); int zmk_keymap_layer_activate(u8_t layer); int zmk_keymap_layer_deactivate(u8_t layer); +int zmk_keymap_layer_toggle(u8_t layer); int zmk_keymap_position_state_changed(u32_t position, bool pressed); diff --git a/app/src/behaviors/behavior_toggle_layer.c b/app/src/behaviors/behavior_toggle_layer.c index ff0fe6ab..13f4a29d 100644 --- a/app/src/behaviors/behavior_toggle_layer.c +++ b/app/src/behaviors/behavior_toggle_layer.c @@ -25,12 +25,7 @@ static int behavior_tog_init(struct device *dev) static int tog_keymap_binding_pressed(struct device *dev, u32_t position, u32_t layer, u32_t _) { - LOG_DBG("position %d layer %d current %d", position, layer, zmk_keymap_layer_active(layer)); - - if (zmk_keymap_layer_active(layer)) - return zmk_keymap_layer_deactivate(layer); - - return zmk_keymap_layer_activate(layer); + return zmk_keymap_layer_toggle(layer); } static int tog_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _) diff --git a/app/src/keymap.c b/app/src/keymap.c index ebb42eff..754305d0 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -91,6 +91,14 @@ int zmk_keymap_layer_deactivate(u8_t layer) SET_LAYER_STATE(layer, false); }; +int zmk_keymap_layer_toggle(u8_t layer) +{ + if (zmk_keymap_layer_active(layer)) + return zmk_keymap_layer_deactivate(layer); + + return zmk_keymap_layer_activate(layer); +}; + bool is_active_position(u32_t position, u8_t layer) { return (zmk_keymap_layer_state & BIT(layer)) == BIT(layer) From bb4f45a57a5d8c62b911cefdada1f80d1ff70a71 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Tue, 18 Aug 2020 14:02:25 -0400 Subject: [PATCH 26/38] fix(docs): add another example to toggle layer --- docs/docs/behavior/layers.md | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/docs/behavior/layers.md b/docs/docs/behavior/layers.md index 09defadc..3e520cab 100644 --- a/docs/docs/behavior/layers.md +++ b/docs/docs/behavior/layers.md @@ -53,4 +53,40 @@ Example: ``` &tog LOWER -``` \ No newline at end of file +``` + +"Toggle layer" for a : +``` +#define DEFAULT 0 +#define NAVI 1 + +#define NONE 0 + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &tog NAVI &kp KDIV &kp KMLT &kp KMIN + &kp NUM_7 &kp NUM_8 &kp NUM_9 &kp KPLS + &kp NUM_4 &kp NUM_5 &kp NUM_6 &kp KPLS + &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp RET + &kp NUM_0 &kp NUM_0 &kp DOT &kp RET + >; + }; + + nav_layer { + bindings = < + &tog NAVI &kp KDIV &kp KMLT &kp KMIN + &kp HOME &kp UARW &kp PGUP &kp KPLS + &kp LARW &none &kp RARW &kp KPLS + &kp END &kp DARW &kp PGDN &kp RET + &kp INS &kp INS &kp DEL &kp RET + >; + }; + }; +}; +``` + +It is possible to use "toggle layer" to have keys that raise and lower the layers as well. \ No newline at end of file From 2ffe09b617419a25e45c387e001ea59d3cbb5652 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 14:11:48 -0400 Subject: [PATCH 27/38] fix(docs): Fix typo in key press behavior doc. --- docs/docs/behavior/key-press.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/behavior/key-press.md b/docs/docs/behavior/key-press.md index 08296bb9..1ae7e316 100644 --- a/docs/docs/behavior/key-press.md +++ b/docs/docs/behavior/key-press.md @@ -4,7 +4,7 @@ title: Key Presses ## Summary -The most basic of behaiors, is the ability to send certain keycode presses and releases in response to activating +The most basic of behaviors, is the ability to send certain keycode presses and releases in response to activating a certain key. For reference on keycode values, see the [USB HID Usage Tables](https://www.usb.org/document-library/hid-usage-tables-12). From 50643b2c561ef58d4c96e7dba6c55c0ef291146a Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Tue, 18 Aug 2020 14:21:39 -0400 Subject: [PATCH 28/38] fix(keymap): add brackets around if statement body --- app/src/keymap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/keymap.c b/app/src/keymap.c index 754305d0..ee6e370d 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -94,7 +94,9 @@ int zmk_keymap_layer_deactivate(u8_t layer) int zmk_keymap_layer_toggle(u8_t layer) { if (zmk_keymap_layer_active(layer)) - return zmk_keymap_layer_deactivate(layer); + { + return zmk_keymap_layer_deactivate(layer); + } return zmk_keymap_layer_activate(layer); }; From 63e02d60dcfbf4e4d7f9954075d1e087f816944b Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 14:14:28 -0400 Subject: [PATCH 29/38] feat(behaviors): Add &none behavior --- app/CMakeLists.txt | 1 + app/dts/behaviors.dtsi | 1 + app/dts/behaviors/none.dtsi | 15 ++++++ .../bindings/behaviors/zmk,behavior-none.yaml | 8 ++++ app/src/behaviors/behavior_none.c | 48 +++++++++++++++++++ docs/docs/behavior/misc.md | 41 ++++++++++++++++ docs/sidebars.js | 1 + 7 files changed, 115 insertions(+) create mode 100644 app/dts/behaviors/none.dtsi create mode 100644 app/dts/bindings/behaviors/zmk,behavior-none.yaml create mode 100644 app/src/behaviors/behavior_none.c create mode 100644 docs/docs/behavior/misc.md diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index d0d343b7..28a12046 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -39,6 +39,7 @@ target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources(app PRIVATE src/behaviors/behavior_mod_tap.c) target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c) target_sources(app PRIVATE src/behaviors/behavior_transparent.c) +target_sources(app PRIVATE src/behaviors/behavior_none.c) target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/ble.c) diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 04e42b63..5302c172 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/app/dts/behaviors/none.dtsi b/app/dts/behaviors/none.dtsi new file mode 100644 index 00000000..e84ed491 --- /dev/null +++ b/app/dts/behaviors/none.dtsi @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + +/ { + behaviors { + none: behavior_none { + compatible = "zmk,behavior-none"; + label = "NONE"; + #binding-cells = <0>; + }; + }; +}; diff --git a/app/dts/bindings/behaviors/zmk,behavior-none.yaml b/app/dts/bindings/behaviors/zmk,behavior-none.yaml new file mode 100644 index 00000000..9c66c947 --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-none.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2020, Pete Johanson +# SPDX-License-Identifier: MIT + +description: None Binding Behavior + +compatible: "zmk,behavior-none" + +include: zero_param.yaml diff --git a/app/src/behaviors/behavior_none.c b/app/src/behaviors/behavior_none.c new file mode 100644 index 00000000..7e77e540 --- /dev/null +++ b/app/src/behaviors/behavior_none.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_none + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_none_config { }; +struct behavior_none_data { }; + +static int behavior_none_init(struct device *dev) +{ + return 0; +}; + +static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t _param1, u32_t _param2) +{ + return 1; +} + +static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t _param1, u32_t _param2) +{ + return 1; +} + +static const struct behavior_driver_api behavior_none_driver_api = { + .binding_pressed = on_keymap_binding_pressed, + .binding_released = on_keymap_binding_released, +}; + + +static const struct behavior_none_config behavior_none_config = {}; + +static struct behavior_none_data behavior_none_data; + +DEVICE_AND_API_INIT(behavior_none, DT_INST_LABEL(0), behavior_none_init, + &behavior_none_data, + &behavior_none_config, + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &behavior_none_driver_api); \ No newline at end of file diff --git a/docs/docs/behavior/misc.md b/docs/docs/behavior/misc.md new file mode 100644 index 00000000..799c91c8 --- /dev/null +++ b/docs/docs/behavior/misc.md @@ -0,0 +1,41 @@ +--- +title: Miscellaneous +--- + +## Summary + +There are a few miscellaneous behaviors that are helpful when working with layers in keymaps, +in particular, with handling what happens in higher layers, and if events are passed to +the next layer or not + +## Transparent + +The transparent behavior simply ignores key position presses/releases, so they will be +passed down to the next active layer in the stack. + +### Behavior Binding + +- Reference: `&trans` +- Parameters: None + +Example: + +``` +&trans +``` + +## None + +The none behavior simply swallows and stops key position presses/releases, so they will **not** +be passed down to the next active layer in the stack. + +### Behavior Binding + +- Reference: `&none` +- Parameters: None + +Example: + +``` +&none +``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 1bd0358f..90bdfa28 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -10,6 +10,7 @@ module.exports = { Behaviors: [ "behavior/key-press", "behavior/layers", + "behavior/misc", "behavior/lighting", ], Development: [ From d2d9fc86cf0ed0ab4bb896ee247fb212512d5aaf Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 15:24:38 -0400 Subject: [PATCH 30/38] feat(docs): Basic mod-tap behavior docs. --- docs/docs/behavior/mod-tap.md | 29 +++++++++++++++++++++++++++++ docs/sidebars.js | 1 + 2 files changed, 30 insertions(+) create mode 100644 docs/docs/behavior/mod-tap.md diff --git a/docs/docs/behavior/mod-tap.md b/docs/docs/behavior/mod-tap.md new file mode 100644 index 00000000..cae667e3 --- /dev/null +++ b/docs/docs/behavior/mod-tap.md @@ -0,0 +1,29 @@ +--- +title: Mod-Tap +--- + +## Summary + +The Mod-Tap behavior allows varying the effect of pressing and releasing a key position depending +on whether it is used with other simultaneous key presses at the same time. + +If pressed and released independently, the Mod-Tap behavior will send the press and release events +for the configure keycode. If pressed and held while another key is pressed and released, then +the configured modifiers will be applied to that _other_ key press, and no press will be generated +on the release of the Mod-Tap key. + +## Mod-Tap + +The Mod-Tap behavior either acts as a held modifier, or as a tapped keycode. + +### Behavior Binding + +- Reference: `&mt` +- Parameter #1: The modifiers to be used when activating as a modifier, e.g. `MOD_LSFT` +- Parameter #2: The keycode to sent when used as a tap, e.g. `A`, `B`. + +Example: + +``` +&mt MOD_LSFT A +``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 90bdfa28..be02a657 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -11,6 +11,7 @@ module.exports = { "behavior/key-press", "behavior/layers", "behavior/misc", + "behavior/mod-tap", "behavior/lighting", ], Development: [ From 05235ca96d021c1ec0fce60570d9786ee41aa437 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 16:18:16 -0400 Subject: [PATCH 31/38] fix(bluetooth): Stop peripheral half advertising once connected. --- app/src/ble.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/ble.c b/app/src/ble.c index 71bbccdd..bf1dee74 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -28,6 +28,16 @@ static struct bt_conn *auth_passkey_entry_conn; static u8_t passkey_entries[6] = {0, 0, 0, 0, 0, 0}; static u8_t passkey_digit = 0; +#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) +#define ZMK_ADV_PARAMS BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \ + BT_LE_ADV_OPT_USE_NAME | \ + BT_LE_ADV_OPT_ONE_TIME, \ + BT_GAP_ADV_FAST_INT_MIN_2, \ + BT_GAP_ADV_FAST_INT_MAX_2, NULL) +#else +#define ZMK_ADV_PARAMS BT_LE_ADV_CONN_NAME +#endif + static void connected(struct bt_conn *conn, u8_t err) { char addr[BT_ADDR_LE_STR_LEN]; @@ -159,7 +169,7 @@ static void zmk_ble_ready(int err) return; } - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); + err = bt_le_adv_start(ZMK_ADV_PARAMS, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); if (err) { LOG_ERR("Advertising failed to start (err %d)", err); From 59f85c93cdd1a1a2a420378989323c378907564c Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 16:33:24 -0400 Subject: [PATCH 32/38] fix(boards): Remove dup `uart0` overrides for nano --- app/boards/arm/nice_nano/nice_nano.dts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts index 7c676e3e..c1b9cc07 100644 --- a/app/boards/arm/nice_nano/nice_nano.dts +++ b/app/boards/arm/nice_nano/nice_nano.dts @@ -39,13 +39,6 @@ status = "okay"; }; -&uart0 { - compatible = "nordic,nrf-uart"; - current-speed = <115200>; - tx-pin = <6>; - rx-pin = <8>; -}; - &i2c0 { compatible = "nordic,nrf-twi"; sda-pin = <17>; From 66c4b7ebb0ec914089a8f08905d832b16493dd73 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 17 Aug 2020 22:17:59 -0400 Subject: [PATCH 33/38] fix(usb): Restore write semaphore, release it on write failures. --- app/src/usb_hid.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 4c6dd4b2..784fc250 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -11,18 +11,42 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -static enum usb_dc_status_code usb_status; +static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN; static struct device *hid_dev; +static K_SEM_DEFINE(hid_sem, 1, 1); + +static void in_ready_cb(void) +{ + k_sem_give(&hid_sem); +} + +static const struct hid_ops ops = +{ + .int_in_ready = in_ready_cb, +}; + int zmk_usb_hid_send_report(const u8_t *report, size_t len) { - if (usb_status == USB_DC_SUSPEND) - { + switch(usb_status) { + case USB_DC_SUSPEND: return usb_wakeup_request(); - } + case USB_DC_ERROR: + case USB_DC_RESET: + case USB_DC_DISCONNECTED: + case USB_DC_UNKNOWN: + return -ENODEV; + default: + k_sem_take(&hid_sem, K_MSEC(30)); + int err = hid_int_ep_write(hid_dev, report, len, NULL); - return hid_int_ep_write(hid_dev, report, len, NULL); + if (err) { + k_sem_give(&hid_sem); + } + + return err; + } } void usb_hid_status_cb(enum usb_dc_status_code status, const u8_t *params) @@ -43,7 +67,7 @@ static int zmk_usb_hid_init(struct device *_arg) usb_hid_register_device(hid_dev, zmk_hid_report_desc, sizeof(zmk_hid_report_desc), - NULL); + &ops); usb_hid_init(hid_dev); From 3c4a9686f86ee2ac90e81cfd5a408d08aa380cde Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 21:56:22 -0400 Subject: [PATCH 34/38] fix(boards): Proper last col transform for Corne. --- app/boards/shields/corne/corne.dtsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi index 3df055cd..c5420c46 100644 --- a/app/boards/shields/corne/corne.dtsi +++ b/app/boards/shields/corne/corne.dtsi @@ -21,9 +21,9 @@ // | SW13 | SW14 | SW15 | SW16 | SW17 | SW18 | | SW18 | SW17 | SW16 | SW15 | SW14 | SW13 | // | SW19 | SW20 | SW21 | | SW21 | SW20 | SW19 | map = < -RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,12) -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) RC(1,9) RC(1,10) RC(1,12) -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(2,9) RC(2,10) RC(2,12) +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) +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) RC(1,9) RC(1,10) RC(1,11) +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(2,9) RC(2,10) RC(2,11) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) >; }; From 307e2b3e6366e5b284ee39913d2de46781952148 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 18 Aug 2020 23:24:53 -0400 Subject: [PATCH 35/38] fix(shields): OLED fixes for Corne, add anchors. --- app/boards/shields/corne/corne.dtsi | 7 +++++-- app/boards/shields/lily58/lily58.dtsi | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi index c5420c46..af14bae9 100644 --- a/app/boards/shields/corne/corne.dtsi +++ b/app/boards/shields/corne/corne.dtsi @@ -68,7 +68,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 &pro_micro_i2c { status = "okay"; - ssd1306@3c { + oled: ssd1306@3c { compatible = "solomon,ssd1306fb"; reg = <0x3c>; label = "DISPLAY"; @@ -77,7 +77,10 @@ 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 segment-offset = <0>; page-offset = <0>; display-offset = <0>; - multiplex-ratio = <63>; + multiplex-ratio = <31>; + segment-remap; + com-invdir; + com-sequential; prechargep = <0x22>; }; }; diff --git a/app/boards/shields/lily58/lily58.dtsi b/app/boards/shields/lily58/lily58.dtsi index cbda5237..24f6805d 100644 --- a/app/boards/shields/lily58/lily58.dtsi +++ b/app/boards/shields/lily58/lily58.dtsi @@ -53,7 +53,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) &pro_micro_i2c { status = "okay"; - ssd1306@3c { + oled: ssd1306@3c { compatible = "solomon,ssd1306fb"; reg = <0x3c>; label = "DISPLAY"; From 674c230dbbea00ab56c837744c6f4abc050a89ea Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 18 Aug 2020 23:28:06 -0500 Subject: [PATCH 36/38] fix(board): Cleanup nice!nano DT --- app/boards/arm/nice_nano/Kconfig | 1 + app/boards/arm/nice_nano/Kconfig.defconfig | 2 -- app/boards/arm/nice_nano/nice_nano.dts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/boards/arm/nice_nano/Kconfig b/app/boards/arm/nice_nano/Kconfig index a1904253..fb5537ab 100644 --- a/app/boards/arm/nice_nano/Kconfig +++ b/app/boards/arm/nice_nano/Kconfig @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: MIT config BOARD_ENABLE_DCDC bool "Enable DCDC mode" diff --git a/app/boards/arm/nice_nano/Kconfig.defconfig b/app/boards/arm/nice_nano/Kconfig.defconfig index 2431813c..0961ddd1 100644 --- a/app/boards/arm/nice_nano/Kconfig.defconfig +++ b/app/boards/arm/nice_nano/Kconfig.defconfig @@ -1,5 +1,3 @@ -# Electronut Labs Papyr board configuration - # Copyright (c) 2020 Pete Johanson # SPDX-License-Identifier: MIT diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts index c1b9cc07..2e9556b8 100644 --- a/app/boards/arm/nice_nano/nice_nano.dts +++ b/app/boards/arm/nice_nano/nice_nano.dts @@ -24,7 +24,7 @@ leds { compatible = "gpio-leds"; blue_led: led_0 { - gpios = <&gpio0 15 GPIO_ACTIVE_LOW>; + gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>; label = "Blue LED"; }; }; From cab34d835f244cb9f7c3cc29cd5a1a2f154a27fc Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 18 Aug 2020 23:28:34 -0500 Subject: [PATCH 37/38] fix(board): Fix status LED on BlueMicro --- app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts index c56ca189..f8abc667 100644 --- a/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts +++ b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts @@ -24,7 +24,7 @@ leds { compatible = "gpio-leds"; blue_led: led_0 { - gpios = <&gpio0 42 GPIO_ACTIVE_LOW>; + gpios = <&gpio0 42 GPIO_ACTIVE_HIGH>; label = "Blue LED"; }; }; From 4085145b8506257bca2aeddc46f8f249fd648cf0 Mon Sep 17 00:00:00 2001 From: Jared Giles Date: Wed, 19 Aug 2020 18:37:47 +0100 Subject: [PATCH 38/38] Working on corne default keymap --- app/boards/shields/corne/corne.keymap | 60 ++++++++++++++++++++------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/app/boards/shields/corne/corne.keymap b/app/boards/shields/corne/corne.keymap index 2f7f38b9..a88d0368 100644 --- a/app/boards/shields/corne/corne.keymap +++ b/app/boards/shields/corne/corne.keymap @@ -2,21 +2,49 @@ #include / { - keymap { - compatible = "zmk,keymap"; + keymap { + compatible = "zmk,keymap"; - default_layer { -// --------------------------------------------------------------------------------------------------------------------------------- -// | ESC | Q | W | E | R | T | | Y | U | I | O | P | \ | -// | TAB | A | S | D | F | G | | H | J | K | L | ; | ' | -// | SHIFT | Z | X | C | V | B | | N | M | , | . | / | CTRL | -// | GUI | DEL | RET | | TAB | BSPC | R-ALT | - bindings = < - &kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSLH - &kp TAB &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp QUOT - &kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp RCTL - &kp LGUI &kp DEL &kp RET &kp TAB &kp BKSP &kp RALT - >; - }; - }; + default_layer { +// ----------------------------------------------------------------------------------------- +// | TAB | Q | W | E | R | T | | Y | U | I | O | P | BKSP | +// | CTRL | A | S | D | F | G | | H | J | K | L | ; | ' | +// | SHFT | Z | X | C | V | B | | N | M | , | . | / | SHFT | +// | GUI | LWR | SPC | | ENT | RSE | ALT | + bindings = < + &kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BKSP + &kp LCTL &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp QUOT + &kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp RSFT + &kp LGUI &mo 1 &kp SPC &kp RET &mo 2 &kp RALT + >; + }; + lower_layer { +// ----------------------------------------------------------------------------------------- +// | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | BKSP | +// | CTRL | | | | | | | RGT | UP | DWN | LFT | | | +// | SHFT | | | | | | | | | | | | | +// | GUI | | SPC | | ENT | | ALT | + bindings = < + &kp ESC &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 &kp NUM_5 &kp NUM_6 &kp NUM_7 &kp NUM_8 &kp NUM_9 &kp NUM_0 &kp BKSP + &kp LCTL &trans &trans &trans &trans &trans &kp RARW &kp UARW &kp DARW &kp LARW &trans &trans + &kp LSFT &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans + &kp LGUI &trans &kp SPC &kp RET &trans &kp RALT + >; + }; + + raise_layer { +// ----------------------------------------------------------------------------------------- +// | ESC | ! | @ | # | $ | % | | ^ | & | * | ( | ) | BKSP | +// | CTRL | | | | | | | - | = | { | } | "|" | ` | +// | SHFT | | | | | | | _ | + | [ | ] | \ | ~ | // TODO: Fix this row when &mkp is committed +// | GUI | | SPC | | ENT | | ALT | + bindings = < + &kp ESC &kp BANG &kp ATSN &kp HASH &kp CURU &kp PRCT &kp CRRT &kp AMPS &kp KMLT &kp LPRN &kp RPRN &kp BKSP + &kp LCTL &trans &trans &trans &trans &trans &kp MINUS &kp EQL &kp LBKT &kp RBKT &kp PIPE &trans + &kp LSFT &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans + &kp LGUI &trans &kp SPC &kp RET &trans &kp RALT + >; + }; + }; }; +