作者:cp
时间:2019-05-14
申明:本文一些素材取自网络,归原作者所有
写在前面
LittlevGL是一个开源免费的GUI,支持触摸屏操作,移植简单方便,开发者一直在不断完善更新。
目前AliOS Things已集成开源图形库littlevGL,可以在Linux上进行图形界面开发。
有了前面FB操作经验,移植基于Framebuffer的LittlevGL应该比较容易了。
1.eclipse配置LittlevGL源码
由于使用IDE便于自动生成Makefile和工程管理,这里以eclipse配置LittlevGL源码进行编译。
- 新建eclipse工程LittlevGL_t
- 控制台进入工程目录下载LittlevGL源码
cd C-SKY/eclipse/LittlevGL_t
git clone https://github.com/littlevgl/lvgl.git
git clone https://github.com/littlevgl/lv_drivers.git
git clone https://github.com/littlevgl/lv_examples.git
此处用到三个配置文件,分别是:
lvgl/lv_conf_templ.h
lv_drivers/lv_drv_conf_templ.h
lv_examples/lv_ex_conf_templ.h
将此三配置文件从模块文件夹中复制到项目文件夹,并将其命名为:
lv_conf.h
lv_drv.h
lv_ex_conf.h
操作为:
cp lvgl/lv_conf_templ.h ./lv_conf.h
cp lv_drivers/lv_drv_conf_templ.h ./lv_drv_conf.h
cp lv_examples/lv_ex_conf_templ.h ./lv_ex_conf.h
- 进入eclipse右击工程选择Refresh(F5)刷新工程目录,再向工程添加
mian.c
,其源码为:
#include <unistd.h>
#include "lvgl/lvgl.h"
/* 添加 fb 支持 */
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include "lv_examples/lv_apps/demo/demo.h"
int main(void)
{
/*LittlevGL init*/
lv_init();
/*Linux frame buffer device init*/
fbdev_init();
/*Add a display the LittlevGL sing the frame buffer driver*/
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.disp_flush = fbdev_flush; /*It flushes the internal graphical buffer to the frame buffer*/
lv_disp_drv_register(&disp_drv);
evdev_init();
lv_indev_drv_t indev_drv; /*Descriptor of an input device driver*/
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER; /*The touchpad is pointer type device*/
indev_drv.read = evdev_read; /*Library ready your touchpad via this function*/
//lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); /*Create an image for the cursor */
lv_img_set_src(cursor_obj, SYMBOL_GPS); /*For simlicity add a built in symbol not an image*/
lv_indev_set_cursor(mouse_indev, cursor_obj); /* connect the object to the driver*/
/* 选择示例启动 */
//benchmark_create();
demo_create();
//sysmon_create();
//terminal_create();
//tpcal_create();
/*Handle LitlevGL tasks (tickless mode)*/
while(1) {
lv_tick_inc(5);
lv_task_handler();
usleep(5000);
}
return 0;
}
此时工程目录为:
- 将工程目录加入include路径
右击工程选择Properties(Alt+Enter)–>C/C++ Build–>Settings–>Cross GCC Compiler–>includes添加路径,如下:
2.LittlevGL板级配置
- lv_conf.h
首先在lv_conf.h中开启使能,找到屏幕的定义并进行修改,此处修改为:
#if 1 /*Set it to "1" to enable content*/
...
/* Horizontal and vertical resolution of the library.*/
#define LV_HOR_RES (1280)
#define LV_VER_RES (680)
- lv_drv_conf.h
再看到lv_drv_conf.h,此文件中定义了输入输出设备的选择,由于main.c中已经调用linux下framebuffer设备和鼠标,需要修改:
#if 1 /*Set it to "1" to enable content*/
...
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 1
#endif
...
/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_EVDEV
# define USE_EVDEV 1
#endif
- lv_ex_conf.h
此配置文件定义你将要编译哪个应用示例,由于main.c中已经调用demo_create(),故修改如下:
#if 1 /*Set it to "1" to enable the content*/
...
#define USE_LV_DEMO 1
3.LittlevGL编译
在eclipse下编译即可
4.LittlevGL运行
拷贝至开发板运行即可(需要插入鼠标并确保设备节点为/dev/input/event0
)
参考
[1]https://c-sky.github.io/docs/gx6605s.html
[2]https://github.com/littlevgl
[3]http://nano.lichee.pro/application/littlevgl.html
[4]http://www.icode9.com/content-4-2420.html