Refreshing

Default Refresh Behavior

Normally the dirty (a.k.a invalid) areas are checked and redrawn in every LV_DEF_REFR_PERIOD milliseconds (set in lv_conf.h). This happens as a result of a refresh Timer (lv_timer) created that gets created when the display is created executed at that interval

Decoupling the Display Refresh Timer

However, in some cases you might need more control on when display refreshing happens, for example:

  • to synchronize rendering with VSYNC or the TE signal;

  • to time display refreshes immediately after a single screen update of all widgets that needed to have their display data updated (i.e. only updated once immediately before display refresh to reduce CPU overhead).

You can do this in the following way:

/* Delete original display refresh timer */
lv_display_delete_refr_timer(display1);

/* Call this to refresh dirty (changed) areas of the display. */
lv_display_refr_timer(NULL);

If you have multiple displays call lv_display_set_default(display1) to select the display to refresh before _lv_display_refr_timer(NULL).

Note

lv_timer_handler() and _lv_display_refr_timer() must not run at the same time.

If the performance monitor is enabled, the value of LV_DEF_REFR_PERIOD needs to be set to be consistent with the refresh period of the display to ensure that the statistical results are correct.

Forcing a Refresh

Normally the invalidated areas (marked for redrawing) are rendered in lv_timer_handler() in every LV_DEF_REFR_PERIOD milliseconds. However, by using lv_refr_now(display) you can tell LVGL to redraw the invalid areas immediately. The refreshing will happen in lv_refr_now() which might take longer.

The parameter of lv_refr_now() is a pointer to the display to refresh. If NULL is passed, all displays that have active refresh timers will be refreshed.