lv_display.h
API reference for lv_display.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)| Name | Type | Description |
|---|---|---|
disp | lv_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
hor_res | int32_t | the new horizontal resolution |
ver_res | int32_t | the 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
hor_res | int32_t | the new physical horizontal resolution, or -1 to assume it's the same as the normal hor. res. |
ver_res | int32_t | the 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
x | int32_t | X offset |
y | int32_t | Y 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display (NULL to use the default display) |
rotation | lv_display_rotation_t | LV_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display (NULL to use the default display) |
enable | bool | true: 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
dpi | int32_t | the 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
buf1 | void * | first buffer |
buf2 | void * | second buffer (can be NULL) |
buf_size | uint32_t | buffer size in byte |
render_mode | lv_display_render_mode_t | LV_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | |
buf1 | void * | |
buf2 | void * | |
buf_size | uint32_t | buffer size in byte |
stride | uint32_t | buffer stride in bytes |
render_mode | lv_display_render_mode_t | LV_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
buf1 | lv_draw_buf_t * | first buffer |
buf2 | lv_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
buf3 | lv_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
render_mode | lv_display_render_mode_t | LV_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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
flush_cb | lv_display_flush_cb_t | the 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
wait_cb | lv_display_flush_wait_cb_t | a 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
sync_cb | lv_display_sync_cb_t | the 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
wait_cb | lv_display_sync_wait_cb_t | a 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
color_format | lv_color_format_t | Possible 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
tile_cnt | uint32_t | number 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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
en | bool | true/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)| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | pointer to a display |
th | lv_theme_t * | pointer to a theme |
lv_display_set_user_data
void lv_display_set_user_data(lv_display_t *disp, void *user_data)| Name | Type |
|---|---|
disp | lv_display_t * |
user_data | void * |
lv_display_set_driver_data
void lv_display_set_driver_data(lv_display_t *disp, void *driver_data)| Name | Type |
|---|---|
disp | lv_display_t * |
driver_data | void * |
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))| Name | Type | Description |
|---|---|---|
disp | lv_display_t * | Pointer to a display |
data | void * | User-defined data pointer to associate with the display |
free_cb | void(*)(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
| Name | Value |
|---|---|
LV_DISPLAY_ROTATION_0 | 0 |
LV_DISPLAY_ROTATION_90 | |
LV_DISPLAY_ROTATION_180 | |
LV_DISPLAY_ROTATION_270 |
Used by 3 functions
lv_display_set_rotation— paramrotationlv_draw_pxp_rotate— paramrotationlv_draw_sw_rotate— paramrotation
lv_display_render_mode_t
| Name | Description |
|---|---|
LV_DISPLAY_RENDER_MODE_PARTIAL | Use 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_DIRECT | The 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_FULL | Always 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— paramrender_modelv_display_set_buffers_with_stride— paramrender_modelv_display_set_render_mode— paramrender_mode
lv_screen_load_anim_t
| Name | Value |
|---|---|
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_ON | LV_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— paramanim_typelv_obj_add_screen_create_event— paramanim_typelv_screen_load_anim— paramanim_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— paramflush_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— paramwait_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— paramsync_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— paramwait_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
lv_obj_tree.hlv_refr.hlv_display_private.hlv_draw_sdl.hlv_draw_sw.hlv_draw_sw_utils.hlv_linux_drm.hlv_linux_fbdev.hlv_ft81x.hlv_lcd_generic_mipi.hlv_lovyan_gfx.hlv_nxp_elcdif.hlv_renesas_glcdc.hlv_st_ltdc.hlv_tft_espi.hlv_nuttx_entry.hlv_nuttx_fbdev.hlv_nuttx_lcd.hlv_nuttx_libuv.hlv_opengles_texture.hlv_qnx.hlv_sdl_window.hlv_uefi_display.hlv_wayland_window.hlv_windows_context.hlv_windows_display.hlv_windows_input.hlv_x11.hlv_theme_simple.h
How is this guide?
Last updated on