LVGL v9.1.1 移植至海思3516AV300 (Linux fb)
【一、海思移植 LVGL及SquareLine代码移植】
【二、海思移植 LVGL及NXP GUI-Guider代码移植】
文章目录
前言
之前使用移植QT5至海思发现内存占用过大,现在移植一下LVGL测试一下
一、移植步骤
1.1 下载源码
-
海思使用的是linux framebuffer的方式在屏幕上显示界面, 因此需要下载适配有framebuffer的linux系统的接口,操作如下:
sunshine@sunshine:~/CSDN/LVGL$ git clone https://github.com/lvgl/lv_port_linux.git 正克隆到 'lv_port_linux'... remote: Enumerating objects: 188, done. remote: Counting objects: 100% (85/85), done. remote: Compressing objects: 100% (51/51), done. remote: Total 188 (delta 52), reused 40 (delta 34), pack-reused 103 接收对象中: 100% (188/188), 959.23 KiB | 1.75 MiB/s, 完成. 处理 delta 中: 100% (86/86), 完成. sunshine@sunshine:~/CSDN/LVGL$ cd lv_port_linux/ sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ git submodule update --init --recursive 正克隆到 '/home/sunshine/CSDN/LVGL/lv_port_linux/lvgl'... 子模组路径 'lvgl':检出 'e29d35b43c509b6d7189f5dac87139441669ae66'
-
查看lvgl库版本, 版本号在lvgl/lv_conf_template.h文件里, 发现版本为9.0.1,删除lvgl文件夹,重新克隆
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ git clone https://github.com/lvgl/lvgl.git 正克隆到 'lvgl'... remote: Enumerating objects: 105567, done. remote: Counting objects: 100% (5097/5097), done. remote: Compressing objects: 100% (655/655), done. remote: Total 105567 (delta 4650), reused 4569 (delta 4438), pack-reused 100470 接收对象中: 100% (105567/105567), 337.68 MiB | 8.56 MiB/s, 完成. 处理 delta 中: 100% (80167/80167), 完成
2.编译源码
-
根据reamde得知,Makdefile使用不了,建议使用Cmake。
Notes The Makefile is broken right now, so Cmake shall be used.
-
指定海思交叉编译工具。创建一个文件
toolchain.cmake
,用于指定交叉编译工具:set(CMAKE_SYSTEM_NAME Linux) #如果是arm,就写arm;这里是risv set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_C_COMPILER arm-himix200-linux-gcc) set(CMAKE_CXX_COMPILER arm-himix200-linux-g++)
-
为了方便编译,编写一个脚本
build.sh
:rm -rf build mkdir -p build cd build/ cmake -DCMAKE_TOOLCHAIN_FILE="../toolchain.cmake" .. make -j8
-
目录结构如下
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ tree -L 1 . ├── CMakeLists.txt ├── LICENSE ├── lv_conf.h ├── lvgl ├── main.c ├── Makefile ├── mouse_cursor_icon.c └── README.md 1 directory, 7 files
-
直接编译会报错,需要修改
CMakeLists.txt
(参考readme)
执行./build.sh
,编译还是报错如下:sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ ./build.sh -- The C compiler identification is GNU 6.3.0 -- The CXX compiler identification is GNU 6.3.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc - 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: /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- The ASM compiler identification is GNU -- Found assembler: /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc -- Configuring done -- Generating done -- Build files have been written to: /home/sunshine/CSDN/LVGL/lv_port_linux/build Scanning dependencies of target lvgl [ 0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_group.c.o [ 0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_event.c.o [ 0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_class.c.o [ 1%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_pos.c.o [ 1%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_id_builtin.c.o [ 1%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_property.c.o [ 1%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_draw.c.o [ 1%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj.c.o In file included from /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/../core/../draw/sw/lv_draw_sw.h:24:0, from /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/../core/lv_global.h:21, from /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/lv_group.c:11: /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/../core/../draw/sw/../../draw/lv_draw_vector.h:23:2: error: #error "lv_draw_vector needs LV_USE_MATRIX = 1" #error "lv_draw_vector needs LV_USE_MATRIX = 1"
-
根据报错修改
lv_conf.h
配置文件添加 #define LV_USE_MATRIX 1
-
继续编译,报错如下:
/home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/../display/../draw/../misc/lv_matrix.h:30:2: error: #error "LV_USE_FLOAT is required for lv_matrix" #error "LV_USE_FLOAT is required for lv_matrix" ^~~~~ In file included from /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/../draw/lv_draw.h:22:0, from /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/lv_obj_draw.h:17, from /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/lv_obj_draw.c:9: /home/sunshine/CSDN/LVGL/lv_port_linux/lvgl/src/core/../draw/../misc/lv_matrix.h:30:2: error: #error "LV_USE_FLOAT is required for lv_matrix" #error "LV_USE_FLOAT is required for lv_matrix
-
继续修改
lv_conf.h
配置文件#define LV_USE_FLOAT 1 (默认为0)
-
继续编译,执行
./build.sh
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ ./build.sh -- The C compiler identification is GNU 6.3.0 -- The CXX compiler identification is GNU 6.3.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc - 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: /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- The ASM compiler identification is GNU -- Found assembler: /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc -- Configuring done -- Generating done -- Build files have been written to: /home/sunshine/CSDN/LVGL/lv_port_linux/build Scanning dependencies of target lvgl [ 0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_id_builtin.c.o ······ [ 99%] Building C object lvgl/CMakeFiles/lvgl_examples.dir/examples/widgets/textarea/lv_example_textarea_3.c.o [ 99%] Building C object lvgl/CMakeFiles/lvgl_examples.dir/examples/widgets/tileview/lv_example_tileview_1.c.o [ 99%] Building C object lvgl/CMakeFiles/lvgl_examples.dir/examples/widgets/win/lv_example_win_1.c.o [ 99%] Linking C static library ../lib/liblvgl_examples.a [ 99%] Built target lvgl_examples [ 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 ../bin/main [100%] Built target main
-
至此编译完成,可执行程序保存在bin/目录下
二、海思板上测试
1. 运行Sample_vio程序(使用HDMI输出测试)
LVGL是linux fb方式显示依赖于VO
2.上传程序至开发板运行
/home # tftp -gr main 192.168.1.102
main 100% |*****************************************************************************************************| 2563k 0:00:00 ETA
/home # ./main
[Warn] (0.000, +0) lv_init: Memory integrity checks are enabled via LV_USE_ASSERT_MEM_INTEGRITY which makes LVGL much slower lv_init.c:241
[Warn] (0.000, +0) lv_init: Object sanity checks are enabled via LV_USE_ASSERT_OBJ which makes LVGL much slower lv_init.c:245
[Warn] (0.000, +0) lv_init: Style sanity checks are enabled that uses more RAM lv_init.c:249
ioctl(FBIOBLANK): Invalid argument
3.解决warn
根据警告,修改lv_conf.h
:
/*Enable asserts if an operation is failed or an invalid data is found.
*If LV_USE_LOG is enabled an error message will be printed on failure*/
#define LV_USE_ASSERT_NULL 0 /*Check if the parameter is NULL. (Very fast, recommended)*/
#define LV_USE_ASSERT_MALLOC 0 /*Checks is the memory is successfully allocated or no. (Very fast, recommended)*/
#define LV_USE_ASSERT_STYLE 0 /*Check if the styles are properly initialized. (Very fast, recommended)*/
#define LV_USE_ASSERT_MEM_INTEGRITY 0 /*Check the integrity of `lv_mem` after critical operations. (Slow)*/
#define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/
修改lv_port_linux/lvgl/src/drivers/display/fb/lv_linux_fbdev.c
文件, 注释下面代码:
#if 0
/* Make sure that the display is on.*/
if(ioctl(dsc->fbfd, FBIOBLANK, FB_BLANK_UNBLANK) != 0) {
perror("ioctl(FBIOBLANK)");
/* Don't return. Some framebuffer drivers like efifb or simplefb don't implement FBIOBLANK.*/
}
#endif
4.再次编译./build.sh
,上传执行即可。
5.感觉显示的颜色有点异常,根据官方手册,修改main函数测试一下。
static lv_style_t style_btn;
static lv_style_t style_button_pressed;
static lv_style_t style_button_red;
static lv_color_t darken(const lv_color_filter_dsc_t * dsc, lv_color_t color, lv_opa_t opa)
{
LV_UNUSED(dsc);
return lv_color_darken(color, opa);
}
static void style_init(void)
{
/*Create a simple button style*/
lv_style_init(&style_btn);
lv_style_set_radius(&style_btn, 10);
lv_style_set_bg_opa(&style_btn, LV_OPA_COVER);
lv_style_set_bg_color(&style_btn, lv_palette_lighten(LV_PALETTE_GREY, 3));
lv_style_set_bg_grad_color(&style_btn, lv_palette_main(LV_PALETTE_GREY));
lv_style_set_bg_grad_dir(&style_btn, LV_GRAD_DIR_VER);
lv_style_set_border_color(&style_btn, lv_color_black());
lv_style_set_border_opa(&style_btn, LV_OPA_20);
lv_style_set_border_width(&style_btn, 2);
lv_style_set_text_color(&style_btn, lv_color_black());
/*Create a style for the pressed state.
*Use a color filter to simply modify all colors in this state*/
static lv_color_filter_dsc_t color_filter;
lv_color_filter_dsc_init(&color_filter, darken);
lv_style_init(&style_button_pressed);
lv_style_set_color_filter_dsc(&style_button_pressed, &color_filter);
lv_style_set_color_filter_opa(&style_button_pressed, LV_OPA_20);
/*Create a red style. Change only some colors.*/
lv_style_init(&style_button_red);
lv_style_set_bg_color(&style_button_red, lv_palette_main(LV_PALETTE_RED));
lv_style_set_bg_grad_color(&style_button_red, lv_palette_lighten(LV_PALETTE_RED, 3));
}
/**
* Create styles from scratch for buttons.
*/
void lv_example_get_started_3(void)
{
/*Initialize the style*/
style_init();
/*Create a button and use the new styles*/
lv_obj_t * btn = lv_button_create(lv_screen_active());
/* Remove the styles coming from the theme
* Note that size and position are also stored as style properties
* so lv_obj_remove_style_all will remove the set size and position too */
lv_obj_remove_style_all(btn);
lv_obj_set_pos(btn, 10, 10);
lv_obj_set_size(btn, 120, 50);
lv_obj_add_style(btn, &style_btn, 0);
lv_obj_add_style(btn, &style_button_pressed, LV_STATE_PRESSED);
/*Add a label to the button*/
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, "Button");
lv_obj_center(label);
/*Create another button and use the red style too*/
lv_obj_t * btn2 = lv_button_create(lv_screen_active());
lv_obj_remove_style_all(btn2); /*Remove the styles coming from the theme*/
lv_obj_set_pos(btn2, 10, 80);
lv_obj_set_size(btn2, 120, 50);
lv_obj_add_style(btn2, &style_btn, 0);
lv_obj_add_style(btn2, &style_button_red, 0);
lv_obj_add_style(btn2, &style_button_pressed, LV_STATE_PRESSED);
lv_obj_set_style_radius(btn2, LV_RADIUS_CIRCLE, 0); /*Add a local style too*/
label = lv_label_create(btn2);
lv_label_set_text(label, "Button 2");
lv_obj_center(label);
}
int main(void)
{
lv_init();
/*Linux display device init*/
lv_linux_disp_init();
/*Create a Demo*/
// lv_demo_widgets();
// lv_demo_widgets_start_slideshow();
//lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0xffff32), LV_PART_MAIN); //背景颜色
//lv_obj_set_style_bg_opa(lv_screen_active(), LV_OPA_0, LV_PART_MAIN); //背景透明度
lv_example_get_started_3();
/*Handle LVGL tasks*/
while(1) {
lv_timer_handler();
usleep(5000);
}
return 0;
}
上传板端测试
发现与官方例程显示的颜色不一样,分析跟海思的显示的像素格式有关; 海思像素格式默认为 ARGB1555,而LVGL不支持ARGB1555, 但是海思和LGVL都只支持ARGB8888, 将海思显示像素格式与LGVL设置成ARGB8888即可。
三、修改源码适配海思ARGB8888
1. 修改LVGL源码,lv_port_linux/lvgl/src/drivers/display/fb/lv_linux_fbdev.c
在文件开头加入下面代码:
#if 1
#include "../../../../../hisi/include/hi_type.h"
#include "../../../../../hisi/include/hifb.h"
#include "../../../../../hisi/include/mpi_vo.h"
#include "../../../../../hisi/include/hi_comm_vo.h"
#include "../../../../../hisi/include/hi_tde_api.h"
#include "../../../../../hisi/include/mpi_sys.h"
static struct fb_bitfield s_r16 = {10, 5, 0};
static struct fb_bitfield s_g16 = {5, 5, 0};
static struct fb_bitfield s_b16 = {0, 5, 0};
static struct fb_bitfield s_a16 = {15, 1, 0};
static struct fb_bitfield s_a32 = {24, 8, 0};
static struct fb_bitfield s_r32 = {16, 8, 0};
static struct fb_bitfield s_g32 = {8, 8, 0};
static struct fb_bitfield s_b32 = {0, 8, 0};
#define SCREEN_WIDTH 1920
#define SCREEN_HEIGHT 1080
#define Start_X 0
#define Start_Y 0
#endif
修改void lv_linux_fbdev_set_file(lv_display_t * disp, const char * file)
函数
#if LV_LINUX_FBDEV_BSD
struct fbtype fb;
unsigned line_length;
/*Get fb type*/
if(ioctl(dsc->fbfd, FBIOGTYPE, &fb) != 0) {
perror("ioctl(FBIOGTYPE)");
return;
}
/*Get screen width*/
if(ioctl(dsc->fbfd, FBIO_GETLINEWIDTH, &line_length) != 0) {
perror("ioctl(FBIO_GETLINEWIDTH)");
return;
}
dsc->vinfo.xres = (unsigned) fb.fb_width;
dsc->vinfo.yres = (unsigned) fb.fb_height;
dsc->vinfo.bits_per_pixel = fb.fb_depth;
dsc->vinfo.xoffset = 0;
dsc->vinfo.yoffset = 0;
dsc->finfo.line_length = line_length;
dsc->finfo.smem_len = dsc->finfo.line_length * dsc->vinfo.yres;
#else /* LV_LINUX_FBDEV_BSD */
/* Get fixed screen information*/
if(ioctl(dsc->fbfd, FBIOGET_FSCREENINFO, &dsc->finfo) == -1) {
perror("Error reading fixed information");
return;
}
/* Get variable screen information*/
if(ioctl(dsc->fbfd, FBIOGET_VSCREENINFO, &dsc->vinfo) == -1) {
perror("Error reading variable information");
return;
}
LV_LOG_INFO("FBIOGET_VSCREENINFO: %dx%d, %dbpp", dsc->vinfo.xres, dsc->vinfo.yres, dsc->vinfo.bits_per_pixel);
/* 1. disable HIFB show */
HI_BOOL bShow = HI_FALSE;
if (ioctl(dsc->fbfd, FBIOPUT_SHOW_HIFB, &bShow) < 0)
{
perror("FBIOPUT_SHOW_HIFB failed!\n");
return;
}
/* 2. set the screen original position */
HIFB_POINT_S stPoint = {0, 0};
stPoint.s32XPos = Start_X;
stPoint.s32YPos = Start_Y;
if (ioctl(dsc->fbfd, FBIOPUT_SCREEN_ORIGIN_HIFB, &stPoint) < 0)
{
perror("set screen original show position failed!\n");
return;
}
/* **********************************************************
*3. modify the variable screen info
* the screen size: IMAGE_WIDTH*IMAGE_HEIGHT
* the virtual screen size: VIR_SCREEN_WIDTH*VIR_SCREEN_HEIGHT
* (which equals to VIR_SCREEN_WIDTH*(IMAGE_HEIGHT*2))
* the pixel format: ARGB1555
**************************************************************/
HIFB_COLOR_FMT_E enClrFmt = HIFB_FMT_ARGB8888; //HIFB_FMT_ARGB8888;
switch (enClrFmt)
{
case HIFB_FMT_ARGB8888:
dsc->vinfo.transp = s_a32;
dsc->vinfo.red = s_r32;
dsc->vinfo.green = s_g32;
dsc->vinfo.blue = s_b32;
dsc->vinfo.bits_per_pixel = 32;
break;
default:
dsc->vinfo.transp = s_a16;
dsc->vinfo.red = s_r16;
dsc->vinfo.green = s_g16;
dsc->vinfo.blue = s_b16;
dsc->vinfo.bits_per_pixel = 16;
break;
}
HI_BOOL bDoubleBuffer = HI_FALSE;
HI_U32 u32Width = SCREEN_WIDTH;
HI_U32 u32Height = SCREEN_HEIGHT;
switch(bDoubleBuffer)
{
case HI_FALSE:
{
dsc->vinfo.xres_virtual = u32Width;
dsc->vinfo.yres_virtual = u32Height;
dsc->vinfo.xres = u32Width;
dsc->vinfo.yres = u32Height;
}
break;
default:
{
dsc->vinfo.xres_virtual = u32Width;
dsc->vinfo.yres_virtual = u32Height * 2;
dsc->vinfo.xres = u32Width;
dsc->vinfo.yres = u32Height;
break;
}
}
dsc->vinfo.activate = FB_ACTIVATE_NOW;
/* 4. set the variable screen information */
if (ioctl(dsc->fbfd, FBIOPUT_VSCREENINFO, &dsc->vinfo) < 0)
{
perror("Put variable screen info failed!\n");
return;
}
LV_LOG_INFO("FBIOPUT_VSCREENINFO: %dx%d, %dbpp", dsc->vinfo.xres, dsc->vinfo.yres, dsc->vinfo.bits_per_pixel);
/* 5. get the fix screen information */
if (ioctl(dsc->fbfd, FBIOGET_FSCREENINFO, &dsc->finfo) < 0)
{
perror("Get fix screen info failed!\n");
return;
}
#if 0
/* 6. fix some lcd color's bug */
VO_CSC_S stVoCSC;
if (HI_MPI_VO_GetGraphicLayerCSC(0, &stVoCSC) != HI_SUCCESS )
{
LV_LOG_WARN("HI_MPI_VO_GetGraphicLayerCSC failed!\n");
}
else
{
LV_LOG_INFO("HI_MPI_VO_GetGraphicLayerCSC success!");
}
stVoCSC.enCscMatrix = VO_CSC_MATRIX_IDENTITY;
if (HI_SUCCESS != HI_MPI_VO_SetGraphicLayerCSC(0, &stVoCSC))
{
LV_LOG_WARN("HI_MPI_VO_SetGraphicLayerCSC failed!\n");
}
else
{
LV_LOG_INFO("HI_MPI_VO_SetGraphicLayerCSC success!");
}
#endif
/* 7. it's time to play */
bShow = HI_TRUE;
if (ioctl(dsc->fbfd, FBIOPUT_SHOW_HIFB, &bShow) < 0)
{
perror("FBIOPUT_SHOW_HIFB failed!\n");
return ;
}
LV_LOG_INFO("============= HIFB init ok!==============");
#endif /* LV_LINUX_FBDEV_BSD */
2. 修改配置文件lv_conf.h
/*Color depth: 8 (A8), 16 (RGB565), 24 (RGB888), 32 (XRGB8888)*/
#define LV_COLOR_DEPTH 32 //默认为16
3.将海思SDK里的库与头文件加入项目里
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ mkdir hisi
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ tree hisi/ -L 1
hisi/
├── common
├── include
└── lib
3 directories, 0 files
4. 修改CMkeLists
cmake_minimum_required(VERSION 3.10)
project(lvgl)
set(CMAKE_C_STANDARD 99)#C99 # lvgl officially support C99 and above
set(CMAKE_CXX_STANDARD 17)#C17
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
include_directories(${PROJECT_SOURCE_DIR}/hisi/include)
link_directories(${PROJECT_SOURCE_DIR}/hisi/lib)
add_subdirectory(lvgl)
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})
add_executable(main main.c mouse_cursor_icon.c)
file(GLOB HISI_LIBS "${PROJECT_SOURCE_DIR}/hisi/lib/*.a")
target_link_libraries(main
lvgl
lvgl::examples
lvgl::demos
lvgl::thorvg
${HISI_LIBS}
m
pthread
)
add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)
5. 重新编译,执行./build.sh
,编译完成后拷贝至板端测试
至此解决了LVGL在海思上显示异常的问题
四、使用SquareLine Studio开发LVGL界面
1.简介
SquareLine Studio是一款针对嵌入式系统设计的UI开发工具,它与LVGL(Light and Versatile Graphics Library)紧密集成,提供了拖放组件进行UI设计的功能。
2.安装软件,直接去官网下载安装即可官网 (可以免费使用30天)
3.新建工程
-
打开软件新建一个工程
项目文件夹如下
-
图片与字体库(中文字库)加载
将图片与字体库放大assets文件夹里会自动加载资源(若没有该文件手动建立文件夹,软件里手动导入资源)
中文字库加载
Lalel添加文字
-
生成UI文件
-
生成的文件
4.UI项目移植
- 新建ui文件夹,将上面生成的文件拷贝到此
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ mkdir ui
sunshine@sunshine:~/CSDN/LVGL/lv_port_linux$ tree ui -L 1
ui
├── assets
├── autosave
├── backup
├── cache
├── CMakeLists.txt
├── components
├── filelist.txt
├── fonts
├── images
├── screens
├── SquareLine_Project.sll
├── SquareLine_Project.spj
├── Themes.slt
├── ui.c
├── ui_events.h
├── ui.h
├── ui_helpers.c
└── ui_helpers.h
8 directories, 10 files
- 修改
main.c
#include "ui/ui.h" //添加头文件
int main(void)
{
lv_init();
/*Linux display device init*/
lv_linux_disp_init();
/*Create a Demo*/
// lv_demo_widgets();
// lv_demo_widgets_start_slideshow();
// lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0xffff32), LV_PART_MAIN);
// lv_obj_set_style_bg_opa(lv_screen_active(), LV_OPA_0, LV_PART_MAIN);
// lv_example_get_started_3();
ui_init();
/*Handle LVGL tasks*/
while(1) {
lv_timer_handler();
usleep(5000);
}
return 0;
}
- 修改CMakeLists
cmake_minimum_required(VERSION 3.10)
project(lvgl)
set(CMAKE_C_STANDARD 99)#C99 # lvgl officially support C99 and above
set(CMAKE_CXX_STANDARD 17)#C17
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
include_directories(${PROJECT_SOURCE_DIR}/lvgl)
include_directories(${PROJECT_SOURCE_DIR}/hisi/include)
link_directories(${PROJECT_SOURCE_DIR}/hisi/lib)
add_subdirectory(ui)
target_include_directories(ui PUBLIC ${PROJECT_SOURCE_DIR})
add_subdirectory(lvgl)
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})
add_executable(main main.c mouse_cursor_icon.c)
file(GLOB HISI_LIBS "${PROJECT_SOURCE_DIR}/hisi/lib/*.a")
target_link_libraries(main
lvgl
lvgl::examples
lvgl::demos
lvgl::thorvg
ui
${HISI_LIBS}
m
pthread
)
add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)
-
重新编译,执行
./build.sh
,编译完成后拷贝至板端测试
报错如下CMake Error at ui/CMakeLists.txt:10 (add_library): Cannot find source file: ui_events.c Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at ui/CMakeLists.txt:10 (add_library): No SOURCES given to target: ui
解决: 修改ui文件下的CMakeLists
SET(SOURCES screens/ui_Screen1.c
ui.c
components/ui_comp_hook.c
ui_helpers.c
#ui_events.c //SquareLine Studio里没有events设置,所有没有生成ui_events.c文件
images/ui_img_1_png.c
images/ui_img_2_png.c
fonts/ui_font_Font1.c)
add_library(ui ${SOURCES})
编译成功至板端测试
五、源码链接
总结
LVGL所占用的内存比QT小,板端加载图片和自定义控制信号(类似QT信号与槽)的方式还需要进一步研究。
参考博客链接
LVGL v9.1.0 移植至全志D1H开发板
【海思篇】【Hi3516DV300】十二、海思framebuffer的qt移植