Skip to content

Commit b694f03

Browse files
pdgendtjhedberg
authored andcommitted
samples: modules: lvgl: demos: Sync main with LVGL work queue thread
If LVGL uses a work queue thread, we can't call LVGL functions from the main thread. Use a k_event variable to signal between threads. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent b5883d3 commit b694f03

File tree

1 file changed

+12
-1
lines changed
  • samples/modules/lvgl/demos/src

1 file changed

+12
-1
lines changed

samples/modules/lvgl/demos/src/main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <zephyr/drivers/display.h>
99
#include <lvgl.h>
1010
#include <lvgl_mem.h>
11+
#include <lvgl_zephyr.h>
1112
#include <lv_demos.h>
1213
#include <stdio.h>
1314

@@ -29,6 +30,8 @@ int main(void)
2930
return 0;
3031
}
3132

33+
lvgl_lock();
34+
3235
#if defined(CONFIG_LV_Z_DEMO_MUSIC)
3336
lv_demo_music();
3437
#elif defined(CONFIG_LV_Z_DEMO_BENCHMARK)
@@ -56,6 +59,7 @@ int main(void)
5659
#ifndef CONFIG_LV_Z_RUN_LVGL_ON_WORKQUEUE
5760
lv_timer_handler();
5861
#endif
62+
lvgl_unlock();
5963

6064
display_blanking_off(display_dev);
6165
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
@@ -65,7 +69,12 @@ int main(void)
6569
#endif
6670
while (1) {
6771
#ifndef CONFIG_LV_Z_RUN_LVGL_ON_WORKQUEUE
68-
uint32_t sleep_ms = lv_timer_handler();
72+
uint32_t sleep_ms;
73+
74+
lvgl_lock();
75+
sleep_ms = lv_timer_handler();
76+
lvgl_unlock();
77+
6978
k_msleep(MIN(sleep_ms, INT32_MAX));
7079
#else
7180
/* LVGL managed by dedicated workqueue, just put an application side delay */
@@ -74,7 +83,9 @@ int main(void)
7483
#ifdef CONFIG_LV_Z_DEMO_RENDER_SCENE_DYNAMIC
7584
if (sys_timepoint_expired(next_scene_switch)) {
7685
cur_scene = (cur_scene + 1) % LV_DEMO_RENDER_SCENE_NUM;
86+
lvgl_lock();
7787
lv_demo_render(cur_scene, 255);
88+
lvgl_unlock();
7889
next_scene_switch = sys_timepoint_calc(
7990
K_SECONDS(CONFIG_LV_Z_DEMO_RENDER_DYNAMIC_SCENE_TIMEOUT));
8091
}

0 commit comments

Comments
 (0)