When creating an embedded GUI using
LVGL, the display being used must be initalized and LVGL must be configured to work
with the display. This initalization and configuration is done through the LVGL
global function lv_port_disp_init. This function is broken into three
sections:
- Display Initalization
- LVGL includes a
global function, disp_init. This function is called in
lv_port_disp_init and can be used to trigger the
initalization sequence for the display being used.
- Color Buffer Allocation and
Refresh Mode Selection
- LVGL uses a color
buffer to store the pixel data for a rendered image. This buffer,
lv_disp_draw_buf_t, is allocated in lv_port_disp_init. There
are two typical buffering configurations:
- Single
Buffer: A single buffer is allocated and passed into
lv_disp_draw_buf_init. The size of this buffer is
typically ten times the horizontal resultion (10 rows of
pixels). This buffer is solely populated with the pixel data
for a rendered image and the CPU is responsible for
transfering the color buffer's pixel information to the
communication interface used to communication with the
display.
- Double Buffer
with DMA: Two buffers are allocated with the same amount of
memory and passed into lv_disp_draw_buf_init. The
size of both buffers is typically 10 rows of pixels. LVGL
populates one buffer with part of the pixel data for a
rendered image and then makes the data available for the DMA
to begin transfering data to the communication
interface.
- There are, also, two
modes to configure how LVGL performs image refreshes:
- Partial
Refresh: In partial refresh, only the portion of the
rendered image that is being updated is written to the color
buffer. This is enabled by default. This mode allows for
faster refreshes and a smaller color buffer, however, can
result in residual display artifacts if the display is
partial to tearing or banding.
- Full Refresh:
In full refresh, the entire rendered image is written to the
color buffer. This is enabled by setting the
full_refresh field in the lv_disp_drv_t
display driver. This mode elimiates the issue of residual
display artificacts, but is much slower and requires a color
buffer that is equal to the resolution of the screen.
- Display Driver
Configuration
- LVGL provides a
display driver structure that must be configured so that LVGL
properly renders the display. The first step is initializing the
display driver by calling lv_disp_drv_init with a new
instance of the driver, lv_disp_drv_t
- After the display
driver has been initalized, the main values that must be configured
are:
- The
horizontal and veritical resolutions: The horizontal and
vertical resolutions, hor_res and ver_res, are
members of the display driver and can be set with the
previously defined MY_DISP_HOR_RES and MY_DISP_VER_RES
- The flush
callback: The display driver must be configured with the
location of the flush callback, flush_cb. The flush
callback is the method that is called when LVGL is to flush
the color buffer that has been populated with the pixel data
of the rendered image. This callback method is discussed
further in this application note
- The draw
buffer: The display driver must be configured with the
location of the color buffer that was previosuly initalized,
draw_buf
- The refresh
mode: If using the full refresh mode, the display driver
must be configured with full_refresh being set to
1
- Finally, the display
driver must be registered with LVGL, by calling
lv_disp_drv_register
LVGL has support for several types of
input devices, including a touchpad, mouse, keypad, encoder, or button. All of these
input devices must initalized and configured with LVGL. This is performed in the
LVGL global function lv_port_indev_init, and is broken into two sections:
- Input Device Initalization
- LVGL includes several global functions that can be used to initalize the
input device. For example, when using a display that has either
resistive or capacitve touch, the global function touchpad_init
can be called to perform the touchpad initialization.
- Input Device Driver Configuration
- LVGL provides an input device driver structure that must be configured
so that LVGL properly processes inputs. The first step is initializing
the input device driver by calling lv_indev_drv_init with a new
instance of the driver, lv_indev_drv_t
- After the input device driver has been initalized, the main values that
must be configured are:
- The input device type: The type of input device being used:
pointer (touchpad or mouse), keypad, button, and encoder
- The input read callback: The input device driver must be
configured with the location of the input read callback,
read_cb. The input read callback is the method that
is called when LVGL is to read for any input from the input
device. This callback method is discussed further in this
application note
- Finally, the input device driver must be registered with LVGL, by
calling lv_indev_drv_register