LVGL Example#
Introduction#
This example demonstrates how to use the LVGL (Light and Versatile Graphics Library) graphics library on the K230 platform. LVGL is a free, open-source embedded graphics library that supports a rich set of graphical widgets, smooth animation effects, and various input devices, suitable for MCU and MPU platforms.
Functionality Description#
LVGL Features#
This example showcases LVGL applications on the K230 platform:
Multi-resolution support: Automatically adapts to displays with different resolutions
Touch screen support: Integrated touch screen input driver
Rich UI widgets: Buttons, progress bars, sliders, switches, etc.
Responsive layout: Automatically adjusts widget size and position based on screen size
Smooth animation: Supports widget animation effects
LVGL Widgets#
This example includes demonstrations of the following LVGL widgets:
Label: Displays text information
Button: Responsive button, supports different colors
Bar: Displays progress information
Slider: Draggable slider widget
Switch: On/off state toggle
Container: Layout container
Display Driver#
This example uses the display driver of the K230 platform:
Resolution support: Supports up to 1920x1080 resolution
Double buffering: Reduces screen flickering
DMA acceleration: Uses K230’s GSDMA for image data transfer
Input Devices#
Touch screen input: Supports capacitive/resistive touch screens
Gesture recognition: Supports tap, swipe, and other gestures
Code Location#
Demo source code location: src/rtsmart/examples/3rd-party/lvgl/lvgl_basic
Usage Instructions#
Compilation Method#
Firmware Compilation#
In the root directory of K230 RTOS SDK, use make menuconfig to configure the compilation options, select to compile the LVGL example into the firmware, and then compile the firmware.
Standalone Compilation#
Enter the LVGL example directory and use CMake to compile:
cd src/rtsmart/examples/3rd-party/lvgl/lvgl_basic
mkdir build && cd build
cmake ..
make
After successful compilation, an executable file will be generated.
Hardware Preparation#
Prepare an LCD display (supports MIPI DSI or RGB interface)
Connect the touch screen (if using touch input)
Ensure the display and touch screen are correctly connected to the K230 development board
Running the Example#
Copy the compiled executable to the development board, enter the storage directory, and run:
./lvgl_basic
Viewing the Result#
After the program runs, it will start the LVGL graphical interface and display the following content:
Screen: 800x480
===========================
LVGL Multi-Resolution Demo
[Button 1] [Button 2] [Button 3]
Progress Bar:
[===========> ] 70%
Slider:
[----O----]
Switch:
[ON]
Interface features:
The top displays screen resolution information
The middle shows three buttons with different colors
The bottom shows a progress bar, slider, and switch controls
All controls support touch interaction
Users can interact with the interface through the touch screen:
Click buttons to see responses
Drag the slider to adjust values
Toggle the switch state
Customizing the Interface#
LVGL provides a rich set of APIs, and users can customize the interface as needed:
// 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
Various parameters can be adjusted in the LVGL configuration file (lv_conf.h), such as memory size, screen resolution, font selection, etc. For detailed API and configuration of LVGL, please refer to the LVGL Official Documentation.
Tip
LVGL requires periodic calling of the lv_timer_handler() function to refresh the interface. It is recommended to call this function periodically in the main loop.
