lv_display.h

API reference for lv_display.h

Report on GitHub
See Also: Private HeaderThis header has a companion private implementation with internal data structures.lv_display_private.h

Functions

lv_display_set_default

Set a default display. The new screens will be created on it by default.

 
void lv_display_set_default(lv_display_t *disp)
Parameters
NameTypeDescription
displv_display_t *pointer to a display

lv_display_set_resolution

Sets the resolution of a display. LV_EVENT_RESOLUTION_CHANGED event will be sent. Here the native resolution of the device should be set. If the display will be rotated later with lv_display_set_rotation LVGL will swap the hor. and ver. resolution automatically.

 
void lv_display_set_resolution(lv_display_t *disp, int32_t hor_res, int32_t ver_res)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
hor_resint32_tthe new horizontal resolution
ver_resint32_tthe new vertical resolution

lv_display_set_physical_resolution

It's not mandatory to use the whole display for LVGL, however in some cases physical resolution is important. For example the touchpad still sees whole resolution and the values needs to be converted to the active LVGL display area.

 
void lv_display_set_physical_resolution(lv_display_t *disp, int32_t hor_res, int32_t ver_res)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
hor_resint32_tthe new physical horizontal resolution, or -1 to assume it's the same as the normal hor. res.
ver_resint32_tthe new physical vertical resolution, or -1 to assume it's the same as the normal hor. res.

lv_display_set_offset

If physical resolution is not the same as the normal resolution the offset of the active display area can be set here.

 
void lv_display_set_offset(lv_display_t *disp, int32_t x, int32_t y)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
xint32_tX offset
yint32_tY offset

lv_display_set_rotation

Set the rotation of this display. LVGL will swap the horizontal and vertical resolutions internally.

 
void lv_display_set_rotation(lv_display_t *disp, lv_display_rotation_t rotation)
Parameters
NameTypeDescription
displv_display_t *pointer to a display (NULL to use the default display)
rotationlv_display_rotation_tLV_DISPLAY_ROTATION_0/90/180/270

lv_display_set_matrix_rotation

Use matrix rotation for the display. This function is depended on LV_DRAW_TRANSFORM_USE_MATRIX

 
void lv_display_set_matrix_rotation(lv_display_t *disp, bool enable)
Parameters
NameTypeDescription
displv_display_t *pointer to a display (NULL to use the default display)
enablebooltrue: enable matrix rotation, false: disable

lv_display_set_dpi

Set the DPI (dot per inch) of the display. dpi = sqrt(hor_res^2 + ver_res^2) / diagonal"

 
void lv_display_set_dpi(lv_display_t *disp, int32_t dpi)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
dpiint32_tthe new DPI

lv_display_set_buffers

Set the buffers for a display, similarly to lv_display_set_draw_buffers, but accept the raw buffer pointers. For DIRECT/FULL rending modes, the buffer size must be at least hor_res * ver_res * lv_color_format_get_size(lv_display_get_color_format(disp))

 
void lv_display_set_buffers(lv_display_t *disp, void *buf1, void *buf2, uint32_t buf_size, lv_display_render_mode_t render_mode)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
buf1void *first buffer
buf2void *second buffer (can be NULL)
buf_sizeuint32_tbuffer size in byte
render_modelv_display_render_mode_tLV_DISPLAY_RENDER_MODE_PARTIAL/DIRECT/FULL

lv_display_set_buffers_with_stride

