From ec06163402ec7e7a24e4097920ee9efc6b2d4920 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 28 Feb 2022 09:23:32 +0100 Subject: [PATCH] pkg/lvgl: adapt to SDL display and input driver --- pkg/lvgl/contrib/lvgl.c | 33 +++++++++++++++++++++++++-- pkg/lvgl/doc.txt | 4 ++++ pkg/lvgl/include/lvgl_riot_conf.h | 4 ++++ sys/auto_init/screen/auto_init_lvgl.c | 2 ++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/pkg/lvgl/contrib/lvgl.c b/pkg/lvgl/contrib/lvgl.c index 4935be8632..3cc5460f70 100644 --- a/pkg/lvgl/contrib/lvgl.c +++ b/pkg/lvgl/contrib/lvgl.c @@ -31,6 +31,13 @@ #include "screen_dev.h" +#if IS_USED(MODULE_LV_DRIVERS_INDEV_MOUSE) +#include "indev/mouse.h" +#endif +#if IS_USED(MODULE_LV_DRIVERS_SDL) +#include "sdl/sdl.h" +#endif + #ifndef LVGL_COLOR_BUF_SIZE #define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10) #endif @@ -52,12 +59,13 @@ static kernel_pid_t _task_thread_pid; static lv_disp_draw_buf_t disp_buf; static lv_color_t draw_buf[LVGL_COLOR_BUF_SIZE]; -static screen_dev_t *_screen_dev = NULL; static lv_disp_drv_t disp_drv; #if IS_USED(MODULE_TOUCH_DEV) static lv_indev_drv_t indev_drv; #endif +#if !IS_USED(MODULE_LV_DRIVERS_SDL) +static screen_dev_t *_screen_dev = NULL; static void _disp_map(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) { if (!_screen_dev->display) { @@ -75,8 +83,9 @@ static void _disp_map(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *col lv_disp_flush_ready(drv); } +#endif -#if IS_USED(MODULE_TOUCH_DEV) +#if IS_USED(MODULE_TOUCH_DEV) && !IS_USED(MODULE_LV_DRIVERS_SDL) /* adapted from https://github.com/lvgl/lvgl/tree/v6.1.2#add-littlevgl-to-your-project */ static void _touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) { @@ -113,22 +122,41 @@ static void _touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) void lvgl_init(screen_dev_t *screen_dev) { lv_init(); + +#if !IS_USED(MODULE_LV_DRIVERS_SDL) _screen_dev = screen_dev; assert(screen_dev->display); +#else + (void)screen_dev; +#endif lv_disp_draw_buf_init(&disp_buf, draw_buf, NULL, LVGL_COLOR_BUF_SIZE); lv_disp_drv_init(&disp_drv); disp_drv.draw_buf = &disp_buf; +#if IS_USED(MODULE_LV_DRIVERS_SDL) + /* Use SDL driver which creates window on PC's monitor to simulate a display */ + sdl_init(); + /* Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing) */ + disp_drv.flush_cb = sdl_display_flush; +#else disp_drv.flush_cb = _disp_map; /* Configure horizontal and vertical resolutions based on the underlying display device parameters */ disp_drv.hor_res = disp_dev_width(screen_dev->display); disp_drv.ver_res = disp_dev_height(screen_dev->display); +#endif lv_disp_drv_register(&disp_drv); #if IS_USED(MODULE_TOUCH_DEV) +#if IS_USED(MODULE_LV_DRIVERS_SDL) + /* Add the mouse as input device, use SDL driver which reads the PC's mouse */ + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = sdl_mouse_read; + lv_indev_drv_register(&indev_drv); +#else if (screen_dev->touch) { lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; @@ -136,6 +164,7 @@ void lvgl_init(screen_dev_t *screen_dev) lv_indev_drv_register(&indev_drv); } #endif +#endif } void lvgl_run(void) diff --git a/pkg/lvgl/doc.txt b/pkg/lvgl/doc.txt index d0f9e67a16..93a5483eaa 100644 --- a/pkg/lvgl/doc.txt +++ b/pkg/lvgl/doc.txt @@ -26,4 +26,8 @@ Example of command line for changing the max activity period to 5s: CFLAGS=-DCONFIG_LVGL_ACTIVITY_PERIOD=5000 make -C tests/pkg_lvgl ``` +### SDL Usage + +See @ref pkg_lv_drivers. + */ diff --git a/pkg/lvgl/include/lvgl_riot_conf.h b/pkg/lvgl/include/lvgl_riot_conf.h index 0344fd4cfa..c169573d1f 100644 --- a/pkg/lvgl/include/lvgl_riot_conf.h +++ b/pkg/lvgl/include/lvgl_riot_conf.h @@ -19,7 +19,11 @@ #ifndef LVGL_RIOT_CONF_H #define LVGL_RIOT_CONF_H +#include "kernel_defines.h" #include "board.h" +#if IS_USED(MODULE_LV_DRIVERS_SDL) +#include "lv_drv_conf.h" +#endif #ifdef __cplusplus extern "C" { diff --git a/sys/auto_init/screen/auto_init_lvgl.c b/sys/auto_init/screen/auto_init_lvgl.c index 1cc6876e20..3771b1f337 100644 --- a/sys/auto_init/screen/auto_init_lvgl.c +++ b/sys/auto_init/screen/auto_init_lvgl.c @@ -48,8 +48,10 @@ void auto_init_lvgl(void) LOG_DEBUG("[auto_init_screen] initializing lvgl\n"); /* 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); s_screen.display = disp_dev->dev; +#endif #if IS_USED(MODULE_TOUCH_DEV) touch_dev_reg_t *touch_dev = touch_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);