From a6cbf3146a67f9022f94682e673ef5a27db17303 Mon Sep 17 00:00:00 2001 From: "Man, Jianting (Meco)" <920369182@qq.com> Date: Tue, 10 May 2022 13:55:22 -0400 Subject: [PATCH] improve rt-thread initialization process (#3345) --- env_support/rt-thread/lv_rt_thread_port.c | 54 ++++++++++++++++++----- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/env_support/rt-thread/lv_rt_thread_port.c b/env_support/rt-thread/lv_rt_thread_port.c index a438a4111..60218c34a 100644 --- a/env_support/rt-thread/lv_rt_thread_port.c +++ b/env_support/rt-thread/lv_rt_thread_port.c @@ -5,40 +5,74 @@ * * Change Logs: * Date Author Notes - * 2021-10-18 Meco Man The first version + * 2021-10-18 Meco Man the first version + * 2022-05-10 Meco Man improve rt-thread initialization process */ #ifdef __RTTHREAD__ +#include #include + #define DBG_TAG "LVGL" #define DBG_LVL DBG_INFO #include -#include -#include -#include +#ifndef LVGL_THREAD_STACK_SIZE +#define LVGL_THREAD_STACK_SIZE 4096 +#endif /* LVGL_THREAD_STACK_SIZE */ + +#ifndef LVGL_THREAD_PRIO +#define LVGL_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3) +#endif /* LVGL_THREAD_PRIO */ + +extern void lv_port_disp_init(void); +extern void lv_port_indev_init(void); +extern void lv_user_gui_init(void); + +static struct rt_thread lvgl_thread; +static rt_uint8_t lvgl_thread_stack[LVGL_THREAD_STACK_SIZE]; #if LV_USE_LOG static void lv_rt_log(const char *buf) { LOG_I(buf); } -#endif +#endif /* LV_USE_LOG */ -static int lv_port_init(void) +static void lvgl_thread_entry(void *parameter) { #if LV_USE_LOG lv_log_register_print_cb(lv_rt_log); -#endif - +#endif /* LV_USE_LOG */ lv_init(); - lv_port_disp_init(); lv_port_indev_init(); + lv_user_gui_init(); + + /* handle the tasks of LVGL */ + while(1) + { + lv_task_handler(); + rt_thread_mdelay(10); + } +} + +static int lvgl_thread_init(void) +{ + rt_err_t err; + + err = rt_thread_init(&lvgl_thread, "LVGL", lvgl_thread_entry, RT_NULL, + &lvgl_thread_stack[0], sizeof(lvgl_thread_stack), LVGL_THREAD_PRIO, 0); + if(err != RT_EOK) + { + LOG_E("Failed to create LVGL thread"); + return -1; + } + rt_thread_startup(&lvgl_thread); return 0; } -INIT_COMPONENT_EXPORT(lv_port_init); +INIT_ENV_EXPORT(lvgl_thread_init); #endif /*__RTTHREAD__*/