mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 18:13:49 +01:00
pkg/lvgl: adapt to SDL display and input driver
This commit is contained in:
parent
bab49e520d
commit
ec06163402
@ -31,6 +31,13 @@
|
|||||||
|
|
||||||
#include "screen_dev.h"
|
#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
|
#ifndef LVGL_COLOR_BUF_SIZE
|
||||||
#define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10)
|
#define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 10)
|
||||||
#endif
|
#endif
|
||||||
@ -52,12 +59,13 @@ static kernel_pid_t _task_thread_pid;
|
|||||||
static lv_disp_draw_buf_t disp_buf;
|
static lv_disp_draw_buf_t disp_buf;
|
||||||
static lv_color_t draw_buf[LVGL_COLOR_BUF_SIZE];
|
static lv_color_t draw_buf[LVGL_COLOR_BUF_SIZE];
|
||||||
|
|
||||||
static screen_dev_t *_screen_dev = NULL;
|
|
||||||
static lv_disp_drv_t disp_drv;
|
static lv_disp_drv_t disp_drv;
|
||||||
#if IS_USED(MODULE_TOUCH_DEV)
|
#if IS_USED(MODULE_TOUCH_DEV)
|
||||||
static lv_indev_drv_t indev_drv;
|
static lv_indev_drv_t indev_drv;
|
||||||
#endif
|
#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)
|
static void _disp_map(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p)
|
||||||
{
|
{
|
||||||
if (!_screen_dev->display) {
|
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);
|
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 */
|
/* 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)
|
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)
|
void lvgl_init(screen_dev_t *screen_dev)
|
||||||
{
|
{
|
||||||
lv_init();
|
lv_init();
|
||||||
|
|
||||||
|
#if !IS_USED(MODULE_LV_DRIVERS_SDL)
|
||||||
_screen_dev = screen_dev;
|
_screen_dev = screen_dev;
|
||||||
assert(screen_dev->display);
|
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_draw_buf_init(&disp_buf, draw_buf, NULL, LVGL_COLOR_BUF_SIZE);
|
||||||
|
|
||||||
lv_disp_drv_init(&disp_drv);
|
lv_disp_drv_init(&disp_drv);
|
||||||
disp_drv.draw_buf = &disp_buf;
|
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;
|
disp_drv.flush_cb = _disp_map;
|
||||||
/* Configure horizontal and vertical resolutions based on the
|
/* Configure horizontal and vertical resolutions based on the
|
||||||
underlying display device parameters */
|
underlying display device parameters */
|
||||||
disp_drv.hor_res = disp_dev_width(screen_dev->display);
|
disp_drv.hor_res = disp_dev_width(screen_dev->display);
|
||||||
disp_drv.ver_res = disp_dev_height(screen_dev->display);
|
disp_drv.ver_res = disp_dev_height(screen_dev->display);
|
||||||
|
#endif
|
||||||
|
|
||||||
lv_disp_drv_register(&disp_drv);
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
#if IS_USED(MODULE_TOUCH_DEV)
|
#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) {
|
if (screen_dev->touch) {
|
||||||
lv_indev_drv_init(&indev_drv);
|
lv_indev_drv_init(&indev_drv);
|
||||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
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);
|
lv_indev_drv_register(&indev_drv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void lvgl_run(void)
|
void lvgl_run(void)
|
||||||
|
|||||||
@ -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
|
CFLAGS=-DCONFIG_LVGL_ACTIVITY_PERIOD=5000 make -C tests/pkg_lvgl
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### SDL Usage
|
||||||
|
|
||||||
|
See @ref pkg_lv_drivers.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -19,7 +19,11 @@
|
|||||||
#ifndef LVGL_RIOT_CONF_H
|
#ifndef LVGL_RIOT_CONF_H
|
||||||
#define LVGL_RIOT_CONF_H
|
#define LVGL_RIOT_CONF_H
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#if IS_USED(MODULE_LV_DRIVERS_SDL)
|
||||||
|
#include "lv_drv_conf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@ -48,8 +48,10 @@ void auto_init_lvgl(void)
|
|||||||
LOG_DEBUG("[auto_init_screen] initializing lvgl\n");
|
LOG_DEBUG("[auto_init_screen] initializing lvgl\n");
|
||||||
|
|
||||||
/* Only a single screen is supported by lvgl */
|
/* 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);
|
disp_dev_reg_t *disp_dev = disp_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);
|
||||||
s_screen.display = disp_dev->dev;
|
s_screen.display = disp_dev->dev;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if IS_USED(MODULE_TOUCH_DEV)
|
#if IS_USED(MODULE_TOUCH_DEV)
|
||||||
touch_dev_reg_t *touch_dev = touch_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);
|
touch_dev_reg_t *touch_dev = touch_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user