lvgl基础

一、lvgl简介

LVGL(Light and Versatile Graphics Library)是一个免费的轻量级开源图形库。LVGL 是一款具有丰富部件,具备高级图形特性,支持多种输入设备和多国语言,独立于硬件之外的开源图形库。LVGL 官方网址为:https://lvgl.io/。LVGL 源代码网址为:https://github.com/lvgl/lvgl/

图形用户界面(GUI)是指采用图形方式显示的计算机操作用户界面,允许用户使用鼠标等输入设备操纵屏幕上的图标或菜单选项。图形用户界面由多种控件及其相应的控制机制构成,在各种新式应用程序中都是标准化的,即相同的操作总是以同样的方式来完成,在图形用户界面,用户看到和操作的都是图形对象,应用的是计算机图形学的技术。

二、运行

lvgl只是一个库,需要定期调用lv_timer_handler()以使库相关事件或函数调用。

image

要驱动 LVGL 的定时器,需要在以下情况之一中定期调用 lv_timer_handler() 函数: - 在 main() 函数的 while(1) 循环中,或者 - 在操作系统任务中定期调用。

while(1) {
  uint32_t time_till_next = lv_timer_handler();
  my_delay_ms(time_till_next);
}

while(1) {
   ...
   lv_timer_handler_run_in_period(5); /* run lv_timer_handler() every 5ms */
   ...
}

while(1) {
  ...
  lv_timer_periodic_handler();
  ...
}

三、集成

参考linux下工程

1、vscode

LVGL is available for VSCode, a well-known cross-platform code editor.

It uses SDL to open a window, show the rendered content, and manage mouse and keyboard.

A ready-to-use LVGL project for VSCode is available at https://github.com/lvgl/lv_port_pc_vscode.

2、Generic Linux Port

The lv_port_linux project is typically meant to be used for embedded hardware, but it runs perfectly on PC as well.

3、embedded

# user_cross_compile_setup.cmake
# Usage:
# cmake -DCMAKE_TOOLCHAIN_FILE=./user_cross_compile_setup.cmake -B build -S .
# cmake -DCMAKE_TOOLCHAIN_FILE=../user_cross_compile_setup.cmake  ..
# make  -C build -j

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)

set(CMAKE_SYSROOT /opt/resource/lc/sysroot)

set(TOOLCHAIN_PATH /opt/toolchain/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.0/bin)
set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/riscv64-unknown-linux-gnu-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -rdynamic -funwind-tables")

# If necessary, set STAGING_DIR
# if not work, please try(in shell command): export STAGING_DIR=/home/ubuntu/Your_SDK/out/xxx/openwrt/staging_dir/target
#set(ENV{STAGING_DIR} "/home/ubuntu/Your_SDK/out/xxx/openwrt/staging_dir/target")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
set(ENV{PKG_CONFIG_PATH}
    "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")

include_directories(${CMAKE_SYSROOT}/usr/include/)
include_directories(${CMAKE_SYSROOT}/usr/include/drm)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

四、常用widgets

参考:

1、官方文档

2、中文文档

3、lvgl初识 博客

4、lvgl demos 官网

posted @ 2026-04-29 21:45  yuxi_o  阅读(4)  评论(0)    收藏  举报