From ef6646379eb378c837b74f7b8bb786ee6d5b6382 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Tue, 9 Sep 2025 14:25:16 +0200 Subject: [PATCH 1/3] pkg/lvgl/lv_conf: fix documentation --- pkg/lvgl/include/lv_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/lvgl/include/lv_conf.h b/pkg/lvgl/include/lv_conf.h index 0eaf494033..305c63b57f 100644 --- a/pkg/lvgl/include/lv_conf.h +++ b/pkg/lvgl/include/lv_conf.h @@ -30,7 +30,7 @@ extern "C" { *====================*/ /* Color depth: - * - 1: 1 byte per pixel + * - 1: 1 bit per pixel * - 8: RGB233 * - 16: RGB565 * - 32: ARGB8888 From d4e18fb555fc3cf9d73c0eac20d6c01047212b9d Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Wed, 10 Sep 2025 13:39:20 +0200 Subject: [PATCH 2/3] sys/auto_init/screen/lvgl: check if display is present --- sys/auto_init/screen/auto_init_lvgl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/auto_init/screen/auto_init_lvgl.c b/sys/auto_init/screen/auto_init_lvgl.c index 3771b1f337..3ffa04f11a 100644 --- a/sys/auto_init/screen/auto_init_lvgl.c +++ b/sys/auto_init/screen/auto_init_lvgl.c @@ -50,6 +50,10 @@ void auto_init_lvgl(void) /* Only a single screen is supported by lvgl */ #if !IS_USED(MODULE_LV_DRIVERS_SDL) disp_dev_reg_t *disp_dev = disp_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT); + if (disp_dev == NULL) { + puts("[auto_init_screen] error: no display device found\n"); + return; + } s_screen.display = disp_dev->dev; #endif From 1dae523f07f74f41e045d2926682ddac177e544f Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Tue, 9 Sep 2025 14:26:01 +0200 Subject: [PATCH 3/3] pkg/lvgl: allow monochrome displays --- pkg/lvgl/contrib/lvgl.c | 29 ++++++++++++++++++++++++++++- pkg/lvgl/include/lv_conf.h | 6 +++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pkg/lvgl/contrib/lvgl.c b/pkg/lvgl/contrib/lvgl.c index 28d16a6f78..96347a3900 100644 --- a/pkg/lvgl/contrib/lvgl.c +++ b/pkg/lvgl/contrib/lvgl.c @@ -39,7 +39,11 @@ #endif #ifndef LVGL_COLOR_BUF_SIZE -#define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10) +# if IS_USED(MODULE_U8G2_DISP_DEV) +# define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10 * 8) +# else +# define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10) +# endif #endif #ifndef CONFIG_LVGL_INACTIVITY_PERIOD_MS @@ -134,6 +138,23 @@ static void _touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) } #endif +/* Pixel placement for monochrome displays where color depth is 1 bit, and each bit represents + a pixel */ +static void _monochrome_1bit_set_px_cb(lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, + lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa) +{ + (void)disp_drv; + (void)opa; + + uint16_t byte = (y * buf_w / 8) + (x / 8); + if (lv_color_brightness(color) > 128) { + (buf[byte]) |= (1 << (x % 8)); + } + else { + (buf[byte]) &= ~(1 << (x % 8)); + } +} + void lvgl_init(screen_dev_t *screen_dev) { lv_init(); @@ -164,6 +185,11 @@ void lvgl_init(screen_dev_t *screen_dev) disp_drv.ver_res = disp_dev_height(screen_dev->display); #endif + if (disp_dev_color_depth(screen_dev->display) == 1) { + disp_drv.full_refresh = 1; + disp_drv.set_px_cb = _monochrome_1bit_set_px_cb; + } + lv_disp_drv_register(&disp_drv); #if IS_USED(MODULE_TOUCH_DEV) @@ -208,5 +234,6 @@ void lvgl_run(void) void lvgl_wakeup(void) { thread_t *tcb = thread_get(_task_thread_pid); + thread_flags_set(tcb, LVGL_THREAD_FLAG); } diff --git a/pkg/lvgl/include/lv_conf.h b/pkg/lvgl/include/lv_conf.h index 305c63b57f..f57f70ffdc 100644 --- a/pkg/lvgl/include/lv_conf.h +++ b/pkg/lvgl/include/lv_conf.h @@ -36,7 +36,11 @@ extern "C" { * - 32: ARGB8888 */ #ifndef LV_COLOR_DEPTH -#define LV_COLOR_DEPTH 16 +# if IS_USED(MODULE_U8G2_DISP_DEV) +# define LV_COLOR_DEPTH 1 +# else +# define LV_COLOR_DEPTH 16 +# endif #endif /* Swap the 2 bytes of RGB565 color.