diff --git a/app/boards/arm/tornblue/led_driver.c b/app/boards/arm/tornblue/led_driver.c index ddc26f0a..e63c3ba5 100644 --- a/app/boards/arm/tornblue/led_driver.c +++ b/app/boards/arm/tornblue/led_driver.c @@ -1,5 +1,3 @@ -#ifdef CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL - #include #include #include @@ -42,32 +40,38 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #error "Unsupported board: led3 devicetree alias is not defined" #endif -int led_event_handler(const zmk_event_t *eh) { - const struct device *dev = device_get_binding(LED1); +static void led_pin_init(const char *name, gpio_pin_t pin, gpio_dt_flags_t dt_flags) { + const struct device *dev = device_get_binding(name); + gpio_pin_configure(dev, pin, GPIO_OUTPUT_ACTIVE | dt_flags); + gpio_pin_set(dev, pin, 0); +} + +static void led_pin_set(const char *name, gpio_pin_t pin, int value) { + const struct device *dev = device_get_binding(name); + gpio_pin_set(dev, pin, value); +} + +static int led_event_handler(const zmk_event_t *eh) { const uint8_t layer_active = zmk_keymap_highest_layer_active(); - gpio_pin_set(dev, PIN3, layer_active == 3 /* Nav */); - gpio_pin_set(dev, PIN2, layer_active == 7 /* Symbol */); - gpio_pin_set(dev, PIN1, layer_active == 6 /* Num */); + led_pin_set(LED3, PIN3, layer_active == 3 /* Nav */); + led_pin_set(LED2, PIN2, layer_active == 7 /* Symbol */); + led_pin_set(LED1, PIN1, layer_active == 6 /* Num */); return 0; } static int led_init(const struct device *port) { - const struct device *dev = device_get_binding(LED1); - gpio_pin_configure(dev, PIN1, GPIO_OUTPUT_ACTIVE | FLAGS1); - gpio_pin_configure(dev, PIN2, GPIO_OUTPUT_ACTIVE | FLAGS2); - gpio_pin_configure(dev, PIN3, GPIO_OUTPUT_ACTIVE | FLAGS3); - - gpio_pin_set(dev, PIN3, 0); - gpio_pin_set(dev, PIN2, 0); - gpio_pin_set(dev, PIN1, 0); + led_pin_init(LED1, PIN1, FLAGS1); + led_pin_init(LED2, PIN2, FLAGS2); + led_pin_init(LED3, PIN3, FLAGS3); return 0; } ZMK_LISTENER(led, led_event_handler); + +#ifdef CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL ZMK_SUBSCRIPTION(led, zmk_layer_state_changed); +#endif SYS_INIT(led_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); - -#endif \ No newline at end of file diff --git a/app/boards/arm/tornblue/tornblue.dtsi b/app/boards/arm/tornblue/tornblue.dtsi index d924bacf..171b7b27 100644 --- a/app/boards/arm/tornblue/tornblue.dtsi +++ b/app/boards/arm/tornblue/tornblue.dtsi @@ -76,30 +76,6 @@ RC(2,0) RC(2,1) RC(3,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(3,9) status = "okay"; }; -&spi0 { - compatible = "nordic,nrf-spim"; - // Cannot be used together with i2c0 - status = "okay"; - mosi-pin = <23>; - // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. - sck-pin = <6>; - miso-pin = <8>; - - 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 = <6>; /* LED strip length */ - spi-one-frame = <0x70>; - spi-zero-frame = <0x40>; - }; -}; - &usbd { status = "okay"; }; diff --git a/app/boards/arm/tornblue/tornblue.keymap b/app/boards/arm/tornblue/tornblue.keymap index ed72896e..5c6e4abb 100644 --- a/app/boards/arm/tornblue/tornblue.keymap +++ b/app/boards/arm/tornblue/tornblue.keymap @@ -8,6 +8,7 @@ #include #include #include +#include #define DEFAULT 0 #define NAVI 1 @@ -26,7 +27,7 @@ &kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSPC &kp LCTRL &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp ESC - &kp SPACE &kp LGUI &mo 1 &kp SPACE &kp RET &mo 2 &kp RALT &kp RET + &kp SPACE &kp LGUI &mo 1 &kp SPACE &rgb_ug RGB_TOG &rgb_ug RGB_EFF &kp RALT &kp RET >; sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; diff --git a/app/boards/arm/tornblue/tornblue_left.dts b/app/boards/arm/tornblue/tornblue_left.dts index 27d3b8d5..71cf8b1a 100644 --- a/app/boards/arm/tornblue/tornblue_left.dts +++ b/app/boards/arm/tornblue/tornblue_left.dts @@ -41,16 +41,16 @@ leds { compatible = "gpio-leds"; led1: led1 { - gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; - label = "LED 1"; + gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; + label = "LED 1"; /* D28 */ }; led2: led2 { - gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; - label = "LED 2"; + gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; + label = "LED 2"; /* D27 */ }; led3: led3 { - gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; - label = "LED 3"; + gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>; + label = "LED 3"; /* D26 */ }; }; @@ -61,6 +61,30 @@ }; }; +&spi0 { + compatible = "nordic,nrf-spim"; + // Cannot be used together with i2c0 + status = "okay"; + mosi-pin = <23>; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + sck-pin = <6>; + miso-pin = <8>; + + 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 = <6>; /* LED strip length */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + }; +}; + &left_encoder { status = "okay"; }; diff --git a/app/boards/arm/tornblue/tornblue_left_defconfig b/app/boards/arm/tornblue/tornblue_left_defconfig index 38b9af42..62aade0c 100644 --- a/app/boards/arm/tornblue/tornblue_left_defconfig +++ b/app/boards/arm/tornblue/tornblue_left_defconfig @@ -20,11 +20,10 @@ CONFIG_FLASH_MAP=y CONFIG_ZMK_RGB_UNDERGLOW=y CONFIG_WS2812_STRIP=y -CONFIG_ZMK_RGB_UNDERGLOW_HUE_START=160 -CONFIG_ZMK_RGB_UNDERGLOW_EFF_START=3 - CONFIG_EC11=y CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y # Turn on logging, and set ZMK logging to debug output #CONFIG_ZMK_USB_LOGGING=y + +#CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y diff --git a/app/boards/arm/tornblue/tornblue_right.dts b/app/boards/arm/tornblue/tornblue_right.dts index 8c857654..372d5dd1 100644 --- a/app/boards/arm/tornblue/tornblue_right.dts +++ b/app/boards/arm/tornblue/tornblue_right.dts @@ -33,15 +33,15 @@ compatible = "gpio-leds"; led1: led1 { gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>; - label = "LED 1"; + label = "LED 4"; /* D42 */ }; led2: led2 { gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>; - label = "LED 2"; + label = "LED 5"; /* D43 */ }; led3: led3 { gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>; - label = "LED 3"; + label = "LED 6"; /* D44 */ }; }; @@ -51,3 +51,27 @@ control-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>; }; }; + +&spi0 { + compatible = "nordic,nrf-spim"; + // Cannot be used together with i2c0 + status = "okay"; + mosi-pin = <22>; + // Unused pins, needed for SPI definition, but not used by the ws2812 driver itself. + sck-pin = <27>; + miso-pin = <8>; + + 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 = <6>; /* LED strip length */ + spi-one-frame = <0x70>; + spi-zero-frame = <0x40>; + }; +}; diff --git a/app/boards/arm/tornblue/tornblue_right_defconfig b/app/boards/arm/tornblue/tornblue_right_defconfig index 22750b7d..6faaee59 100644 --- a/app/boards/arm/tornblue/tornblue_right_defconfig +++ b/app/boards/arm/tornblue/tornblue_right_defconfig @@ -17,5 +17,13 @@ CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y +CONFIG_ZMK_RGB_UNDERGLOW=y +CONFIG_WS2812_STRIP=y + +CONFIG_EC11=y +CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y + # Turn on logging, and set ZMK logging to debug output #CONFIG_ZMK_USB_LOGGING=y + +#CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y