mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-28 08:55:17 -05:00
feat: Add LED indicator support (#3239)
This adds a new zmk,indicator-leds device, which maps HID indicator states onto any devices that implement the LED driver API. This adds support for things like a caps lock LED. The name was chosen so that more drivers could be added later as zmk,indicator-*, for example a version that uses the LED strip API.
This commit is contained in:
41
docs/docs/config/led-indicators.md
Normal file
41
docs/docs/config/led-indicators.md
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
title: LED Indicators Configuration
|
||||
sidebar_label: LED Indicators
|
||||
---
|
||||
|
||||
See the [LED indicators feature page](../features/led-indicators.md) for more details.
|
||||
|
||||
See [Configuration Overview](index.md) for instructions on how to change these settings.
|
||||
|
||||
## Kconfig
|
||||
|
||||
Definition files:
|
||||
|
||||
- [zmk/app/src/indicators/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/src/indicators/Kconfig)
|
||||
|
||||
| Config | Type | Description | Default |
|
||||
| ----------------------------------------- | ---- | --------------------------------------------------- | ------- |
|
||||
| `CONFIG_ZMK_INDICATOR_LEDS_INIT_PRIORITY` | int | Indicator LED device driver initialization priority | 91 |
|
||||
|
||||
`CONFIG_ZMK_INDICATOR_LEDS_INIT_PRIORITY` must be set to a larger value than `CONFIG_LED_INIT_PRIORITY`.
|
||||
|
||||
## Indicator LED Driver
|
||||
|
||||
This driver maps HID indicator states to [LED API](https://docs.zephyrproject.org/4.1.0/hardware/peripherals/led.html) devices.
|
||||
|
||||
### Devicetree
|
||||
|
||||
Applies to: `compatible = "zmk,indicator-leds"`
|
||||
|
||||
Definition file: [zmk/app/dts/bindings/indicators/zmk,indicator-leds.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/indicators/zmk%2Cindicator-leds.yaml)
|
||||
|
||||
| Property | Type | Description | Default |
|
||||
| ------------------------- | -------- | --------------------------------------------------------------------- | ------- |
|
||||
| `indicator` | int | The `HID_INDICATOR_*` value to indicate | |
|
||||
| `leds` | phandles | One or more LED devices to control | |
|
||||
| `active-brightness` | int | LED brightness in percent when the indicator is active | 100 |
|
||||
| `inactive-brightness` | int | LED brightness in percent when the indicator is not active | 0 |
|
||||
| `disconnected-brightness` | int | LED brightness in percent when the keyboard is not connected | 0 |
|
||||
| `on-while-idle` | bool | Keep LEDs enabled even when the keyboard is idle and on battery power | false |
|
||||
|
||||
The `indicator` property must be one of the `HID_INDICATOR_*` values defined in [zmk/app/include/dt-bindings/zmk/hid_indicators.h](https://github.com/zmkfirmware/zmk/blob/main/app/include/dt-bindings/zmk/hid_indicators.h). You may also combine values with `|` to make the LED be lit when any of the indicator states are active.
|
||||
@@ -0,0 +1,118 @@
|
||||
---
|
||||
title: LED Indicators
|
||||
sidebar_label: LED Indicators
|
||||
description: Lighting system that indicates HID states such as caps lock.
|
||||
---
|
||||
|
||||
ZMK supports the following five LED indicator states from the HID specification:
|
||||
|
||||
- Num Lock
|
||||
- Caps Lock
|
||||
- Scroll Lock
|
||||
- Compose
|
||||
- Kana
|
||||
|
||||
To connect these indicator states to LEDs on a keyboard, you must do two things in your board or shield files:
|
||||
|
||||
1. Define an LED driver and one or more LEDs to control.
|
||||
2. Configure ZMK to control those LEDs.
|
||||
|
||||
## LED Definitions
|
||||
|
||||
The most common setup is for LEDs to be driven directly from a GPIO pin. The examples on this page show how to controls these using the `gpio-leds` or `pwm-leds` drivers, but you can also use any other [LED driver](https://docs.zephyrproject.org/4.1.0/hardware/peripherals/led.html) from Zephyr.
|
||||
|
||||
:::warning
|
||||
LED strip drivers (e.g. WS2812 LEDs) are not currently supported. More work is needed to support the separate API and avoid conflicts with the underglow system.
|
||||
:::
|
||||
|
||||
In your shield's `.overlay` file or board's `.dts` file, create a `gpio-leds` node and define any LEDs that you want to be able to control. The following example defines two LEDs on `&gpio0 1` and `&gpio0 2` which are enabled by driving the pins high:
|
||||
|
||||
```dts
|
||||
/ {
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
|
||||
num_lock_led: num_lock_led {
|
||||
gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
|
||||
caps_lock_led: caps_lock_led {
|
||||
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
### PWM Brightness Control
|
||||
|
||||
The above example only supports LEDs being off or on at full brightness. If you want to be able to reduce the brightness or use multiple brightness levels, you must use `pwm-leds` instead of `gpio-leds`. Note that this will increase power usage slightly when LEDs are enabled compared to using `gpio-leds`.
|
||||
|
||||
See the [backlight hardware integration page](backlight.mdx) for an example of configuring PWM LEDs.
|
||||
|
||||
## Indicator Definitions
|
||||
|
||||
Now that you have some LEDs defined, you can configure ZMK to use them.
|
||||
|
||||
In your shield's `.overlay` file or board's `.dts` file, add the following include to the top of the file:
|
||||
|
||||
```dts
|
||||
#include <dt-bindings/zmk/hid_indicators.h>
|
||||
```
|
||||
|
||||
Then, add a `zmk,indicator-leds` node. This node can have any number of child nodes. Each child maps an indicator state to one or more LEDs:
|
||||
|
||||
```dts
|
||||
/ {
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
|
||||
// LEDs as defined in the previous step
|
||||
num_lock_led: num_lock_led { ... };
|
||||
caps_lock_led: caps_lock_led { ... };
|
||||
};
|
||||
|
||||
indicators {
|
||||
compatible = "zmk,indicator-leds";
|
||||
|
||||
num_lock_indicator: num_lock {
|
||||
indicator = <HID_INDICATOR_NUM_LOCK>;
|
||||
leds = <&num_lock_led>;
|
||||
};
|
||||
|
||||
caps_lock_indicator: caps_lock {
|
||||
indicator = <HID_INDICATOR_CAPS_LOCK>;
|
||||
leds = <&caps_lock_led>;
|
||||
};
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
The name of each child node is unimportant, but you should give each node a label so users can change their settings in `.keymap` files. Conventionally, you should use one of the following:
|
||||
|
||||
- `num_lock_indicator`
|
||||
- `caps_lock_indicator`
|
||||
- `scroll_lock_indicator`
|
||||
- `compose_indicator`
|
||||
- `kana_indicator`
|
||||
|
||||
(If you have a non-standard setup and need to use different labels, you should document this somewhere so users know how to configure them.)
|
||||
|
||||
Each child node must have an `indicator` property, which is set to one of the following:
|
||||
|
||||
- `HID_INDICATOR_NUM_LOCK`
|
||||
- `HID_INDICATOR_CAPS_LOCK`
|
||||
- `HID_INDICATOR_SCROLL_LOCK`
|
||||
- `HID_INDICATOR_COMPOSE`
|
||||
- `HID_INDICATOR_KANA`
|
||||
|
||||
Each child node must also have an `leds` property, which holds a list of LED nodes to control. In this example, the LEDs are labeled `num_lock_led` and `caps_lock_led`, so the `leds` properties refer to them with `&num_lock_led` and `&caps_lock_led`, respectively.
|
||||
|
||||
You can also control multiple LEDs from the same indicator:
|
||||
|
||||
```dts
|
||||
leds = <&led_1 &led_2>;
|
||||
```
|
||||
|
||||
## LED Behavior
|
||||
|
||||
See the [feature page](../../../features/led-indicators.md) and [configuration page](../../../config/led-indicators.md) for details on configuring LED brightness according to the indicator state.
|
||||
67
docs/docs/features/led-indicators.md
Normal file
67
docs/docs/features/led-indicators.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: LED Indicators
|
||||
sidebar_label: LED Indicators
|
||||
---
|
||||
|
||||
ZMK supports the following five LED indicator states from the HID specification:
|
||||
|
||||
- Num Lock
|
||||
- Caps Lock
|
||||
- Scroll Lock
|
||||
- Compose
|
||||
- Kana
|
||||
|
||||
If your keyboard supports this feature, ZMK will display some or all of these states on LEDs.
|
||||
|
||||
The default behavior for an indicator LED is as follows:
|
||||
|
||||
- If the keyboard is on battery power and idle, the LED is off.
|
||||
- If the keyboard is not connected to any host, the LED is off.
|
||||
- If the indicator state is active, the LED is on at full brightness.
|
||||
- Otherwise, the LED is off.
|
||||
|
||||
If you want to change these behaviors, you can set properties on the devicetree nodes for each indicator in your `.keymap` file. The conventional node labels for indicators are as follows:
|
||||
|
||||
- `num_lock_indicator`
|
||||
- `caps_lock_indicator`
|
||||
- `scroll_lock_indicator`
|
||||
- `compose_indicator`
|
||||
- `kana_indicator`
|
||||
|
||||
The examples below all use `caps_lock_indicator`. To edit a different indicator, use the relevant label for that indicator instead.
|
||||
|
||||
## Idle Behavior
|
||||
|
||||
The `on-while-idle` property prevents the LED from turning off when the keyboard on battery power and idle:
|
||||
|
||||
```dts
|
||||
&caps_lock_indicator {
|
||||
on-while-idle;
|
||||
};
|
||||
```
|
||||
|
||||
## LED Brightness
|
||||
|
||||
The `active-brightness`, `inactive-brightness`, and `disconnected-brightness` properties control the brightness of the LED when the indicator is active, indicator is not active, and the keyboard is not connected to any host, respectively.
|
||||
|
||||
For example, if you want the LED to be off when the indicator is active, 100% brightness when inactive, and 50% brightness when not connected:
|
||||
|
||||
```dts
|
||||
&caps_lock_indicator {
|
||||
active-brightness = <0>;
|
||||
inactive-brightness = <100>;
|
||||
disconnected-brightness = <50>;
|
||||
};
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
If the LED is not configured to support brightness control, any value greater than 0 will result in maximum brightness.
|
||||
|
||||
For most LEDs, you can enable PWM brightness control, though this will increase power usage slightly. See the [LED indicators hardware integration page](../development/hardware-integration/lighting/led-indicators.md) for details on configuring the LEDs.
|
||||
|
||||
:::
|
||||
|
||||
## Adding LED Indicator Support to a Keyboard
|
||||
|
||||
See the [LED indicators hardware integration page](../development/hardware-integration/lighting/led-indicators.md) for instructions to enable this feature on a keyboard.
|
||||
@@ -38,6 +38,7 @@ module.exports = {
|
||||
"features/split-keyboards",
|
||||
"features/debouncing",
|
||||
"features/battery",
|
||||
"features/led-indicators",
|
||||
"features/low-power-states",
|
||||
"features/encoders",
|
||||
"features/pointing",
|
||||
@@ -126,6 +127,7 @@ module.exports = {
|
||||
"config/combos",
|
||||
"config/displays",
|
||||
"config/encoders",
|
||||
"config/led-indicators",
|
||||
"config/lighting",
|
||||
"config/pointing",
|
||||
"config/keymap",
|
||||
@@ -187,6 +189,7 @@ module.exports = {
|
||||
items: [
|
||||
"development/hardware-integration/lighting/underglow",
|
||||
"development/hardware-integration/lighting/backlight",
|
||||
"development/hardware-integration/lighting/led-indicators",
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user