-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target_sources(app PRIVATE leds.c) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ requires: | |
features: | ||
- keys | ||
- backlight | ||
- studio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |