LVGLv9.1.0移植
1. 移植步骤
1.1 下载LVGL源码
名称 | 仓库地址 | 描述 |
---|---|---|
lv_port_linux | https://github.com/lvgl/lv_port_linux.git | 适配有framebuffer、DRM/KMS和SDL2的linux系统的接口 |
在ubuntu上,新建终端,克隆上面的仓库地址:
ubuntu@ubuntu1804:~$ git clone https://github.com/lvgl/lv_port_linux.git
ubuntu@ubuntu1804:~$ cd lv_port_linux/
ubuntu@ubuntu1804:~/lv_port_linux$ git submodule update --init --recursive
Cloning into '/home/ubuntu/lv_port_linux/lvgl'...
Submodule path 'lvgl': checked out 'e29d35b43c509b6d7189f5dac87139441669ae66'
Submodule path 'lvgl': checked out 'e29d35b43c509b6d7189f5dac87139441669ae66'
查看目录结构:
ubuntu@ubuntu1804:~/lv_port_linux$ tree -L 2
.
├── CMakeLists.txt
├── LICENSE
├── lv_conf.h
├── lvgl
│ ├── CMakeLists.txt
│ ├── CMakePresets.json
│ ├── component.mk
│ ├── demos
│ ├── docs
│ ├── env_support
│ ├── examples
│ ├── idf_component.yml
│ ├── Kconfig
│ ├── library.json
│ ├── library.properties
│ ├── LICENCE.txt
│ ├── lv_conf_template.h
│ ├── lvgl.h
│ ├── lvgl.mk
│ ├── lvgl.pc.in
│ ├── README.md
│ ├── SConscript
│ ├── scripts
│ ├── src
│ └── tests
├── main.c
├── Makefile
├── mouse_cursor_icon.c
└── README.md
8 directories, 21 files
查看如果发现lvgl的库是9.0.1版本的,那就删除lvgl/文件夹,重新克隆:
ubuntu@ubuntu1804:~/lv_port_linux$ rm lvgl/ -rf
ubuntu@ubuntu1804:~/lv_port_linux$ git clone https://github.com/lvgl/lvgl.git
Cloning into 'lvgl'...
remote: Enumerating objects: 104172, done.
remote: Counting objects: 100% (15487/15487), done.
remote: Compressing objects: 100% (1633/1633), done.
remote: Total 104172 (delta 14432), reused 13985 (delta 13854), pack-reused 88685
Receiving objects: 100% (104172/104172), 332.99 MiB | 12.14 MiB/s, done.
Resolving deltas: 100% (79168/79168), done.
Checking out files: 100% (2894/2894), done.
ubuntu@ubuntu1804:~/lv_port_linux$
可以看到:
ubuntu@ubuntu1804:~/lv_port_linux$ cd lvgl/
ubuntu@ubuntu1804:~/lv_port_linux/lvgl$ vim lv_conf_template.h
/**
* @file lv_conf.h
* Configuration file for v9.1.1-dev
*/
源码获取完毕!接下来就是编译了。
1.2 编译
想要在开发板上运行,当然是需要指定相应的交叉编译工具的了。
创建一个文件toolchain.cmake
,用于指定交叉编译工具:
set(CMAKE_SYSTEM_NAME Linux)
#如果是arm,就写arm;这里是riscv
set(CMAKE_SYSTEM_PROCESSOR riscv)
set(tools "/home/ubuntu/tina-d1-h/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702")
set(CMAKE_C_COMPILER ${tools}/bin/riscv64-unknown-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/riscv64-unknown-linux-gnu-g++)
为了方便编译,编写一个脚本build.sh
:
rm -rf build
mkdir -p build
cd build/
cmake -DCMAKE_TOOLCHAIN_FILE="../toolchain.cmake" ..
make -j8
目录结构如下:
ubuntu@ubuntu1804:~/lv_port_linux$ tree -L 1
.
├── build.sh
├── CMakeLists.txt
├── LICENSE
├── lv_conf.h
├── lvgl
├── main.c
├── Makefile
├── mouse_cursor_icon.c
├── README.md
└── toolchain.cmake
1 directory, 9 files
经过编译测试,需要修改CMakeLists.txt
,否则编译会报错,注释掉下面几个:
--- CMakeLists.txt-bak 2024-06-24 22:11:40.077461049 -0400
+++ CMakeLists.txt 2024-06-24 22:12:16.549404544 -0400
@@ -12,12 +12,12 @@
add_executable(main main.c mouse_cursor_icon.c)
-include(${CMAKE_CURRENT_LIST_DIR}/lvgl/tests/FindLibDRM.cmake)
-include_directories(${Libdrm_INCLUDE_DIRS})
+#include(${CMAKE_CURRENT_LIST_DIR}/lvgl/tests/FindLibDRM.cmake)
+#include_directories(${Libdrm_INCLUDE_DIRS})
-find_package(SDL2)
-find_package(SDL2_image)
-include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
+#find_package(SDL2)
+#find_package(SDL2_image)
+#include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${Libdrm_LIBRARIES} m pthread)
add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)
执行./build.sh
,编译:
ubuntu@ubuntu1804:~/lv_port_linux$ sudo chmod +x build.sh
ubuntu@ubuntu1804:~/lv_port_linux$ ./build.sh
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
...
[ 99%] Linking C static library ../lib/liblvgl_examples.a
[ 99%] Built target lvgl_examples
[ 99%] Linking C static library ../lib/liblvgl_demos.a
[ 99%] Built target lvgl_demos
[ 99%] Building C object CMakeFiles/main.dir/mouse_cursor_icon.c.o
[ 99%] Building C object CMakeFiles/main.dir/main.c.o
[100%] Linking CXX executable /home/ubuntu/lv_port_linux/bin/main
[100%] Built target main
ubuntu@ubuntu1804:~/lv_port_linux$
编译成功,可执行程序保存在bin/目录下:
ubuntu@ubuntu1804:~/lv_port_linux$ file bin/main
bin/main: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64xthead-lp64d.so.1, for GNU/Linux 4.15.0, with debug_info, not stripped
ubuntu@ubuntu1804:~/lv_port_linux$