5. LVGL User Guide
Light and Versatile Graphics Library (LVGL) is an open-source lightweight graphics library. The following example illustrates how to port LVGL9.2 to the Weston desktop. After porting, the library can be downloaded at https://github.com/rubikpi-ai/lvgl. For more information about LVGL, visit https://lvgl.io/.
- Clone the required code base:
git clone -b release/v9.2 https://github.com/lvgl/lvgl.git
git clone https://github.com/lvgl/lv_port_pc_vscode.git
- Copy lvgl to the root directory of lv_port_pc_vscode, replace the lv_conf.h configuration file, and go to main/src to create a soft link.
cd lv_port_pc_vscode
cp ../lvgl . -r
cp lvgl/lv_conf_template.h lv_conf.h
cd main/src
ln -sf ../../lvgl
- Modify lv_conf.h.
- Enable lv_conf.h.
/* clang-format off */
#if 1 /*Set it to "1" to enable content*/
- Modify the color depth:
#define LV_COLOR_DEPTH 32
- Define LV_MEM_SIZE:
#define LV_MEM_SIZE (20U * 1024U * 1024U)
- Define LV_USE_WAYLAND:
#define LV_USE_WAYLAND 1
- Define LV_WAYLAND_WL_SHELL:
#define LV_WAYLAND_WL_SHELL 1
- Define LV_USE_LINUX_DRM:
#define LV_USE_LINUX_DRM 1
- Enable the demo:
#define LV_USE_DEMO_WIDGETS 1
- Modify CMakeLists.txt.
- Comment out SDL2 library:
# Find and include SDL2 library
# find_package(SDL2 REQUIRED)
- Add the path of the header file and modify the path according to the actual situation. As shown in the following code, /home/zhy/QCOM/sdk is the installation path of the cross-compilation tool. For details, refer to "1.12.2. Compile code".
target_include_directories(lvgl PUBLIC /home/zhy/QCOM/sdk/sysroots/armv8-2a-qcom-linux/usr/include/drm)
- Comment out the following content:
# Remove ARM-specific compile and linker options
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
- Set the link library. Replace the original target_link_libraries:
# Define LVGL configuration as a simple include
target_compile_definitions(main PRIVATE LV_CONF_INCLUDE_SIMPLE)
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg m pthread rt drmfs drm_etnaviv drm_nouveau drm_omap drmtime drm drmutils sdedrm xkbcommon wayland-client wayland-cursor wayland-egl EGL GLESv2)
-
Configure the cross-compilation environment.
For details, refer to "1.11.2.Install cross-compilation tools".
source <your toolchains directory>/environment-setup-armv8-2a-qcom-linux
Modify the hal_init function in lv_port_pc_vscode/main/src/main.c.
/**
* Initialize the Hardware Abstraction Layer (HAL) for the LVGL graphics
* library
*/
static lv_display_t * hal_init(int32_t w, int32_t h)
{
lv_disp_t * disp;
lv_group_set_default(lv_group_create());
lv_group_set_default(lv_group_create());
disp = lv_wayland_window_create(w, h, "Window Title", NULL);
// lv_wayland_window_set_fullscreen(disp, false);
lv_indev_t *kb = lv_wayland_get_keyboard(disp);
lv_indev_set_display(kb, disp);
lv_indev_set_group(kb, lv_group_get_default());
lv_display_set_default(disp);
return disp;
}
- In the main function of lv_port_pc_vscode/nvim main/src/main.c, change lv_timer_handler called in the while loop to lv_wayland_timer_handler.
while(1) {
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_wayland_timer_handler();
usleep(5 * 1000);
}
- Start compilation.
cd lv_port_pc_vscode
mkidr build
cd build
cmake ..
make
- Transfer the compilation artifact to RUBIK Pi 3. The following is an ADB transfer example:
cd lv_port_pc_vscode/bin
adb push main /opt
- Connect the HDMI cable, mouse, and keyboard. Run the following commands in the Weston terminal to execute the LVGL program. Use the mouse and keyboard to perform operations in the user interface.
cd /opt
./main
The porting result: