diff options
30 files changed, 287 insertions, 50 deletions
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 5e1bd88..054f84a 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -44,6 +44,7 @@ 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) +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 b26be48..416c985 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/arm/bluemicro52840_v1/bluemicro52840_v1.dts b/app/boards/arm/bluemicro52840_v1/bluemicro52840_v1.dts index c56ca18..f8abc66 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"; }; }; diff --git a/app/boards/arm/nice_nano/Kconfig b/app/boards/arm/nice_nano/Kconfig index a190425..fb5537a 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 2431813..0961ddd 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 7c676e3..2e9556b 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"; }; }; @@ -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>; diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi index 70d6495..af14bae 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) >; }; @@ -58,13 +58,17 @@ 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)? }; &pro_micro_i2c { status = "okay"; - ssd1306@3c { + oled: ssd1306@3c { compatible = "solomon,ssd1306fb"; reg = <0x3c>; label = "DISPLAY"; @@ -73,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/corne/corne.keymap b/app/boards/shields/corne/corne.keymap index 2f7f38b..a88d036 100644 --- a/app/boards/shields/corne/corne.keymap +++ b/app/boards/shields/corne/corne.keymap @@ -2,21 +2,49 @@ #include <dt-bindings/zmk/keys.h> / { - 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 + >; + }; + }; }; + diff --git a/app/boards/shields/corne/corne_left.conf b/app/boards/shields/corne/corne_left.conf index e51dee4..338fa59 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 399bddd..f12c417 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 a835adc..be344c4 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 652d5ed..9d97d85 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 bbead84..a13f7f0 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 e51dee4..338fa59 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 c8b5be2..441c1a6 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 a835adc..be344c4 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 8163c95..8ee0fcb 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 8655d8c..24f6805 100644 --- a/app/boards/shields/lily58/lily58.dtsi +++ b/app/boards/shields/lily58/lily58.dtsi @@ -44,12 +44,16 @@ 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 { status = "okay"; - ssd1306@3c { + oled: ssd1306@3c { compatible = "solomon,ssd1306fb"; reg = <0x3c>; label = "DISPLAY"; diff --git a/app/boards/shields/lily58/lily58_left.conf b/app/boards/shields/lily58/lily58_left.conf index e51dee4..338fa59 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 c8e2213..c6f630f 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 990cf7c..cf16779 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 748be14..84f0b06 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 baaca30..b19c492 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 0000000..d781347 --- /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 a77237d..e760ed7 100644 --- a/app/include/zmk/ble.h +++ b/app/include/zmk/ble.h @@ -3,5 +3,5 @@ #include <zmk/keys.h> -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 71bbccd..0e96d16 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); @@ -190,6 +200,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 0000000..a33a8e2 --- /dev/null +++ b/app/src/ble_unpair_combo.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#include <device.h> +#include <init.h> + +#include <logging/log.h> + +#define DT_DRV_COMPAT zmk_bt_unpair_combo + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include <zmk/ble.h> +#include <zmk/event-manager.h> +#include <zmk/events/position-state-changed.h> + + +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); diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 4c6dd4b..784fc25 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); + + if (err) { + k_sem_give(&hid_sem); + } + + return err; } - - return hid_int_ep_write(hid_dev, report, len, NULL); } 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); diff --git a/docs/docs/behavior/mod-tap.md b/docs/docs/behavior/mod-tap.md new file mode 100644 index 0000000..cae667e --- /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 90bdfa2..be02a65 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: [ |