Skip to content

Commit 627e6db

Browse files
authored
feat(display): Add ability to set display on/off pin. (#2814)
Zephyr is still working on the plan upstream for generically controlling display "backlight" pins with GPIO/PWM, so in the meantime, add our own chosen property `zmk,display-led` that is set to an LED device child to allow blanking/unblanking of devices that use a dedicated backlight control pin.
1 parent 424e532 commit 627e6db

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

app/src/display/main.c

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
1414

1515
#include <zephyr/drivers/display.h>
16+
#include <zephyr/drivers/led.h>
1617
#include <lvgl.h>
1718

1819
#include "theme.h"
@@ -22,6 +23,14 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
2223
#include <zmk/display/status_screen.h>
2324

2425
static const struct device *display = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
26+
27+
#if DT_HAS_CHOSEN(zmk_display_led)
28+
29+
static const struct device *display_led = DEVICE_DT_GET(DT_PARENT(DT_CHOSEN(zmk_display_led)));
30+
static const uint8_t display_led_idx = DT_NODE_CHILD_IDX(DT_CHOSEN(zmk_display_led));
31+
32+
#endif
33+
2534
static bool initialized = false;
2635

2736
static lv_obj_t *screen;
@@ -55,6 +64,9 @@ void display_timer_cb() { k_work_submit_to_queue(zmk_display_work_q(), &display_
5564
K_TIMER_DEFINE(display_timer, display_timer_cb, NULL);
5665

5766
void unblank_display_cb(struct k_work *work) {
67+
#if DT_HAS_CHOSEN(zmk_display_led)
68+
led_on(display_led, display_led_idx);
69+
#endif
5870
display_blanking_off(display);
5971
#if !IS_ENABLED(CONFIG_ARCH_POSIX)
6072
k_timer_start(&display_timer, K_MSEC(TICK_MS), K_MSEC(TICK_MS));
@@ -68,6 +80,9 @@ void blank_display_cb(struct k_work *work) {
6880
k_timer_stop(&display_timer);
6981
#endif // !IS_ENABLED(CONFIG_ARCH_POSIX)
7082
display_blanking_on(display);
83+
#if DT_HAS_CHOSEN(zmk_display_led)
84+
led_off(display_led, display_led_idx);
85+
#endif
7186
}
7287
K_WORK_DEFINE(blank_display_work, blank_display_cb);
7388
K_WORK_DEFINE(unblank_display_work, unblank_display_cb);

docs/docs/config/displays.md

+9
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ See the Devicetree bindings for your display. Here are the bindings for common d
6262
- [SSD1306 (spi)](https://docs.zephyrproject.org/3.5.0/build/dts/api/bindings/display/solomon,ssd1306fb-spi.html)
6363

6464
A full list of drivers provided by Zephyr can be found in [Zephyr's Devicetree bindings index](https://docs.zephyrproject.org/3.5.0/build/dts/api/bindings.html).
65+
66+
### Chosen nodes
67+
68+
Applies to: [`/chosen` node](https://docs.zephyrproject.org/3.5.0/build/dts/intro-syntax-structure.html#aliases-and-chosen-nodes)
69+
70+
| Property | Type | Description |
71+
| ----------------- | ---- | -------------------------------------------------------------------------------------------------------- |
72+
| `zephyr,display` | path | The display device to use. |
73+
| `zmk,display-led` | path | The LED device to use for on/off blanking, if the hardware requires it. Can be a PWM or GPIO LED device. |

0 commit comments

Comments
 (0)