From 4ab68c5dc18b09e380bc3460e0be381866e0397d Mon Sep 17 00:00:00 2001 From: Rbb666 <64397326+Rbb666@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:39:37 +0800 Subject: [PATCH] feat(rtthread): add cpu usage support (#6310) --- env_support/rt-thread/lv_rt_thread_conf.h | 8 ++++++++ env_support/rt-thread/lv_rt_thread_port.c | 14 ++++++++++++++ env_support/rt-thread/squareline/SConscript | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/env_support/rt-thread/lv_rt_thread_conf.h b/env_support/rt-thread/lv_rt_thread_conf.h index f1697cca3..b39817855 100644 --- a/env_support/rt-thread/lv_rt_thread_conf.h +++ b/env_support/rt-thread/lv_rt_thread_conf.h @@ -30,6 +30,14 @@ #define LV_USE_STDLIB_SPRINTF LV_STDLIB_RTTHREAD #endif +/*========================= + CPU usage + *=========================*/ + +#ifdef PKG_USING_CPU_USAGE + #define LV_SYSMON_GET_IDLE lv_timer_os_get_idle +#endif /* PKG_USING_CPU_USAGE */ + /*================= * OPERATING SYSTEM *=================*/ diff --git a/env_support/rt-thread/lv_rt_thread_port.c b/env_support/rt-thread/lv_rt_thread_port.c index dad548363..cb54e7c54 100644 --- a/env_support/rt-thread/lv_rt_thread_port.c +++ b/env_support/rt-thread/lv_rt_thread_port.c @@ -13,6 +13,9 @@ #include #include +#ifdef PKG_USING_CPU_USAGE +#include "cpu_usage.h" +#endif /* PKG_USING_CPU_USAGE */ #define DBG_TAG "LVGL" #define DBG_LVL DBG_INFO @@ -50,6 +53,13 @@ static void lv_rt_log(const char *buf) } #endif /* LV_USE_LOG */ +#ifdef PKG_USING_CPU_USAGE +uint32_t lv_timer_os_get_idle(void) +{ + return (100 - (uint32_t)cpu_load_average()); +} +#endif /* PKG_USING_CPU_USAGE */ + static void lvgl_thread_entry(void *parameter) { #if LV_USE_LOG @@ -62,6 +72,10 @@ static void lvgl_thread_entry(void *parameter) lv_tick_set_cb(&rt_tick_get_millisecond); +#ifdef PKG_USING_CPU_USAGE + cpu_usage_init(); +#endif /* PKG_USING_CPU_USAGE */ + /* handle the tasks of LVGL */ while(1) { diff --git a/env_support/rt-thread/squareline/SConscript b/env_support/rt-thread/squareline/SConscript index 08220b451..7f2be2f52 100644 --- a/env_support/rt-thread/squareline/SConscript +++ b/env_support/rt-thread/squareline/SConscript @@ -20,6 +20,6 @@ for root, dirs, files in os.walk(sls_src_cwd): if check_h_hpp_exists(current_path): # add .h and .hpp path inc = inc + [current_path] -group = DefineGroup('LVGL-SquareLine', src, depend = ['PKG_USING_LVGL_SQUARELINE'], CPPPATH = inc) +group = DefineGroup('LVGL-SquareLine', src, depend = ['PKG_LVGL_USING_SQUARELINE'], CPPPATH = inc) Return('group')