@@ -81,6 +81,7 @@ BraccioClass::BraccioClass()
8181, _lvgl_draw_buf{}
8282, _lvgl_p_obj_group{nullptr }
8383, _lvgl_kb_indev{nullptr }
84+ , _display_mtx{}
8485, _display_thd{}
8586, _pd_events{}
8687, _pd_timer{}
@@ -238,6 +239,7 @@ int BraccioClass::getKey() {
238239
239240void BraccioClass::connectJoystickTo (lv_obj_t * obj)
240241{
242+ mbed::ScopedLock<rtos::Mutex> lock (_display_mtx);
241243 lv_group_add_obj (_lvgl_p_obj_group, obj);
242244 lv_indev_set_group (_lvgl_kb_indev, _lvgl_p_obj_group);
243245}
@@ -409,31 +411,40 @@ void BraccioClass::lvgl_init()
409411
410412void BraccioClass::display_thread_func ()
411413{
412- for (;;)
414+ for (;; delay (LV_DISP_DEF_REFR_PERIOD) )
413415 {
416+ mbed::ScopedLock<rtos::Mutex> lock (_display_mtx);
414417 lv_task_handler ();
415418 lv_tick_inc (LV_DISP_DEF_REFR_PERIOD);
416- delay (LV_DISP_DEF_REFR_PERIOD);
417419 }
418420}
419421
420422void BraccioClass::lvgl_splashScreen (unsigned long const duration_ms)
421423{
422424 extern const lv_img_dsc_t img_bulb_gif;
425+ lv_obj_t * img = nullptr ;
423426
424- LV_IMG_DECLARE (img_bulb_gif);
425- lv_obj_t * img = lv_gif_create (lv_scr_act ());
426- lv_gif_set_src (img, &img_bulb_gif);
427- lv_obj_align (img, LV_ALIGN_CENTER, 0 , 0 );
427+ {
428+ mbed::ScopedLock<rtos::Mutex> lock (_display_mtx);
429+ LV_IMG_DECLARE (img_bulb_gif);
430+ img = lv_gif_create (lv_scr_act ());
431+ lv_gif_set_src (img, &img_bulb_gif);
432+ lv_obj_align (img, LV_ALIGN_CENTER, 0 , 0 );
433+ }
428434
429435 /* Wait until the splash screen duration is over. */
430436 for (unsigned long const start = millis (); millis () - start < duration_ms; delay (10 )) { }
431437
432- lv_obj_del (img);
438+ {
439+ mbed::ScopedLock<rtos::Mutex> lock (_display_mtx);
440+ lv_obj_del (img);
441+ }
433442}
434443
435444void BraccioClass::lvgl_pleaseConnectPower ()
436445{
446+ mbed::ScopedLock<rtos::Mutex> lock (_display_mtx);
447+
437448 lv_style_set_text_font (&_lv_style, &lv_font_montserrat_32);
438449 lv_obj_t * label1 = lv_label_create (lv_scr_act ());
439450 lv_obj_add_style (label1, &_lv_style, 0 );
@@ -445,7 +456,8 @@ void BraccioClass::lvgl_pleaseConnectPower()
445456
446457void BraccioClass::lvgl_defaultMenu ()
447458{
448- // TODO: create a meaningful default menu
459+ mbed::ScopedLock<rtos::Mutex> lock (_display_mtx);
460+
449461 lv_style_set_text_font (&_lv_style, &lv_font_montserrat_32);
450462 lv_obj_t * label1 = lv_label_create (lv_scr_act ());
451463 lv_obj_add_style (label1, &_lv_style, 0 );
0 commit comments