From 41a185cb92a8b65b357ac4c2f6c4ebc2f55670e6 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 20 May 2021 12:38:55 +0200 Subject: [PATCH 1/4] pkg/lvgl: remove internal background thread --- pkg/lvgl/contrib/lvgl.c | 56 ++++++++++++++---------------------- pkg/lvgl/include/lvgl_riot.h | 4 +-- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/pkg/lvgl/contrib/lvgl.c b/pkg/lvgl/contrib/lvgl.c index 2245b7f9b3..90e1a2f454 100644 --- a/pkg/lvgl/contrib/lvgl.c +++ b/pkg/lvgl/contrib/lvgl.c @@ -30,10 +30,6 @@ #include "screen_dev.h" -#ifndef LVGL_TASK_THREAD_PRIO -#define LVGL_TASK_THREAD_PRIO (THREAD_PRIORITY_MAIN + 1) -#endif - #ifndef LVGL_COLOR_BUF_SIZE #define LVGL_COLOR_BUF_SIZE (LV_HOR_RES_MAX * 5) #endif @@ -50,7 +46,6 @@ #define LVGL_THREAD_FLAG (1 << 7) #endif -static char _task_thread_stack[THREAD_STACKSIZE_LARGE]; static kernel_pid_t _task_thread_pid; static lv_disp_buf_t disp_buf; @@ -59,30 +54,6 @@ static lv_color_t buf[LVGL_COLOR_BUF_SIZE]; static screen_dev_t *_screen_dev = NULL; -static void *_task_thread(void *arg) -{ - (void)arg; - - while (1) { - /* Normal operation (no sleep) in < CONFIG_LVGL_INACTIVITY_PERIOD_MS msec - inactivity */ - if (lv_disp_get_inactive_time(NULL) < CONFIG_LVGL_INACTIVITY_PERIOD_MS) { - lv_task_handler(); - } - else { - /* Block after LVGL_ACTIVITY_PERIOD msec inactivity */ - thread_flags_wait_one(LVGL_THREAD_FLAG); - - /* trigger an activity so the task handler is called on the next loop */ - lv_disp_trig_activity(NULL); - } - - xtimer_usleep(CONFIG_LVGL_TASK_HANDLER_DELAY_US); - } - - return NULL; -} - static void _disp_map(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) { if (!_screen_dev->display) { @@ -154,15 +125,30 @@ void lvgl_init(screen_dev_t *screen_dev) lv_indev_drv_register(&indev_drv); } #endif - - lv_task_handler(); } -void lvgl_start(void) +void lvgl_run(void) { - _task_thread_pid = thread_create(_task_thread_stack, sizeof(_task_thread_stack), - LVGL_TASK_THREAD_PRIO, THREAD_CREATE_STACKTEST, - _task_thread, NULL, "_task_thread"); + _task_thread_pid = thread_getpid(); + + lv_task_handler(); + + while (1) { + /* Normal operation (no sleep) in < CONFIG_LVGL_INACTIVITY_PERIOD_MS msec + inactivity */ + if (lv_disp_get_inactive_time(NULL) < CONFIG_LVGL_INACTIVITY_PERIOD_MS) { + lv_task_handler(); + } + else { + /* Block after LVGL_ACTIVITY_PERIOD msec inactivity */ + thread_flags_wait_one(LVGL_THREAD_FLAG); + + /* trigger an activity so the task handler is called on the next loop */ + lv_disp_trig_activity(NULL); + } + + xtimer_usleep(CONFIG_LVGL_TASK_HANDLER_DELAY_US); + } } void lvgl_wakeup(void) diff --git a/pkg/lvgl/include/lvgl_riot.h b/pkg/lvgl/include/lvgl_riot.h index 7c16cb7879..21203d9a3e 100644 --- a/pkg/lvgl/include/lvgl_riot.h +++ b/pkg/lvgl/include/lvgl_riot.h @@ -33,9 +33,9 @@ extern "C" { void lvgl_init(screen_dev_t *screen_dev); /** - * Start the lvgl task handler background thread + * Run the lvgl task handler */ -void lvgl_start(void); +void lvgl_run(void); /** * @brief Wakeup lvgl when inactive From ef6d377197867cf19fd7a4063402c55f75e8e358 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 20 May 2021 13:06:49 +0200 Subject: [PATCH 2/4] tests/pkg_lvgl*: adapt to new behavior --- tests/pkg_lvgl/main.c | 4 ++-- tests/pkg_lvgl_touch/main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pkg_lvgl/main.c b/tests/pkg_lvgl/main.c index 751f60efb8..6190db9e23 100644 --- a/tests/pkg_lvgl/main.c +++ b/tests/pkg_lvgl/main.c @@ -121,10 +121,10 @@ int main(void) /* Enable backlight */ disp_dev_backlight_on(); - lvgl_start(); - /* Create the system monitor widget */ sysmon_create(); + lvgl_run(); + return 0; } diff --git a/tests/pkg_lvgl_touch/main.c b/tests/pkg_lvgl_touch/main.c index 0b76ef9edb..acb40e3b58 100644 --- a/tests/pkg_lvgl_touch/main.c +++ b/tests/pkg_lvgl_touch/main.c @@ -57,7 +57,7 @@ int main(void) lv_obj_t * label = lv_label_create(btn, NULL); lv_label_set_text(label, "Click me"); - lvgl_start(); + lvgl_run(); return 0; } From c09c7d549da8136101cc549cc691f9f3f2c47c17 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 20 May 2021 20:56:17 +0200 Subject: [PATCH 3/4] tests/pkg_lvgl: remove manual call to sysmon_task --- tests/pkg_lvgl/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/pkg_lvgl/main.c b/tests/pkg_lvgl/main.c index 6190db9e23..44ea287982 100644 --- a/tests/pkg_lvgl/main.c +++ b/tests/pkg_lvgl/main.c @@ -111,9 +111,8 @@ void sysmon_create(void) info_label = lv_label_create(win, NULL); lv_label_set_recolor(info_label, true); - /* Refresh the chart and label manually at first */ + /* Create the task used to refresh the chart and label */ refr_task = lv_task_create(sysmon_task, REFR_TIME, LV_TASK_PRIO_LOW, NULL); - sysmon_task(NULL); } int main(void) From 5a393c64d6587cb7acfdefe25076561f6f7626c4 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 21 May 2021 10:05:17 +0200 Subject: [PATCH 4/4] pkg/lvgl: improve lvgl_run documentation --- pkg/lvgl/include/lvgl_riot.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/lvgl/include/lvgl_riot.h b/pkg/lvgl/include/lvgl_riot.h index 21203d9a3e..595e3d3982 100644 --- a/pkg/lvgl/include/lvgl_riot.h +++ b/pkg/lvgl/include/lvgl_riot.h @@ -33,8 +33,14 @@ extern "C" { void lvgl_init(screen_dev_t *screen_dev); /** - * Run the lvgl task handler -*/ + * @brief Run the lvgl task handler + * + * In order to run the lvgl internal task handler in an endless loop, this + * function must be called manually either from the main thread or from a + * custom thread. + * In case of CONFIG_LVGL_INACTIVITY_PERIOD_MS ms of inactivity, the loop stops + * the thread running the lvgl task handler until @ref lvgl_wakeup is called. + */ void lvgl_run(void); /**