From 4b4a8a35f3f90f1af75cdf5d9c26b47d4b8dcabb Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 7 Feb 2025 00:05:21 -0700 Subject: [PATCH] fix(display): POSIX lvgl fixes (#2812) 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 --- app/src/display/Kconfig | 2 +- app/src/display/main.c | 8 ++++++++ app/src/main.c | 15 +++++++++++++++ app/src/usb_hid.c | 4 +++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/display/Kconfig b/app/src/display/Kconfig index 14a380b92..64e12b73e 100644 --- a/app/src/display/Kconfig +++ b/app/src/display/Kconfig @@ -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 diff --git a/app/src/display/main.c b/app/src/display/main.c index e15e2de0c..361f1fcaf 100644 --- a/app/src/display/main.c +++ b/app/src/display/main.c @@ -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); @@ -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; diff --git a/app/src/main.c b/app/src/main.c index 60df1a45d..0f77382ad 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -12,7 +12,12 @@ #include LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL); +#if IS_ENABLED(CONFIG_ZMK_DISPLAY) + #include +#include + +#endif int main(void) { LOG_INF("Welcome to ZMK!\n"); @@ -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; diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 945ae9890..9adc7db80 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -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: {