Set the frame buffers for a display, similarly to lv_display_set_buffers, but allow for a custom stride as required by a display controller. This allows the frame buffers to have a stride alignment different from the rest of the buffers @param disp pointer to a display @param buf1 first buffer @param buf2 second buffer (can beNULL`)

 
void lv_display_set_buffers_with_stride(lv_display_t *disp, void *buf1, void *buf2, uint32_t buf_size, uint32_t stride, lv_display_render_mode_t render_mode)
Parameters
NameTypeDescription
displv_display_t *
buf1void *
buf2void *
buf_sizeuint32_tbuffer size in byte
strideuint32_tbuffer stride in bytes
render_modelv_display_render_mode_tLV_DISPLAY_RENDER_MODE_PARTIAL/DIRECT/FULL

lv_display_set_draw_buffers

Set the buffers for a display, accept a draw buffer pointer. Normally use lv_display_set_buffers is enough for most cases. Use this function when an existing lv_draw_buf_t is available.

 
void lv_display_set_draw_buffers(lv_display_t *disp, lv_draw_buf_t *buf1, lv_draw_buf_t *buf2)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
buf1lv_draw_buf_t *first buffer
buf2lv_draw_buf_t *second buffer (can be NULL)

lv_display_set_3rd_draw_buffer

Set the third draw buffer for a display.

 
void lv_display_set_3rd_draw_buffer(lv_display_t *disp, lv_draw_buf_t *buf3)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
buf3lv_draw_buf_t *third buffer

lv_display_set_render_mode

Set display render mode

 
void lv_display_set_render_mode(lv_display_t *disp, lv_display_render_mode_t render_mode)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
render_modelv_display_render_mode_tLV_DISPLAY_RENDER_MODE_PARTIAL/DIRECT/FULL

lv_display_set_flush_cb

Set the flush callback which will be called to copy the rendered image to the display.

 
void lv_display_set_flush_cb(lv_display_t *disp, lv_display_flush_cb_t flush_cb)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
flush_cblv_display_flush_cb_tthe flush callback (px_map contains the rendered image as raw pixel map and it should be copied to area on the display)

lv_display_set_flush_wait_cb

Set a callback to be used while LVGL is waiting flushing to be finished. It can do any complex logic to wait, including semaphores, mutexes, polling flags, etc. If not set the disp->flushing flag is used which can be cleared with lv_display_flush_ready()

 
void lv_display_set_flush_wait_cb(lv_display_t *disp, lv_display_flush_wait_cb_t wait_cb)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
wait_cblv_display_flush_wait_cb_ta callback to call while LVGL is waiting for flush ready. If NULL lv_display_flush_ready() can be used to signal that flushing is ready.

lv_display_set_sync_cb

Set the sync callback which will be called to synchronize invalidated areas between frame buffers pre-render.

 
void lv_display_set_sync_cb(lv_display_t *disp, lv_display_sync_cb_t sync_cb)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
sync_cblv_display_sync_cb_tthe sync callback (pointer to area needing to be synchronized)

lv_display_set_sync_wait_cb

Set a callback to be used while LVGL is waiting sync to be finished. It can do any complex logic to wait, including semaphores, mutexes, polling flags, etc. If not set the disp->syncing flag is used which can be cleared with lv_display_sync_ready()

 
void lv_display_set_sync_wait_cb(lv_display_t *disp, lv_display_sync_wait_cb_t wait_cb)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
wait_cblv_display_sync_wait_cb_ta callback to call while LVGL is waiting for sync ready. If NULL lv_display_sync_ready() can be used to signal that syncing is ready.

lv_display_set_color_format

Set the color format of the display.

 
void lv_display_set_color_format(lv_display_t *disp, lv_color_format_t color_format)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
color_formatlv_color_format_tPossible values are
- LV_COLOR_FORMAT_RGB565
- LV_COLOR_FORMAT_RGB888
- LV_COLOR_FORMAT_XRGB888
- LV_COLOR_FORMAT_ARGB888

To change the endianness of the rendered image in case of RGB565 format (i.e. swap the 2 bytes) call lv_draw_sw_rgb565_swap in the flush_cb

lv_display_set_tile_cnt

Set the number of tiles for parallel rendering.

 
void lv_display_set_tile_cnt(lv_display_t *disp, uint32_t tile_cnt)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
tile_cntuint32_tnumber of tiles (1 =< tile_cnt < 256)

lv_display_set_antialiasing

Disabling anti-aliasing is not supported since v9. This function will be removed. Enable anti-aliasing for the render engine

 
void lv_display_set_antialiasing(lv_display_t *disp, bool en)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
enbooltrue/false

lv_display_set_theme

Set the theme of a display. If there are no user created widgets yet the screens' theme will be updated

 
void lv_display_set_theme(lv_display_t *disp, lv_theme_t *th)
Parameters
NameTypeDescription
displv_display_t *pointer to a display
thlv_theme_t *pointer to a theme

lv_display_set_user_data

 
void lv_display_set_user_data(lv_display_t *disp, void *user_data)
Parameters
NameType
displv_display_t *
user_datavoid *

lv_display_set_driver_data

 
void lv_display_set_driver_data(lv_display_t *disp, void *driver_data)
Parameters
NameType
displv_display_t *
driver_datavoid *

lv_display_set_external_data

Attaches external user data and destructor callback to a display.

Associates custom user data with an LVGL display and specifies a destructor function that will be automatically invoked when the display is deleted to properly clean up the associated resources.

 
void lv_display_set_external_data(lv_display_t *disp, void *data, void(*free_cb)(void *data))
Parameters
NameTypeDescription
displv_display_t *Pointer to a display
datavoid *User-defined data pointer to associate with the display
free_cbvoid(*)(void *data)Callback function for cleaning up data when display is deleted. Receives data as parameter. NULL means no cleanup required.

Enums

lv_display_rotation_t

NameValue
LV_DISPLAY_ROTATION_00
LV_DISPLAY_ROTATION_90
LV_DISPLAY_ROTATION_180
LV_DISPLAY_ROTATION_270
Used by 3 functions
  • lv_display_set_rotation — param rotation
  • lv_draw_pxp_rotate — param rotation
  • lv_draw_sw_rotate — param rotation

lv_display_render_mode_t

NameDescription
LV_DISPLAY_RENDER_MODE_PARTIALUse the buffer(s) to render the screen is smaller parts. This way the buffers can be smaller then the display to save RAM. At least 1/10 screen size buffer(s) are recommended.
LV_DISPLAY_RENDER_MODE_DIRECTThe buffer(s) has to be screen sized and LVGL will render into the correct location of the buffer. This way the buffer always contain the whole image. Only the changed ares will be updated. With 2 buffers the buffers' content are kept in sync automatically and in flush_cb only address change is required.
LV_DISPLAY_RENDER_MODE_FULLAlways redraw the whole screen even if only one pixel has been changed. With 2 buffers in flush_cb only an address change is required.
Used by 3 functions
  • lv_display_set_buffers — param render_mode
  • lv_display_set_buffers_with_stride — param render_mode
  • lv_display_set_render_mode — param render_mode

lv_screen_load_anim_t

NameValue
LV_SCREEN_LOAD_ANIM_NONE
LV_SCREEN_LOAD_ANIM_OVER_LEFT
LV_SCREEN_LOAD_ANIM_OVER_RIGHT
LV_SCREEN_LOAD_ANIM_OVER_TOP
LV_SCREEN_LOAD_ANIM_OVER_BOTTOM
LV_SCREEN_LOAD_ANIM_MOVE_LEFT
LV_SCREEN_LOAD_ANIM_MOVE_RIGHT
LV_SCREEN_LOAD_ANIM_MOVE_TOP
LV_SCREEN_LOAD_ANIM_MOVE_BOTTOM
LV_SCREEN_LOAD_ANIM_FADE_IN
LV_SCREEN_LOAD_ANIM_FADE_ONLV_SCREEN_LOAD_ANIM_FADE_IN
LV_SCREEN_LOAD_ANIM_FADE_OUT
LV_SCREEN_LOAD_ANIM_OUT_LEFT
LV_SCREEN_LOAD_ANIM_OUT_RIGHT
LV_SCREEN_LOAD_ANIM_OUT_TOP
LV_SCREEN_LOAD_ANIM_OUT_BOTTOM
Used by 3 functions
  • lv_obj_add_screen_load_event — param anim_type
  • lv_obj_add_screen_create_event — param anim_type
  • lv_screen_load_anim — param anim_type

Typedefs

lv_display_flush_cb_t

 
typedef void(* lv_display_flush_cb_t) (lv_display_t *disp, const lv_area_t *area, uint8_t *px_map)
Used by 1 function
  • lv_display_set_flush_cb — param flush_cb

lv_display_flush_wait_cb_t

 
typedef void(* lv_display_flush_wait_cb_t) (lv_display_t *disp)
Used by 1 function
  • lv_display_set_flush_wait_cb — param wait_cb

lv_display_sync_cb_t

 
typedef void(* lv_display_sync_cb_t) (lv_display_t *disp, const lv_area_t *area)
Used by 1 function
  • lv_display_set_sync_cb — param sync_cb

lv_display_sync_wait_cb_t

 
typedef void(* lv_display_sync_wait_cb_t) (lv_display_t *disp)
Used by 1 function
  • lv_display_set_sync_wait_cb — param wait_cb

Macros

LV_HOR_RES

 
#define LV_HOR_RES lv_display_get_horizontal_resolution(lv_display_get_default())

The horizontal resolution of the currently active display.

LV_VER_RES

 
#define LV_VER_RES lv_display_get_vertical_resolution(lv_display_get_default())

The vertical resolution of the currently active display.

LV_DPX_CALC

 
#define LV_DPX_CALC(dpi, n) \
    ((n) == 0 ? 0 :LV_MAX((( (dpi) * (n) + 80) / 160), 1)) /*+80 for rounding*/

See lv_dpx() and lv_display_dpx(). Same as Android's DIP. (Different name is chosen to avoid mistype between LV_DPI and LV_DIP)

  • 40 dip is 40 px on a 160 DPI screen (distance = 1/4 inch).
  • 40 dip is 80 px on a 320 DPI screen (distance still = 1/4 inch).

See also: https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp

LV_DPX

 
#define LV_DPX(n) \
    LV_DPX_CALC(lv_display_get_dpi(NULL), n)

Dependencies

How is this guide?

Last updated on

On this page

Functionslv_display_set_defaultlv_display_set_resolutionlv_display_set_physical_resolutionlv_display_set_offsetlv_display_set_rotationlv_display_set_matrix_rotationlv_display_set_dpilv_display_set_bufferslv_display_set_buffers_with_stridelv_display_set_draw_bufferslv_display_set_3rd_draw_bufferlv_display_set_render_modelv_display_set_flush_cblv_display_set_flush_wait_cblv_display_set_sync_cblv_display_set_sync_wait_cblv_display_set_color_formatlv_display_set_tile_cntlv_display_set_antialiasinglv_display_set_themelv_display_set_user_datalv_display_set_driver_datalv_display_set_external_datalv_display_get_defaultlv_display_get_nextlv_display_get_horizontal_resolutionlv_display_get_vertical_resolutionlv_display_get_original_horizontal_resolutionlv_display_get_original_vertical_resolutionlv_display_get_physical_horizontal_resolutionlv_display_get_physical_vertical_resolutionlv_display_get_offset_xlv_display_get_offset_ylv_display_get_rotationlv_display_get_matrix_rotationlv_display_get_dpilv_display_get_color_formatlv_display_get_tile_cntlv_display_get_antialiasinglv_display_get_render_modelv_display_get_screen_activelv_display_get_screen_prevlv_display_get_screen_loadinglv_display_get_layer_toplv_display_get_layer_syslv_display_get_layer_bottomlv_display_get_screen_by_namelv_display_get_event_countlv_display_get_event_dsclv_event_get_invalidated_arealv_display_get_themelv_display_get_inactive_timelv_display_get_refr_timerlv_display_get_user_datalv_display_get_driver_datalv_display_get_buf_activelv_display_get_draw_buf_sizelv_display_get_invalidated_draw_buf_sizelv_display_createlv_display_deletelv_display_flush_readylv_display_flush_is_lastlv_display_sync_readylv_display_sync_is_lastlv_display_is_double_bufferedlv_screen_loadlv_screen_load_animlv_screen_activelv_layer_toplv_layer_syslv_layer_bottomlv_display_add_event_cblv_display_remove_eventlv_display_remove_event_cb_with_user_datalv_display_send_eventlv_display_trigger_activitylv_display_enable_invalidationlv_display_is_invalidation_enabledlv_display_delete_refr_timerlv_display_register_vsync_eventlv_display_unregister_vsync_eventlv_display_send_vsync_eventlv_display_rotate_arealv_display_rotate_pointlv_dpxlv_display_dpxEnumslv_display_rotation_tlv_display_render_mode_tlv_screen_load_anim_tTypedefslv_display_flush_cb_tlv_display_flush_wait_cb_tlv_display_sync_cb_tlv_display_sync_wait_cb_tMacrosLV_HOR_RESLV_VER_RESLV_DPX_CALCLV_DPXDependencies