-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
4 changed files
with
103 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) 2021 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: LED indicators | ||
|
||
compatible: "zmk,led-indicators" | ||
|
||
child-binding: | ||
description: LED indicator | ||
|
||
properties: | ||
ctrl: | ||
type: phandle | ||
required: true | ||
index: | ||
type: int | ||
required: true | ||
binding: | ||
type: int | ||
required: true |
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,68 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <device.h> | ||
#include <init.h> | ||
|
||
#include <logging/log.h> | ||
#include <drivers/led.h> | ||
|
||
#include <zmk/event_manager.h> | ||
#include <zmk/led_indicators.h> | ||
#include <zmk/events/led_indicator_changed.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
BUILD_ASSERT(DT_HAS_CHOSEN(zmk_led_indicators), | ||
"CONFIG_ZMK_LED_INDICATORS is enabled but no zmk,led-indicators chosen node found"); | ||
|
||
struct zmk_led_cfg { | ||
const struct device *ctrl; | ||
int index; | ||
int binding; | ||
}; | ||
|
||
#define LED_CFG(node_id) \ | ||
(struct zmk_led_cfg){ \ | ||
.ctrl = DEVICE_DT_GET(DT_PHANDLE(node_id, ctrl)), \ | ||
.index = DT_PROP(node_id, index), \ | ||
.binding = DT_PROP(node_id, binding), \ | ||
}, | ||
|
||
static const struct zmk_led_cfg led_indicators[] = { | ||
DT_FOREACH_CHILD(DT_CHOSEN(zmk_led_indicators), LED_CFG)}; | ||
|
||
static int leds_init(const struct device *_arg) { | ||
for (int i = 0; i < ARRAY_SIZE(led_indicators); i++) { | ||
if (!device_is_ready(led_indicators[i].ctrl)) { | ||
LOG_ERR("LED device \"%s\" is not ready", led_indicators[i].ctrl->name); | ||
return -ENODEV; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int leds_listener(const zmk_event_t *eh) { | ||
zmk_leds_flags_t flags = zmk_leds_get_current_flags(); | ||
|
||
for (int i = 0; i < ARRAY_SIZE(led_indicators); i++) { | ||
uint8_t value = | ||
(flags & BIT(led_indicators[i].binding)) ? CONFIG_ZMK_LED_INDICATORS_BRT : 0; | ||
int rc = led_set_brightness(led_indicators[i].ctrl, led_indicators[i].index, value); | ||
if (rc != 0) { | ||
return rc; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
ZMK_LISTENER(leds_listener, leds_listener); | ||
ZMK_SUBSCRIPTION(leds_listener, zmk_led_changed); | ||
|
||
SYS_INIT(leds_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); |