本次筆記主要記錄博主移植lvgl到linux上的過程,方便偵錯。
兩種編譯方式:
原文:李柱明部落格
參考:
sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev
參考:
拉取lvgl PC 模擬子模組vscode sdl:
git clone --recursive https://github.com/lvgl/lv_sim_vscode_sdl
下載完如下圖:
然後直接make:
make
轉到lv_sim_vscode_sdl/build/bin執行demo韌體即可:
./demo
結果如圖:
如果上述clone下面這三個庫時較慢,可以手動下載庫檔案,再複製到lv_sim_vscode_sdl目錄下對應的目錄中:(選同一版本)
lvgl庫下載 :https://github.com/lvgl/lvgl.git
lvgl_drivers庫下載 :https://github.com/lvgl/lv_drivers.git
lv_examples庫下載 :https://github.com/lvgl/lv_examples.git
打算搭建自己學習、偵錯lvgl的SDK,用CMAKE編譯,所以就自己手把手構建SDK和移植lvgl。
目錄構建如下:
進入ui資料夾,clone兩個庫:
git clone -b release/v8.0 https://github.com/lvgl/lvgl.git
git clone -b release/v8.0 https://github.com/lvgl/lv_drivers.git
新增lv_conf.h:在lvgl目錄下
cp lv_conf_template.h lv_conf.h
使能該檔案:改成1
#if 1 /*Set it to "1" to enable content*/
cp lv_drv_conf_template.h lv_drv_conf.h
#if 1 /*Set it to "1" to enable content*/
開啟SDL需要的宏:
USE_MONITOR
宏改成1。我們用monitor來模擬。USE_MOUSE
改成1。用到滑鼠。USE_MOUSEWHEEL
改成1。滑鼠滾輪也用到。USE_KEYBOARD
改成1。用到鍵盤。可以直接拷貝lv_sim_vscode_sdl/main/src/m*
。
main.c
把標頭檔案改成如下:
/*********************
* INCLUDES
*********************/
#define _DEFAULT_SOURCE /* needed for usleep() */
#include <stdlib.h>
#include <unistd.h>
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
#include <SDL2/SDL.h>
#include "lvgl.h"
#include "examples/lv_examples.h"
#include "monitor.h"
#include "mouse.h"
#include "keyboard.h"
#include "mousewheel.h"
main.c
把lv_demo_widgets();
demo註釋掉。mouse_cursor_icon.c
的標頭檔案改成:#include "lvgl.h"
lvgl 8.0版本我打算全盤使用自己構建的cmake。
lvgl 8.3版本我打算相容原生庫的構建的cmake。
頂層目錄下的cmake:
cmake_minimum_required(VERSION 3.0.0)
set(target lzm_lvgl_test_bin)
project(${target} VERSION 0.1.0)
set(src_lvgl_test
src/main.c
src/mouse_cursor_icon.c
)
add_executable(${target} ${src_lvgl_test})
include_directories(/usr/include)
target_link_libraries(${target} PRIVATE lzm_lvgl_lib lzm_lvgl_drv_lib)
target_link_libraries(${target} PRIVATE SDL2)
add_subdirectory(ui)
./ui:
target_compile_definitions(${target} PUBLIC "-DLV_CONF_INCLUDE_SIMPLE")
target_compile_definitions(${target} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")
add_subdirectory(lvgl)
add_subdirectory(lv_drivers)
./ui/lvgl:
set(target lzm_lvgl_lib)
add_library(${target} STATIC)
target_compile_definitions(${target} PUBLIC "-DLV_CONF_INCLUDE_SIMPLE")
target_compile_definitions(${target} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")
target_include_directories(${target} PUBLIC ./)
target_include_directories(${target} PUBLIC ./src)
target_include_directories(${target} PUBLIC ./src/core)
target_include_directories(${target} PUBLIC ./src/draw)
target_include_directories(${target} PUBLIC ./src/extra)
target_include_directories(${target} PUBLIC ./src/font)
target_include_directories(${target} PUBLIC ./src/gpu)
target_include_directories(${target} PUBLIC ./src/hal)
target_include_directories(${target} PUBLIC ./src/misc)
target_include_directories(${target} PUBLIC ./src/widgets)
# app include
target_include_directories(${target} PUBLIC ./examples)
# app src
file(GLOB_RECURSE src_lvgl_app examples/*.c)
file(GLOB_RECURSE src_lvgl src/*.c)
target_sources(${target} PRIVATE
${src_lvgl}
${src_lvgl_app}
)
./ui/lv_drivers:
set(target lzm_lvgl_drv_lib)
add_library(${target} STATIC)
target_link_libraries(${target} PUBLIC lzm_lvgl_lib)
target_include_directories(${target} PUBLIC ./)
target_include_directories(${target} PUBLIC ./display)
target_include_directories(${target} PUBLIC ./gtkdrv)
target_include_directories(${target} PUBLIC ./indev)
target_include_directories(${target} PUBLIC ./wayland)
target_include_directories(${target} PUBLIC ./win32drv)
file(GLOB_RECURSE src_lvgl_drv ./*.c)
target_sources(${target} PRIVATE
${src_lvgl_drv}
)
cmake ..
:結果如下,Makefile建立成功:jamie@lzm-vm-linux:~/work/study/lvgl/lzm_lvgl_v8.0/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jamie/work/study/lvgl/lzm_lvgl_v8.0/build
jamie@lzm-vm-linux:~/work/study/lvgl/lzm_lvgl_v8.0/build$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile ui
jamie@lzm-vm-linux:~/work/study/lvgl/lzm_lvgl_v8.0/build$ make
[ 90%] Built target lzm_lvgl_lib
Consolidate compiler generated dependencies of target lzm_lvgl_drv_lib
[ 98%] Built target lzm_lvgl_drv_lib
Consolidate compiler generated dependencies of target lzm_lvgl_test_bin
[ 98%] Building C object CMakeFiles/lzm_lvgl_test_bin.dir/src/mouse_cursor_icon.c.o
[ 99%] Linking C executable lzm_lvgl_test_bin
[100%] Built target lzm_lvgl_test_bin
jamie@lzm-vm-linux:~/work/study/lvgl/lzm_lvgl_v8.0/build$
jamie@lzm-vm-linux:~/work/study/lvgl/lzm_lvgl_v8.0/build$ ./lzm_lvgl_test_bin