mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/lvgl: add auto_init_screen by default + setup auto_init
This commit is contained in:
parent
f45d2c7b2a
commit
4e09a54521
@ -1,3 +1,4 @@
|
||||
USEMODULE += lvgl
|
||||
USEMODULE += lvgl_core
|
||||
USEMODULE += lvgl_draw
|
||||
USEMODULE += lvgl_font
|
||||
@ -16,6 +17,8 @@ ifneq (,$(filter lvgl_contrib_touch,$(USEMODULE)))
|
||||
USEMODULE += touch_dev
|
||||
endif
|
||||
|
||||
DEFAULT_MODULE += auto_init_screen
|
||||
|
||||
# lvgl is not compatible with non 32bit platforms
|
||||
# Building lv_misc triggers the error:
|
||||
# "left shift count >= width of type [-Werror=shift-count-overflow]"
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "thread.h"
|
||||
|
||||
#include "xtimer.h"
|
||||
@ -97,7 +98,7 @@ static void _disp_map(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *col
|
||||
lv_disp_flush_ready(drv);
|
||||
}
|
||||
|
||||
#ifdef MODULE_TOUCH_DEV
|
||||
#if IS_USED(MODULE_TOUCH_DEV)
|
||||
/* adapted from https://github.com/lvgl/lvgl/tree/v6.1.2#add-littlevgl-to-your-project */
|
||||
static bool _touch_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
|
||||
{
|
||||
@ -145,13 +146,14 @@ void lvgl_init(screen_dev_t *screen_dev)
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
lv_disp_buf_init(&disp_buf, buf, NULL, LVGL_COLOR_BUF_SIZE);
|
||||
|
||||
#ifdef MODULE_TOUCH_DEV
|
||||
assert(screen_dev->touch);
|
||||
lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = _touch_read;
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
#if IS_USED(MODULE_TOUCH_DEV)
|
||||
if (screen_dev->touch) {
|
||||
lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = _touch_read;
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
}
|
||||
#endif
|
||||
|
||||
lv_task_handler();
|
||||
|
64
sys/auto_init/screen/auto_init_lvgl.c
Normal file
64
sys/auto_init/screen/auto_init_lvgl.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_auto_init
|
||||
* @{
|
||||
* @file
|
||||
* @brief initializes lvgl high level GUI api
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#include "lvgl_riot.h"
|
||||
|
||||
#include "screen_dev.h"
|
||||
#include "disp_dev.h"
|
||||
|
||||
#if IS_USED(MODULE_TOUCH_DEV)
|
||||
#include "touch_dev.h"
|
||||
#endif
|
||||
|
||||
static screen_dev_t s_screen;
|
||||
extern disp_dev_reg_t *disp_dev_reg;
|
||||
|
||||
#if IS_USED(MODULE_TOUCH_DEV)
|
||||
static void _touch_event_callback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
lvgl_wakeup();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LVGL_SCREEN_DEFAULT
|
||||
#define CONFIG_LVGL_SCREEN_DEFAULT 0 /**< Default screen ID used by LVGL */
|
||||
#endif
|
||||
|
||||
void auto_init_lvgl(void)
|
||||
{
|
||||
LOG_DEBUG("[auto_init_screen] initializing lvgl\n");
|
||||
|
||||
/* Only a single screen is supported by lvgl */
|
||||
disp_dev_reg_t *disp_dev = disp_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);
|
||||
s_screen.display = disp_dev->dev;
|
||||
|
||||
#if IS_USED(MODULE_TOUCH_DEV)
|
||||
touch_dev_reg_t *touch_dev = touch_dev_reg_find_screen(CONFIG_LVGL_SCREEN_DEFAULT);
|
||||
if (touch_dev) {
|
||||
s_screen.touch = touch_dev->dev;
|
||||
touch_dev_set_touch_event_callback(touch_dev->dev, _touch_event_callback, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize lvgl with the generic screen */
|
||||
lvgl_init(&s_screen);
|
||||
}
|
Loading…
Reference in New Issue
Block a user