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..595e3d3982 100644 --- a/pkg/lvgl/include/lvgl_riot.h +++ b/pkg/lvgl/include/lvgl_riot.h @@ -33,9 +33,15 @@ extern "C" { void lvgl_init(screen_dev_t *screen_dev); /** - * Start the lvgl task handler background thread -*/ -void lvgl_start(void); + * @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); /** * @brief Wakeup lvgl when inactive diff --git a/tests/pkg_lvgl/main.c b/tests/pkg_lvgl/main.c index 751f60efb8..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) @@ -121,10 +120,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; }