From 88338a9b3cc9b87d48ad1845cffb51b57cffbcb3 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 6 Dec 2023 20:05:29 +0000 Subject: [PATCH] feat(shields): Add ZMK Uno split setup * Make it easier to test split code with ZMK Uno hardware by adding a split left/right setup as well. --- app/boards/shields/zmk_uno/Kconfig.defconfig | 2 +- app/boards/shields/zmk_uno/Kconfig.shield | 15 ++ app/boards/shields/zmk_uno/zmk_uno.dtsi | 172 ++++++++++++++++++ app/boards/shields/zmk_uno/zmk_uno.overlay | 160 +--------------- app/boards/shields/zmk_uno/zmk_uno_split.dtsi | 61 +++++++ .../shields/zmk_uno/zmk_uno_split.keymap | 66 +++++++ .../shields/zmk_uno/zmk_uno_split_left.conf | 18 ++ .../zmk_uno/zmk_uno_split_left.overlay | 11 ++ .../shields/zmk_uno/zmk_uno_split_right.conf | 18 ++ .../zmk_uno/zmk_uno_split_right.overlay | 19 ++ 10 files changed, 382 insertions(+), 160 deletions(-) create mode 100644 app/boards/shields/zmk_uno/zmk_uno.dtsi create mode 100644 app/boards/shields/zmk_uno/zmk_uno_split.dtsi create mode 100644 app/boards/shields/zmk_uno/zmk_uno_split.keymap create mode 100644 app/boards/shields/zmk_uno/zmk_uno_split_left.conf create mode 100644 app/boards/shields/zmk_uno/zmk_uno_split_left.overlay create mode 100644 app/boards/shields/zmk_uno/zmk_uno_split_right.conf create mode 100644 app/boards/shields/zmk_uno/zmk_uno_split_right.overlay diff --git a/app/boards/shields/zmk_uno/Kconfig.defconfig b/app/boards/shields/zmk_uno/Kconfig.defconfig index 11c63a5a005..cccca1d2dee 100644 --- a/app/boards/shields/zmk_uno/Kconfig.defconfig +++ b/app/boards/shields/zmk_uno/Kconfig.defconfig @@ -1,7 +1,7 @@ # Copyright (c) 2022 The ZMK Contributors # SPDX-License-Identifier: MIT -if SHIELD_ZMK_UNO +if SHIELD_ZMK_UNO_BASE config ZMK_KEYBOARD_NAME default "ZMK Uno" diff --git a/app/boards/shields/zmk_uno/Kconfig.shield b/app/boards/shields/zmk_uno/Kconfig.shield index 958915f59c0..0b0b3d73f73 100644 --- a/app/boards/shields/zmk_uno/Kconfig.shield +++ b/app/boards/shields/zmk_uno/Kconfig.shield @@ -1,5 +1,20 @@ # Copyright (c) 2022 The ZMK Contributors # SPDX-License-Identifier: MIT +config SHIELD_ZMK_UNO_BASE + bool + config SHIELD_ZMK_UNO def_bool $(shields_list_contains,zmk_uno) + select SHIELD_ZMK_UNO_BASE + +config SHIELD_ZMK_UNO_SPLIT_LEFT + def_bool $(shields_list_contains,zmk_uno_split_left) + select SHIELD_ZMK_UNO_BASE + select ZMK_SPLIT + select ZMK_SPLIT_ROLE_CENTRAL + +config SHIELD_ZMK_UNO_SPLIT_RIGHT + def_bool $(shields_list_contains,zmk_uno_split_right) + select SHIELD_ZMK_UNO_BASE + select ZMK_SPLIT \ No newline at end of file diff --git a/app/boards/shields/zmk_uno/zmk_uno.dtsi b/app/boards/shields/zmk_uno/zmk_uno.dtsi new file mode 100644 index 00000000000..63deb06a4d1 --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno.dtsi @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +&arduino_i2c { + status = "okay"; +}; + +nice_view_spi: &arduino_spi { + status = "okay"; + + cs-gpios = <&arduino_header 16 GPIO_ACTIVE_HIGH>; + + // Needed so the nice_view shield will enhance the existing node which falls *first* + // on the bus, properly picking up the first `cs-gpios` specifier. + ls0xx@0 { + reg = <0>; + }; + + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + + /* SPI */ + reg = <0>; /* ignored, but necessary for SPI bindings */ + spi-max-frequency = <4000000>; + + /* WS2812 */ + chain-length = <7>; /* 4 underglow + 3 per-key LEDs */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + + color-mapping = ; + }; +}; + +/ { + chosen { + zmk,kscan = &kscan_matrix_comp; + zmk,backlight = &backlight; + zmk,underglow = &led_strip; + zmk,matrix-transform = &matrix_transform; + }; + + // Commented out until we add more powerful power domain support + // external_power { + // compatible = "zmk,ext-power-generic"; + // init-delay-ms = <200>; + // control-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; + // }; + + rgb_power { + compatible = "zmk,ext-power-generic"; + init-delay-ms = <200>; + control-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; + }; + + backlight: gpioleds { + compatible = "gpio-leds"; + gpio_led_0 { + gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; + }; + }; + + matrix_transform: matrix_transform { + compatible = "zmk,matrix-transform"; + rows = <3>; + columns = <4>; + + map = < + RC(0,0) RC(0,1) + RC(1,0) RC(1,1) + RC(2,0) RC(2,1) RC(2,2) + >; + }; + + direct_matrix_transform: direct_matrix_transform { + compatible = "zmk,matrix-transform"; + rows = <3>; + columns = <4>; + + map = < + RC(0,0) RC(0,1) + RC(0,2) RC(0,3) + RC(1,0) RC(1,1) RC(1,2) + >; + }; + + + kscan_matrix_comp: kscan_matrix_comp { + compatible = "zmk,kscan-composite"; + rows = <1>; + columns = <7>; + + matrix { + kscan = <&kscan_matrix>; + }; + + toggle { + kscan = <&kscan_sp3t_toggle>; + row-offset = <2>; + }; + + }; + + kscan_direct_comp: kscan_direct_comp { + compatible = "zmk,kscan-composite"; + status = "disabled"; + + matrix { + kscan = <&kscan_direct>; + }; + + toggle { + kscan = <&kscan_sp3t_toggle>; + row-offset = <1>; + }; + + }; + + kscan_matrix: kscan_matrix { + compatible = "zmk,kscan-gpio-matrix"; + + diode-direction = "col2row"; + + col-gpios + = <&arduino_header 10 GPIO_ACTIVE_HIGH> + , <&arduino_header 9 GPIO_ACTIVE_HIGH> + ; + + row-gpios + = <&arduino_header 13 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&arduino_header 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + + }; + + kscan_direct: kscan_direct { + compatible = "zmk,kscan-gpio-direct"; + status = "disabled"; + + input-gpios + = <&arduino_header 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&arduino_header 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&arduino_header 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&arduino_header 11 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; + + }; + + kscan_sp3t_toggle: kscan_sp3t_toggle { + compatible = "zmk,kscan-gpio-direct"; + toggle-mode; + + input-gpios + = <&arduino_header 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&arduino_header 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + , <&arduino_header 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> + ; + }; + + encoder: encoder { + steps = <80>; + compatible = "alps,ec11"; + a-gpios = <&arduino_header 15 GPIO_PULL_UP>; + b-gpios = <&arduino_header 14 GPIO_PULL_UP>; + }; +}; diff --git a/app/boards/shields/zmk_uno/zmk_uno.overlay b/app/boards/shields/zmk_uno/zmk_uno.overlay index 6d487adbad9..07181280015 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.overlay +++ b/app/boards/shields/zmk_uno/zmk_uno.overlay @@ -4,170 +4,12 @@ * SPDX-License-Identifier: MIT */ -#include -#include - -&arduino_i2c { - status = "okay"; -}; - -nice_view_spi: &arduino_spi { - status = "okay"; - - cs-gpios = <&arduino_header 16 GPIO_ACTIVE_HIGH>; - - // Needed so the nice_view shield will enhance the existing node which falls *first* - // on the bus, properly picking up the first `cs-gpios` specifier. - ls0xx@0 { - reg = <0>; - }; - - led_strip: ws2812@0 { - compatible = "worldsemi,ws2812-spi"; - - /* SPI */ - reg = <0>; /* ignored, but necessary for SPI bindings */ - spi-max-frequency = <4000000>; - - /* WS2812 */ - chain-length = <7>; /* 4 underglow + 3 per-key LEDs */ - spi-one-frame = <0x70>; - spi-zero-frame = <0x40>; - - color-mapping = ; - }; -}; + #include "zmk_uno.dtsi" / { chosen { - zmk,kscan = &kscan_matrix_comp; - zmk,backlight = &backlight; - zmk,underglow = &led_strip; zmk,matrix-transform = &matrix_transform; }; - - // Commented out until we add more powerful power domain support - // external_power { - // compatible = "zmk,ext-power-generic"; - // init-delay-ms = <200>; - // control-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; - // }; - - rgb_power { - compatible = "zmk,ext-power-generic"; - init-delay-ms = <200>; - control-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; - }; - - backlight: gpioleds { - compatible = "gpio-leds"; - gpio_led_0 { - gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; - }; - }; - - matrix_transform: matrix_transform { - compatible = "zmk,matrix-transform"; - rows = <3>; - columns = <4>; - - map = < - RC(0,0) RC(0,1) - RC(1,0) RC(1,1) - RC(2,0) RC(2,1) RC(2,2) - >; - }; - - direct_matrix_transform: direct_matrix_transform { - compatible = "zmk,matrix-transform"; - rows = <3>; - columns = <4>; - - map = < - RC(0,0) RC(0,1) - RC(0,2) RC(0,3) - RC(1,0) RC(1,1) RC(1,2) - >; - }; - - kscan_matrix_comp: kscan_matrix_comp { - compatible = "zmk,kscan-composite"; - rows = <1>; - columns = <7>; - - matrix { - kscan = <&kscan_matrix>; - }; - - toggle { - kscan = <&kscan_sp3t_toggle>; - row-offset = <2>; - }; - - }; - - kscan_direct_comp: kscan_direct_comp { - compatible = "zmk,kscan-composite"; - status = "disabled"; - - matrix { - kscan = <&kscan_direct>; - }; - - toggle { - kscan = <&kscan_sp3t_toggle>; - row-offset = <1>; - }; - - }; - - kscan_matrix: kscan_matrix { - compatible = "zmk,kscan-gpio-matrix"; - - diode-direction = "col2row"; - - col-gpios - = <&arduino_header 10 GPIO_ACTIVE_HIGH> - , <&arduino_header 9 GPIO_ACTIVE_HIGH> - ; - - row-gpios - = <&arduino_header 13 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&arduino_header 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - ; - - }; - - kscan_direct: kscan_direct { - compatible = "zmk,kscan-gpio-direct"; - status = "disabled"; - - input-gpios - = <&arduino_header 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 11 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - ; - - }; - - kscan_sp3t_toggle: kscan_sp3t_toggle { - compatible = "zmk,kscan-gpio-direct"; - toggle-mode; - - input-gpios - = <&arduino_header 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - , <&arduino_header 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> - ; - }; - - encoder: encoder { - steps = <80>; - compatible = "alps,ec11"; - a-gpios = <&arduino_header 15 GPIO_PULL_UP>; - b-gpios = <&arduino_header 14 GPIO_PULL_UP>; - }; sensors { compatible = "zmk,keymap-sensors"; sensors = <&encoder>; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.dtsi b/app/boards/shields/zmk_uno/zmk_uno_split.dtsi new file mode 100644 index 00000000000..f84aacc8e97 --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno_split.dtsi @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + + #include "zmk_uno.dtsi" + + left_encoder: &encoder { + status = "disabled"; + }; + + / { + chosen { + zmk,matrix-transform = &split_matrix_transform; + }; + + split_matrix_transform: split_matrix_transform { + compatible = "zmk,matrix-transform"; + rows = <3>; + columns = <4>; + + map = < + RC(0,0) RC(0,1) + RC(1,0) RC(1,1) + RC(2,0) RC(2,1) RC(2,2) + RC(3,0) RC(3,1) + RC(4,0) RC(4,1) + RC(5,0) RC(5,1) RC(5,2) + >; + }; + + split_direct_matrix_transform: split_direct_matrix_transform { + compatible = "zmk,matrix-transform"; + rows = <3>; + columns = <4>; + + map = < + RC(0,0) RC(0,1) + RC(0,2) RC(0,3) + RC(1,0) RC(1,1) RC(1,2) + RC(2,0) RC(2,1) + RC(2,2) RC(2,3) + RC(3,0) RC(3,1) RC(3,2) + >; + }; + + right_encoder: right_encoder { + steps = <80>; + status = "disabled"; + compatible = "alps,ec11"; + a-gpios = <&arduino_header 15 GPIO_PULL_UP>; + b-gpios = <&arduino_header 14 GPIO_PULL_UP>; + }; + + sensors { + compatible = "zmk,keymap-sensors"; + sensors = <&encoder &right_encoder>; + triggers-per-rotation = <20>; + }; + }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap new file mode 100644 index 00000000000..05f0ffb0b04 --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include +#include + +// Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. + +/* :REMOVE ME + +&kscan_direct_comp { status = "okay"; }; +&kscan_direct { status = "okay"; }; +&kscan_matrix_comp { status = "disabled"; }; +&kscan_matrix { status = "disabled"; }; + +/ { + chosen { + zmk,matrix-transform = &split_direct_matrix_transform; + zmk,kscan = &kscan_direct_comp; + }; +}; + +REMOVE ME: */ + + +/ { + macros { + ZMK_MACRO(ble_zero, + wait-ms = <1>; + tap-ms = <1>; + bindings = <&out OUT_BLE &bt BT_SEL 0>; + ) + ZMK_MACRO(ble_one, + wait-ms = <1>; + tap-ms = <1>; + bindings = <&out OUT_BLE &bt BT_SEL 1>; + ) + }; + + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &kp A &bl BL_TOG + &rgb_ug RGB_EFF &bt BT_CLR + + &out OUT_USB &ble_zero &ble_one + + &kp C &kp D + &kp E &kp F + &none &none &none + >; + + sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>; + }; + }; +}; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split_left.conf b/app/boards/shields/zmk_uno/zmk_uno_split_left.conf new file mode 100644 index 00000000000..cf282bac2cb --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno_split_left.conf @@ -0,0 +1,18 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +CONFIG_LOG=y +CONFIG_ZMK_LOG_LEVEL_DBG=y + +# Uncomment for Single color backlight +# CONFIG_ZMK_BACKLIGHT=y + +# Uncomment for RGB +# CONFIG_ZMK_RGB_UNDERGLOW=y + +# Uncomment for Display +# CONFIG_ZMK_DISPLAY=y + +# Uncomment these two lines to enable encoder support +# CONFIG_EC11=y +# CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y diff --git a/app/boards/shields/zmk_uno/zmk_uno_split_left.overlay b/app/boards/shields/zmk_uno/zmk_uno_split_left.overlay new file mode 100644 index 00000000000..5782e612d92 --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno_split_left.overlay @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include "zmk_uno_split.dtsi" + +&left_encoder { + status = "okay"; +}; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split_right.conf b/app/boards/shields/zmk_uno/zmk_uno_split_right.conf new file mode 100644 index 00000000000..cf282bac2cb --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno_split_right.conf @@ -0,0 +1,18 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +CONFIG_LOG=y +CONFIG_ZMK_LOG_LEVEL_DBG=y + +# Uncomment for Single color backlight +# CONFIG_ZMK_BACKLIGHT=y + +# Uncomment for RGB +# CONFIG_ZMK_RGB_UNDERGLOW=y + +# Uncomment for Display +# CONFIG_ZMK_DISPLAY=y + +# Uncomment these two lines to enable encoder support +# CONFIG_EC11=y +# CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y diff --git a/app/boards/shields/zmk_uno/zmk_uno_split_right.overlay b/app/boards/shields/zmk_uno/zmk_uno_split_right.overlay new file mode 100644 index 00000000000..9c2e7d7f2ee --- /dev/null +++ b/app/boards/shields/zmk_uno/zmk_uno_split_right.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include "zmk_uno_split.dtsi" + +&split_matrix_transform { + row-offset = <3>; +}; + +&split_direct_matrix_transform { + row-offset = <2>; +}; + +&right_encoder { + status = "okay"; +};