Skip to content

Commit

Permalink
fix(display): POSIX lvgl fixes (zmkfirmware#2812)
Browse files Browse the repository at this point in the history
fix(display): Do LVGL task processing in main on POSIX.

An SDL/Zephyr bug prevents proper display when SDL calls are
made from anything but the main thread, so add task handling
in our simple main function when on POSIX.

fix(usb): Compilation fix for 64-bit targets

Properly handle differences in the size of `size_t` on 64-bit
architectures.

fix(display): Imply, but don't force, LVGL mono theme

Some targets may be using color displays, so instead of forcing
on the mono theme, merely imply it to default it
  • Loading branch information
petejohanson authored and tjmitchem committed Feb 12, 2025
1 parent 03f197a commit 4a2bc34
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/display/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ menuconfig ZMK_DISPLAY
bool "Enable ZMK Display"
select DISPLAY
select LVGL
select LV_CONF_MINIMAL
imply LV_CONF_MINIMAL

if ZMK_DISPLAY

Expand Down
8 changes: 8 additions & 0 deletions app/src/display/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ K_TIMER_DEFINE(display_timer, display_timer_cb, NULL);

void unblank_display_cb(struct k_work *work) {
display_blanking_off(display);
#if !IS_ENABLED(CONFIG_ARCH_POSIX)
k_timer_start(&display_timer, K_MSEC(TICK_MS), K_MSEC(TICK_MS));
#endif // !IS_ENABLED(CONFIG_ARCH_POSIX)
}

#if IS_ENABLED(CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE)

void blank_display_cb(struct k_work *work) {
#if !IS_ENABLED(CONFIG_ARCH_POSIX)
k_timer_stop(&display_timer);
#endif // !IS_ENABLED(CONFIG_ARCH_POSIX)
display_blanking_on(display);
}
K_WORK_DEFINE(blank_display_work, blank_display_cb);
Expand Down Expand Up @@ -132,7 +136,11 @@ int zmk_display_init() {
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY, NULL);
#endif

#if IS_ENABLED(CONFIG_ARCH_POSIX)
initialize_display(NULL);
#else
k_work_submit_to_queue(zmk_display_work_q(), &init_work);
#endif

LOG_DBG("");
return 0;
Expand Down
15 changes: 15 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL);

#if IS_ENABLED(CONFIG_ZMK_DISPLAY)

#include <zmk/display.h>
#include <lvgl.h>

#endif

int main(void) {
LOG_INF("Welcome to ZMK!\n");
Expand All @@ -24,6 +29,16 @@ int main(void) {

#ifdef CONFIG_ZMK_DISPLAY
zmk_display_init();

#if IS_ENABLED(CONFIG_ARCH_POSIX)
// Workaround for an SDL display issue:
// https://github.com/zephyrproject-rtos/zephyr/issues/71410
while (1) {
lv_task_handler();
k_sleep(K_MSEC(10));
}
#endif

#endif /* CONFIG_ZMK_DISPLAY */

return 0;
Expand Down
4 changes: 3 additions & 1 deletion app/src/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ static int get_report_cb(const struct device *dev, struct usb_setup_packet *setu
case HID_REPORT_TYPE_INPUT:
switch (setup->wValue & HID_GET_REPORT_ID_MASK) {
case ZMK_HID_REPORT_ID_KEYBOARD: {
*data = get_keyboard_report(len);
size_t size;
*data = get_keyboard_report(&size);
*len = (int32_t)size;
break;
}
case ZMK_HID_REPORT_ID_CONSUMER: {
Expand Down

0 comments on commit 4a2bc34

Please sign in to comment.