LVGL Example#
Overview#
This example demonstrates how to use LVGL (Light and Versatile Graphics Library) on K230. LVGL is a free and open-source embedded graphics library that provides rich widgets, smooth animation effects, and support for multiple input devices, and is suitable for both MCU and MPU platforms.
Feature Summary#
LVGL Capabilities Demonstrated#
Multi-resolution display support
Touch-screen input integration
Common UI widgets such as labels, buttons, bars, sliders, and switches
Responsive layout behavior
Double buffering and GSDMA-assisted display updates
Widget Examples#
The sample demonstrates:
Label
Button
Bar
Slider
Switch
Container-based layout
Display Driver Notes#
The example is designed around the K230 display path and supports:
up to
1920x1080display resolutiondouble buffering to reduce flicker
GSDMA-assisted image transfer
Input Device Notes#
capacitive or resistive touch input
gesture operations such as click and slide
Source Location#
Demo source path: src/rtsmart/examples/3rd-party/lvgl/lvgl_basic
Usage#
Build#
Firmware Build#
At the root of K230 RTOS SDK, use make menuconfig to enable the LVGL example in the firmware build, then build the firmware.
Standalone Build#
You can either enable the LVGL example in make menuconfig, or build it directly:
cd src/rtsmart/examples/3rd-party/lvgl/lvgl_basic
mkdir build && cd build
cmake ..
make
Hardware Preparation#
Connect a supported LCD panel
Connect a touch panel if touch input is required
Verify that the board-side display and touch wiring matches the sample configuration
Run#
Copy the built executable to the board, enter the target directory, then run:
./lvgl_basic
Expected Result#
After startup, the sample initializes the display, registers touch input if available, creates the LVGL demo UI, and starts the LVGL task loop. The screen shows content similar to:
Screen: 800x480
===========================
LVGL Multi-Resolution Demo
[Button 1] [Button 2] [Button 3]
Progress Bar:
[===========> ] 70%
Slider:
[----O----]
Switch:
[ON]
UI characteristics:
the top area shows the current screen resolution
the middle area shows three buttons with different colors
the lower area shows a progress bar, slider, and switch
all widgets support touch interaction
You can interact with the interface through the touch screen:
tap the buttons to trigger responses
drag the slider to change the value
toggle the switch on and off
Custom UI#
LVGL provides rich APIs for building custom interfaces. For example:
// Create a label
lv_obj_t* label = lv_label_create(parent);
lv_label_set_text(label, "Hello LVGL!");
// Create a button
lv_obj_t* btn = lv_button_create(parent);
lv_obj_t* btn_label = lv_label_create(btn);
lv_label_set_text(btn_label, "Click Me");
lv_obj_center(btn_label);
// Create a progress bar
lv_obj_t* bar = lv_bar_create(parent);
lv_bar_set_value(bar, 50, LV_ANIM_OFF);
Tip
You can adjust many LVGL parameters in the lv_conf.h configuration file, such as memory size, screen resolution, and font selection. For detailed APIs and configuration options, refer to the LVGL official documentation.
Tip
LVGL requires periodic calls to lv_timer_handler() to refresh the UI. It is recommended to call this function regularly inside the main loop.
