Skip to content

Commit

Permalink
feat(helios): syncing with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvinsh committed Nov 15, 2024
1 parent 5a33c7a commit 5493f05
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 13 deletions.
1 change: 1 addition & 0 deletions boards/shields/helios/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_sources(app PRIVATE leds.c)
File renamed without changes.
4 changes: 3 additions & 1 deletion boards/shields/helios/helios.conf
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CONFIG_ZMK_BACKLIGHT=y
CONFIG_ZMK_STUDIO=y
CONFIG_ZMK_HID_INDICATORS=y
CONFIG_LED=y
31 changes: 19 additions & 12 deletions boards/shields/helios/helios.overlay
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <dt-bindings/led/led.h>
#include <dt-bindings/zmk/matrix_transform.h>

#include "helios_layout.dtsi"
#include "helios-layout.dtsi"

&helios_layout {
transform = <&default_transform>;
Expand All @@ -10,23 +9,31 @@
/ {
chosen {
zmk,kscan = &kscan0;
zmk,backlight = &backlight;
zmk,physical-layout = &helios_layout;
zephyr,code-partition = &code_partition;
};

backlight: gpioleds {
aliases {
led-caps = &led_0;
led-num = &led_1;
led-scroll = &led_2;
led-layer = &led_3;
};

leds {
compatible = "gpio-leds";
gpio_led_0 {
gpios = <&blackpill 46 GPIO_ACTIVE_LOW>;
status = "okay";
led_0: led_0 {
gpios = <&blackpill 46 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
gpio_led_1 {
gpios = <&blackpill 10 GPIO_ACTIVE_LOW>;
led_1: led_1 {
gpios = <&blackpill 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
gpio_led_2 {
gpios = <&blackpill 11 GPIO_ACTIVE_LOW>;
led_2: led_2 {
gpios = <&blackpill 11 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
gpio_led_3 {
gpios = <&blackpill 12 GPIO_ACTIVE_LOW>;
led_3: led_3 {
gpios = <&blackpill 12 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
};

Expand Down
1 change: 1 addition & 0 deletions boards/shields/helios/helios.zmk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ requires:
features:
- keys
- backlight
- studio
71 changes: 71 additions & 0 deletions boards/shields/helios/leds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/led.h>
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <zmk/hid_indicators.h>
#include <zmk/events/hid_indicators_changed.h>
#include <zmk/events/layer_state_changed.h>

#define LED_GPIO_NODE_ID DT_COMPAT_GET_ANY_STATUS_OKAY(gpio_leds)

// GPIO-based LED device
static const struct device *led_dev = DEVICE_DT_GET(LED_GPIO_NODE_ID);

static int led_keylock_listener_cb(const zmk_event_t *eh) {
zmk_hid_indicators_t flags = zmk_hid_indicators_get_current_profile();
unsigned int capsBit = 1 << (HID_USAGE_LED_CAPS_LOCK - 1);
unsigned int numBit = 1 << (HID_USAGE_LED_NUM_LOCK - 1);
unsigned int scrollBit = 1 << (HID_USAGE_LED_SCROLL_LOCK - 1);

if (flags & capsBit) {
led_on(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_caps)));
} else {
led_off(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_caps)));
}

if (flags & numBit) {
led_on(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_num)));
} else {
led_off(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_num)));
}

if (flags & scrollBit) {
led_on(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_scroll)));
} else {
led_off(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_scroll)));
}

return 0;
}

ZMK_LISTENER(led_indicators_listener, led_keylock_listener_cb);
ZMK_SUBSCRIPTION(led_indicators_listener, zmk_hid_indicators_changed);

// Layer state listener for layer #1 LED
static int led_layer_listener_cb(const zmk_event_t *eh) {
const struct zmk_layer_state_changed *ev = as_zmk_layer_state_changed(eh);

if (ev->layer == 1) { // Check if the event is for layer #1
if (ev->state) {
led_on(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_layer)));
} else {
led_off(led_dev, DT_NODE_CHILD_IDX(DT_ALIAS(led_layer)));
}
}
return 0;
}

ZMK_LISTENER(layer_led_listener, led_layer_listener_cb);
ZMK_SUBSCRIPTION(layer_led_listener, zmk_layer_state_changed);

static int leds_init(const struct device *device) {
if (!device_is_ready(led_dev)) {
return -ENODEV;
}

return 0;
}

// run leds_init on boot
SYS_INIT(leds_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

0 comments on commit 5493f05

Please sign in to comment.