Skip to content

Commit 768e43a

Browse files
faxe1008kartben
authored andcommitted
modules: lvgl: Add lv_os_get_idle_percent to OSAL
Adds an implementation of lv_os_get_idle_percent to the zephyr OSAL. This is needed for usage of the system monitor. Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
1 parent 0b0fd7d commit 768e43a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

modules/lvgl/lvgl_zephyr_osal.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include "lvgl_zephyr_osal.h"
7+
#include <zephyr/debug/cpu_load.h>
88
#include <lvgl.h>
99

1010
#include <zephyr/logging/log.h>
1111
LOG_MODULE_DECLARE(lvgl, CONFIG_LV_Z_LOG_LEVEL);
1212

13+
#ifdef CONFIG_LV_Z_USE_OSAL
14+
15+
#include "lvgl_zephyr_osal.h"
16+
1317
typedef void (*lv_thread_entry)(void *);
1418
static void thread_entry(void *thread, void *cb, void *user_data);
1519

@@ -151,3 +155,22 @@ void thread_entry(void *thread, void *cb, void *user_data)
151155
entry_cb(user_data);
152156
lv_thread_delete((lv_thread_t *)thread);
153157
}
158+
159+
#endif /* CONFIG_LV_Z_USE_OSAL */
160+
161+
uint32_t lv_os_get_idle_percent(void)
162+
{
163+
#ifdef CONFIG_CPU_LOAD
164+
int load = cpu_load_get();
165+
166+
if (load < 0) {
167+
LOG_ERR("Failed to get CPU load, returning UINT32_MAX");
168+
return UINT32_MAX;
169+
}
170+
171+
return 100 - (load / 10);
172+
#else
173+
LOG_WRN_ONCE("CONFIG_CPU_LOAD is not enabled, idle percent will always be 0");
174+
return 0;
175+
#endif
176+
}

0 commit comments

Comments
 (0)