Screen update in LVGL - Good practices - Opinion?

Hmmm, actually if you see the function name it is named as other_thread which indicates that this is a different thread or different task, hence mutex is needed here. (Maybe I am wrong, but this is what I understood as of now)

static void gui_task(void *pvParameter)
{
  gui_q_msg_t msg;
  msg.event_id = GUI_MNG_EV_NONE;

  while(1)
  {
    vTaskDelay(pdMS_TO_TICKS(20));

    // refresh the display
    gui_refresh();

    // wait only 5 ms and then proceed
    if( xQueueReceive(gui_event, &msg, pdMS_TO_TICKS(10)) )
    {
      // the below is the code to handle the state machine
      if( GUI_MNG_EV_NONE != msg.event_id )
      {
        switch( msg.event_id )
        {
          case GUI_MNG_EV_TEMP_HUMID:
            gui_update_temp_humid();
            break;
          default:
            break;
        } // switch case end
      }   // if event received in limit end
    }     // xQueueReceive end
  }
}

/**
 * @brief gui refresh, this function will refresh the lvgl
 * @param  none
 */
static int max_flushing_time = 0;
static void gui_refresh( void )
{
  int64_t start_time = 0;
  if( GUI_LOCK() )
  {
    start_time = esp_timer_get_time();
    lv_timer_handler();
    // Semaphore is released when flushing is completed, this is checked using
    // tft_flush_status function, and then we release the semaphore
    // GUI_UNLOCK();
  }

  // check flushing status
  if( tft_flush_status() == true )
  {
    // printf("Flushing Time: %d" PRId64 ", %" PRId64 "\n", esp_timer_get_time(), start_time);
    int time_taken = (int32_t)((esp_timer_get_time() - start_time)/1000);
    if( time_taken > max_flushing_time )
    {
      max_flushing_time = time_taken;
      printf("Flushing Time: %d ms\n", max_flushing_time );
    }
    GUI_UNLOCK();
  }
}

The above code snippet is from my project, from this link.

Also if you ask me, we shouldn’t lock and unlock other the LVGL function calls if the lv_timer_handler is present in the same task, although it doesn’t do any harm, will waste only some CPU cycles.
The most important thing is that we should call other LVGL function in the same task, then as per my understanding mutex is not needed, if using in other tasks, mutex is needed and that too the same mutex.
In the example I shared above, I am updating everything in the same task, so mutex is needed only for lv_timer_handler function.

Also check this message.

I would like to highlight again, that as you I am learning, so I might be wrong.
Let’s wait for some comments from some experts.