From 3ee2d1196b9335a081d841ff3918d2fdf722d5b9 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 20 Aug 2020 00:07:04 -0500 Subject: feat(rgb): underglow state Kconfig and settings --- app/Kconfig | 24 +++++++++++++++ app/src/rgb_underglow.c | 77 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 83 insertions(+), 18 deletions(-) (limited to 'app') diff --git a/app/Kconfig b/app/Kconfig index 416c985..cefae21 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -180,6 +180,30 @@ config ZMK_RGB_UNDERGLOW_BRT_STEP int "RGB underglow brightness step in percent" default 10 +config ZMK_RGB_UNDERGLOW_HUE_START + int "RGB underglow start hue value from 0-359" + default 0 + +config ZMK_RGB_UNDERGLOW_SAT_START + int "RGB underglow start saturations value from 0-100" + default 100 + +config ZMK_RGB_UNDERGLOW_BRT_START + int "RGB underglow start brightness value from 0-100" + default 100 + +config ZMK_RGB_UNDERGLOW_SPD_START + int "RGB underglow start animation speed value from 1-5" + default 3 + +config ZMK_RGB_UNDERGLOW_EFF_START + int "RGB underglow start effect int value related to the effect enum list" + default 0 + +config ZMK_RGB_UNDERGLOW_ON_START + bool "Whether RGB underglow starts on by default" + default y + endif endmenu diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 95adcec..5f55798 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -45,12 +46,39 @@ struct rgb_underglow_state { bool on; }; -struct rgb_underglow_state state; - struct device *led_strip; struct led_rgb pixels[STRIP_NUM_PIXELS]; +struct rgb_underglow_state state; + +static int rgb_settings_set(const char *name, size_t len, + settings_read_cb read_cb, void *cb_arg) +{ + const char *next; + int rc; + + if (settings_name_steq(name, "state", &next) && !next) { + if (len != sizeof(state)) { + return -EINVAL; + } + + rc = read_cb(cb_arg, &state, sizeof(state)); + if (rc >= 0) { + return 0; + } + + return rc; + } + + return -ENOENT; +} + +struct settings_handler rgb_conf = { + .name = "rgb", + .h_set = rgb_settings_set +}; + static struct led_rgb hsb_to_rgb(struct led_hsb hsb) { double r, g, b; @@ -187,20 +215,35 @@ static int zmk_rgb_underglow_init(struct device *_arg) } state = (struct rgb_underglow_state){ - hue: 0, - saturation: 100, - brightness: 100, - animation_speed: 3, - current_effect: 0, + hue: CONFIG_ZMK_RGB_UNDERGLOW_HUE_START, + saturation: CONFIG_ZMK_RGB_UNDERGLOW_SAT_START, + brightness: CONFIG_ZMK_RGB_UNDERGLOW_BRT_START, + animation_speed: CONFIG_ZMK_RGB_UNDERGLOW_SPD_START, + current_effect: CONFIG_ZMK_RGB_UNDERGLOW_EFF_START, animation_step: 0, +#ifdef CONFIG_ZMK_RGB_UNDERGLOW_ON_START on: true +#else + on: false +#endif }; - k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); + settings_subsys_init(); + settings_register(&rgb_conf); + settings_load(); + + if (state.on) { + k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); + } return 0; } +int zmk_rgb_underglow_save_state() +{ + return settings_save_one("rgb/state", &state, sizeof(state)); +} + int zmk_rgb_underglow_cycle_effect(int direction) { if (!led_strip) return -ENODEV; @@ -218,7 +261,7 @@ int zmk_rgb_underglow_cycle_effect(int direction) state.animation_step = 0; - return 0; + return zmk_rgb_underglow_save_state(); } int zmk_rgb_underglow_toggle() @@ -242,7 +285,7 @@ int zmk_rgb_underglow_toggle() k_timer_stop(&underglow_tick); } - return 0; + return zmk_rgb_underglow_save_state(); } int zmk_rgb_underglow_change_hue(int direction) @@ -250,17 +293,15 @@ int zmk_rgb_underglow_change_hue(int direction) if (!led_strip) return -ENODEV; if (state.hue == 0 && direction < 0) { - state.hue = 350; + state.hue = 360 - CONFIG_ZMK_RGB_UNDERGLOW_HUE_STEP; return 0; } state.hue += direction * CONFIG_ZMK_RGB_UNDERGLOW_HUE_STEP; - if (state.hue > 350) { - state.hue = 0; - } + state.hue = state.hue % 360; - return 0; + return zmk_rgb_underglow_save_state(); } int zmk_rgb_underglow_change_sat(int direction) @@ -277,7 +318,7 @@ int zmk_rgb_underglow_change_sat(int direction) state.saturation = 100; } - return 0; + return zmk_rgb_underglow_save_state(); } int zmk_rgb_underglow_change_brt(int direction) @@ -294,7 +335,7 @@ int zmk_rgb_underglow_change_brt(int direction) state.brightness = 100; } - return 0; + return zmk_rgb_underglow_save_state(); } int zmk_rgb_underglow_change_spd(int direction) @@ -311,7 +352,7 @@ int zmk_rgb_underglow_change_spd(int direction) state.animation_speed = 5; } - return 0; + return zmk_rgb_underglow_save_state(); } SYS_INIT(zmk_rgb_underglow_init, -- cgit v1.2.3 From 74fd4fc997c0cf78cc9acabdd61466fa4857e7ba Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 20 Aug 2020 21:13:17 -0500 Subject: fix(rgb): fix underglow settings location --- app/src/rgb_underglow.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 5f55798..86223b1 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -75,7 +75,7 @@ static int rgb_settings_set(const char *name, size_t len, } struct settings_handler rgb_conf = { - .name = "rgb", + .name = "rgb/underglow", .h_set = rgb_settings_set }; @@ -241,7 +241,7 @@ static int zmk_rgb_underglow_init(struct device *_arg) int zmk_rgb_underglow_save_state() { - return settings_save_one("rgb/state", &state, sizeof(state)); + return settings_save_one("rgb/underglow/state", &state, sizeof(state)); } int zmk_rgb_underglow_cycle_effect(int direction) -- cgit v1.2.3 From c5c21022a23cae3fecaf17e13d18d7d1ebd5f150 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 23 Aug 2020 10:33:19 -0500 Subject: Move settings load --- app/CMakeLists.txt | 1 + app/src/rgb_underglow.c | 40 ++++++++++++++++++++++------------------ app/src/settings.c | 13 +++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 app/src/settings.c (limited to 'app') diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 054f84a..bb4af55 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -55,4 +55,5 @@ target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c) target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/hid_listener.c) +target_sources(app PRIVATE src/settings.c) target_sources(app PRIVATE src/main.c) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 86223b1..3851421 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -15,7 +15,6 @@ #include #include -#include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -106,6 +105,16 @@ static struct led_rgb hsb_to_rgb(struct led_hsb hsb) return rgb; } +static void zmk_rgb_underglow_off() +{ + for (int i=0; i +#include +#include +#include + +static int zmk_settings_init(struct device *_arg) +{ + return settings_load(); +} + +SYS_INIT(zmk_settings_init, + APPLICATION, + CONFIG_APPLICATION_INIT_PRIORITY); -- cgit v1.2.3 From 979a5bffffeac0fed12db00409dedb8ed6c4ad87 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 23 Aug 2020 15:56:18 -0500 Subject: fix(rgb): check if settings enabled --- app/CMakeLists.txt | 2 +- app/src/rgb_underglow.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index bb4af55..bbb54b9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -55,5 +55,5 @@ target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c) target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/hid_listener.c) -target_sources(app PRIVATE src/settings.c) +target_sources_ifdef(CONFIG_SETTINGS app PRIVATE src/settings.c) target_sources(app PRIVATE src/main.c) diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 3851421..cb98e8d 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -51,6 +51,7 @@ struct led_rgb pixels[STRIP_NUM_PIXELS]; struct rgb_underglow_state state; +#if IS_ENABLED(CONFIG_SETTINGS) static int rgb_settings_set(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg) { @@ -77,6 +78,7 @@ struct settings_handler rgb_conf = { .name = "rgb/underglow", .h_set = rgb_settings_set }; +#endif static struct led_rgb hsb_to_rgb(struct led_hsb hsb) { @@ -242,7 +244,9 @@ static int zmk_rgb_underglow_init(struct device *_arg) on: IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_ON_START) }; +#if IS_ENABLED(CONFIG_SETTINGS) settings_register(&rgb_conf); +#endif k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); @@ -251,7 +255,11 @@ static int zmk_rgb_underglow_init(struct device *_arg) int zmk_rgb_underglow_save_state() { +#if IS_ENABLED(CONFIG_SETTINGS) return settings_save_one("rgb/underglow/state", &state, sizeof(state)); +#else + return 0; +#endif } int zmk_rgb_underglow_cycle_effect(int direction) -- cgit v1.2.3 From 4551d307693dae30802a3f06d5f62fcf3155f8c0 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 3 Sep 2020 13:20:05 +0100 Subject: ad cradios --- app/boards/shields/cradios/Kconfig.defconfig | 14 +++++++++ app/boards/shields/cradios/Kconfig.shield | 5 ++++ app/boards/shields/cradios/cradios.dtsi | 31 +++++++++++++++++++ app/boards/shields/cradios/cradios.keymap | 17 +++++++++++ app/boards/shields/cradios/cradios_left.conf | 2 ++ app/boards/shields/cradios/cradios_left.overlay | 34 +++++++++++++++++++++ app/boards/shields/cradios/cradios_right.conf | 2 ++ app/boards/shields/cradios/cradios_right.overlay | 38 ++++++++++++++++++++++++ app/boards/shields/cradios/default.keymap | 19 ++++++++++++ 9 files changed, 162 insertions(+) create mode 100644 app/boards/shields/cradios/Kconfig.defconfig create mode 100644 app/boards/shields/cradios/Kconfig.shield create mode 100644 app/boards/shields/cradios/cradios.dtsi create mode 100644 app/boards/shields/cradios/cradios.keymap create mode 100644 app/boards/shields/cradios/cradios_left.conf create mode 100644 app/boards/shields/cradios/cradios_left.overlay create mode 100644 app/boards/shields/cradios/cradios_right.conf create mode 100644 app/boards/shields/cradios/cradios_right.overlay create mode 100644 app/boards/shields/cradios/default.keymap (limited to 'app') diff --git a/app/boards/shields/cradios/Kconfig.defconfig b/app/boards/shields/cradios/Kconfig.defconfig new file mode 100644 index 0000000..0aca38f --- /dev/null +++ b/app/boards/shields/cradios/Kconfig.defconfig @@ -0,0 +1,14 @@ + +if SHIELD_CRADIOS + +config ZMK_KEYBOARD_NAME + default "cradios" + +# Unable to use interrupts as the same pin number is used +# across A & B controllers, and STM32F303CCT6 can't enable +# interrutps for multiple controllers for the same "line" +# for the external interrupts. +config ZMK_KSCAN_GPIO_POLLING + default y + +endif diff --git a/app/boards/shields/cradios/Kconfig.shield b/app/boards/shields/cradios/Kconfig.shield new file mode 100644 index 0000000..844d433 --- /dev/null +++ b/app/boards/shields/cradios/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2020 Pete Johanson +# SPDX-License-Identifier: MIT + +config SHIELD_CRADIOS + def_bool $(shields_list_contains,cradios) diff --git a/app/boards/shields/cradios/cradios.dtsi b/app/boards/shields/cradios/cradios.dtsi new file mode 100644 index 0000000..7c20c00 --- /dev/null +++ b/app/boards/shields/cradios/cradios.dtsi @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + #include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <10>; + rows = <4>; + map = < +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(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(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(3,4) RC(3,5) RC(3,6) RC(3,7) + >; + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-direct"; + }; + + }; diff --git a/app/boards/shields/cradios/cradios.keymap b/app/boards/shields/cradios/cradios.keymap new file mode 100644 index 0000000..2939224 --- /dev/null +++ b/app/boards/shields/cradios/cradios.keymap @@ -0,0 +1,17 @@ +#include +#include + + +/ { + keymap0: keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P + &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN + &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH + &kp DEL &kp RET &kp RET &SPC + }; + }; +}; diff --git a/app/boards/shields/cradios/cradios_left.conf b/app/boards/shields/cradios/cradios_left.conf new file mode 100644 index 0000000..1e028a7 --- /dev/null +++ b/app/boards/shields/cradios/cradios_left.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_SPLIT=y +CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y diff --git a/app/boards/shields/cradios/cradios_left.overlay b/app/boards/shields/cradios/cradios_left.overlay new file mode 100644 index 0000000..6f53d8b --- /dev/null +++ b/app/boards/shields/cradios/cradios_left.overlay @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ +#include "cradios.dtsi" + +kscan_0 { + + input-gpios + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; +}; + +&bt_unpair_combo { + key-positions = <0 38>; +}; + diff --git a/app/boards/shields/cradios/cradios_right.conf b/app/boards/shields/cradios/cradios_right.conf new file mode 100644 index 0000000..990cf7c --- /dev/null +++ b/app/boards/shields/cradios/cradios_right.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_SPLIT=y +CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y diff --git a/app/boards/shields/cradios/cradios_right.overlay b/app/boards/shields/cradios/cradios_right.overlay new file mode 100644 index 0000000..f991ef9 --- /dev/null +++ b/app/boards/shields/cradios/cradios_right.overlay @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ +#include "cradios.dtsi" + +&default_transform { + col-offset = <5>; +}; + + &kscan0 { + input-gpios + + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; +}; + +&bt_unpair_combo { + key-positions = <0 38>; +}; + diff --git a/app/boards/shields/cradios/default.keymap b/app/boards/shields/cradios/default.keymap new file mode 100644 index 0000000..0821005 --- /dev/null +++ b/app/boards/shields/cradios/default.keymap @@ -0,0 +1,19 @@ +#include +#include + + +/ { + keymap0: keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P + &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN + &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH + &kp DEL &kp RET &kp RET &kp SPC + + >; + }; + }; +}; -- cgit v1.2.3 From 95bb220702121756a1f7458dcf549bd3c9187216 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 3 Sep 2020 14:46:54 +0100 Subject: now compiles, not work, baby steps --- app/boards/shields/cradios/cradios.dtsi | 11 ++++++----- app/boards/shields/cradios/cradios.keymap | 13 +++++++------ app/boards/shields/cradios/cradios_left.overlay | 7 +++---- app/boards/shields/cradios/cradios_right.overlay | 9 +++------ 4 files changed, 19 insertions(+), 21 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradios/cradios.dtsi b/app/boards/shields/cradios/cradios.dtsi index 7c20c00..f5ebb96 100644 --- a/app/boards/shields/cradios/cradios.dtsi +++ b/app/boards/shields/cradios/cradios.dtsi @@ -14,18 +14,19 @@ default_transform: keymap_transform_0 { compatible = "zmk,matrix-transform"; - columns = <10>; - rows = <4>; + columns = <34>; + rows = <1>; map = < 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(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(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(3,4) RC(3,5) RC(3,6) RC(3,7) +RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,15) RC(0,16) RC(0,17) RC(0,18) RC(0,19) RC(0,20) +RC(0,21) RC(0,22) RC(0,23) RC(0,24) RC(0,25) RC(0,26) RC(0,27) RC(0,28) RC(0,29) RC(0,30) +RC(0,31) RC(0,32) RC(0,33) RC(0,34) >; }; kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + label = "KSCAN"; }; }; diff --git a/app/boards/shields/cradios/cradios.keymap b/app/boards/shields/cradios/cradios.keymap index 2939224..3da61b7 100644 --- a/app/boards/shields/cradios/cradios.keymap +++ b/app/boards/shields/cradios/cradios.keymap @@ -3,15 +3,16 @@ / { - keymap0: keymap { - compatible = "zmk,keymap"; + keymap { + compatible = "zmk,keymap"; - default_layer { + default_layer { bindings = < &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P - &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN - &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp DEL &kp RET &kp RET &SPC + &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN + &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH + &kp 3 &kp 4 &kp 2 &kp 1 + >; }; }; }; diff --git a/app/boards/shields/cradios/cradios_left.overlay b/app/boards/shields/cradios/cradios_left.overlay index 6f53d8b..3c3e986 100644 --- a/app/boards/shields/cradios/cradios_left.overlay +++ b/app/boards/shields/cradios/cradios_left.overlay @@ -5,7 +5,8 @@ */ #include "cradios.dtsi" -kscan_0 { + +&kscan0 { input-gpios = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> @@ -28,7 +29,5 @@ kscan_0 { ; }; -&bt_unpair_combo { - key-positions = <0 38>; -}; + diff --git a/app/boards/shields/cradios/cradios_right.overlay b/app/boards/shields/cradios/cradios_right.overlay index f991ef9..7b47924 100644 --- a/app/boards/shields/cradios/cradios_right.overlay +++ b/app/boards/shields/cradios/cradios_right.overlay @@ -6,12 +6,11 @@ #include "cradios.dtsi" &default_transform { - col-offset = <5>; + col-offset = <17>; }; - &kscan0 { +&kscan0 { input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> @@ -32,7 +31,5 @@ ; }; -&bt_unpair_combo { - key-positions = <0 38>; -}; + -- cgit v1.2.3 From 8bad40282b89859766cd28949b48fe34c24371fe Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 3 Sep 2020 22:02:25 +0100 Subject: actually working --- app/boards/shields/cradios/Kconfig.defconfig | 4 ++-- app/boards/shields/cradios/cradios.dtsi | 10 +++++----- app/boards/shields/cradios/cradios.keymap | 2 +- app/boards/shields/cradios/cradios_left.overlay | 3 +-- app/boards/shields/cradios/cradios_right.overlay | 5 ++--- 5 files changed, 11 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradios/Kconfig.defconfig b/app/boards/shields/cradios/Kconfig.defconfig index 0aca38f..5b9ca9a 100644 --- a/app/boards/shields/cradios/Kconfig.defconfig +++ b/app/boards/shields/cradios/Kconfig.defconfig @@ -1,5 +1,5 @@ -if SHIELD_CRADIOS + config ZMK_KEYBOARD_NAME default "cradios" @@ -11,4 +11,4 @@ config ZMK_KEYBOARD_NAME config ZMK_KSCAN_GPIO_POLLING default y -endif + diff --git a/app/boards/shields/cradios/cradios.dtsi b/app/boards/shields/cradios/cradios.dtsi index f5ebb96..95b4f27 100644 --- a/app/boards/shields/cradios/cradios.dtsi +++ b/app/boards/shields/cradios/cradios.dtsi @@ -17,11 +17,11 @@ columns = <34>; rows = <1>; map = < -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(0,12) RC(0,13) RC(0,14) RC(0,15) RC(0,16) RC(0,17) RC(0,18) RC(0,19) RC(0,20) -RC(0,21) RC(0,22) RC(0,23) RC(0,24) RC(0,25) RC(0,26) RC(0,27) RC(0,28) RC(0,29) RC(0,30) -RC(0,31) RC(0,32) RC(0,33) RC(0,34) - >; +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,17) RC(0,18) RC(0,19) RC(0,20) RC(0,21) +RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,22) RC(0,23) RC(0,24) RC(0,25) RC(0,26) +RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,27) RC(0,28) RC(0,29) RC(0,30) RC(0,31) +RC(0,15) RC(0,16) RC(0,32) RC(0,33) +>; }; kscan0: kscan { diff --git a/app/boards/shields/cradios/cradios.keymap b/app/boards/shields/cradios/cradios.keymap index 3da61b7..c46468d 100644 --- a/app/boards/shields/cradios/cradios.keymap +++ b/app/boards/shields/cradios/cradios.keymap @@ -11,7 +11,7 @@ &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp 3 &kp 4 &kp 2 &kp 1 + &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 >; }; }; diff --git a/app/boards/shields/cradios/cradios_left.overlay b/app/boards/shields/cradios/cradios_left.overlay index 3c3e986..ab5a874 100644 --- a/app/boards/shields/cradios/cradios_left.overlay +++ b/app/boards/shields/cradios/cradios_left.overlay @@ -7,9 +7,8 @@ &kscan0 { - input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/cradios/cradios_right.overlay b/app/boards/shields/cradios/cradios_right.overlay index 7b47924..59a81ba 100644 --- a/app/boards/shields/cradios/cradios_right.overlay +++ b/app/boards/shields/cradios/cradios_right.overlay @@ -8,10 +8,9 @@ &default_transform { col-offset = <17>; }; - &kscan0 { input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + = <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> @@ -27,7 +26,7 @@ , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> ; }; -- cgit v1.2.3 From 81bc157f539235ad032fde78b6f6cec7a16d2c39 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 15 Sep 2020 14:31:59 -0500 Subject: Fix underglow not working by default --- app/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app') diff --git a/app/Kconfig b/app/Kconfig index cefae21..cda5c58 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -168,6 +168,10 @@ menuconfig ZMK_RGB_UNDERGLOW if ZMK_RGB_UNDERGLOW +# This default value cuts down on tons of excess .conf files, if you're using GPIO, manually disable this +config SPI + default y + config ZMK_RGB_UNDERGLOW_HUE_STEP int "RGB underglow hue step in degrees of 360" default 10 -- cgit v1.2.3 From 608ae0df6dfe4d75bc98c36f6756dc4d69399109 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 15 Sep 2020 14:47:19 -0500 Subject: fix lint with clang-format --- app/src/rgb_underglow.c | 57 +++++++++++++++++++------------------------------ app/src/settings.c | 9 ++------ 2 files changed, 24 insertions(+), 42 deletions(-) (limited to 'app') diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index d453755..b371c94 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -52,9 +52,7 @@ struct led_rgb pixels[STRIP_NUM_PIXELS]; struct rgb_underglow_state state; #if IS_ENABLED(CONFIG_SETTINGS) -static int rgb_settings_set(const char *name, size_t len, - settings_read_cb read_cb, void *cb_arg) -{ +static int rgb_settings_set(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg) { const char *next; int rc; @@ -74,14 +72,10 @@ static int rgb_settings_set(const char *name, size_t len, return -ENOENT; } -struct settings_handler rgb_conf = { - .name = "rgb/underglow", - .h_set = rgb_settings_set -}; +struct settings_handler rgb_conf = {.name = "rgb/underglow", .h_set = rgb_settings_set}; #endif -static struct led_rgb hsb_to_rgb(struct led_hsb hsb) -{ +static struct led_rgb hsb_to_rgb(struct led_hsb hsb) { double r, g, b; u8_t i = hsb.h / 60; @@ -130,20 +124,16 @@ static struct led_rgb hsb_to_rgb(struct led_hsb hsb) return rgb; } -static void zmk_rgb_underglow_off() -{ - for (int i=0; i #include -static int zmk_settings_init(struct device *_arg) -{ - return settings_load(); -} +static int zmk_settings_init(struct device *_arg) { return settings_load(); } -SYS_INIT(zmk_settings_init, - APPLICATION, - CONFIG_APPLICATION_INIT_PRIORITY); +SYS_INIT(zmk_settings_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); -- cgit v1.2.3 From 2855ba75f53554887f6e788736c45b7c818d09ac Mon Sep 17 00:00:00 2001 From: David Barr Date: Sat, 19 Sep 2020 10:55:07 +0100 Subject: Actually really working Ok, both sides work as expected, need to write a keymap. --- app/boards/shields/Kconfig.defconfig | 14 +++++++ app/boards/shields/Kconfig.shield | 5 +++ app/boards/shields/cradios.dtsi | 67 ++++++++++++++++++++++++++++++++ app/boards/shields/cradios.keymap | 18 +++++++++ app/boards/shields/cradios_left.conf | 2 + app/boards/shields/cradios_left.overlay | 15 +++++++ app/boards/shields/cradios_right.conf | 2 + app/boards/shields/cradios_right.overlay | 17 ++++++++ 8 files changed, 140 insertions(+) create mode 100644 app/boards/shields/Kconfig.defconfig create mode 100644 app/boards/shields/Kconfig.shield create mode 100644 app/boards/shields/cradios.dtsi create mode 100644 app/boards/shields/cradios.keymap create mode 100644 app/boards/shields/cradios_left.conf create mode 100644 app/boards/shields/cradios_left.overlay create mode 100644 app/boards/shields/cradios_right.conf create mode 100644 app/boards/shields/cradios_right.overlay (limited to 'app') diff --git a/app/boards/shields/Kconfig.defconfig b/app/boards/shields/Kconfig.defconfig new file mode 100644 index 0000000..5b9ca9a --- /dev/null +++ b/app/boards/shields/Kconfig.defconfig @@ -0,0 +1,14 @@ + + + +config ZMK_KEYBOARD_NAME + default "cradios" + +# Unable to use interrupts as the same pin number is used +# across A & B controllers, and STM32F303CCT6 can't enable +# interrutps for multiple controllers for the same "line" +# for the external interrupts. +config ZMK_KSCAN_GPIO_POLLING + default y + + diff --git a/app/boards/shields/Kconfig.shield b/app/boards/shields/Kconfig.shield new file mode 100644 index 0000000..844d433 --- /dev/null +++ b/app/boards/shields/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2020 Pete Johanson +# SPDX-License-Identifier: MIT + +config SHIELD_CRADIOS + def_bool $(shields_list_contains,cradios) diff --git a/app/boards/shields/cradios.dtsi b/app/boards/shields/cradios.dtsi new file mode 100644 index 0000000..68d1fc5 --- /dev/null +++ b/app/boards/shields/cradios.dtsi @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + #include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <34>; + rows = <1>; + map = < +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) +RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) +RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) +RC(0,15) RC(0,16) RC(0,33) RC(0,32) +>; + + + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-direct"; + label = "KSCAN"; + }; + + + + + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; + }; + + + + }; + + + &kscan0 { + input-gpios + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; +}; + + diff --git a/app/boards/shields/cradios.keymap b/app/boards/shields/cradios.keymap new file mode 100644 index 0000000..c46468d --- /dev/null +++ b/app/boards/shields/cradios.keymap @@ -0,0 +1,18 @@ +#include +#include + + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P + &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN + &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH + &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 + >; + }; + }; +}; diff --git a/app/boards/shields/cradios_left.conf b/app/boards/shields/cradios_left.conf new file mode 100644 index 0000000..1e028a7 --- /dev/null +++ b/app/boards/shields/cradios_left.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_SPLIT=y +CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y diff --git a/app/boards/shields/cradios_left.overlay b/app/boards/shields/cradios_left.overlay new file mode 100644 index 0000000..b0bdc6f --- /dev/null +++ b/app/boards/shields/cradios_left.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ +#include "cradios.dtsi" + + + + + + +&bt_unpair_combo { + key-positions = <0 16>; +}; diff --git a/app/boards/shields/cradios_right.conf b/app/boards/shields/cradios_right.conf new file mode 100644 index 0000000..990cf7c --- /dev/null +++ b/app/boards/shields/cradios_right.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_SPLIT=y +CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y diff --git a/app/boards/shields/cradios_right.overlay b/app/boards/shields/cradios_right.overlay new file mode 100644 index 0000000..ef920ac --- /dev/null +++ b/app/boards/shields/cradios_right.overlay @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ +#include "cradios.dtsi" + +&default_transform { + col-offset = <17>; +}; + + + + +&bt_unpair_combo { + key-positions = <21 32>; +}; -- cgit v1.2.3 From ed5d3646fe7596fb40d0b7505f8062cdac6537be Mon Sep 17 00:00:00 2001 From: David Barr Date: Sat, 19 Sep 2020 10:56:40 +0100 Subject: Add files via upload --- app/boards/shields/cradios/cradios.dtsi | 51 ++++++++++++++++++++---- app/boards/shields/cradios/cradios_left.overlay | 25 ++---------- app/boards/shields/cradios/cradios_right.overlay | 25 ++---------- 3 files changed, 51 insertions(+), 50 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradios/cradios.dtsi b/app/boards/shields/cradios/cradios.dtsi index 95b4f27..68d1fc5 100644 --- a/app/boards/shields/cradios/cradios.dtsi +++ b/app/boards/shields/cradios/cradios.dtsi @@ -10,23 +10,58 @@ zmk,kscan = &kscan0; zmk,matrix_transform = &default_transform; }; - default_transform: keymap_transform_0 { compatible = "zmk,matrix-transform"; columns = <34>; rows = <1>; map = < -RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,17) RC(0,18) RC(0,19) RC(0,20) RC(0,21) -RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,22) RC(0,23) RC(0,24) RC(0,25) RC(0,26) -RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,27) RC(0,28) RC(0,29) RC(0,30) RC(0,31) -RC(0,15) RC(0,16) RC(0,32) RC(0,33) +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) +RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) +RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) +RC(0,15) RC(0,16) RC(0,33) RC(0,32) >; + + }; - kscan0: kscan { - compatible = "zmk,kscan-gpio-direct"; - label = "KSCAN"; + kscan0: kscan { + compatible = "zmk,kscan-gpio-direct"; + label = "KSCAN"; + }; + + + + + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; }; + + }; + + + &kscan0 { + input-gpios + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; +}; + + diff --git a/app/boards/shields/cradios/cradios_left.overlay b/app/boards/shields/cradios/cradios_left.overlay index ab5a874..b0bdc6f 100644 --- a/app/boards/shields/cradios/cradios_left.overlay +++ b/app/boards/shields/cradios/cradios_left.overlay @@ -6,27 +6,10 @@ #include "cradios.dtsi" -&kscan0 { - input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - ; -}; + +&bt_unpair_combo { + key-positions = <0 16>; +}; diff --git a/app/boards/shields/cradios/cradios_right.overlay b/app/boards/shields/cradios/cradios_right.overlay index 59a81ba..ef920ac 100644 --- a/app/boards/shields/cradios/cradios_right.overlay +++ b/app/boards/shields/cradios/cradios_right.overlay @@ -8,27 +8,10 @@ &default_transform { col-offset = <17>; }; -&kscan0 { - input-gpios - = <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - ; -}; + +&bt_unpair_combo { + key-positions = <21 32>; +}; -- cgit v1.2.3 From 844f2c76749cbc5ff611d8e69819af82b698089a Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 19 Sep 2020 19:14:59 -0500 Subject: Voltage divider driver initial implementation --- app/boards/arm/nice_nano/nice_nano.dts | 10 ++ app/boards/arm/nice_nano/nice_nano_defconfig | 4 + app/drivers/zephyr/CMakeLists.txt | 1 + app/drivers/zephyr/battery_voltage_divider.c | 115 +++++++++++++++++++++ .../dts/bindings/zmk,battery-voltage-divider.yaml | 9 ++ 5 files changed, 139 insertions(+) create mode 100644 app/drivers/zephyr/battery_voltage_divider.c create mode 100644 app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml (limited to 'app') diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts index 2e9556b..18312ec 100644 --- a/app/boards/arm/nice_nano/nice_nano.dts +++ b/app/boards/arm/nice_nano/nice_nano.dts @@ -29,6 +29,16 @@ }; }; + vbatt { + compatible = "zmk,battery-voltage-divider"; + io-channels = <&adc 2>; + output-ohms = <2000000>; + full-ohms = <(2000000 + 806000)>; + }; +}; + +&adc { + status = "okay"; }; &gpio0 { diff --git a/app/boards/arm/nice_nano/nice_nano_defconfig b/app/boards/arm/nice_nano/nice_nano_defconfig index 393d61f..b727fe0 100644 --- a/app/boards/arm/nice_nano/nice_nano_defconfig +++ b/app/boards/arm/nice_nano/nice_nano_defconfig @@ -10,6 +10,10 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y +CONFIG_ADC=y + +CONFIG_NEWLIB_LIBC=y + CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/drivers/zephyr/CMakeLists.txt b/app/drivers/zephyr/CMakeLists.txt index 8778ded..0b1d18f 100644 --- a/app/drivers/zephyr/CMakeLists.txt +++ b/app/drivers/zephyr/CMakeLists.txt @@ -5,6 +5,7 @@ if(CONFIG_ZMK_KSCAN_GPIO_DRIVER) zephyr_library_sources( kscan_gpio_matrix.c kscan_gpio_direct.c + battery_voltage_divider.c ) zephyr_library_sources_ifdef(CONFIG_EC11 ec11.c) diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c new file mode 100644 index 0000000..35fc799 --- /dev/null +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_battery_voltage_divider + +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) + +#define VBATT DT_PATH(vbatt) + +struct battery_config { + struct device *adc; + struct adc_channel_cfg acc; + struct adc_sequence as; + int16_t adc_raw; +}; + +static struct battery_config battery_config; + +static int lithium_ion_mv_to_pct(int16_t bat_mv) { + // Magic function that maps mV to this discharge graph from adafruit: https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages + return round(106.818 + (-0.032685 - 106.818) / pow(1 + pow(bat_mv/3679.35, 58.979), 0.347386)); +} + +static void battery_read(struct k_work *workd) { + struct battery_config *cfg = &battery_config; + struct adc_sequence *as = &cfg->as; + + int rc = adc_read(cfg->adc, as); + as->calibrate = false; + if (rc == 0) { + int32_t val = cfg->adc_raw; + + adc_raw_to_millivolts(adc_ref_internal(cfg->adc), cfg->acc.gain, as->resolution, &val); + + rc = val * (uint64_t)DT_PROP(VBATT, full_ohms) / DT_PROP(VBATT, output_ohms); + LOG_DBG("ADC raw %d ~ %d mV => %d mV\n", cfg->adc_raw, val, rc); + int percent = lithium_ion_mv_to_pct(rc); + LOG_DBG("Percent: %d", percent); + } else { + LOG_DBG("Failed to read ADC: %d", rc); + } +} + +K_WORK_DEFINE(battery_work, battery_read); + +static void battery_handler(struct k_timer *timer) +{ + k_work_submit(&battery_work); +} + +K_TIMER_DEFINE(battery_tick, battery_handler, NULL); + +static int battery_setup(struct device *_arg) { + struct battery_config *cfg = &battery_config; + struct adc_sequence *as = &cfg->as; + struct adc_channel_cfg *acc = &cfg->acc; + + cfg->adc = device_get_binding(DT_IO_CHANNELS_LABEL(VBATT)); + + if (cfg->adc == NULL) { + LOG_ERR("ADC %s failed to retrieve", DT_IO_CHANNELS_LABEL(VBATT)); + return -ENOENT; + } + + *as = (struct adc_sequence){ + .channels = BIT(0), + .buffer = &cfg->adc_raw, + .buffer_size = sizeof(cfg->adc_raw), + .oversampling = 4, + .calibrate = true, + }; + +#ifdef CONFIG_ADC_NRFX_SAADC + *acc = (struct adc_channel_cfg){ + .gain = ADC_GAIN_1_5, + .reference = ADC_REF_INTERNAL, + .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40), + .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + DT_IO_CHANNELS_INPUT(VBATT), + }; + + as->resolution = 12; +#else +#error Unsupported ADC +#endif + + int adc_rc = adc_channel_setup(cfg->adc, acc); + LOG_DBG("AIN%u setup returned %d", DT_IO_CHANNELS_INPUT(VBATT), adc_rc); + + if (adc_rc != 0) { + return adc_rc; + } + + k_timer_start(&battery_tick, K_NO_WAIT, K_SECONDS(5)); + + return 0; +} + +SYS_INIT(battery_setup, + APPLICATION, + CONFIG_APPLICATION_INIT_PRIORITY); + +#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ \ No newline at end of file diff --git a/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml b/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml new file mode 100644 index 0000000..f6e0642 --- /dev/null +++ b/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Battery SoC monitoring using voltage divider + +compatible: "zmk,battery-voltage-divider" + +include: voltage-divider.yaml + \ No newline at end of file -- cgit v1.2.3 From f5909f9c265ec1d88ee4fc13d45745873a2ad081 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 19 Sep 2020 19:18:03 -0500 Subject: fix(clang-format) --- app/drivers/zephyr/battery_voltage_divider.c | 117 +++++++++++++-------------- 1 file changed, 57 insertions(+), 60 deletions(-) (limited to 'app') diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 35fc799..34de6cf 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -21,95 +21,92 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define VBATT DT_PATH(vbatt) struct battery_config { - struct device *adc; - struct adc_channel_cfg acc; - struct adc_sequence as; - int16_t adc_raw; + struct device *adc; + struct adc_channel_cfg acc; + struct adc_sequence as; + int16_t adc_raw; }; static struct battery_config battery_config; static int lithium_ion_mv_to_pct(int16_t bat_mv) { - // Magic function that maps mV to this discharge graph from adafruit: https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages - return round(106.818 + (-0.032685 - 106.818) / pow(1 + pow(bat_mv/3679.35, 58.979), 0.347386)); + // Magic function that maps mV to this discharge graph from adafruit: + // https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages + return round(106.818 + + (-0.032685 - 106.818) / pow(1 + pow(bat_mv / 3679.35, 58.979), 0.347386)); } static void battery_read(struct k_work *workd) { - struct battery_config *cfg = &battery_config; - struct adc_sequence *as = &cfg->as; - - int rc = adc_read(cfg->adc, as); - as->calibrate = false; - if (rc == 0) { - int32_t val = cfg->adc_raw; - - adc_raw_to_millivolts(adc_ref_internal(cfg->adc), cfg->acc.gain, as->resolution, &val); - - rc = val * (uint64_t)DT_PROP(VBATT, full_ohms) / DT_PROP(VBATT, output_ohms); - LOG_DBG("ADC raw %d ~ %d mV => %d mV\n", cfg->adc_raw, val, rc); - int percent = lithium_ion_mv_to_pct(rc); - LOG_DBG("Percent: %d", percent); - } else { - LOG_DBG("Failed to read ADC: %d", rc); - } + struct battery_config *cfg = &battery_config; + struct adc_sequence *as = &cfg->as; + + int rc = adc_read(cfg->adc, as); + as->calibrate = false; + if (rc == 0) { + int32_t val = cfg->adc_raw; + + adc_raw_to_millivolts(adc_ref_internal(cfg->adc), cfg->acc.gain, as->resolution, &val); + + rc = val * (uint64_t)DT_PROP(VBATT, full_ohms) / DT_PROP(VBATT, output_ohms); + LOG_DBG("ADC raw %d ~ %d mV => %d mV\n", cfg->adc_raw, val, rc); + int percent = lithium_ion_mv_to_pct(rc); + LOG_DBG("Percent: %d", percent); + } else { + LOG_DBG("Failed to read ADC: %d", rc); + } } K_WORK_DEFINE(battery_work, battery_read); -static void battery_handler(struct k_timer *timer) -{ - k_work_submit(&battery_work); -} +static void battery_handler(struct k_timer *timer) { k_work_submit(&battery_work); } K_TIMER_DEFINE(battery_tick, battery_handler, NULL); static int battery_setup(struct device *_arg) { - struct battery_config *cfg = &battery_config; - struct adc_sequence *as = &cfg->as; - struct adc_channel_cfg *acc = &cfg->acc; + struct battery_config *cfg = &battery_config; + struct adc_sequence *as = &cfg->as; + struct adc_channel_cfg *acc = &cfg->acc; - cfg->adc = device_get_binding(DT_IO_CHANNELS_LABEL(VBATT)); + cfg->adc = device_get_binding(DT_IO_CHANNELS_LABEL(VBATT)); - if (cfg->adc == NULL) { - LOG_ERR("ADC %s failed to retrieve", DT_IO_CHANNELS_LABEL(VBATT)); - return -ENOENT; - } + if (cfg->adc == NULL) { + LOG_ERR("ADC %s failed to retrieve", DT_IO_CHANNELS_LABEL(VBATT)); + return -ENOENT; + } - *as = (struct adc_sequence){ - .channels = BIT(0), - .buffer = &cfg->adc_raw, - .buffer_size = sizeof(cfg->adc_raw), - .oversampling = 4, - .calibrate = true, - }; + *as = (struct adc_sequence){ + .channels = BIT(0), + .buffer = &cfg->adc_raw, + .buffer_size = sizeof(cfg->adc_raw), + .oversampling = 4, + .calibrate = true, + }; #ifdef CONFIG_ADC_NRFX_SAADC - *acc = (struct adc_channel_cfg){ - .gain = ADC_GAIN_1_5, - .reference = ADC_REF_INTERNAL, - .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40), - .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + DT_IO_CHANNELS_INPUT(VBATT), - }; - - as->resolution = 12; + *acc = (struct adc_channel_cfg){ + .gain = ADC_GAIN_1_5, + .reference = ADC_REF_INTERNAL, + .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40), + .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + DT_IO_CHANNELS_INPUT(VBATT), + }; + + as->resolution = 12; #else #error Unsupported ADC #endif - int adc_rc = adc_channel_setup(cfg->adc, acc); - LOG_DBG("AIN%u setup returned %d", DT_IO_CHANNELS_INPUT(VBATT), adc_rc); + int adc_rc = adc_channel_setup(cfg->adc, acc); + LOG_DBG("AIN%u setup returned %d", DT_IO_CHANNELS_INPUT(VBATT), adc_rc); - if (adc_rc != 0) { - return adc_rc; - } + if (adc_rc != 0) { + return adc_rc; + } - k_timer_start(&battery_tick, K_NO_WAIT, K_SECONDS(5)); + k_timer_start(&battery_tick, K_NO_WAIT, K_SECONDS(5)); - return 0; + return 0; } -SYS_INIT(battery_setup, - APPLICATION, - CONFIG_APPLICATION_INIT_PRIORITY); +SYS_INIT(battery_setup, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); #endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ \ No newline at end of file -- cgit v1.2.3 From a3d0c03726a0bc607d4daab7a90dda57d4ba6a6f Mon Sep 17 00:00:00 2001 From: David Barr Date: Wed, 30 Sep 2020 16:20:41 +0100 Subject: rename cradios to cradio --- app/.DS_Store | Bin 0 -> 8196 bytes app/boards/.DS_Store | Bin 0 -> 8196 bytes app/boards/shields/.DS_Store | Bin 0 -> 8196 bytes app/boards/shields/cradio/Kconfig.defconfig | 11 ++++ app/boards/shields/cradio/Kconfig.shield | 5 ++ app/boards/shields/cradio/cradio.dtsi | 63 +++++++++++++++++++++ app/boards/shields/cradio/cradio.keymap | 18 ++++++ app/boards/shields/cradio/cradio_left.conf | 2 + app/boards/shields/cradio/cradio_left.overlay | 11 ++++ app/boards/shields/cradio/cradio_right.conf | 2 + app/boards/shields/cradio/cradio_right.overlay | 14 +++++ app/boards/shields/cradio/default.keymap | 19 +++++++ app/boards/shields/cradios.dtsi | 67 ----------------------- app/boards/shields/cradios.keymap | 18 ------ app/boards/shields/cradios/Kconfig.defconfig | 14 ----- app/boards/shields/cradios/Kconfig.shield | 5 -- app/boards/shields/cradios/cradios.dtsi | 67 ----------------------- app/boards/shields/cradios/cradios.keymap | 18 ------ app/boards/shields/cradios/cradios_left.conf | 2 - app/boards/shields/cradios/cradios_left.overlay | 15 ----- app/boards/shields/cradios/cradios_right.conf | 2 - app/boards/shields/cradios/cradios_right.overlay | 17 ------ app/boards/shields/cradios/default.keymap | 19 ------- app/boards/shields/cradios_left.conf | 2 - app/boards/shields/cradios_left.overlay | 15 ----- app/boards/shields/cradios_right.conf | 2 - app/boards/shields/cradios_right.overlay | 17 ------ 27 files changed, 145 insertions(+), 280 deletions(-) create mode 100644 app/.DS_Store create mode 100644 app/boards/.DS_Store create mode 100644 app/boards/shields/.DS_Store create mode 100644 app/boards/shields/cradio/Kconfig.defconfig create mode 100644 app/boards/shields/cradio/Kconfig.shield create mode 100644 app/boards/shields/cradio/cradio.dtsi create mode 100644 app/boards/shields/cradio/cradio.keymap create mode 100644 app/boards/shields/cradio/cradio_left.conf create mode 100644 app/boards/shields/cradio/cradio_left.overlay create mode 100644 app/boards/shields/cradio/cradio_right.conf create mode 100644 app/boards/shields/cradio/cradio_right.overlay create mode 100644 app/boards/shields/cradio/default.keymap delete mode 100644 app/boards/shields/cradios.dtsi delete mode 100644 app/boards/shields/cradios.keymap delete mode 100644 app/boards/shields/cradios/Kconfig.defconfig delete mode 100644 app/boards/shields/cradios/Kconfig.shield delete mode 100644 app/boards/shields/cradios/cradios.dtsi delete mode 100644 app/boards/shields/cradios/cradios.keymap delete mode 100644 app/boards/shields/cradios/cradios_left.conf delete mode 100644 app/boards/shields/cradios/cradios_left.overlay delete mode 100644 app/boards/shields/cradios/cradios_right.conf delete mode 100644 app/boards/shields/cradios/cradios_right.overlay delete mode 100644 app/boards/shields/cradios/default.keymap delete mode 100644 app/boards/shields/cradios_left.conf delete mode 100644 app/boards/shields/cradios_left.overlay delete mode 100644 app/boards/shields/cradios_right.conf delete mode 100644 app/boards/shields/cradios_right.overlay (limited to 'app') diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..7b9df97 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/boards/.DS_Store b/app/boards/.DS_Store new file mode 100644 index 0000000..f1a7fab Binary files /dev/null and b/app/boards/.DS_Store differ diff --git a/app/boards/shields/.DS_Store b/app/boards/shields/.DS_Store new file mode 100644 index 0000000..242a19d Binary files /dev/null and b/app/boards/shields/.DS_Store differ diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig new file mode 100644 index 0000000..ab38e25 --- /dev/null +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -0,0 +1,11 @@ +config ZMK_KEYBOARD_NAME + default "cradio" + +# Unable to use interrupts as the same pin number is used +# across A & B controllers, and STM32F303CCT6 can't enable +# interrutps for multiple controllers for the same "line" +# for the external interrupts. +config ZMK_KSCAN_GPIO_POLLING + default y + + diff --git a/app/boards/shields/cradio/Kconfig.shield b/app/boards/shields/cradio/Kconfig.shield new file mode 100644 index 0000000..0385d23 --- /dev/null +++ b/app/boards/shields/cradio/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2020 Pete Johanson +# SPDX-License-Identifier: MIT + +config SHIELD_CRADIO + def_bool $(shields_list_contains,cradio) diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi new file mode 100644 index 0000000..19225f9 --- /dev/null +++ b/app/boards/shields/cradio/cradio.dtsi @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + #include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <34>; + rows = <1>; + map = < +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) +RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) +RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) +RC(0,15) RC(0,16) RC(0,33) RC(0,32) +>; + + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-direct"; + label = "KSCAN"; + }; + + + + + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; + }; + + }; + + &kscan0 { + input-gpios + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; +}; + + diff --git a/app/boards/shields/cradio/cradio.keymap b/app/boards/shields/cradio/cradio.keymap new file mode 100644 index 0000000..c46468d --- /dev/null +++ b/app/boards/shields/cradio/cradio.keymap @@ -0,0 +1,18 @@ +#include +#include + + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P + &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN + &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH + &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 + >; + }; + }; +}; diff --git a/app/boards/shields/cradio/cradio_left.conf b/app/boards/shields/cradio/cradio_left.conf new file mode 100644 index 0000000..1e028a7 --- /dev/null +++ b/app/boards/shields/cradio/cradio_left.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_SPLIT=y +CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y diff --git a/app/boards/shields/cradio/cradio_left.overlay b/app/boards/shields/cradio/cradio_left.overlay new file mode 100644 index 0000000..c660072 --- /dev/null +++ b/app/boards/shields/cradio/cradio_left.overlay @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ +#include "cradio.dtsi" + +&bt_unpair_combo { + + key-positions = <0 16>; +}; diff --git a/app/boards/shields/cradio/cradio_right.conf b/app/boards/shields/cradio/cradio_right.conf new file mode 100644 index 0000000..990cf7c --- /dev/null +++ b/app/boards/shields/cradio/cradio_right.conf @@ -0,0 +1,2 @@ +CONFIG_ZMK_SPLIT=y +CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y diff --git a/app/boards/shields/cradio/cradio_right.overlay b/app/boards/shields/cradio/cradio_right.overlay new file mode 100644 index 0000000..3469199 --- /dev/null +++ b/app/boards/shields/cradio/cradio_right.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ +#include "cradio.dtsi" + +&default_transform { + col-offset = <17>; +}; + +&bt_unpair_combo { + key-positions = <21 32>; +}; diff --git a/app/boards/shields/cradio/default.keymap b/app/boards/shields/cradio/default.keymap new file mode 100644 index 0000000..0821005 --- /dev/null +++ b/app/boards/shields/cradio/default.keymap @@ -0,0 +1,19 @@ +#include +#include + + +/ { + keymap0: keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P + &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN + &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH + &kp DEL &kp RET &kp RET &kp SPC + + >; + }; + }; +}; diff --git a/app/boards/shields/cradios.dtsi b/app/boards/shields/cradios.dtsi deleted file mode 100644 index 68d1fc5..0000000 --- a/app/boards/shields/cradios.dtsi +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2020 Pete Johanson - * - * SPDX-License-Identifier: MIT - */ - #include - -/ { - chosen { - zmk,kscan = &kscan0; - zmk,matrix_transform = &default_transform; - }; - - default_transform: keymap_transform_0 { - compatible = "zmk,matrix-transform"; - columns = <34>; - rows = <1>; - map = < -RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) -RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) -RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) -RC(0,15) RC(0,16) RC(0,33) RC(0,32) ->; - - - }; - - kscan0: kscan { - compatible = "zmk,kscan-gpio-direct"; - label = "KSCAN"; - }; - - - - - bt_unpair_combo: bt_unpair_combo { - compatible = "zmk,bt-unpair-combo"; - }; - - - - }; - - - &kscan0 { - input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - ; -}; - - diff --git a/app/boards/shields/cradios.keymap b/app/boards/shields/cradios.keymap deleted file mode 100644 index c46468d..0000000 --- a/app/boards/shields/cradios.keymap +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - - -/ { - keymap { - compatible = "zmk,keymap"; - - default_layer { - bindings = < - &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P - &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN - &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 - >; - }; - }; -}; diff --git a/app/boards/shields/cradios/Kconfig.defconfig b/app/boards/shields/cradios/Kconfig.defconfig deleted file mode 100644 index 5b9ca9a..0000000 --- a/app/boards/shields/cradios/Kconfig.defconfig +++ /dev/null @@ -1,14 +0,0 @@ - - - -config ZMK_KEYBOARD_NAME - default "cradios" - -# Unable to use interrupts as the same pin number is used -# across A & B controllers, and STM32F303CCT6 can't enable -# interrutps for multiple controllers for the same "line" -# for the external interrupts. -config ZMK_KSCAN_GPIO_POLLING - default y - - diff --git a/app/boards/shields/cradios/Kconfig.shield b/app/boards/shields/cradios/Kconfig.shield deleted file mode 100644 index 844d433..0000000 --- a/app/boards/shields/cradios/Kconfig.shield +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright (c) 2020 Pete Johanson -# SPDX-License-Identifier: MIT - -config SHIELD_CRADIOS - def_bool $(shields_list_contains,cradios) diff --git a/app/boards/shields/cradios/cradios.dtsi b/app/boards/shields/cradios/cradios.dtsi deleted file mode 100644 index 68d1fc5..0000000 --- a/app/boards/shields/cradios/cradios.dtsi +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2020 Pete Johanson - * - * SPDX-License-Identifier: MIT - */ - #include - -/ { - chosen { - zmk,kscan = &kscan0; - zmk,matrix_transform = &default_transform; - }; - - default_transform: keymap_transform_0 { - compatible = "zmk,matrix-transform"; - columns = <34>; - rows = <1>; - map = < -RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) -RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) -RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) -RC(0,15) RC(0,16) RC(0,33) RC(0,32) ->; - - - }; - - kscan0: kscan { - compatible = "zmk,kscan-gpio-direct"; - label = "KSCAN"; - }; - - - - - bt_unpair_combo: bt_unpair_combo { - compatible = "zmk,bt-unpair-combo"; - }; - - - - }; - - - &kscan0 { - input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_a 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - ; -}; - - diff --git a/app/boards/shields/cradios/cradios.keymap b/app/boards/shields/cradios/cradios.keymap deleted file mode 100644 index c46468d..0000000 --- a/app/boards/shields/cradios/cradios.keymap +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - - -/ { - keymap { - compatible = "zmk,keymap"; - - default_layer { - bindings = < - &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P - &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN - &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 - >; - }; - }; -}; diff --git a/app/boards/shields/cradios/cradios_left.conf b/app/boards/shields/cradios/cradios_left.conf deleted file mode 100644 index 1e028a7..0000000 --- a/app/boards/shields/cradios/cradios_left.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y diff --git a/app/boards/shields/cradios/cradios_left.overlay b/app/boards/shields/cradios/cradios_left.overlay deleted file mode 100644 index b0bdc6f..0000000 --- a/app/boards/shields/cradios/cradios_left.overlay +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2020 Pete Johanson - * - * SPDX-License-Identifier: MIT - */ -#include "cradios.dtsi" - - - - - - -&bt_unpair_combo { - key-positions = <0 16>; -}; diff --git a/app/boards/shields/cradios/cradios_right.conf b/app/boards/shields/cradios/cradios_right.conf deleted file mode 100644 index 990cf7c..0000000 --- a/app/boards/shields/cradios/cradios_right.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y diff --git a/app/boards/shields/cradios/cradios_right.overlay b/app/boards/shields/cradios/cradios_right.overlay deleted file mode 100644 index ef920ac..0000000 --- a/app/boards/shields/cradios/cradios_right.overlay +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2020 Pete Johanson - * - * SPDX-License-Identifier: MIT - */ -#include "cradios.dtsi" - -&default_transform { - col-offset = <17>; -}; - - - - -&bt_unpair_combo { - key-positions = <21 32>; -}; diff --git a/app/boards/shields/cradios/default.keymap b/app/boards/shields/cradios/default.keymap deleted file mode 100644 index 0821005..0000000 --- a/app/boards/shields/cradios/default.keymap +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - - -/ { - keymap0: keymap { - compatible = "zmk,keymap"; - - default_layer { - bindings = < - &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P - &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN - &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp DEL &kp RET &kp RET &kp SPC - - >; - }; - }; -}; diff --git a/app/boards/shields/cradios_left.conf b/app/boards/shields/cradios_left.conf deleted file mode 100644 index 1e028a7..0000000 --- a/app/boards/shields/cradios_left.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y diff --git a/app/boards/shields/cradios_left.overlay b/app/boards/shields/cradios_left.overlay deleted file mode 100644 index b0bdc6f..0000000 --- a/app/boards/shields/cradios_left.overlay +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2020 Pete Johanson - * - * SPDX-License-Identifier: MIT - */ -#include "cradios.dtsi" - - - - - - -&bt_unpair_combo { - key-positions = <0 16>; -}; diff --git a/app/boards/shields/cradios_right.conf b/app/boards/shields/cradios_right.conf deleted file mode 100644 index 990cf7c..0000000 --- a/app/boards/shields/cradios_right.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ZMK_SPLIT=y -CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y diff --git a/app/boards/shields/cradios_right.overlay b/app/boards/shields/cradios_right.overlay deleted file mode 100644 index ef920ac..0000000 --- a/app/boards/shields/cradios_right.overlay +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2020 Pete Johanson - * - * SPDX-License-Identifier: MIT - */ -#include "cradios.dtsi" - -&default_transform { - col-offset = <17>; -}; - - - - -&bt_unpair_combo { - key-positions = <21 32>; -}; -- cgit v1.2.3 From 17bee0223aa90037896d3a83d08fe01db1cab97b Mon Sep 17 00:00:00 2001 From: David Barr Date: Wed, 30 Sep 2020 17:12:39 +0100 Subject: remove ds_store files --- app/.DS_Store | Bin 8196 -> 0 bytes app/boards/.DS_Store | Bin 8196 -> 0 bytes app/boards/shields/.DS_Store | Bin 8196 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/.DS_Store delete mode 100644 app/boards/.DS_Store delete mode 100644 app/boards/shields/.DS_Store (limited to 'app') diff --git a/app/.DS_Store b/app/.DS_Store deleted file mode 100644 index 7b9df97..0000000 Binary files a/app/.DS_Store and /dev/null differ diff --git a/app/boards/.DS_Store b/app/boards/.DS_Store deleted file mode 100644 index f1a7fab..0000000 Binary files a/app/boards/.DS_Store and /dev/null differ diff --git a/app/boards/shields/.DS_Store b/app/boards/shields/.DS_Store deleted file mode 100644 index 242a19d..0000000 Binary files a/app/boards/shields/.DS_Store and /dev/null differ -- cgit v1.2.3 From 16df1522c282343c3350402360db918a9a1b66e5 Mon Sep 17 00:00:00 2001 From: Mubeen Khan Date: Wed, 30 Sep 2020 21:35:51 -0500 Subject: Add TG4X rev 2.1 shield --- app/boards/shields/tg4x/Kconfig.defconfig | 9 +++++ app/boards/shields/tg4x/Kconfig.shield | 5 +++ app/boards/shields/tg4x/tg4x.keymap | 58 +++++++++++++++++++++++++++++++ app/boards/shields/tg4x/tg4x.overlay | 56 +++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 app/boards/shields/tg4x/Kconfig.defconfig create mode 100644 app/boards/shields/tg4x/Kconfig.shield create mode 100644 app/boards/shields/tg4x/tg4x.keymap create mode 100644 app/boards/shields/tg4x/tg4x.overlay (limited to 'app') diff --git a/app/boards/shields/tg4x/Kconfig.defconfig b/app/boards/shields/tg4x/Kconfig.defconfig new file mode 100644 index 0000000..ca9fa2c --- /dev/null +++ b/app/boards/shields/tg4x/Kconfig.defconfig @@ -0,0 +1,9 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +if SHIELD_TG4X + +config ZMK_KEYBOARD_NAME + default "TG4X" + +endif \ No newline at end of file diff --git a/app/boards/shields/tg4x/Kconfig.shield b/app/boards/shields/tg4x/Kconfig.shield new file mode 100644 index 0000000..7e98b71 --- /dev/null +++ b/app/boards/shields/tg4x/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +config SHIELD_TG4X + def_bool $(shields_list_contains,tg4x) diff --git a/app/boards/shields/tg4x/tg4x.keymap b/app/boards/shields/tg4x/tg4x.keymap new file mode 100644 index 0000000..64e98bb --- /dev/null +++ b/app/boards/shields/tg4x/tg4x.keymap @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +#define DEFAULT 0 +#define LOWER 1 +#define RAISE 2 + +/ { + behaviors { + hm: homerow_mods { + compatible = "zmk,behavior-hold-tap"; + label = "homerow mods"; + #binding-cells = <2>; + tapping_term_ms = <225>; + flavor = "tap-preferred"; + bindings = <&kp>, <&kp>; + }; + }; +}; + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp GRAV &kp Q &kp W &kp F &kp P &kp B &kp J &kp L &kp U &kp Y &kp SCLN &kp BKSP + &kp TAB &hm LGUI A &hm LALT R &hm LCTL S &hm LSFT T &kp G &kp M &hm RSFT N &hm RCTL E &hm RALT I &hm RGUI O &kp RET + &kp LSFT &kp Z &kp X &kp C &kp D &kp V &kp K &kp H &kp CMMA &kp DOT &kp FSLH &kp QUOT + &kp LCTL &kp LALT &kp LGUI < 1 BKSP < 2 SPC &kp LARW &kp DARW &kp UARW &kp RARW + >; + }; + lower { + bindings = < + &kp ESC &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 PRSC + &kp DEL &trans &kp VOLU &trans &trans &trans &trans &kp LARW &kp DARW &kp UARW &kp RARW &trans + &trans &trans &kp VOLD &trans &trans &trans &trans &trans &trans &bt BT_PRV &bt BT_NXT &bt BT_CLR + &bootloader &reset &trans &trans &trans &trans &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 + >; + }; + + raise { + 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 PRSC + &kp DEL &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp MINUS &kp EQL &kp LBKT &kp RBKT &kp BSLH + &trans &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 &kp TILD &kp HOME &kp PGUP &kp PGDN &kp END + &trans &trans &trans &trans &trans &trans &kp M_NEXT &kp M_VOLD &kp M_VOLU &kp M_PLAY + >; + }; + }; +}; \ No newline at end of file diff --git a/app/boards/shields/tg4x/tg4x.overlay b/app/boards/shields/tg4x/tg4x.overlay new file mode 100644 index 0000000..acab2e3 --- /dev/null +++ b/app/boards/shields/tg4x/tg4x.overlay @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 Pete Johanson, Richard Jones + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <7>; + rows = <8>; + map = < + RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,5) + RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(5,0) RC(5,1) RC(5,2) RC(5,3) RC(5,4) + RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(6,0) RC(6,1) RC(6,2) RC(6,3) RC(6,4) + RC(3,0) RC(3,1) RC(3,2) RC(3,4) RC(3,5) RC(7,1) RC(7,2) RC(7,3) RC(7,4) + >; + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + + col-gpios + = <&pro_micro_d 1 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 14 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 15 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 0 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 1 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 2 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 3 GPIO_ACTIVE_HIGH> + ; + + row-gpios + = <&pro_micro_a 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 8 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + + }; + +}; + -- cgit v1.2.3 From 38a418a1d16707d721d85900c0c7c637cd1795a3 Mon Sep 17 00:00:00 2001 From: David Barr Date: Fri, 2 Oct 2020 14:16:59 +0100 Subject: updates as per PR changes (i hope) --- app/boards/shields/cradio/Kconfig.defconfig | 7 +++---- app/boards/shields/cradio/Kconfig.shield | 2 +- app/boards/shields/cradio/cradio.dtsi | 23 ++++++++++------------- app/boards/shields/cradio/cradio_left.conf | 3 +++ app/boards/shields/cradio/cradio_left.overlay | 7 +------ app/boards/shields/cradio/cradio_right.conf | 3 +++ app/boards/shields/cradio/cradio_right.overlay | 3 ++- 7 files changed, 23 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig index ab38e25..46799b9 100644 --- a/app/boards/shields/cradio/Kconfig.defconfig +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -1,10 +1,9 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + config ZMK_KEYBOARD_NAME default "cradio" -# Unable to use interrupts as the same pin number is used -# across A & B controllers, and STM32F303CCT6 can't enable -# interrutps for multiple controllers for the same "line" -# for the external interrupts. config ZMK_KSCAN_GPIO_POLLING default y diff --git a/app/boards/shields/cradio/Kconfig.shield b/app/boards/shields/cradio/Kconfig.shield index 0385d23..71a439e 100644 --- a/app/boards/shields/cradio/Kconfig.shield +++ b/app/boards/shields/cradio/Kconfig.shield @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Pete Johanson +# Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT config SHIELD_CRADIO diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index 19225f9..582f58a 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -1,8 +1,9 @@ /* * Copyright (c) 2020 Pete Johanson * - * SPDX-License-Identifier: MIT + * Copyright (c) 2020 The ZMK Contributors */ + #include / { @@ -16,31 +17,27 @@ columns = <34>; rows = <1>; map = < -RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) -RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) -RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) -RC(0,15) RC(0,16) RC(0,33) RC(0,32) ->; + RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) + RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) + RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) + RC(0,15) RC(0,16) RC(0,33) RC(0,32) + >; - }; - kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; label = "KSCAN"; }; - - - bt_unpair_combo: bt_unpair_combo { compatible = "zmk,bt-unpair-combo"; }; - }; + }; + }; &kscan0 { input-gpios - = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/cradio/cradio_left.conf b/app/boards/shields/cradio/cradio_left.conf index 1e028a7..405f04d 100644 --- a/app/boards/shields/cradio/cradio_left.conf +++ b/app/boards/shields/cradio/cradio_left.conf @@ -1,2 +1,5 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + CONFIG_ZMK_SPLIT=y CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y diff --git a/app/boards/shields/cradio/cradio_left.overlay b/app/boards/shields/cradio/cradio_left.overlay index c660072..6caf8e3 100644 --- a/app/boards/shields/cradio/cradio_left.overlay +++ b/app/boards/shields/cradio/cradio_left.overlay @@ -1,11 +1,6 @@ /* * Copyright (c) 2020 Pete Johanson * - * SPDX-License-Identifier: MIT + * Copyright (c) 2020 The ZMK Contributors */ -#include "cradio.dtsi" -&bt_unpair_combo { - - key-positions = <0 16>; -}; diff --git a/app/boards/shields/cradio/cradio_right.conf b/app/boards/shields/cradio/cradio_right.conf index 990cf7c..bd2c93b 100644 --- a/app/boards/shields/cradio/cradio_right.conf +++ b/app/boards/shields/cradio/cradio_right.conf @@ -1,2 +1,5 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + CONFIG_ZMK_SPLIT=y CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL=y diff --git a/app/boards/shields/cradio/cradio_right.overlay b/app/boards/shields/cradio/cradio_right.overlay index 3469199..09efc53 100644 --- a/app/boards/shields/cradio/cradio_right.overlay +++ b/app/boards/shields/cradio/cradio_right.overlay @@ -1,8 +1,9 @@ /* * Copyright (c) 2020 Pete Johanson * - * SPDX-License-Identifier: MIT + * Copyright (c) 2020 The ZMK Contributors */ + #include "cradio.dtsi" &default_transform { -- cgit v1.2.3 From 260044ae5e8dfc531ed98d08d0a3c9b9328e2ffe Mon Sep 17 00:00:00 2001 From: David Barr Date: Fri, 2 Oct 2020 14:17:35 +0100 Subject: Delete default.keymap --- app/boards/shields/cradio/default.keymap | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 app/boards/shields/cradio/default.keymap (limited to 'app') diff --git a/app/boards/shields/cradio/default.keymap b/app/boards/shields/cradio/default.keymap deleted file mode 100644 index 0821005..0000000 --- a/app/boards/shields/cradio/default.keymap +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - - -/ { - keymap0: keymap { - compatible = "zmk,keymap"; - - default_layer { - bindings = < - &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P - &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN - &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp DEL &kp RET &kp RET &kp SPC - - >; - }; - }; -}; -- cgit v1.2.3 From d5d8d79a76a9fbe65981d4f5455097e5258d1564 Mon Sep 17 00:00:00 2001 From: David Barr Date: Wed, 7 Oct 2020 16:23:59 +0100 Subject: Update cradio_right.overlay --- app/boards/shields/cradio/cradio_right.overlay | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio_right.overlay b/app/boards/shields/cradio/cradio_right.overlay index 09efc53..232d7d4 100644 --- a/app/boards/shields/cradio/cradio_right.overlay +++ b/app/boards/shields/cradio/cradio_right.overlay @@ -9,7 +9,3 @@ &default_transform { col-offset = <17>; }; - -&bt_unpair_combo { - key-positions = <21 32>; -}; -- cgit v1.2.3 From 426b25892f2fd6c569b9d0b983fd7fbaff6c9d93 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:09:35 +0100 Subject: rename gpio to direct polling --- app/boards/shields/cradio/Kconfig.defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig index 46799b9..43509a4 100644 --- a/app/boards/shields/cradio/Kconfig.defconfig +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -4,7 +4,7 @@ config ZMK_KEYBOARD_NAME default "cradio" -config ZMK_KSCAN_GPIO_POLLING +config ZMK_KSCAN_DIRECT_POLLING default y -- cgit v1.2.3 From 7d582b6b8e16cf64cadf27dacba050dfb88d543a Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:11:01 +0100 Subject: remove dupe copyright --- app/boards/shields/cradio/cradio_left.overlay | 2 -- 1 file changed, 2 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio_left.overlay b/app/boards/shields/cradio/cradio_left.overlay index 6caf8e3..61fc3bd 100644 --- a/app/boards/shields/cradio/cradio_left.overlay +++ b/app/boards/shields/cradio/cradio_left.overlay @@ -1,6 +1,4 @@ /* - * Copyright (c) 2020 Pete Johanson - * * Copyright (c) 2020 The ZMK Contributors */ -- cgit v1.2.3 From 95b94009a9b3b9b953220ab48f0276fc5a083499 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:11:40 +0100 Subject: remove dupe copyright --- app/boards/shields/cradio/cradio_right.overlay | 2 -- 1 file changed, 2 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio_right.overlay b/app/boards/shields/cradio/cradio_right.overlay index 232d7d4..1c06006 100644 --- a/app/boards/shields/cradio/cradio_right.overlay +++ b/app/boards/shields/cradio/cradio_right.overlay @@ -1,6 +1,4 @@ /* - * Copyright (c) 2020 Pete Johanson - * * Copyright (c) 2020 The ZMK Contributors */ -- cgit v1.2.3 From 24e73f68610a9a4a1497c6e7737b615d6181836b Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:12:04 +0100 Subject: Update cradio.dtsi --- app/boards/shields/cradio/cradio.dtsi | 2 -- 1 file changed, 2 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index 582f58a..d32d2ed 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -1,6 +1,4 @@ /* - * Copyright (c) 2020 Pete Johanson - * * Copyright (c) 2020 The ZMK Contributors */ -- cgit v1.2.3 From a3cdab9e9f9940a854ec68e60622443ae376183e Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:14:46 +0100 Subject: update header --- app/boards/shields/cradio/cradio.keymap | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio.keymap b/app/boards/shields/cradio/cradio.keymap index c46468d..1d11cfd 100644 --- a/app/boards/shields/cradio/cradio.keymap +++ b/app/boards/shields/cradio/cradio.keymap @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + + #include #include -- cgit v1.2.3 From 55c1f51b3147490d994d846907e9fd99039e4e8b Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:16:08 +0100 Subject: update header --- app/boards/shields/cradio/cradio_right.overlay | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio_right.overlay b/app/boards/shields/cradio/cradio_right.overlay index 1c06006..fea59c2 100644 --- a/app/boards/shields/cradio/cradio_right.overlay +++ b/app/boards/shields/cradio/cradio_right.overlay @@ -1,5 +1,7 @@ /* - * Copyright (c) 2020 The ZMK Contributors + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT */ #include "cradio.dtsi" -- cgit v1.2.3 From eeac54e9a4f24e5a455cbc52ba0930a10d2bcfc9 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:16:28 +0100 Subject: Update cradio_left.overlay --- app/boards/shields/cradio/cradio_left.overlay | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio_left.overlay b/app/boards/shields/cradio/cradio_left.overlay index 61fc3bd..cac9575 100644 --- a/app/boards/shields/cradio/cradio_left.overlay +++ b/app/boards/shields/cradio/cradio_left.overlay @@ -1,4 +1,5 @@ /* - * Copyright (c) 2020 The ZMK Contributors + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT */ - -- cgit v1.2.3 From a629aa0b42caf6a86152ef5eedc6160b90200627 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:17:53 +0100 Subject: Update Kconfig.defconfig --- app/boards/shields/cradio/Kconfig.defconfig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig index 43509a4..1043c7e 100644 --- a/app/boards/shields/cradio/Kconfig.defconfig +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -1,8 +1,20 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT +if SHIELD_CRADIO_LEFT + config ZMK_KEYBOARD_NAME - default "cradio" + default "Cradio Left" + +endif + + +if SHIELD_CRADIO_RIGHT + +config ZMK_KEYBOARD_NAME + default "Cradio Right" + +endif config ZMK_KSCAN_DIRECT_POLLING default y -- cgit v1.2.3 From ad77df59897ae973824377373665a4fdc6542d3c Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:20:22 +0100 Subject: capital C --- app/boards/shields/cradio/Kconfig.defconfig | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig index 1043c7e..5f8bb80 100644 --- a/app/boards/shields/cradio/Kconfig.defconfig +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -1,20 +1,8 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT -if SHIELD_CRADIO_LEFT - config ZMK_KEYBOARD_NAME - default "Cradio Left" - -endif - - -if SHIELD_CRADIO_RIGHT - -config ZMK_KEYBOARD_NAME - default "Cradio Right" - -endif + default "Cradio" config ZMK_KSCAN_DIRECT_POLLING default y -- cgit v1.2.3 From 2b09174ec1a171e043018cbe28e47d86025ce1de Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 8 Oct 2020 11:22:34 +0100 Subject: update header again based on corne --- app/boards/shields/cradio/cradio.dtsi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index d32d2ed..ab22e92 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -1,5 +1,7 @@ /* - * Copyright (c) 2020 The ZMK Contributors + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT */ #include -- cgit v1.2.3 From 01b0bad7a246ac9aef7aa170895dab5ae4790525 Mon Sep 17 00:00:00 2001 From: David Barr Date: Fri, 9 Oct 2020 17:05:09 +0100 Subject: update headers, spruce up keymap, streamline dtsi. --- app/boards/shields/cradio/Kconfig.defconfig | 2 +- app/boards/shields/cradio/cradio.dtsi | 23 ++++++-------------- app/boards/shields/cradio/cradio.keymap | 30 ++++++++++++++++++++------ app/boards/shields/cradio/cradio_left.overlay | 4 +++- app/boards/shields/cradio/cradio_right.overlay | 2 +- 5 files changed, 36 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig index 5f8bb80..43509a4 100644 --- a/app/boards/shields/cradio/Kconfig.defconfig +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: MIT config ZMK_KEYBOARD_NAME - default "Cradio" + default "cradio" config ZMK_KSCAN_DIRECT_POLLING default y diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index ab22e92..1f2603c 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -9,9 +9,9 @@ / { chosen { zmk,kscan = &kscan0; - zmk,matrix_transform = &default_transform; + //zmk,matrix_transform = &default_transform; }; - + default_transform: keymap_transform_0 { compatible = "zmk,matrix-transform"; columns = <34>; @@ -19,23 +19,13 @@ map = < RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,21) RC(0,20) RC(0,19) RC(0,18) RC(0,17) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,26) RC(0,25) RC(0,24) RC(0,23) RC(0,22) - RC(0,10)RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) + RC(0,10) RC(0,11) RC(0,12) RC(0,13) RC(0,14) RC(0,31) RC(0,30) RC(0,29) RC(0,28) RC(0,27) RC(0,15) RC(0,16) RC(0,33) RC(0,32) >; kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; label = "KSCAN"; - }; - - bt_unpair_combo: bt_unpair_combo { - compatible = "zmk,bt-unpair-combo"; - }; - - }; - }; - - &kscan0 { input-gpios = <&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> @@ -55,6 +45,7 @@ , <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> ; -}; - - + }; + }; + }; + diff --git a/app/boards/shields/cradio/cradio.keymap b/app/boards/shields/cradio/cradio.keymap index 1d11cfd..487f6dc 100644 --- a/app/boards/shields/cradio/cradio.keymap +++ b/app/boards/shields/cradio/cradio.keymap @@ -3,23 +3,41 @@ * * SPDX-License-Identifier: MIT */ - - + #include #include +#include / { keymap { compatible = "zmk,keymap"; - - default_layer { + + default_layer { bindings = < &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH - &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 - >; + &mo 1 &kp LCTL &kp SPC &mo 2 + >; }; + upper_layer { + bindings = < + &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 + &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &kp H &kp J &kp K &kp L &kp SCLN + &kp LSFT &trans &trans &trans &trans &trans &trans &trans &trans &trans + &mo 1 &kp LCTL &kp SPC &mo 2 + >; + }; + + lower_layer { + bindings = < + &kp BANG &kp ATSN &kp HASH &kp CURU &kp PRCT &kp CRRT &kp AMPS &kp KMLT &kp LPRN &kp RPRN + &trans &trans &trans &trans &trans &kp MINUS &kp EQL &kp LBKT &kp RBKT &kp PIPE + &trans &trans &trans &trans &trans &trans &trans &trans &kp BSLH &kp TILD + &mo 1 &kp LCTL &kp SPC &mo 2 + >; + }; + }; }; diff --git a/app/boards/shields/cradio/cradio_left.overlay b/app/boards/shields/cradio/cradio_left.overlay index cac9575..6a3704a 100644 --- a/app/boards/shields/cradio/cradio_left.overlay +++ b/app/boards/shields/cradio/cradio_left.overlay @@ -1,5 +1,7 @@ /* - * Copyright (c) 2020 Pete Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ + +#include "cradio.dtsi" diff --git a/app/boards/shields/cradio/cradio_right.overlay b/app/boards/shields/cradio/cradio_right.overlay index fea59c2..01aa1ab 100644 --- a/app/boards/shields/cradio/cradio_right.overlay +++ b/app/boards/shields/cradio/cradio_right.overlay @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Pete Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ -- cgit v1.2.3 From 7fc7a351170fb2017cb40e8de79b4535a936a6f6 Mon Sep 17 00:00:00 2001 From: Mubeen Khan Date: Sat, 10 Oct 2020 16:51:17 -0500 Subject: Revised keymap to Qwerty --- app/boards/shields/tg4x/tg4x.keymap | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/boards/shields/tg4x/tg4x.keymap b/app/boards/shields/tg4x/tg4x.keymap index 64e98bb..bee5c87 100644 --- a/app/boards/shields/tg4x/tg4x.keymap +++ b/app/boards/shields/tg4x/tg4x.keymap @@ -31,27 +31,27 @@ default_layer { bindings = < - &kp GRAV &kp Q &kp W &kp F &kp P &kp B &kp J &kp L &kp U &kp Y &kp SCLN &kp BKSP - &kp TAB &hm LGUI A &hm LALT R &hm LCTL S &hm LSFT T &kp G &kp M &hm RSFT N &hm RCTL E &hm RALT I &hm RGUI O &kp RET - &kp LSFT &kp Z &kp X &kp C &kp D &kp V &kp K &kp H &kp CMMA &kp DOT &kp FSLH &kp QUOT - &kp LCTL &kp LALT &kp LGUI < 1 BKSP < 2 SPC &kp LARW &kp DARW &kp UARW &kp RARW + &kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BKSP + &kp TAB &hm LGUI A &hm LALT S &hm LCTL D &hm LSFT F &kp G &kp H &hm RSFT J &hm RCTL K &hm RALT L &hm RGUI SCLN &kp RET + &kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp QUOT + &kp LCTL &kp LALT &kp LGUI < 1 BKSP < 2 SPC &kp LARW &kp DARW &kp UARW &kp RARW >; }; lower { bindings = < - &kp ESC &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 PRSC - &kp DEL &trans &kp VOLU &trans &trans &trans &trans &kp LARW &kp DARW &kp UARW &kp RARW &trans - &trans &trans &kp VOLD &trans &trans &trans &trans &trans &trans &bt BT_PRV &bt BT_NXT &bt BT_CLR - &bootloader &reset &trans &trans &trans &trans &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 + &kp GRAV &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 PRSC + &kp DEL &trans &kp VOLU &trans &trans &trans &trans &kp LARW &kp DARW &kp UARW &kp RARW &trans + &trans &trans &kp VOLD &trans &trans &trans &trans &trans &trans &bt BT_PRV &bt BT_NXT &bt BT_CLR + &bootloader &reset &trans &trans &trans &trans &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 >; }; raise { 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 PRSC - &kp DEL &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp MINUS &kp EQL &kp LBKT &kp RBKT &kp BSLH - &trans &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 &kp TILD &kp HOME &kp PGUP &kp PGDN &kp END - &trans &trans &trans &trans &trans &trans &kp M_NEXT &kp M_VOLD &kp M_VOLU &kp M_PLAY + &kp GRAV &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 PRSC + &kp DEL &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp MINUS &kp EQL &kp LBKT &kp RBKT &kp BSLH + &trans &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 &kp TILD &kp HOME &kp PGUP &kp PGDN &kp END + &trans &trans &trans &trans &trans &trans &kp M_NEXT &kp M_VOLD &kp M_VOLU &kp M_PLAY >; }; }; -- cgit v1.2.3 From 78cb6c8b2115b5eebeddc03d7d8ecff6ba2574a7 Mon Sep 17 00:00:00 2001 From: Nuxiom <61762260+nuxiom@users.noreply.github.com> Date: Sun, 11 Oct 2020 16:57:26 +1100 Subject: Fix kscan_gpio_irq_callback_handler_##n conditional macro --- app/drivers/zephyr/kscan_gpio_matrix.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/drivers/zephyr/kscan_gpio_matrix.c b/app/drivers/zephyr/kscan_gpio_matrix.c index a0b22e4..ea07ee8 100644 --- a/app/drivers/zephyr/kscan_gpio_matrix.c +++ b/app/drivers/zephyr/kscan_gpio_matrix.c @@ -181,19 +181,19 @@ static int kscan_gpio_config_interrupts(struct device **devices, struct kscan_gpio_data_##n *data = CONTAINER_OF(work, struct kscan_gpio_data_##n, work); \ kscan_gpio_read_##n(data->dev); \ } \ - COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, (), \ - (static void kscan_gpio_irq_callback_handler_##n( \ - struct device *dev, struct gpio_callback *cb, gpio_port_pins_t pin) { \ - struct kscan_gpio_irq_callback_##n *data = \ - CONTAINER_OF(cb, struct kscan_gpio_irq_callback_##n, callback); \ - kscan_gpio_disable_interrupts_##n(data->dev); \ - COND_CODE_0(DT_INST_PROP(n, debounce_period), \ - ({ k_work_submit(data->work); }), ({ \ - k_delayed_work_cancel(data->work); \ - k_delayed_work_submit( \ - data->work, K_MSEC(DT_INST_PROP(n, debounce_period))); \ - })) \ - })) \ + static void kscan_gpio_irq_callback_handler_##n( \ + struct device *dev, struct gpio_callback *cb, gpio_port_pins_t pin) { \ + struct kscan_gpio_irq_callback_##n *data = \ + CONTAINER_OF(cb, struct kscan_gpio_irq_callback_##n, callback); \ + COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, (), \ + (kscan_gpio_disable_interrupts_##n(data->dev);)) \ + COND_CODE_0(DT_INST_PROP(n, debounce_period), \ + ({ k_work_submit(data->work); }), ({ \ + k_delayed_work_cancel(data->work); \ + k_delayed_work_submit( \ + data->work, K_MSEC(DT_INST_PROP(n, debounce_period))); \ + })) \ + } \ \ static struct kscan_gpio_data_##n kscan_gpio_data_##n = { \ .rows = {[INST_MATRIX_ROWS(n) - 1] = NULL}, .cols = {[INST_MATRIX_COLS(n) - 1] = NULL}}; \ -- cgit v1.2.3 From 1c0c02e09773413752e5f166a30178073c570349 Mon Sep 17 00:00:00 2001 From: Nuxiom <61762260+nuxiom@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:51:06 +1100 Subject: Reformatted according to clang-format lint --- app/drivers/zephyr/kscan_gpio_matrix.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/drivers/zephyr/kscan_gpio_matrix.c b/app/drivers/zephyr/kscan_gpio_matrix.c index ea07ee8..ec4fb39 100644 --- a/app/drivers/zephyr/kscan_gpio_matrix.c +++ b/app/drivers/zephyr/kscan_gpio_matrix.c @@ -181,17 +181,16 @@ static int kscan_gpio_config_interrupts(struct device **devices, struct kscan_gpio_data_##n *data = CONTAINER_OF(work, struct kscan_gpio_data_##n, work); \ kscan_gpio_read_##n(data->dev); \ } \ - static void kscan_gpio_irq_callback_handler_##n( \ - struct device *dev, struct gpio_callback *cb, gpio_port_pins_t pin) { \ + static void kscan_gpio_irq_callback_handler_##n(struct device *dev, struct gpio_callback *cb, \ + gpio_port_pins_t pin) { \ struct kscan_gpio_irq_callback_##n *data = \ CONTAINER_OF(cb, struct kscan_gpio_irq_callback_##n, callback); \ COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, (), \ (kscan_gpio_disable_interrupts_##n(data->dev);)) \ - COND_CODE_0(DT_INST_PROP(n, debounce_period), \ - ({ k_work_submit(data->work); }), ({ \ + COND_CODE_0(DT_INST_PROP(n, debounce_period), ({ k_work_submit(data->work); }), ({ \ k_delayed_work_cancel(data->work); \ - k_delayed_work_submit( \ - data->work, K_MSEC(DT_INST_PROP(n, debounce_period))); \ + k_delayed_work_submit(data->work, \ + K_MSEC(DT_INST_PROP(n, debounce_period))); \ })) \ } \ \ -- cgit v1.2.3 From 7798c974f697afb43d13cf8692802caf87210b02 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 11 Oct 2020 14:58:24 -0500 Subject: fix: don't leak bt_conn refs bt_conn_lookup_addr_le() gives us a new reference that must be released with bt_conn_unref() --- app/src/hog.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/hog.c b/app/src/hog.c index 11349ac..bcd652d 100644 --- a/app/src/hog.c +++ b/app/src/hog.c @@ -164,8 +164,10 @@ int zmk_hog_send_keypad_report(struct zmk_hid_keypad_report_body *report) { LOG_DBG("Sending to NULL? %s", conn == NULL ? "yes" : "no"); - return bt_gatt_notify(conn, &hog_svc.attrs[5], report, - sizeof(struct zmk_hid_keypad_report_body)); + int err = + bt_gatt_notify(conn, &hog_svc.attrs[5], report, sizeof(struct zmk_hid_keypad_report_body)); + bt_conn_unref(conn); + return err; }; int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report) { @@ -174,6 +176,8 @@ int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report) { return -ENOTCONN; } - return bt_gatt_notify(conn, &hog_svc.attrs[10], report, - sizeof(struct zmk_hid_consumer_report_body)); + int err = bt_gatt_notify(conn, &hog_svc.attrs[10], report, + sizeof(struct zmk_hid_consumer_report_body)); + bt_conn_unref(conn); + return err; }; -- cgit v1.2.3 From b5e1c8a7addc186d0bd542082482157ffb2d1f5a Mon Sep 17 00:00:00 2001 From: Mega Mind <68985133+megamind4089@users.noreply.github.com> Date: Sat, 10 Oct 2020 09:29:07 +0800 Subject: New behavior for ext power control --- app/CMakeLists.txt | 1 + app/boards/shields/lily58/lily58.keymap | 11 +++-- app/dts/behaviors.dtsi | 3 +- app/dts/behaviors/ext_power.dtsi | 9 ++++ .../bindings/behaviors/zmk,behavior-ext-power.yaml | 10 ++++ app/include/dt-bindings/zmk/ext_power.h | 16 +++++++ app/src/behaviors/behavior_ext_power.c | 54 ++++++++++++++++++++++ 7 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 app/dts/behaviors/ext_power.dtsi create mode 100644 app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml create mode 100644 app/include/dt-bindings/zmk/ext_power.h create mode 100644 app/src/behaviors/behavior_ext_power.c (limited to 'app') diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 31d28f5..39509ed 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -46,6 +46,7 @@ if (NOT CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) 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_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c) target_sources(app PRIVATE src/keymap.c) endif() target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c) diff --git a/app/boards/shields/lily58/lily58.keymap b/app/boards/shields/lily58/lily58.keymap index 997a124..90dec23 100644 --- a/app/boards/shields/lily58/lily58.keymap +++ b/app/boards/shields/lily58/lily58.keymap @@ -7,6 +7,7 @@ #include #include #include +#include / { keymap { @@ -38,11 +39,11 @@ // | | | | | | | | | | | _ | + | { | } | "|" | // | | | | | | | | | | 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 GRAV &kp BANG &kp ATSN &kp HASH &kp CURU &kp PRCT &kp CRRT &kp AMPS &kp KMLT &kp LPRN &kp RPRN &kp TILD -&trans &trans &trans &trans &trans &trans &trans &trans &trans &kp MINUS &kp KPLS &kp LCUR &kp RCUR &kp PIPE - &trans &trans &trans &trans &trans &trans &trans &trans +&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 GRAV &kp BANG &kp ATSN &kp HASH &kp CURU &kp PRCT &kp CRRT &kp AMPS &kp KMLT &kp LPRN &kp RPRN &kp TILD +&trans &ext_power EP_ON &ext_power EP_OFF &trans &trans &trans &trans &trans &trans &kp MINUS &kp KPLS &kp LCUR &kp RCUR &kp PIPE + &trans &trans &trans &trans &trans &trans &trans &trans >; sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD>; diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 202202b..36c918c 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -8,4 +8,5 @@ #include #include #include -#include \ No newline at end of file +#include +#include diff --git a/app/dts/behaviors/ext_power.dtsi b/app/dts/behaviors/ext_power.dtsi new file mode 100644 index 0000000..c4d8714 --- /dev/null +++ b/app/dts/behaviors/ext_power.dtsi @@ -0,0 +1,9 @@ +/ { + behaviors { + ext_power: behavior_ext_power { + compatible = "zmk,behavior-ext-power"; + label = "EXT_POWER_BEHAVIOR"; + #binding-cells = <2>; + }; + }; +}; diff --git a/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml b/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml new file mode 100644 index 0000000..b9abd92 --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml @@ -0,0 +1,10 @@ +# +# Copyright (c) 2020, The ZMK Contributors +# SPDX-License-Identifier: MIT +# + +description: External power control Behavior + +compatible: "zmk,behavior-ext-power" + +include: two_param.yaml diff --git a/app/include/dt-bindings/zmk/ext_power.h b/app/include/dt-bindings/zmk/ext_power.h new file mode 100644 index 0000000..a72b657 --- /dev/null +++ b/app/include/dt-bindings/zmk/ext_power.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define EXT_POWER_OFF_CMD 0 +#define EXT_POWER_ON_CMD 1 + +/* + * Note: Some future commands might include additional parameters, so we + * defines these aliases up front. + */ + +#define EP_ON EXT_POWER_ON_CMD 0 +#define EP_OFF EXT_POWER_OFF_CMD 0 diff --git a/app/src/behaviors/behavior_ext_power.c b/app/src/behaviors/behavior_ext_power.c new file mode 100644 index 0000000..2bd93ee --- /dev/null +++ b/app/src/behaviors/behavior_ext_power.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_ext_power + +#include +#include +#include + +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#include + +static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t command, u32_t arg) { + const struct device *ext_power = device_get_binding("EXT_POWER"); + if (ext_power == NULL) { + LOG_ERR("Unable to retrieve ext_power device: %d", command); + return -EIO; + } + const struct ext_power_api *ext_power_api = ext_power->driver_api; + + switch (command) { + case EXT_POWER_OFF_CMD: + return ext_power_api->disable(ext_power); + case EXT_POWER_ON_CMD: + return ext_power_api->enable(ext_power); + default: + LOG_ERR("Unknown ext_power command: %d", command); + } + + return -ENOTSUP; +} + +static int behavior_ext_power_init(struct device *dev) { return 0; }; + +static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t command, + u32_t arg) { + return 0; +} + +static const struct behavior_driver_api behavior_ext_power_driver_api = { + .binding_pressed = on_keymap_binding_pressed, + .binding_released = on_keymap_binding_released, +}; + +DEVICE_AND_API_INIT(behavior_ext_power, DT_INST_LABEL(0), behavior_ext_power_init, NULL, NULL, + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &behavior_ext_power_driver_api); -- cgit v1.2.3 From 5d1c083959967b6f55ce7cff3c83442bc71d23cb Mon Sep 17 00:00:00 2001 From: Mega Mind <68985133+megamind4089@users.noreply.github.com> Date: Mon, 12 Oct 2020 00:30:51 +0800 Subject: Added toggle and removed a param --- app/include/dt-bindings/zmk/ext_power.h | 11 ++++------- app/src/behaviors/behavior_ext_power.c | 5 +++++ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/include/dt-bindings/zmk/ext_power.h b/app/include/dt-bindings/zmk/ext_power.h index a72b657..2a3e846 100644 --- a/app/include/dt-bindings/zmk/ext_power.h +++ b/app/include/dt-bindings/zmk/ext_power.h @@ -6,11 +6,8 @@ #define EXT_POWER_OFF_CMD 0 #define EXT_POWER_ON_CMD 1 +#define EXT_POWER_TOGGLE_CMD 2 -/* - * Note: Some future commands might include additional parameters, so we - * defines these aliases up front. - */ - -#define EP_ON EXT_POWER_ON_CMD 0 -#define EP_OFF EXT_POWER_OFF_CMD 0 +#define EP_ON EXT_POWER_ON_CMD +#define EP_OFF EXT_POWER_OFF_CMD +#define EP_TOG EXT_POWER_TOGGLE_CMD diff --git a/app/src/behaviors/behavior_ext_power.c b/app/src/behaviors/behavior_ext_power.c index 2bd93ee..7f06e1d 100644 --- a/app/src/behaviors/behavior_ext_power.c +++ b/app/src/behaviors/behavior_ext_power.c @@ -30,6 +30,11 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t c return ext_power_api->disable(ext_power); case EXT_POWER_ON_CMD: return ext_power_api->enable(ext_power); + case EXT_POWER_TOGGLE_CMD: + if(ext_power_api->get(ext_power) > 0) + return ext_power_api->disable(ext_power); + else + return ext_power_api->enable(ext_power); default: LOG_ERR("Unknown ext_power command: %d", command); } -- cgit v1.2.3 From 4adcb396ff01bf4a8ab98799139ed3f3339d207c Mon Sep 17 00:00:00 2001 From: Mega Mind <68985133+megamind4089@users.noreply.github.com> Date: Mon, 12 Oct 2020 23:50:54 +0800 Subject: Rebased and fixed nasty code --- app/boards/shields/lily58/lily58.keymap | 2 +- app/src/behaviors/behavior_ext_power.c | 32 ++++++++++++++------------------ app/src/behaviors/behavior_key_press.c | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'app') diff --git a/app/boards/shields/lily58/lily58.keymap b/app/boards/shields/lily58/lily58.keymap index 90dec23..d44b3fe 100644 --- a/app/boards/shields/lily58/lily58.keymap +++ b/app/boards/shields/lily58/lily58.keymap @@ -42,7 +42,7 @@ &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 GRAV &kp BANG &kp ATSN &kp HASH &kp CURU &kp PRCT &kp CRRT &kp AMPS &kp KMLT &kp LPRN &kp RPRN &kp TILD -&trans &ext_power EP_ON &ext_power EP_OFF &trans &trans &trans &trans &trans &trans &kp MINUS &kp KPLS &kp LCUR &kp RCUR &kp PIPE +&trans &ext_power EP_ON &ext_power EP_OFF &ext_power EP_TOG &trans &trans &trans &trans &trans &kp MINUS &kp KPLS &kp LCUR &kp RCUR &kp PIPE &trans &trans &trans &trans &trans &trans &trans &trans >; diff --git a/app/src/behaviors/behavior_ext_power.c b/app/src/behaviors/behavior_ext_power.c index 7f06e1d..e8190c1 100644 --- a/app/src/behaviors/behavior_ext_power.c +++ b/app/src/behaviors/behavior_ext_power.c @@ -9,32 +9,29 @@ #include #include #include - -#include +#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -#include - -static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t command, u32_t arg) { +static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { const struct device *ext_power = device_get_binding("EXT_POWER"); if (ext_power == NULL) { LOG_ERR("Unable to retrieve ext_power device: %d", command); return -EIO; } - const struct ext_power_api *ext_power_api = ext_power->driver_api; - switch (command) { + switch (binding->param1) { case EXT_POWER_OFF_CMD: - return ext_power_api->disable(ext_power); + return ext_power_disable(ext_power); case EXT_POWER_ON_CMD: - return ext_power_api->enable(ext_power); + return ext_power_enable(ext_power); case EXT_POWER_TOGGLE_CMD: - if(ext_power_api->get(ext_power) > 0) - return ext_power_api->disable(ext_power); + if (ext_power_get(ext_power) > 0) + return ext_power_disable(ext_power); else - return ext_power_api->enable(ext_power); + return ext_power_enable(ext_power); default: LOG_ERR("Unknown ext_power command: %d", command); } @@ -42,18 +39,17 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t c return -ENOTSUP; } -static int behavior_ext_power_init(struct device *dev) { return 0; }; - -static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t command, - u32_t arg) { +static int on_keymap_binding_released(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { return 0; } +static int behavior_ext_power_init(struct device *dev) { return 0; }; + static const struct behavior_driver_api behavior_ext_power_driver_api = { .binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released, }; DEVICE_AND_API_INIT(behavior_ext_power, DT_INST_LABEL(0), behavior_ext_power_init, NULL, NULL, - APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &behavior_ext_power_driver_api); + APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY, &behavior_ext_power_driver_api); diff --git a/app/src/behaviors/behavior_key_press.c b/app/src/behaviors/behavior_key_press.c index d691e9f..923b098 100644 --- a/app/src/behaviors/behavior_key_press.c +++ b/app/src/behaviors/behavior_key_press.c @@ -54,4 +54,4 @@ static const struct behavior_driver_api behavior_key_press_driver_api = { &behavior_key_press_data_##n, &behavior_key_press_config_##n, APPLICATION, \ CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_key_press_driver_api); -DT_INST_FOREACH_STATUS_OKAY(KP_INST) \ No newline at end of file +DT_INST_FOREACH_STATUS_OKAY(KP_INST) -- cgit v1.2.3 From 2e649b7fd4113ff2f0e6ffdfa1ac6ede5feaebf6 Mon Sep 17 00:00:00 2001 From: Mega Mind <68985133+megamind4089@users.noreply.github.com> Date: Tue, 13 Oct 2020 00:09:57 +0800 Subject: Fix compilation errors and minor tweaks --- app/dts/behaviors/ext_power.dtsi | 2 +- app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml | 2 +- app/src/behaviors/behavior_ext_power.c | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/dts/behaviors/ext_power.dtsi b/app/dts/behaviors/ext_power.dtsi index c4d8714..92f0035 100644 --- a/app/dts/behaviors/ext_power.dtsi +++ b/app/dts/behaviors/ext_power.dtsi @@ -3,7 +3,7 @@ ext_power: behavior_ext_power { compatible = "zmk,behavior-ext-power"; label = "EXT_POWER_BEHAVIOR"; - #binding-cells = <2>; + #binding-cells = <1>; }; }; }; diff --git a/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml b/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml index b9abd92..d86c6f9 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-ext-power.yaml @@ -7,4 +7,4 @@ description: External power control Behavior compatible: "zmk,behavior-ext-power" -include: two_param.yaml +include: one_param.yaml diff --git a/app/src/behaviors/behavior_ext_power.c b/app/src/behaviors/behavior_ext_power.c index e8190c1..825f983 100644 --- a/app/src/behaviors/behavior_ext_power.c +++ b/app/src/behaviors/behavior_ext_power.c @@ -11,14 +11,16 @@ #include #include +#include + #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { - const struct device *ext_power = device_get_binding("EXT_POWER"); + struct device *ext_power = device_get_binding("EXT_POWER"); if (ext_power == NULL) { - LOG_ERR("Unable to retrieve ext_power device: %d", command); + LOG_ERR("Unable to retrieve ext_power device: %d", binding->param1); return -EIO; } @@ -33,7 +35,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, else return ext_power_enable(ext_power); default: - LOG_ERR("Unknown ext_power command: %d", command); + LOG_ERR("Unknown ext_power command: %d", binding->param1); } return -ENOTSUP; -- cgit v1.2.3 From 6d9aa4f5ea033d08e6db8c368242e80e205b6f1a Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 12 Oct 2020 13:03:10 -0400 Subject: fix: Updated copyright headers to single author file. --- app/include/dt-bindings/zmk/bt.h | 2 +- app/include/zmk/ble/profile.h | 2 +- app/include/zmk/events/ble-active-profile-changed.h | 2 +- app/src/behaviors/behavior_bt.c | 2 +- app/src/events/ble_active_profile_changed.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/include/dt-bindings/zmk/bt.h b/app/include/dt-bindings/zmk/bt.h index a403d35..8ca1060 100644 --- a/app/include/dt-bindings/zmk/bt.h +++ b/app/include/dt-bindings/zmk/bt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Peter Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ diff --git a/app/include/zmk/ble/profile.h b/app/include/zmk/ble/profile.h index 9a79c6d..1df2743 100644 --- a/app/include/zmk/ble/profile.h +++ b/app/include/zmk/ble/profile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Peter Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ diff --git a/app/include/zmk/events/ble-active-profile-changed.h b/app/include/zmk/events/ble-active-profile-changed.h index 66f40c7..1e3a198 100644 --- a/app/include/zmk/events/ble-active-profile-changed.h +++ b/app/include/zmk/events/ble-active-profile-changed.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Peter Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ diff --git a/app/src/behaviors/behavior_bt.c b/app/src/behaviors/behavior_bt.c index 922c157..066c437 100644 --- a/app/src/behaviors/behavior_bt.c +++ b/app/src/behaviors/behavior_bt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Peter Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ diff --git a/app/src/events/ble_active_profile_changed.c b/app/src/events/ble_active_profile_changed.c index a270a14..06988e2 100644 --- a/app/src/events/ble_active_profile_changed.c +++ b/app/src/events/ble_active_profile_changed.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Peter Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ -- cgit v1.2.3 From eee8eb6e776c81192e81f685bd24a3795467ec91 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 12 Oct 2020 13:04:24 -0400 Subject: fix: Single author file copyright header fix. --- app/boards/shields/tg4x/tg4x.overlay | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/boards/shields/tg4x/tg4x.overlay b/app/boards/shields/tg4x/tg4x.overlay index acab2e3..10ce524 100644 --- a/app/boards/shields/tg4x/tg4x.overlay +++ b/app/boards/shields/tg4x/tg4x.overlay @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Pete Johanson, Richard Jones + * Copyright (c) 2020 The ZMK Contrbutors * * SPDX-License-Identifier: MIT */ -- cgit v1.2.3 From 59e8c58051298175bc1c77593f1b24d9394aa848 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 13 Oct 2020 00:11:08 -0400 Subject: fix: Copyright header for cradio.dtsi --- app/boards/shields/cradio/cradio.dtsi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index 1f2603c..43f9049 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Pete Johanson + * Copyright (c) 2020 The ZMK Contributors * * SPDX-License-Identifier: MIT */ @@ -48,4 +48,3 @@ }; }; }; - -- cgit v1.2.3 From 3186a553a5d18f24fc6fbac2987cf8054afadcbb Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 13 Oct 2020 21:00:54 -0400 Subject: fix(shields): Add default qaz.conf file. --- app/boards/shields/qaz/qaz.conf | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/boards/shields/qaz/qaz.conf (limited to 'app') diff --git a/app/boards/shields/qaz/qaz.conf b/app/boards/shields/qaz/qaz.conf new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 204d1300ba6b13041e9a69cc297c06ac189f1f0d Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Thu, 15 Oct 2020 00:00:37 -0400 Subject: fix(ble): Only advertise when needed.* Once we have a peer connected to for the active profile, don't continue advertising. --- app/src/ble.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 24 deletions(-) (limited to 'app') diff --git a/app/src/ble.c b/app/src/ble.c index 49e2b3b..8cc42bc 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -45,6 +45,18 @@ static u8_t passkey_digit = 0; #define PROFILE_COUNT CONFIG_BT_MAX_PAIRED #endif +enum advertising_type { + ZMK_ADV_NONE, + ZMK_ADV_DIR, + ZMK_ADV_CONN, +} advertising_status; + +#define CURR_ADV(adv) (adv << 4) + +#define ZMK_ADV_CONN_NAME \ + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_USE_NAME, \ + BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL) + static struct zmk_ble_profile profiles[PROFILE_COUNT]; static u8_t active_profile; @@ -92,29 +104,97 @@ void set_profile_address(u8_t index, const bt_addr_le_t *addr) { raise_profile_changed_event(); } -int zmk_ble_adv_pause() { - int err = bt_le_adv_stop(); - if (err) { - LOG_ERR("Failed to stop advertising (err %d)", err); - return err; +bool active_profile_is_connected() { + struct bt_conn *conn; + bt_addr_le_t *addr = zmk_ble_active_profile_addr(); + if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) { + return false; + } else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) { + return false; } - return 0; -}; + bt_conn_unref(conn); -int zmk_ble_adv_resume() { - LOG_DBG("active_profile %d, directed? %s", active_profile, - active_profile_is_open() ? "no" : "yes"); + return true; +} - int err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); - if (err) { - LOG_ERR("Advertising failed to start (err %d)", err); - return err; +#define CHECKED_ADV_STOP() \ + err = bt_le_adv_stop(); \ + advertising_status = ZMK_ADV_NONE; \ + if (err) { \ + LOG_ERR("Failed to stop advertising (err %d)", err); \ + return err; \ + } + +#define CHECKED_DIR_ADV() \ + addr = zmk_ble_active_profile_addr(); \ + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr); \ + if (conn != NULL) { /* TODO: Check status of connection */ \ + LOG_DBG("Skipping advertising, profile host is already connected"); \ + bt_conn_unref(conn); \ + return 0; \ + } \ + err = bt_le_adv_start(BT_LE_ADV_CONN_DIR_LOW_DUTY(addr), zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), \ + NULL, 0); \ + if (err) { \ + LOG_ERR("Advertising failed to start (err %d)", err); \ + return err; \ + } \ + advertising_status = ZMK_ADV_DIR; + +#define CHECKED_OPEN_ADV() \ + err = bt_le_adv_start(ZMK_ADV_CONN_NAME, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); \ + if (err) { \ + LOG_ERR("Advertising failed to start (err %d)", err); \ + return err; \ + } \ + advertising_status = ZMK_ADV_CONN; + +int update_advertising() { + int err = 0; + bt_addr_le_t *addr; + struct bt_conn *conn; + enum advertising_type desired_adv = ZMK_ADV_NONE; + + if (active_profile_is_open() || !active_profile_is_connected()) { + desired_adv = ZMK_ADV_CONN; + } else if (!active_profile_is_connected()) { + desired_adv = ZMK_ADV_CONN; + // Need to fix directed advertising for privacy centrals. See + // https://github.com/zephyrproject-rtos/zephyr/pull/14984 char + // addr_str[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(zmk_ble_active_profile_addr(), addr_str, + // sizeof(addr_str)); + + // LOG_DBG("Directed advertising to %s", log_strdup(addr_str)); + // desired_adv = ZMK_ADV_DIR; + } + LOG_DBG("advertising from %d to %d", advertising_status, desired_adv); + + switch (desired_adv + CURR_ADV(advertising_status)) { + case ZMK_ADV_DIR + CURR_ADV(ZMK_ADV_DIR): + case ZMK_ADV_DIR + CURR_ADV(ZMK_ADV_CONN): + CHECKED_ADV_STOP(); + CHECKED_DIR_ADV(); + break; + case ZMK_ADV_DIR + CURR_ADV(ZMK_ADV_NONE): + CHECKED_DIR_ADV(); + break; + case ZMK_ADV_CONN + CURR_ADV(ZMK_ADV_DIR): + CHECKED_ADV_STOP(); + CHECKED_OPEN_ADV(); + break; + case ZMK_ADV_CONN + CURR_ADV(ZMK_ADV_NONE): + CHECKED_OPEN_ADV(); + break; } return 0; }; +static void update_advertising_callback(struct k_work *work) { update_advertising(); } + +K_WORK_DEFINE(update_advertising_work, update_advertising_callback); + int zmk_ble_clear_bonds() { LOG_DBG(""); @@ -124,6 +204,8 @@ int zmk_ble_clear_bonds() { set_profile_address(active_profile, BT_ADDR_LE_ANY); } + update_advertising(); + return 0; }; @@ -134,9 +216,13 @@ int zmk_ble_prof_select(u8_t index) { } active_profile = index; - return settings_save_one("ble/active_profile", &active_profile, sizeof(active_profile)); + settings_save_one("ble/active_profile", &active_profile, sizeof(active_profile)); + + update_advertising(); raise_profile_changed_event(); + + return 0; }; int zmk_ble_prof_next() { @@ -234,8 +320,11 @@ static void connected(struct bt_conn *conn, u8_t err) { char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + advertising_status = ZMK_ADV_NONE; + if (err) { LOG_WRN("Failed to connect to %s (%u)", log_strdup(addr), err); + update_advertising(); return; } @@ -250,6 +339,8 @@ static void connected(struct bt_conn *conn, u8_t err) { if (bt_conn_set_security(conn, BT_SECURITY_L2)) { LOG_ERR("Failed to set security"); } + + update_advertising(); } static void disconnected(struct bt_conn *conn, u8_t reason) { @@ -259,14 +350,9 @@ static void disconnected(struct bt_conn *conn, u8_t reason) { LOG_DBG("Disconnected from %s (reason 0x%02x)", log_strdup(addr), reason); -#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) - // if (bt_addr_le_cmp(&peripheral_addr, BT_ADDR_LE_ANY) && bt_addr_le_cmp(&peripheral_addr, - // bt_conn_get_dst(conn))) { - // zmk_ble_adv_resume(); - // } -#else - // zmk_ble_adv_resume(); -#endif + // We need to do this in a work callback, otherwise the advertising update will still see the + // connection for a profile as active, and not start advertising yet. + k_work_submit(&update_advertising_work); } static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) { @@ -361,6 +447,7 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded) { #endif /* !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) */ set_profile_address(active_profile, dst); + update_advertising(); }; static struct bt_conn_auth_cb zmk_ble_auth_cb_display = { @@ -383,7 +470,7 @@ static void zmk_ble_ready(int err) { return; } - zmk_ble_adv_resume(); + update_advertising(); } static int zmk_ble_init(struct device *_arg) { -- cgit v1.2.3 From e468677c4ea5f382a8e48793eda87ecd3d07a4dd Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Thu, 15 Oct 2020 20:29:00 -0400 Subject: fix(shields): Proper cradio Kconfig setup. --- app/boards/shields/cradio/Kconfig.defconfig | 17 +++++++++++++++-- app/boards/shields/cradio/Kconfig.shield | 7 +++++-- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/boards/shields/cradio/Kconfig.defconfig b/app/boards/shields/cradio/Kconfig.defconfig index 43509a4..4d200c9 100644 --- a/app/boards/shields/cradio/Kconfig.defconfig +++ b/app/boards/shields/cradio/Kconfig.defconfig @@ -1,10 +1,23 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT +if SHIELD_CRADIO_LEFT + +config ZMK_KEYBOARD_NAME + default "cradio left" + +endif + +if SHIELD_CRADIO_RIGHT + config ZMK_KEYBOARD_NAME - default "cradio" + default "cradio right" + +endif + +if SHIELD_CRADIO_RIGHT || SHIELD_CRADIO_LEFT config ZMK_KSCAN_DIRECT_POLLING default y - +endif diff --git a/app/boards/shields/cradio/Kconfig.shield b/app/boards/shields/cradio/Kconfig.shield index 71a439e..bb5f073 100644 --- a/app/boards/shields/cradio/Kconfig.shield +++ b/app/boards/shields/cradio/Kconfig.shield @@ -1,5 +1,8 @@ # Copyright (c) 2020 The ZMK Contributors # SPDX-License-Identifier: MIT -config SHIELD_CRADIO - def_bool $(shields_list_contains,cradio) +config SHIELD_CRADIO_LEFT + def_bool $(shields_list_contains,cradio_left) + +config SHIELD_CRADIO_RIGHT + def_bool $(shields_list_contains,cradio_right) -- cgit v1.2.3 From 818f0a1f91020f3315ae09f70ddda6f8362fab98 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 16 Oct 2020 00:48:53 -0400 Subject: fix(bluetooth): Advertise name + appearance. * Properly put device name and GAP appearance in advertising packets, for proper display in macOS, Android, etc. * Closes #124 --- app/src/ble.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/ble.c b/app/src/ble.c index 8cc42bc..ddc92e9 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -54,13 +54,18 @@ enum advertising_type { #define CURR_ADV(adv) (adv << 4) #define ZMK_ADV_CONN_NAME \ - BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_USE_NAME, \ - BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL) + BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME, BT_GAP_ADV_FAST_INT_MIN_2, \ + BT_GAP_ADV_FAST_INT_MAX_2, NULL) static struct zmk_ble_profile profiles[PROFILE_COUNT]; static u8_t active_profile; +#define DEVICE_NAME CONFIG_BT_DEVICE_NAME +#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) + static const struct bt_data zmk_ble_ad[] = { + BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), + BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0xC1, 0x03), BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_SOME, #if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) -- cgit v1.2.3 From b07475b7d475a592ad974bb36a5580b1c863344f Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 16 Oct 2020 00:56:05 -0400 Subject: fix(bluetooth): Stop adv on connected profile. --- app/src/ble.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app') diff --git a/app/src/ble.c b/app/src/ble.c index ddc92e9..1b25ca2 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -176,6 +176,10 @@ int update_advertising() { LOG_DBG("advertising from %d to %d", advertising_status, desired_adv); switch (desired_adv + CURR_ADV(advertising_status)) { + case ZMK_ADV_NONE + CURR_ADV(ZMK_ADV_DIR): + case ZMK_ADV_NONE + CURR_ADV(ZMK_ADV_CONN): + CHECKED_ADV_STOP(); + break; case ZMK_ADV_DIR + CURR_ADV(ZMK_ADV_DIR): case ZMK_ADV_DIR + CURR_ADV(ZMK_ADV_CONN): CHECKED_ADV_STOP(); -- cgit v1.2.3 From 9d512eaef01d92b930054d6528279944afe221ce Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 16 Oct 2020 09:49:28 -0400 Subject: fix(bluetooth): Add adv data in non-peripherals. --- app/src/ble.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app') diff --git a/app/src/ble.c b/app/src/ble.c index 1b25ca2..9090582 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -64,8 +64,10 @@ static u8_t active_profile; #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) static const struct bt_data zmk_ble_ad[] = { +#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0xC1, 0x03), +#endif BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_SOME, #if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) -- cgit v1.2.3 From 36d3d01a22a46cdc4f1ebcabe27666dec4afface Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 18 Oct 2020 13:24:37 -0400 Subject: feat(usb): Add proper USB product ID. * Use openmoko product ID from: https://github.com/openmoko/openmoko-usb-oui/pull/15 --- app/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app') diff --git a/app/Kconfig b/app/Kconfig index fca4912..4cd01eb 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -9,6 +9,15 @@ config USB_DEVICE_PRODUCT config BT_DEVICE_NAME default ZMK_KEYBOARD_NAME +config USB_DEVICE_VID + default 0x1D50 + +config USB_DEVICE_PID + default 0x615E + +config USB_DEVICE_MANUFACTURER + default "ZMK Project" + config ZMK_KSCAN_EVENT_QUEUE_SIZE int "Size of the event queue for KSCAN events to buffer events" default 4 -- cgit v1.2.3 From 3082455aecc98532807aba3226321a94d2ed4b0c Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 23 Oct 2020 00:45:59 -0500 Subject: Refactor driver to use Sensor API --- app/boards/arm/bluemicro840/bluemicro840_v1.dts | 8 + app/boards/arm/nice_nano/nice_nano.dts | 1 + app/boards/arm/nrfmicro/nrfmicro_13.dts | 8 + app/drivers/zephyr/battery_voltage_divider.c | 179 ++++++++++++++++----- .../dts/bindings/zmk,battery-voltage-divider.yaml | 5 + 5 files changed, 158 insertions(+), 43 deletions(-) (limited to 'app') diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1.dts b/app/boards/arm/bluemicro840/bluemicro840_v1.dts index c693662..ac8ba56 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1.dts +++ b/app/boards/arm/bluemicro840/bluemicro840_v1.dts @@ -29,6 +29,14 @@ }; }; + vbatt { + compatible = "zmk,battery-voltage-divider"; + label = "VOLTAGE_DIVIDER"; + io-channels = <&adc 7>; + output-ohms = <2000000>; + full-ohms = <(2000000 + 806000)>; + }; + }; &gpio0 { diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts index 18312ec..72804e3 100644 --- a/app/boards/arm/nice_nano/nice_nano.dts +++ b/app/boards/arm/nice_nano/nice_nano.dts @@ -31,6 +31,7 @@ vbatt { compatible = "zmk,battery-voltage-divider"; + label = "VOLTAGE_DIVIDER"; io-channels = <&adc 2>; output-ohms = <2000000>; full-ohms = <(2000000 + 806000)>; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13.dts b/app/boards/arm/nrfmicro/nrfmicro_13.dts index 95bd8ad..840014a 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13.dts @@ -26,6 +26,14 @@ }; }; + vbatt { + compatible = "zmk,battery-voltage-divider"; + label = "VOLTAGE_DIVIDER"; + io-channels = <&adc 2>; + output-ohms = <2000000>; + full-ohms = <(2000000 + 820000)>; + }; + }; &gpio0 { diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 34de6cf..abe7cb5 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -16,97 +16,190 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +struct io_channel_config { + const char *label; + uint8_t channel; +}; + +struct gpio_channel_config { + const char *label; + uint8_t pin; + uint8_t flags; +}; -#define VBATT DT_PATH(vbatt) +struct bvd_config { + struct io_channel_config io_channel; + struct gpio_channel_config power_gpios; + uint32_t output_ohm; + uint32_t full_ohm; +}; -struct battery_config { +struct bvd_data { struct device *adc; + struct device *gpio; struct adc_channel_cfg acc; struct adc_sequence as; - int16_t adc_raw; + uint16_t adc_raw; + uint16_t voltage; + uint8_t state_of_charge; }; -static struct battery_config battery_config; - -static int lithium_ion_mv_to_pct(int16_t bat_mv) { +static uint8_t lithium_ion_mv_to_pct(int16_t bat_mv) { // Magic function that maps mV to this discharge graph from adafruit: // https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages return round(106.818 + (-0.032685 - 106.818) / pow(1 + pow(bat_mv / 3679.35, 58.979), 0.347386)); } -static void battery_read(struct k_work *workd) { - struct battery_config *cfg = &battery_config; - struct adc_sequence *as = &cfg->as; +static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) { + struct bvd_data *drv_data = dev->driver_data; + const struct bvd_config *drv_cfg = dev->config_info; + struct adc_sequence *as = &drv_data->as; + + int rc = 0; + + // Enable power GPIO if present + if (drv_data->gpio) { + rc = gpio_pin_set(drv_data->gpio, drv_cfg->power_gpios.pin, 1); - int rc = adc_read(cfg->adc, as); + if (rc != 0) { + LOG_DBG("Failed to enable ADC power GPIO: %d", rc); + return rc; + } + } + + // Read ADC + rc = adc_read(drv_data->adc, as); as->calibrate = false; + if (rc == 0) { - int32_t val = cfg->adc_raw; + int32_t val = drv_data->adc_raw; - adc_raw_to_millivolts(adc_ref_internal(cfg->adc), cfg->acc.gain, as->resolution, &val); + adc_raw_to_millivolts(adc_ref_internal(drv_data->adc), drv_data->acc.gain, as->resolution, &val); - rc = val * (uint64_t)DT_PROP(VBATT, full_ohms) / DT_PROP(VBATT, output_ohms); - LOG_DBG("ADC raw %d ~ %d mV => %d mV\n", cfg->adc_raw, val, rc); - int percent = lithium_ion_mv_to_pct(rc); + uint16_t millivolts = val * (uint64_t)drv_cfg->full_ohm / drv_cfg->output_ohm; + LOG_DBG("ADC raw %d ~ %d mV => %d mV\n", drv_data->adc_raw, val, millivolts); + uint8_t percent = lithium_ion_mv_to_pct(millivolts); LOG_DBG("Percent: %d", percent); + + drv_data->voltage = millivolts; + drv_data->state_of_charge = percent; } else { LOG_DBG("Failed to read ADC: %d", rc); } + + // Disable power GPIO if present + if (drv_data->gpio) { + rc = gpio_pin_set(drv_data->gpio, drv_cfg->power_gpios.pin, 0); + + if (rc != 0) { + LOG_DBG("Failed to disable ADC power GPIO: %d", rc); + } + } + + return rc; } -K_WORK_DEFINE(battery_work, battery_read); +static int bvd_channel_get(struct device *dev, enum sensor_channel chan, + struct sensor_value *val) { + struct bvd_data *drv_data = dev->driver_data; + + switch(chan) { + case SENSOR_CHAN_GAUGE_VOLTAGE: + val->val1 = drv_data->voltage / 1000; + val->val2 = (drv_data->voltage % 1000) * 1000U; + break; -static void battery_handler(struct k_timer *timer) { k_work_submit(&battery_work); } + case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE: + val->val1 = drv_data->state_of_charge; + val->val2 = 0; + break; + + default: + return -ENOTSUP; + } -K_TIMER_DEFINE(battery_tick, battery_handler, NULL); + return 0; +} + +static const struct sensor_driver_api bvd_api = { + .sample_fetch = bvd_sample_fetch, + .channel_get = bvd_channel_get, +}; -static int battery_setup(struct device *_arg) { - struct battery_config *cfg = &battery_config; - struct adc_sequence *as = &cfg->as; - struct adc_channel_cfg *acc = &cfg->acc; - cfg->adc = device_get_binding(DT_IO_CHANNELS_LABEL(VBATT)); +static int bvd_init(struct device *dev) { + struct bvd_data *drv_data = dev->driver_data; + const struct bvd_config *drv_cfg = dev->config_info; - if (cfg->adc == NULL) { - LOG_ERR("ADC %s failed to retrieve", DT_IO_CHANNELS_LABEL(VBATT)); + drv_data->adc = device_get_binding(drv_cfg->io_channel.label); + + if (drv_data->adc == NULL) { + LOG_ERR("ADC %s failed to retrieve", drv_cfg->io_channel.label); return -ENOENT; } - *as = (struct adc_sequence){ + int rc = 0; + + if (drv_cfg->power_gpios.label) { + drv_data->gpio = device_get_binding(drv_cfg->power_gpios.label); + if (drv_data->gpio == NULL) { + LOG_ERR("Failed to get GPIO %s", drv_cfg->power_gpios.label); + return -ENOENT; + } + rc = gpio_pin_configure(drv_data->gpio, drv_cfg->power_gpios.pin, + GPIO_OUTPUT_INACTIVE | drv_cfg->power_gpios.flags); + if (rc != 0) { + LOG_ERR("Failed to control feed %s.%u: %d", + drv_cfg->power_gpios.label, drv_cfg->power_gpios.pin, rc); + return rc; + } + } + + drv_data->as = (struct adc_sequence){ .channels = BIT(0), - .buffer = &cfg->adc_raw, - .buffer_size = sizeof(cfg->adc_raw), + .buffer = &drv_data->adc_raw, + .buffer_size = sizeof(drv_data->adc_raw), .oversampling = 4, .calibrate = true, }; #ifdef CONFIG_ADC_NRFX_SAADC - *acc = (struct adc_channel_cfg){ + drv_data->acc = (struct adc_channel_cfg){ .gain = ADC_GAIN_1_5, .reference = ADC_REF_INTERNAL, .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40), - .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + DT_IO_CHANNELS_INPUT(VBATT), + .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + drv_cfg->io_channel.channel, }; - as->resolution = 12; + drv_data->as.resolution = 12; #else #error Unsupported ADC #endif - int adc_rc = adc_channel_setup(cfg->adc, acc); - LOG_DBG("AIN%u setup returned %d", DT_IO_CHANNELS_INPUT(VBATT), adc_rc); - - if (adc_rc != 0) { - return adc_rc; - } - - k_timer_start(&battery_tick, K_NO_WAIT, K_SECONDS(5)); + rc = adc_channel_setup(drv_data->adc, &drv_data->acc); + LOG_DBG("AIN%u setup returned %d", drv_cfg->io_channel.channel, rc); - return 0; + return rc; } -SYS_INIT(battery_setup, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); +static struct bvd_data bvd_data; +static const struct bvd_config bvd_cfg = { + .io_channel = { + DT_INST_IO_CHANNELS_LABEL(0), + DT_INST_IO_CHANNELS_INPUT(0), + }, +#if DT_INST_NODE_HAS_PROP(0, power_gpios) + .power_gpios = { + DT_INST_GPIO_LABEL(0, power_gpios), + DT_INST_PIN(0, power_gpios), + DT_INST_FLAGS(0, power_gpios), + }, +#endif + .output_ohm = DT_INST_PROP(0, output_ohms), + .full_ohm = DT_INST_PROP(0, full_ohms), +}; -#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ \ No newline at end of file +DEVICE_AND_API_INIT(bvd_dev, DT_INST_LABEL(0), &bvd_init, + &bvd_data, &bvd_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, + &bvd_api); diff --git a/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml b/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml index f6e0642..3f391d7 100644 --- a/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml +++ b/app/drivers/zephyr/dts/bindings/zmk,battery-voltage-divider.yaml @@ -6,4 +6,9 @@ description: Battery SoC monitoring using voltage divider compatible: "zmk,battery-voltage-divider" include: voltage-divider.yaml + +properties: + label: + required: true + type: string \ No newline at end of file -- cgit v1.2.3 From 162c6b77db27c158b05ed65effa8d8ded68ba9b7 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 23 Oct 2020 00:50:39 -0500 Subject: clang-format and add missing defconfig values --- .../arm/bluemicro840/bluemicro840_v1_defconfig | 4 + app/boards/arm/nrfmicro/nrfmicro_13_defconfig | 4 + app/drivers/zephyr/battery_voltage_divider.c | 86 +++++++++++----------- 3 files changed, 51 insertions(+), 43 deletions(-) (limited to 'app') diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig index 96f03ca..2a79981 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig +++ b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig @@ -10,6 +10,10 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y +CONFIG_ADC=y + +CONFIG_NEWLIB_LIBC=y + CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig index cac1164..0421653 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig +++ b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig @@ -10,6 +10,10 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y +CONFIG_ADC=y + +CONFIG_NEWLIB_LIBC=y + CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index abe7cb5..7dba86a 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -17,21 +17,21 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct io_channel_config { - const char *label; - uint8_t channel; + const char *label; + uint8_t channel; }; struct gpio_channel_config { - const char *label; - uint8_t pin; - uint8_t flags; + const char *label; + uint8_t pin; + uint8_t flags; }; struct bvd_config { - struct io_channel_config io_channel; - struct gpio_channel_config power_gpios; - uint32_t output_ohm; - uint32_t full_ohm; + struct io_channel_config io_channel; + struct gpio_channel_config power_gpios; + uint32_t output_ohm; + uint32_t full_ohm; }; struct bvd_data { @@ -75,7 +75,8 @@ static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) { if (rc == 0) { int32_t val = drv_data->adc_raw; - adc_raw_to_millivolts(adc_ref_internal(drv_data->adc), drv_data->acc.gain, as->resolution, &val); + adc_raw_to_millivolts(adc_ref_internal(drv_data->adc), drv_data->acc.gain, as->resolution, + &val); uint16_t millivolts = val * (uint64_t)drv_cfg->full_ohm / drv_cfg->output_ohm; LOG_DBG("ADC raw %d ~ %d mV => %d mV\n", drv_data->adc_raw, val, millivolts); @@ -94,17 +95,16 @@ static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) { if (rc != 0) { LOG_DBG("Failed to disable ADC power GPIO: %d", rc); - } + } } return rc; } -static int bvd_channel_get(struct device *dev, enum sensor_channel chan, - struct sensor_value *val) { +static int bvd_channel_get(struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bvd_data *drv_data = dev->driver_data; - switch(chan) { + switch (chan) { case SENSOR_CHAN_GAUGE_VOLTAGE: val->val1 = drv_data->voltage / 1000; val->val2 = (drv_data->voltage % 1000) * 1000U; @@ -119,7 +119,7 @@ static int bvd_channel_get(struct device *dev, enum sensor_channel chan, return -ENOTSUP; } - return 0; + return 0; } static const struct sensor_driver_api bvd_api = { @@ -127,7 +127,6 @@ static const struct sensor_driver_api bvd_api = { .channel_get = bvd_channel_get, }; - static int bvd_init(struct device *dev) { struct bvd_data *drv_data = dev->driver_data; const struct bvd_config *drv_cfg = dev->config_info; @@ -142,19 +141,19 @@ static int bvd_init(struct device *dev) { int rc = 0; if (drv_cfg->power_gpios.label) { - drv_data->gpio = device_get_binding(drv_cfg->power_gpios.label); - if (drv_data->gpio == NULL) { - LOG_ERR("Failed to get GPIO %s", drv_cfg->power_gpios.label); - return -ENOENT; - } - rc = gpio_pin_configure(drv_data->gpio, drv_cfg->power_gpios.pin, - GPIO_OUTPUT_INACTIVE | drv_cfg->power_gpios.flags); - if (rc != 0) { - LOG_ERR("Failed to control feed %s.%u: %d", - drv_cfg->power_gpios.label, drv_cfg->power_gpios.pin, rc); - return rc; - } - } + drv_data->gpio = device_get_binding(drv_cfg->power_gpios.label); + if (drv_data->gpio == NULL) { + LOG_ERR("Failed to get GPIO %s", drv_cfg->power_gpios.label); + return -ENOENT; + } + rc = gpio_pin_configure(drv_data->gpio, drv_cfg->power_gpios.pin, + GPIO_OUTPUT_INACTIVE | drv_cfg->power_gpios.flags); + if (rc != 0) { + LOG_ERR("Failed to control feed %s.%u: %d", drv_cfg->power_gpios.label, + drv_cfg->power_gpios.pin, rc); + return rc; + } + } drv_data->as = (struct adc_sequence){ .channels = BIT(0), @@ -185,21 +184,22 @@ static int bvd_init(struct device *dev) { static struct bvd_data bvd_data; static const struct bvd_config bvd_cfg = { - .io_channel = { - DT_INST_IO_CHANNELS_LABEL(0), - DT_INST_IO_CHANNELS_INPUT(0), - }, + .io_channel = + { + DT_INST_IO_CHANNELS_LABEL(0), + DT_INST_IO_CHANNELS_INPUT(0), + }, #if DT_INST_NODE_HAS_PROP(0, power_gpios) - .power_gpios = { - DT_INST_GPIO_LABEL(0, power_gpios), - DT_INST_PIN(0, power_gpios), - DT_INST_FLAGS(0, power_gpios), - }, + .power_gpios = + { + DT_INST_GPIO_LABEL(0, power_gpios), + DT_INST_PIN(0, power_gpios), + DT_INST_FLAGS(0, power_gpios), + }, #endif - .output_ohm = DT_INST_PROP(0, output_ohms), - .full_ohm = DT_INST_PROP(0, full_ohms), + .output_ohm = DT_INST_PROP(0, output_ohms), + .full_ohm = DT_INST_PROP(0, full_ohms), }; -DEVICE_AND_API_INIT(bvd_dev, DT_INST_LABEL(0), &bvd_init, - &bvd_data, &bvd_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, - &bvd_api); +DEVICE_AND_API_INIT(bvd_dev, DT_INST_LABEL(0), &bvd_init, &bvd_data, &bvd_cfg, POST_KERNEL, + CONFIG_SENSOR_INIT_PRIORITY, &bvd_api); -- cgit v1.2.3 From 8efcd80f3ae594a489339ac23de8890399f22f59 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 23 Oct 2020 00:57:32 -0500 Subject: Add missing ADC and fix formatting --- app/boards/arm/bluemicro840/bluemicro840_v1.dts | 4 ++++ app/boards/arm/nice_nano/nice_nano.dts | 4 ++-- app/boards/arm/nrfmicro/nrfmicro_13.dts | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1.dts b/app/boards/arm/bluemicro840/bluemicro840_v1.dts index ac8ba56..32aa2e6 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1.dts +++ b/app/boards/arm/bluemicro840/bluemicro840_v1.dts @@ -39,6 +39,10 @@ }; +&adc { + status = "okay"; +}; + &gpio0 { status = "okay"; }; diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts index 997d195..1819541 100644 --- a/app/boards/arm/nice_nano/nice_nano.dts +++ b/app/boards/arm/nice_nano/nice_nano.dts @@ -28,8 +28,8 @@ label = "Blue LED"; }; }; - - ext-power { + + ext-power { compatible = "zmk,ext-power-generic"; label = "EXT_POWER"; control-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; diff --git a/app/boards/arm/nrfmicro/nrfmicro_13.dts b/app/boards/arm/nrfmicro/nrfmicro_13.dts index ae6c1af..5ae11ba 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13.dts +++ b/app/boards/arm/nrfmicro/nrfmicro_13.dts @@ -25,8 +25,8 @@ label = "Blue LED"; }; }; - - ext-power { + + ext-power { compatible = "zmk,ext-power-generic"; label = "EXT_POWER"; control-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; -- cgit v1.2.3 From 6047415b1c26ec06198edecf656d6d9edcd01446 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 23 Oct 2020 01:19:47 -0500 Subject: Fix build for boards without voltage divider --- app/drivers/zephyr/battery_voltage_divider.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app') diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 7dba86a..980f1b4 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -16,6 +16,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) + struct io_channel_config { const char *label; uint8_t channel; @@ -203,3 +205,5 @@ static const struct bvd_config bvd_cfg = { DEVICE_AND_API_INIT(bvd_dev, DT_INST_LABEL(0), &bvd_init, &bvd_data, &bvd_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &bvd_api); + +#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ -- cgit v1.2.3 From a67a8cd3b87e67176fb88c1d04d95004f7ff905d Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 23 Oct 2020 22:37:44 -0500 Subject: Check if fetch channel is supported --- app/drivers/zephyr/battery_voltage_divider.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app') diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 980f1b4..6139d46 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -58,6 +58,11 @@ static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) { const struct bvd_config *drv_cfg = dev->config_info; struct adc_sequence *as = &drv_data->as; + // Make sure selected channel is supported + if (chan != SENSOR_CHAN_GAUGE_VOLTAGE && chan != SENSOR_CHAN_GAUGE_STATE_OF_CHARGE) { + return -ENOTSUP; + } + int rc = 0; // Enable power GPIO if present -- cgit v1.2.3 From 6a9a6e6d8edaae5f3e5bc37033a9391bc66e786a Mon Sep 17 00:00:00 2001 From: Nigel Rodriguez Date: Sat, 24 Oct 2020 12:21:15 +0800 Subject: Add Boardsource 3x4 shield --- .../shields/boardsource3x4/Kconfig.defconfig | 13 ++++++ app/boards/shields/boardsource3x4/Kconfig.shield | 9 ++++ .../shields/boardsource3x4/boardsource3x4.conf | 0 .../shields/boardsource3x4/boardsource3x4.keymap | 49 ++++++++++++++++++++++ .../shields/boardsource3x4/boardsource3x4.overlay | 38 +++++++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 app/boards/shields/boardsource3x4/Kconfig.defconfig create mode 100644 app/boards/shields/boardsource3x4/Kconfig.shield create mode 100644 app/boards/shields/boardsource3x4/boardsource3x4.conf create mode 100644 app/boards/shields/boardsource3x4/boardsource3x4.keymap create mode 100644 app/boards/shields/boardsource3x4/boardsource3x4.overlay (limited to 'app') diff --git a/app/boards/shields/boardsource3x4/Kconfig.defconfig b/app/boards/shields/boardsource3x4/Kconfig.defconfig new file mode 100644 index 0000000..c03703b --- /dev/null +++ b/app/boards/shields/boardsource3x4/Kconfig.defconfig @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + + +if SHIELD_BOARDSOURCE3X4 + +config ZMK_KEYBOARD_NAME + default "Boardsource 3x4" + +endif \ No newline at end of file diff --git a/app/boards/shields/boardsource3x4/Kconfig.shield b/app/boards/shields/boardsource3x4/Kconfig.shield new file mode 100644 index 0000000..2e9e228 --- /dev/null +++ b/app/boards/shields/boardsource3x4/Kconfig.shield @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +config SHIELD_BOARDSOURCE3X4 + def_bool $(shields_list_contains,boardsource3x4) + diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.conf b/app/boards/shields/boardsource3x4/boardsource3x4.conf new file mode 100644 index 0000000..e69de29 diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.keymap b/app/boards/shields/boardsource3x4/boardsource3x4.keymap new file mode 100644 index 0000000..031b7c9 --- /dev/null +++ b/app/boards/shields/boardsource3x4/boardsource3x4.keymap @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + + bindings = < + &tog 1 &cp M_PREV &cp M_PLAY &cp M_NEXT + &mo 2 &cp M_VOLD &kp UARW &cp M_VOLU + &mo 3 &kp LARW &kp DARW &kp RARW + >; + + }; + + num_layer { + bindings = < + &tog 1 &kp NUM_7 &kp NUM_8 &kp NUM_9 + &mo 2 &kp NUM_4 &kp NUM_5 &kp NUM_6 + < 3 NUM_0 &kp NUM_1 &kp NUM_2 &kp NUM_3 + >; + }; + + lower_layer { + bindings = < + &bt BT_CLR &none &reset &bootloader + &trans &bt BT_SEL 3 &bt BT_SEL 4 &none + &none &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 + >; + }; + + raise_layer { + bindings = < + &kp 0x68 &kp 0x69 &kp 0x6A &kp 0x6B + &kp 0x6C &kp 0x6D &kp 0x6E &kp 0x6F + &trans &kp 0x70 &kp 0x71 &kp 0x72 + >; + }; + }; +}; \ No newline at end of file diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.overlay b/app/boards/shields/boardsource3x4/boardsource3x4.overlay new file mode 100644 index 0000000..d68ac30 --- /dev/null +++ b/app/boards/shields/boardsource3x4/boardsource3x4.overlay @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + chosen { + zmk,kscan = &kscan0; + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + + row-gpios + = <&pro_micro_a 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + + col-gpios + = <&pro_micro_d 10 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 16 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 14 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 15 GPIO_ACTIVE_HIGH> + ; + + }; + + bt_unpair_combo: bt_unpair_combo { + compatible = "zmk,bt-unpair-combo"; + key-positions = <0 11>; + }; +}; \ No newline at end of file -- cgit v1.2.3 From 9d624740d9227d8a6bbc2918e782edd3f22145fb Mon Sep 17 00:00:00 2001 From: Nigel Rodriguez Date: Sat, 24 Oct 2020 12:40:49 +0800 Subject: Fix wrong comment tokens --- app/boards/shields/boardsource3x4/Kconfig.defconfig | 8 ++------ app/boards/shields/boardsource3x4/Kconfig.shield | 7 ++----- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/boards/shields/boardsource3x4/Kconfig.defconfig b/app/boards/shields/boardsource3x4/Kconfig.defconfig index c03703b..4c55aab 100644 --- a/app/boards/shields/boardsource3x4/Kconfig.defconfig +++ b/app/boards/shields/boardsource3x4/Kconfig.defconfig @@ -1,9 +1,5 @@ -/* - * Copyright (c) 2020 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT if SHIELD_BOARDSOURCE3X4 diff --git a/app/boards/shields/boardsource3x4/Kconfig.shield b/app/boards/shields/boardsource3x4/Kconfig.shield index 2e9e228..cda55d0 100644 --- a/app/boards/shields/boardsource3x4/Kconfig.shield +++ b/app/boards/shields/boardsource3x4/Kconfig.shield @@ -1,8 +1,5 @@ -/* - * Copyright (c) 2020 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT config SHIELD_BOARDSOURCE3X4 def_bool $(shields_list_contains,boardsource3x4) -- cgit v1.2.3 From adb07926b1d6760e63e19134b338f8b1ba460483 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 24 Oct 2020 18:52:34 -0500 Subject: Remove newlib dep --- app/boards/arm/bluemicro840/bluemicro840_v1_defconfig | 2 -- app/boards/arm/nice_nano/nice_nano_defconfig | 2 -- app/boards/arm/nrfmicro/nrfmicro_13_defconfig | 2 -- app/drivers/zephyr/battery_voltage_divider.c | 18 +++++++++++------- 4 files changed, 11 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig index 2a79981..00d5661 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig +++ b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig @@ -12,8 +12,6 @@ CONFIG_GPIO=y CONFIG_ADC=y -CONFIG_NEWLIB_LIBC=y - CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/boards/arm/nice_nano/nice_nano_defconfig b/app/boards/arm/nice_nano/nice_nano_defconfig index b727fe0..a888cb3 100644 --- a/app/boards/arm/nice_nano/nice_nano_defconfig +++ b/app/boards/arm/nice_nano/nice_nano_defconfig @@ -12,8 +12,6 @@ CONFIG_GPIO=y CONFIG_ADC=y -CONFIG_NEWLIB_LIBC=y - CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig index 0421653..4e44ea3 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig +++ b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig @@ -12,8 +12,6 @@ CONFIG_GPIO=y CONFIG_ADC=y -CONFIG_NEWLIB_LIBC=y - CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 6139d46..5bac544 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -7,12 +7,10 @@ #define DT_DRV_COMPAT zmk_battery_voltage_divider #include -#include #include #include #include #include -#include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -47,10 +45,16 @@ struct bvd_data { }; static uint8_t lithium_ion_mv_to_pct(int16_t bat_mv) { - // Magic function that maps mV to this discharge graph from adafruit: + // Simple linear approximation of a battery based off adafruit's discharge graph: // https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages - return round(106.818 + - (-0.032685 - 106.818) / pow(1 + pow(bat_mv / 3679.35, 58.979), 0.347386)); + + if (bat_mv >= 4200) { + return 100; + } else if (bat_mv <= 3450) { + return 0; + } + + return bat_mv * 2 / 15 - 459; } static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) { @@ -142,7 +146,7 @@ static int bvd_init(struct device *dev) { if (drv_data->adc == NULL) { LOG_ERR("ADC %s failed to retrieve", drv_cfg->io_channel.label); - return -ENOENT; + return -ENODEV; } int rc = 0; @@ -151,7 +155,7 @@ static int bvd_init(struct device *dev) { drv_data->gpio = device_get_binding(drv_cfg->power_gpios.label); if (drv_data->gpio == NULL) { LOG_ERR("Failed to get GPIO %s", drv_cfg->power_gpios.label); - return -ENOENT; + return -ENODEV; } rc = gpio_pin_configure(drv_data->gpio, drv_cfg->power_gpios.pin, GPIO_OUTPUT_INACTIVE | drv_cfg->power_gpios.flags); -- cgit v1.2.3 From 63007fb6c136b8475894a6315f12eabeea952ca4 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 24 Oct 2020 18:54:56 -0500 Subject: fix: clang-format --- app/drivers/zephyr/battery_voltage_divider.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 5bac544..09a353a 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -47,7 +47,7 @@ struct bvd_data { 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) { -- cgit v1.2.3 From 7296b967978be3483a11a3a5ea2b2eaeb8b23ce8 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 24 Oct 2020 21:08:00 -0500 Subject: Add Reviung41 Shield Definitions --- app/boards/shields/reviung41/Kconfig.defconfig | 9 +++ app/boards/shields/reviung41/Kconfig.shield | 5 ++ .../shields/reviung41/boards/nice_nano.overlay | 28 +++++++++ app/boards/shields/reviung41/reviung41.conf | 3 + app/boards/shields/reviung41/reviung41.keymap | 72 ++++++++++++++++++++++ app/boards/shields/reviung41/reviung41.overlay | 52 ++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 app/boards/shields/reviung41/Kconfig.defconfig create mode 100644 app/boards/shields/reviung41/Kconfig.shield create mode 100644 app/boards/shields/reviung41/boards/nice_nano.overlay create mode 100644 app/boards/shields/reviung41/reviung41.conf create mode 100644 app/boards/shields/reviung41/reviung41.keymap create mode 100644 app/boards/shields/reviung41/reviung41.overlay (limited to 'app') diff --git a/app/boards/shields/reviung41/Kconfig.defconfig b/app/boards/shields/reviung41/Kconfig.defconfig new file mode 100644 index 0000000..0625cb2 --- /dev/null +++ b/app/boards/shields/reviung41/Kconfig.defconfig @@ -0,0 +1,9 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +if SHIELD_REVIUNG41 + +config ZMK_KEYBOARD_NAME + default "Reviung41" + +endif diff --git a/app/boards/shields/reviung41/Kconfig.shield b/app/boards/shields/reviung41/Kconfig.shield new file mode 100644 index 0000000..e51f9e6 --- /dev/null +++ b/app/boards/shields/reviung41/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +config SHIELD_REVIUNG41 + def_bool $(shields_list_contains,reviung41) diff --git a/app/boards/shields/reviung41/boards/nice_nano.overlay b/app/boards/shields/reviung41/boards/nice_nano.overlay new file mode 100644 index 0000000..a05d0eb --- /dev/null +++ b/app/boards/shields/reviung41/boards/nice_nano.overlay @@ -0,0 +1,28 @@ +&spi1 { + compatible = "nordic,nrf-spi"; + status = "okay"; + mosi-pin = <6>; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + sck-pin = <5>; + miso-pin = <7>; + + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + label = "WS2812"; + + /* SPI */ + reg = <0>; /* ignored, but necessary for SPI bindings */ + spi-max-frequency = <4000000>; + + /* WS2812 */ + chain-length = <11>; /* arbitrary; change at will */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + }; +}; + +/ { + chosen { + zmk,underglow = &led_strip; + }; +}; diff --git a/app/boards/shields/reviung41/reviung41.conf b/app/boards/shields/reviung41/reviung41.conf new file mode 100644 index 0000000..289f070 --- /dev/null +++ b/app/boards/shields/reviung41/reviung41.conf @@ -0,0 +1,3 @@ +# Uncomment the following lines to enable RGB underglow +# CONFIG_ZMK_RGB_UNDERGLOW=y +# CONFIG_WS2812_STRIP=y diff --git a/app/boards/shields/reviung41/reviung41.keymap b/app/boards/shields/reviung41/reviung41.keymap new file mode 100644 index 0000000..26b4093 --- /dev/null +++ b/app/boards/shields/reviung41/reviung41.keymap @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + + 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(RET) | +// | ALT | LWR | SPC | 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 &mt RSFT RET + &kp LALT &mo 1 &kp SPC &mo 2 &kp RALT + >; + }; + + lower_layer { +// ---------------------------------------------------------------------------------- +// | | ! | @ | # | $ | % | | ^ | & | * | ( | ) | DEL | +// | | _ | + | { | } | "|" | | LFT | DWN | UP | RGT | ` | ~ | +// | | ESC | GUI | ALT | CAPS| " | | HOME| END | PGUP| PGDN| PRSC| SHFT(RET) | +// | | | RET | ADJ | | + bindings = < + &trans &kp BANG &kp ATSN &kp HASH &kp CURU &kp PRCT &kp CRRT &kp AMPS &kp NUM_8 &kp LPRN &kp RPRN &kp DEL + &trans &kp MINUS &kp KPLS &kp LCUR &kp RCUR &kp PIPE &kp LARW &kp DARW &kp UARW &kp RARW &kp GRAV &kp GRAV + &trans &kp ESC &kp LGUI &kp LALT &kp CLCK &kp QUOT &kp HOME &kp END &kp PGUP &kp PGDN &kp PRSC &mt RSFT RET + &trans &trans &kp RET &mo 3 &trans + >; + }; + + raise_layer { +// ----------------------------------------------------------------------------------------- +// | | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | DEL | +// | | - | = | [ | ] | \ | | F1 | F2 | F3 | F4 | F5 | F6 | +// | | ESC | GUI | ALT | CAPS| " | | F7 | F8 | F9 | F10 | F11 | F12 | +// | | ADJ | BKSP | | | + bindings = < + &trans &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 DEL + &trans &kp MINUS &kp EQL &kp LBKT &kp RBKT &kp BSLH &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 + &trans &kp ESC &kp LGUI &kp RALT &kp CLCK &kp QUOT &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 + &trans &mo 3 &kp BKSP &trans &trans + >; + }; + + adjust_layer { +// ----------------------------------------------------------------------------------------- +// | RGB BRI+ | RGB SAT+ | RGB HUE+ | RGB ANI+ | | RGB TOG | | BT1 | BT2 | BT3 | BT4 | BT5 | BT CLR | +// | RGB BRI- | RGB SAT- | RGB HUE- | RGB ANI+ | | | | | | | | | | +// | | | | | | | | RESET | | | | | | +// | | | | | | + bindings = < + &rgb_ug RGB_BRI &rgb_ug RGB_SAI &rgb_ug RGB_HUI &rgb_ug RGB_EFF &none &rgb_ug RGB_TOG &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &bt BT_CLR + &rgb_ug RGB_BRD &rgb_ug RGB_SAD &rgb_ug RGB_HUD &rgb_ug RGB_EFR &none &none &none &none &none &none &none &none + &none &none &none &none &none &none &reset &none &none &none &none &none + &trans &trans &tog 3 &trans &trans + >; + }; + }; +}; diff --git a/app/boards/shields/reviung41/reviung41.overlay b/app/boards/shields/reviung41/reviung41.overlay new file mode 100644 index 0000000..06270ca --- /dev/null +++ b/app/boards/shields/reviung41/reviung41.overlay @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <6>; + rows = <7>; + + map = < +RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) +RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) +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) RC(5,4) RC(5,5) + RC(6,0) RC(6,1) RC(6,2) RC(6,3) RC(6,4) + >; + }; + + kscan0: kscan_0 { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + + col-gpios + = <&pro_micro_d 4 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 5 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 6 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 7 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 8 GPIO_ACTIVE_HIGH> + , <&pro_micro_d 9 GPIO_ACTIVE_HIGH> + ; + + row-gpios + = <&pro_micro_a 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_a 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 15 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 14 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro_d 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + }; +}; -- cgit v1.2.3 From 9c4b766bc678b2f57bcadb63bd9e37de274f8e20 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:15:15 +0100 Subject: feat(kscan_mock): Increase max number of events This is necessary for testing a large number of events (e.g. every key code) within a single build/pass. The u8_t limitation became apparent during end-to-end testing of #21. --- app/src/kscan_mock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/kscan_mock.c b/app/src/kscan_mock.c index e9c15a0..f1614f1 100644 --- a/app/src/kscan_mock.c +++ b/app/src/kscan_mock.c @@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct kscan_mock_data { kscan_callback_t callback; - u8_t event_index; + u32_t event_index; struct k_delayed_work work; struct device *dev; }; -- cgit v1.2.3 From a0087311038e9b21c2a45499e669d1300af16f83 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 26 Oct 2020 16:01:57 -0500 Subject: Implement Kconfig and enhance error checks --- app/boards/arm/bluemicro840/Kconfig.defconfig | 3 +++ app/boards/arm/bluemicro840/bluemicro840_v1_defconfig | 2 -- app/boards/arm/nice_nano/Kconfig.defconfig | 3 +++ app/boards/arm/nice_nano/nice_nano_defconfig | 2 -- app/boards/arm/nrfmicro/Kconfig.defconfig | 3 +++ app/boards/arm/nrfmicro/nrfmicro_13_defconfig | 2 -- app/drivers/zephyr/CMakeLists.txt | 2 +- app/drivers/zephyr/Kconfig | 6 ++++++ app/drivers/zephyr/battery_voltage_divider.c | 11 ++++------- 9 files changed, 20 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/boards/arm/bluemicro840/Kconfig.defconfig b/app/boards/arm/bluemicro840/Kconfig.defconfig index 566b5a4..2b55e17 100644 --- a/app/boards/arm/bluemicro840/Kconfig.defconfig +++ b/app/boards/arm/bluemicro840/Kconfig.defconfig @@ -27,4 +27,7 @@ config ZMK_BLE config ZMK_USB default y +config ZMK_BATTERY_VOLTAGE_DIVIDER + default y + endif # BOARD_BLUEMICRO840_V1 diff --git a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig index 00d5661..96f03ca 100644 --- a/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig +++ b/app/boards/arm/bluemicro840/bluemicro840_v1_defconfig @@ -10,8 +10,6 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y -CONFIG_ADC=y - CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/boards/arm/nice_nano/Kconfig.defconfig b/app/boards/arm/nice_nano/Kconfig.defconfig index 0961ddd..205050a 100644 --- a/app/boards/arm/nice_nano/Kconfig.defconfig +++ b/app/boards/arm/nice_nano/Kconfig.defconfig @@ -25,4 +25,7 @@ config ZMK_BLE config ZMK_USB default y +config ZMK_BATTERY_VOLTAGE_DIVIDER + default y + endif # BOARD_NICE_NANO diff --git a/app/boards/arm/nice_nano/nice_nano_defconfig b/app/boards/arm/nice_nano/nice_nano_defconfig index a888cb3..393d61f 100644 --- a/app/boards/arm/nice_nano/nice_nano_defconfig +++ b/app/boards/arm/nice_nano/nice_nano_defconfig @@ -10,8 +10,6 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y -CONFIG_ADC=y - CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/boards/arm/nrfmicro/Kconfig.defconfig b/app/boards/arm/nrfmicro/Kconfig.defconfig index 7957b4a..a3c02c2 100644 --- a/app/boards/arm/nrfmicro/Kconfig.defconfig +++ b/app/boards/arm/nrfmicro/Kconfig.defconfig @@ -35,6 +35,9 @@ if BOARD_NRFMICRO_13 config BOARD_NRFMICRO_CHARGER default y +config ZMK_BATTERY_VOLTAGE_DIVIDER + default y + endif # BOARD_NRFMICRO_13 endif # BOARD_NRFMICRO_11 || BOARD_NRFMICRO_11_FLIPPED || BOARD_NRFMICRO_13 diff --git a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig index 4e44ea3..cac1164 100644 --- a/app/boards/arm/nrfmicro/nrfmicro_13_defconfig +++ b/app/boards/arm/nrfmicro/nrfmicro_13_defconfig @@ -10,8 +10,6 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y -CONFIG_ADC=y - CONFIG_USE_DT_CODE_PARTITION=y CONFIG_MPU_ALLOW_FLASH_WRITE=y diff --git a/app/drivers/zephyr/CMakeLists.txt b/app/drivers/zephyr/CMakeLists.txt index 0b1d18f..fc43fb8 100644 --- a/app/drivers/zephyr/CMakeLists.txt +++ b/app/drivers/zephyr/CMakeLists.txt @@ -5,9 +5,9 @@ if(CONFIG_ZMK_KSCAN_GPIO_DRIVER) zephyr_library_sources( kscan_gpio_matrix.c kscan_gpio_direct.c - battery_voltage_divider.c ) zephyr_library_sources_ifdef(CONFIG_EC11 ec11.c) zephyr_library_sources_ifdef(CONFIG_EC11_TRIGGER ec11_trigger.c) + zephyr_library_sources_ifdef(CONFIG_ZMK_BATTERY_VOLTAGE_DIVIDER battery_voltage_divider.c) endif() diff --git a/app/drivers/zephyr/Kconfig b/app/drivers/zephyr/Kconfig index 0534cab..6b177fb 100644 --- a/app/drivers/zephyr/Kconfig +++ b/app/drivers/zephyr/Kconfig @@ -21,6 +21,12 @@ config ZMK_KSCAN_INIT_PRIORITY help Keyboard scan device driver initialization priority. +config ZMK_BATTERY_VOLTAGE_DIVIDER + bool "ZMK battery voltage divider" + select ADC + help + Enable ZMK battery voltage divider driver for battery monitoring. + menuconfig EC11 bool "EC11 Incremental Encoder Sensor" depends on GPIO diff --git a/app/drivers/zephyr/battery_voltage_divider.c b/app/drivers/zephyr/battery_voltage_divider.c index 09a353a..37ac024 100644 --- a/app/drivers/zephyr/battery_voltage_divider.c +++ b/app/drivers/zephyr/battery_voltage_divider.c @@ -14,8 +14,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) - struct io_channel_config { const char *label; uint8_t channel; @@ -102,10 +100,11 @@ static int bvd_sample_fetch(struct device *dev, enum sensor_channel chan) { // Disable power GPIO if present if (drv_data->gpio) { - rc = gpio_pin_set(drv_data->gpio, drv_cfg->power_gpios.pin, 0); + int rc2 = gpio_pin_set(drv_data->gpio, drv_cfg->power_gpios.pin, 0); - if (rc != 0) { - LOG_DBG("Failed to disable ADC power GPIO: %d", rc); + if (rc2 != 0) { + LOG_DBG("Failed to disable ADC power GPIO: %d", rc2); + return rc2; } } @@ -214,5 +213,3 @@ static const struct bvd_config bvd_cfg = { DEVICE_AND_API_INIT(bvd_dev, DT_INST_LABEL(0), &bvd_init, &bvd_data, &bvd_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &bvd_api); - -#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ -- cgit v1.2.3 From 1522c91d73d7f35643986daa508dd7704a5f2798 Mon Sep 17 00:00:00 2001 From: Jay Greco Date: Wed, 21 Oct 2020 20:15:55 -0700 Subject: Add new kscan_gpio_demux driver + zmk,kscan_gpio_demux is now a compatible kscan option + kscan_gpio_demux is based heavily off of the implementation of kscan_gpio_matrix, modified to address cols using an n-to-1 demultiplexer chip instead of discrete IO + Added zmk,kscan_gpio_demux.yaml file * modified CMakeLists to include new source files --- app/drivers/zephyr/CMakeLists.txt | 1 + .../zephyr/dts/bindings/zmk,kscan-gpio-demux.yaml | 22 ++ app/drivers/zephyr/kscan_gpio_demux.c | 270 +++++++++++++++++++++ 3 files changed, 293 insertions(+) create mode 100644 app/drivers/zephyr/dts/bindings/zmk,kscan-gpio-demux.yaml create mode 100644 app/drivers/zephyr/kscan_gpio_demux.c (limited to 'app') diff --git a/app/drivers/zephyr/CMakeLists.txt b/app/drivers/zephyr/CMakeLists.txt index fc43fb8..e3a192d 100644 --- a/app/drivers/zephyr/CMakeLists.txt +++ b/app/drivers/zephyr/CMakeLists.txt @@ -5,6 +5,7 @@ if(CONFIG_ZMK_KSCAN_GPIO_DRIVER) zephyr_library_sources( kscan_gpio_matrix.c kscan_gpio_direct.c + kscan_gpio_demux.c ) zephyr_library_sources_ifdef(CONFIG_EC11 ec11.c) diff --git a/app/drivers/zephyr/dts/bindings/zmk,kscan-gpio-demux.yaml b/app/drivers/zephyr/dts/bindings/zmk,kscan-gpio-demux.yaml new file mode 100644 index 0000000..a2d8d24 --- /dev/null +++ b/app/drivers/zephyr/dts/bindings/zmk,kscan-gpio-demux.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2020, The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: GPIO keyboard demux controller + +compatible: "zmk,kscan-gpio-demux" + +include: kscan.yaml + +properties: + input-gpios: + type: phandle-array + required: true + output-gpios: + type: phandle-array + required: true + debounce-period: + type: int + default: 5 + polling-interval-msec: + type: int + default: 25 diff --git a/app/drivers/zephyr/kscan_gpio_demux.c b/app/drivers/zephyr/kscan_gpio_demux.c new file mode 100644 index 0000000..98c04e6 --- /dev/null +++ b/app/drivers/zephyr/kscan_gpio_demux.c @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_kscan_gpio_demux + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) + +struct kscan_gpio_item_config { + char *label; + gpio_pin_t pin; + gpio_flags_t flags; +}; + +// Helper macro +#define PWR_TWO(x) (1 << (x)) + +// Define GPIO cfg +#define _KSCAN_GPIO_ITEM_CFG_INIT(n, prop, idx) \ + { \ + .label = DT_INST_GPIO_LABEL_BY_IDX(n, prop, idx), \ + .pin = DT_INST_GPIO_PIN_BY_IDX(n, prop, idx), \ + .flags = DT_INST_GPIO_FLAGS_BY_IDX(n, prop, idx), \ + }, + +// Define row and col cfg +#define _KSCAN_GPIO_INPUT_CFG_INIT(idx, n) _KSCAN_GPIO_ITEM_CFG_INIT(n, input_gpios, idx) +#define _KSCAN_GPIO_OUTPUT_CFG_INIT(idx, n) _KSCAN_GPIO_ITEM_CFG_INIT(n, output_gpios, idx) + +// Check debounce config +#define CHECK_DEBOUNCE_CFG(n, a, b) COND_CODE_0(DT_INST_PROP(n, debounce_period), a, b) + +// Define the row and column lengths +#define INST_MATRIX_INPUTS(n) DT_INST_PROP_LEN(n, input_gpios) +#define INST_DEMUX_GPIOS(n) DT_INST_PROP_LEN(n, output_gpios) +#define INST_MATRIX_OUTPUTS(n) PWR_TWO(INST_DEMUX_GPIOS(n)) +#define POLL_INTERVAL(n) DT_INST_PROP(n, polling_interval_msec) + +#define GPIO_INST_INIT(n) \ + struct kscan_gpio_irq_callback_##n { \ + struct CHECK_DEBOUNCE_CFG(n, (k_work), (k_delayed_work)) * work; \ + struct gpio_callback callback; \ + struct device *dev; \ + }; \ + \ + static struct kscan_gpio_irq_callback_##n irq_callbacks_##n[INST_MATRIX_INPUTS(n)]; \ + \ + struct kscan_gpio_config_##n { \ + struct kscan_gpio_item_config rows[INST_MATRIX_INPUTS(n)]; \ + struct kscan_gpio_item_config cols[INST_DEMUX_GPIOS(n)]; \ + }; \ + \ + struct kscan_gpio_data_##n { \ + kscan_callback_t callback; \ + struct k_timer poll_timer; \ + struct CHECK_DEBOUNCE_CFG(n, (k_work), (k_delayed_work)) work; \ + bool matrix_state[INST_MATRIX_INPUTS(n)][INST_MATRIX_OUTPUTS(n)]; \ + struct device *rows[INST_MATRIX_INPUTS(n)]; \ + struct device *cols[INST_MATRIX_OUTPUTS(n)]; \ + struct device *dev; \ + }; \ + /* IO/GPIO SETUP */ \ + /* gpio_input_devices are PHYSICAL IO devices */ \ + static struct device **kscan_gpio_input_devices_##n(struct device *dev) { \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + return data->rows; \ + } \ + \ + static const struct kscan_gpio_item_config *kscan_gpio_input_configs_##n(struct device *dev) { \ + const struct kscan_gpio_config_##n *cfg = dev->config_info; \ + return cfg->rows; \ + } \ + \ + /* gpio_output_devices are PHYSICAL IO devices */ \ + static struct device **kscan_gpio_output_devices_##n(struct device *dev) { \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + return data->cols; \ + } \ + \ + static const struct kscan_gpio_item_config *kscan_gpio_output_configs_##n( \ + struct device *dev) { \ + const struct kscan_gpio_config_##n *cfg = dev->config_info; \ + /* If row2col, rows = outputs & cols = inputs */ \ + return cfg->cols; \ + } \ + /* POLLING SETUP */ \ + static void kscan_gpio_timer_handler(struct k_timer *timer) { \ + struct kscan_gpio_data_##n *data = \ + CONTAINER_OF(timer, struct kscan_gpio_data_##n, poll_timer); \ + k_work_submit(&data->work.work); \ + } \ + \ + /* Read the state of the input GPIOs */ \ + /* This is the core matrix_scan func */ \ + static int kscan_gpio_read_##n(struct device *dev) { \ + bool submit_follow_up_read = false; \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + static bool read_state[INST_MATRIX_INPUTS(n)][INST_MATRIX_OUTPUTS(n)]; \ + for (int o = 0; o < INST_MATRIX_OUTPUTS(n); o++) { \ + /* Iterate over bits and set GPIOs accordingly */ \ + for (u8_t bit = 0; bit < INST_DEMUX_GPIOS(n); bit++) { \ + u8_t state = (o & (0b1 << bit)) >> bit; \ + struct device *out_dev = kscan_gpio_output_devices_##n(dev)[bit]; \ + const struct kscan_gpio_item_config *out_cfg = \ + &kscan_gpio_output_configs_##n(dev)[bit]; \ + gpio_pin_set(out_dev, out_cfg->pin, state); \ + } \ + \ + for (int i = 0; i < INST_MATRIX_INPUTS(n); i++) { \ + /* Get the input device (port) */ \ + struct device *in_dev = kscan_gpio_input_devices_##n(dev)[i]; \ + /* Get the input device config (pin) */ \ + const struct kscan_gpio_item_config *in_cfg = \ + &kscan_gpio_input_configs_##n(dev)[i]; \ + read_state[i][o] = gpio_pin_get(in_dev, in_cfg->pin) > 0; \ + } \ + } \ + for (int r = 0; r < INST_MATRIX_INPUTS(n); r++) { \ + for (int c = 0; c < INST_MATRIX_OUTPUTS(n); c++) { \ + bool pressed = read_state[r][c]; \ + submit_follow_up_read = (submit_follow_up_read || pressed); \ + if (pressed != data->matrix_state[r][c]) { \ + LOG_DBG("Sending event at %d,%d state %s", r, c, (pressed ? "on" : "off")); \ + data->matrix_state[r][c] = pressed; \ + data->callback(dev, r, c, pressed); \ + } \ + } \ + } \ + if (submit_follow_up_read) { \ + CHECK_DEBOUNCE_CFG(n, ({ k_work_submit(&data->work); }), ({ \ + k_delayed_work_cancel(&data->work); \ + k_delayed_work_submit(&data->work, K_MSEC(5)); \ + })) \ + } \ + return 0; \ + } \ + \ + static void kscan_gpio_work_handler_##n(struct k_work *work) { \ + struct kscan_gpio_data_##n *data = CONTAINER_OF(work, struct kscan_gpio_data_##n, work); \ + kscan_gpio_read_##n(data->dev); \ + } \ + \ + static void kscan_gpio_irq_callback_handler_##n(struct device *dev, struct gpio_callback *cb, \ + gpio_port_pins_t pin) { \ + struct kscan_gpio_irq_callback_##n *data = \ + CONTAINER_OF(cb, struct kscan_gpio_irq_callback_##n, callback); \ + CHECK_DEBOUNCE_CFG(n, ({ k_work_submit(data->work); }), ({ \ + k_delayed_work_cancel(data->work); \ + k_delayed_work_submit(data->work, \ + K_MSEC(DT_INST_PROP(n, debounce_period))); \ + })) \ + } \ + \ + static struct kscan_gpio_data_##n kscan_gpio_data_##n = { \ + .rows = {[INST_MATRIX_INPUTS(n) - 1] = NULL}, .cols = {[INST_DEMUX_GPIOS(n) - 1] = NULL}}; \ + \ + /* KSCAN API configure function */ \ + static int kscan_gpio_configure_##n(struct device *dev, kscan_callback_t callback) { \ + LOG_DBG("KSCAN API configure"); \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + if (!callback) { \ + return -EINVAL; \ + } \ + data->callback = callback; \ + LOG_DBG("Configured GPIO %d", n); \ + return 0; \ + }; \ + \ + /* KSCAN API enable function */ \ + static int kscan_gpio_enable_##n(struct device *dev) { \ + LOG_DBG("KSCAN API enable"); \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + k_timer_start(&data->poll_timer, K_MSEC(POLL_INTERVAL(n)), K_MSEC(POLL_INTERVAL(n))); \ + return 0; \ + }; \ + \ + /* KSCAN API disable function */ \ + static int kscan_gpio_disable_##n(struct device *dev) { \ + LOG_DBG("KSCAN API disable"); \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + k_timer_stop(&data->poll_timer); \ + return 0; \ + }; \ + \ + /* GPIO init function*/ \ + static int kscan_gpio_init_##n(struct device *dev) { \ + LOG_DBG("KSCAN GPIO init"); \ + struct kscan_gpio_data_##n *data = dev->driver_data; \ + int err; \ + /* configure input devices*/ \ + struct device **input_devices = kscan_gpio_input_devices_##n(dev); \ + for (int i = 0; i < INST_MATRIX_INPUTS(n); i++) { \ + const struct kscan_gpio_item_config *in_cfg = &kscan_gpio_input_configs_##n(dev)[i]; \ + input_devices[i] = device_get_binding(in_cfg->label); \ + if (!input_devices[i]) { \ + LOG_ERR("Unable to find input GPIO device"); \ + return -EINVAL; \ + } \ + err = gpio_pin_configure(input_devices[i], in_cfg->pin, GPIO_INPUT | in_cfg->flags); \ + if (err) { \ + LOG_ERR("Unable to configure pin %d on %s for input", in_cfg->pin, in_cfg->label); \ + return err; \ + } else { \ + LOG_DBG("Configured pin %d on %s for input", in_cfg->pin, in_cfg->label); \ + } \ + irq_callbacks_##n[i].work = &data->work; \ + irq_callbacks_##n[i].dev = dev; \ + gpio_init_callback(&irq_callbacks_##n[i].callback, \ + kscan_gpio_irq_callback_handler_##n, BIT(in_cfg->pin)); \ + err = gpio_add_callback(input_devices[i], &irq_callbacks_##n[i].callback); \ + if (err) { \ + LOG_ERR("Error adding the callback to the column device"); \ + return err; \ + } \ + } \ + /* configure output devices*/ \ + struct device **output_devices = kscan_gpio_output_devices_##n(dev); \ + for (int o = 0; o < INST_DEMUX_GPIOS(n); o++) { \ + const struct kscan_gpio_item_config *out_cfg = &kscan_gpio_output_configs_##n(dev)[o]; \ + output_devices[o] = device_get_binding(out_cfg->label); \ + if (!output_devices[o]) { \ + LOG_ERR("Unable to find output GPIO device"); \ + return -EINVAL; \ + } \ + err = gpio_pin_configure(output_devices[o], out_cfg->pin, \ + GPIO_OUTPUT_ACTIVE | out_cfg->flags); \ + if (err) { \ + LOG_ERR("Unable to configure pin %d on %s for output", out_cfg->pin, \ + out_cfg->label); \ + return err; \ + } else { \ + LOG_DBG("Configured pin %d on %s for output", out_cfg->pin, out_cfg->label); \ + } \ + } \ + data->dev = dev; \ + \ + k_timer_init(&data->poll_timer, kscan_gpio_timer_handler, NULL); \ + \ + (CHECK_DEBOUNCE_CFG(n, (k_work_init), (k_delayed_work_init)))( \ + &data->work, kscan_gpio_work_handler_##n); \ + return 0; \ + } \ + \ + static const struct kscan_driver_api gpio_driver_api_##n = { \ + .config = kscan_gpio_configure_##n, \ + .enable_callback = kscan_gpio_enable_##n, \ + .disable_callback = kscan_gpio_disable_##n, \ + }; \ + \ + static const struct kscan_gpio_config_##n kscan_gpio_config_##n = { \ + .rows = {UTIL_LISTIFY(INST_MATRIX_INPUTS(n), _KSCAN_GPIO_INPUT_CFG_INIT, n)}, \ + .cols = {UTIL_LISTIFY(INST_DEMUX_GPIOS(n), _KSCAN_GPIO_OUTPUT_CFG_INIT, n)}, \ + }; \ + \ + DEVICE_AND_API_INIT(kscan_gpio_##n, DT_INST_LABEL(n), kscan_gpio_init_##n, \ + &kscan_gpio_data_##n, &kscan_gpio_config_##n, APPLICATION, \ + CONFIG_APPLICATION_INIT_PRIORITY, &gpio_driver_api_##n); + +DT_INST_FOREACH_STATUS_OKAY(GPIO_INST_INIT) + +#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ -- cgit v1.2.3 From d90592aac5cec02da1959d7ede7ceccb5265f126 Mon Sep 17 00:00:00 2001 From: Jay Greco Date: Wed, 21 Oct 2020 20:17:31 -0700 Subject: Add NIBBLE shield + Added required files for nullbits NIBBLE --- app/boards/shields/nibble/Kconfig.defconfig | 13 ++++++++ app/boards/shields/nibble/Kconfig.shield | 5 +++ app/boards/shields/nibble/nibble.conf | 0 app/boards/shields/nibble/nibble.keymap | 37 ++++++++++++++++++++++ app/boards/shields/nibble/nibble.overlay | 49 +++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 app/boards/shields/nibble/Kconfig.defconfig create mode 100644 app/boards/shields/nibble/Kconfig.shield create mode 100644 app/boards/shields/nibble/nibble.conf create mode 100644 app/boards/shields/nibble/nibble.keymap create mode 100644 app/boards/shields/nibble/nibble.overlay (limited to 'app') diff --git a/app/boards/shields/nibble/Kconfig.defconfig b/app/boards/shields/nibble/Kconfig.defconfig new file mode 100644 index 0000000..30cb21b --- /dev/null +++ b/app/boards/shields/nibble/Kconfig.defconfig @@ -0,0 +1,13 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +if SHIELD_NIBBLE + +config ZMK_KEYBOARD_NAME + default "NIBBLE_BLE" + +config ZMK_USB + default y + +endif + diff --git a/app/boards/shields/nibble/Kconfig.shield b/app/boards/shields/nibble/Kconfig.shield new file mode 100644 index 0000000..44364f4 --- /dev/null +++ b/app/boards/shields/nibble/Kconfig.shield @@ -0,0 +1,5 @@ +# Copyright (c) 2020 The ZMK Contributors +# SPDX-License-Identifier: MIT + +config SHIELD_NIBBLE + def_bool $(shields_list_contains,nibble) diff --git a/app/boards/shields/nibble/nibble.conf b/app/boards/shields/nibble/nibble.conf new file mode 100644 index 0000000..e69de29 diff --git a/app/boards/shields/nibble/nibble.keymap b/app/boards/shields/nibble/nibble.keymap new file mode 100644 index 0000000..dd37ad9 --- /dev/null +++ b/app/boards/shields/nibble/nibble.keymap @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +#define DEFAULT 0 +#define FUNC 1 + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + 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 MINUS &kp EQL &kp BKSP &kp HOME +&cp M_VOLU &kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp LBKT &kp RBKT &kp BSLH &kp DEL +&cp M_VOLD &kp CLCK &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp QUOT &kp RET &kp PGUP +&trans &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 UARW &kp PGDN +&trans &kp LCTL &kp LGUI &kp LALT &kp SPC &mo FUNC &kp RALT &kp RCTL &kp LARW &kp DARW &kp RARW + >; + }; + func { + bindings = < + &kp TILD &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 &trans &kp END +&bt BT_CLR &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &bootloader +&trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans +&bt BT_PRV &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans +&bt BT_NXT &trans &trans &trans &trans &trans &trans &trans &cp M_PREV &cp M_PLAY &cp M_NEXT + >; + }; + }; +}; diff --git a/app/boards/shields/nibble/nibble.overlay b/app/boards/shields/nibble/nibble.overlay new file mode 100644 index 0000000..7975c3c --- /dev/null +++ b/app/boards/shields/nibble/nibble.overlay @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-demux"; + label = "KSCAN"; + polling-interval-msec = <25>; + input-gpios + = <&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&pro_micro_d 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; + output-gpios + = <&pro_micro_a 3 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 2 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 1 GPIO_ACTIVE_HIGH> + , <&pro_micro_a 0 GPIO_ACTIVE_HIGH> + ; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <16>; + rows = <5>; + + //TODO: Add a keymap graphic here + + map = < + 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(0,12) RC(0,13) RC(0,14) RC(0,15) +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(1,12) RC(1,13) RC(1,14) RC(1,15) +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(2,12) RC(2,14) RC(2,15) +RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) RC(3,14) RC(3,15) +RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,6) RC(4,9) RC(4,10) RC(4,11) RC(4,12) RC(4,14) RC(4,15) + >; + }; +}; -- cgit v1.2.3 From 1a6fe846e4c1eb211c838f1e9635ca29d85d8341 Mon Sep 17 00:00:00 2001 From: Jay Greco Date: Tue, 27 Oct 2020 09:29:04 -0700 Subject: Update NIBBLE keyboard name as per PR feedback - Revert accidental VS code settings change --- app/boards/shields/nibble/Kconfig.defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/boards/shields/nibble/Kconfig.defconfig b/app/boards/shields/nibble/Kconfig.defconfig index 30cb21b..01d0bba 100644 --- a/app/boards/shields/nibble/Kconfig.defconfig +++ b/app/boards/shields/nibble/Kconfig.defconfig @@ -4,7 +4,7 @@ if SHIELD_NIBBLE config ZMK_KEYBOARD_NAME - default "NIBBLE_BLE" + default "NIBBLE" config ZMK_USB default y -- cgit v1.2.3 From 8a98212a02a3a6304a1f275450264f46a60d011b Mon Sep 17 00:00:00 2001 From: Jay Greco Date: Tue, 27 Oct 2020 09:39:30 -0700 Subject: Update demux kscan driver as per PR feedback - Remove kscan_gpio_irq_callback - Remove kscan_gpio_irq_callback_handler - Remove irq_callbacks + Add TODO noting timer and sleep state interactions --- app/drivers/zephyr/kscan_gpio_demux.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'app') diff --git a/app/drivers/zephyr/kscan_gpio_demux.c b/app/drivers/zephyr/kscan_gpio_demux.c index 98c04e6..6113d7c 100644 --- a/app/drivers/zephyr/kscan_gpio_demux.c +++ b/app/drivers/zephyr/kscan_gpio_demux.c @@ -52,8 +52,6 @@ struct kscan_gpio_item_config { struct device *dev; \ }; \ \ - static struct kscan_gpio_irq_callback_##n irq_callbacks_##n[INST_MATRIX_INPUTS(n)]; \ - \ struct kscan_gpio_config_##n { \ struct kscan_gpio_item_config rows[INST_MATRIX_INPUTS(n)]; \ struct kscan_gpio_item_config cols[INST_DEMUX_GPIOS(n)]; \ @@ -149,17 +147,6 @@ struct kscan_gpio_item_config { kscan_gpio_read_##n(data->dev); \ } \ \ - static void kscan_gpio_irq_callback_handler_##n(struct device *dev, struct gpio_callback *cb, \ - gpio_port_pins_t pin) { \ - struct kscan_gpio_irq_callback_##n *data = \ - CONTAINER_OF(cb, struct kscan_gpio_irq_callback_##n, callback); \ - CHECK_DEBOUNCE_CFG(n, ({ k_work_submit(data->work); }), ({ \ - k_delayed_work_cancel(data->work); \ - k_delayed_work_submit(data->work, \ - K_MSEC(DT_INST_PROP(n, debounce_period))); \ - })) \ - } \ - \ static struct kscan_gpio_data_##n kscan_gpio_data_##n = { \ .rows = {[INST_MATRIX_INPUTS(n) - 1] = NULL}, .cols = {[INST_DEMUX_GPIOS(n) - 1] = NULL}}; \ \ @@ -179,6 +166,8 @@ struct kscan_gpio_item_config { static int kscan_gpio_enable_##n(struct device *dev) { \ LOG_DBG("KSCAN API enable"); \ struct kscan_gpio_data_##n *data = dev->driver_data; \ + /* TODO: we might want a follow up to hook into the sleep state hooks in Zephyr, */ \ + /* and disable this timer when we enter a sleep state */ \ k_timer_start(&data->poll_timer, K_MSEC(POLL_INTERVAL(n)), K_MSEC(POLL_INTERVAL(n))); \ return 0; \ }; \ @@ -212,11 +201,6 @@ struct kscan_gpio_item_config { } else { \ LOG_DBG("Configured pin %d on %s for input", in_cfg->pin, in_cfg->label); \ } \ - irq_callbacks_##n[i].work = &data->work; \ - irq_callbacks_##n[i].dev = dev; \ - gpio_init_callback(&irq_callbacks_##n[i].callback, \ - kscan_gpio_irq_callback_handler_##n, BIT(in_cfg->pin)); \ - err = gpio_add_callback(input_devices[i], &irq_callbacks_##n[i].callback); \ if (err) { \ LOG_ERR("Error adding the callback to the column device"); \ return err; \ -- cgit v1.2.3 From 75b7f2a7c52614f21a417a1b6cef255e6aea00ee Mon Sep 17 00:00:00 2001 From: Nigel Rodriguez Date: Wed, 28 Oct 2020 06:55:00 +0800 Subject: Remove bt unpair combo + fix keymap --- app/boards/shields/boardsource3x4/boardsource3x4.keymap | 6 +++--- app/boards/shields/boardsource3x4/boardsource3x4.overlay | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.keymap b/app/boards/shields/boardsource3x4/boardsource3x4.keymap index 031b7c9..dfeeade 100644 --- a/app/boards/shields/boardsource3x4/boardsource3x4.keymap +++ b/app/boards/shields/boardsource3x4/boardsource3x4.keymap @@ -24,9 +24,9 @@ num_layer { bindings = < - &tog 1 &kp NUM_7 &kp NUM_8 &kp NUM_9 - &mo 2 &kp NUM_4 &kp NUM_5 &kp NUM_6 - < 3 NUM_0 &kp NUM_1 &kp NUM_2 &kp NUM_3 + &trans &kp NUM_7 &kp NUM_8 &kp NUM_9 + &trans &kp NUM_4 &kp NUM_5 &kp NUM_6 + < 3 NUM_0 &kp NUM_1 &kp NUM_2 &kp NUM_3 >; }; diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.overlay b/app/boards/shields/boardsource3x4/boardsource3x4.overlay index d68ac30..ad51794 100644 --- a/app/boards/shields/boardsource3x4/boardsource3x4.overlay +++ b/app/boards/shields/boardsource3x4/boardsource3x4.overlay @@ -28,11 +28,5 @@ , <&pro_micro_d 14 GPIO_ACTIVE_HIGH> , <&pro_micro_d 15 GPIO_ACTIVE_HIGH> ; - }; - - bt_unpair_combo: bt_unpair_combo { - compatible = "zmk,bt-unpair-combo"; - key-positions = <0 11>; - }; }; \ No newline at end of file -- cgit v1.2.3