Enable RGB and leds

This commit is contained in:
Richard Titmuss 2022-03-07 07:56:22 +01:00 committed by Panayiotis Constantinou Briggs
parent e53d85e1a7
commit f83a4dd711
7 changed files with 90 additions and 54 deletions

View file

@ -1,5 +1,3 @@
#ifdef CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL
#include <init.h>
#include <device.h>
#include <devicetree.h>
@ -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

View file

@ -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";
};

View file

@ -8,6 +8,7 @@
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/ext_power.h>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/rgb.h>
#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>;

View file

@ -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";
};

View file

@ -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

View file

@ -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>;
};
};

View file

@ -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