|
前提,已经准备好交叉编译工具链和tslib,我用的是buildroot制作好的。
一、下载lvgl源码:
- git clone <a href="https://github.com/littlevgl/pc_simulator.git" target="_blank">https://github.com/littlevgl/pc_simulator.git</a>
- cd pc_simulator
- git submodule update --init
复制代码
二、修改Makefile
1. 修改CC为自己的gcc;
2. 修改链接标志,添加tslib支持;
3. 注释掉mouse_cursor_icon.c,用不上;
代码片断:
- # 1:修改成自己的工具链
- #CC = gcc
- CC = /home/vmzys/work/2019/code/v3s/my_buildroot/buildroot-2017.08.1/output/host/bin/arm-linux-gnueabihf-gcc
- # 2: 添加 tslab共享链接库
- #LDFLAGS += -lSDL2 -lm
- LDFLAGS += -lts
- # 3:用不上,注释掉
- #CSRCS +=$(LVGL_DIR)/mouse_cursor_icon.c
复制代码
三、修改lvgl配置文件
1. 修改lv_conf.h
按实际屏幕尺寸修改
- /* Horizontal and vertical resolution of the library.*/
- #define LV_HOR_RES (800)
- #define LV_VER_RES (480)
复制代码
2. 修改lv_drv_conf.h
主要修改记录如下,其它按需处理:
- # define USE_MONITOR 0
- # define USE_FBDEV 1
- # define USE_MOUSE 0
- # define USE_MOUSEWHEEL 0
- # define USE_EVDEV 1
- // 这里按实际修改
- # define EVDEV_NAME "/dev/input/event1" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
- # define USE_KEYBOARD 0
复制代码
3. 修改lv_ex_conf.h
- /*******************
- * GENERAL SETTING
- *******************/
- #define LV_EX_PRINTF 0 /*Enable printf-ing data*/
- #define LV_EX_KEYBOARD 0 /*Add PC keyboard support to some examples (`lv_drivers` repository is required)*/
- #define LV_EX_MOUSEWHEEL 0 /*Add 'encoder' (mouse wheel) support to some examples (`lv_drivers` repository is required)*/
- #define USE_LV_TUTORIALS 0
- #define USE_LV_BENCHMARK 0
- /*MCU and memory usage monitoring*/
- #define USE_LV_SYSMON 0
- /*A terminal to display received characters*/
- #define USE_LV_TERMINAL 0
- /*Touch pad calibration with 4 points*/
- #define USE_LV_TPCAL 0
复制代码
四、整合tslib到输入驱动 pc_simulator/lv_drivers/indev/evdev.c
代码片断:
- // 1: 添加头文件包含
- #include "tslib.h"
- // 2: ts结构体声明
- struct tsdev *ts;
- // 3: 修改初始化代码
- void evdev_init(void)
- {
- #if 0
- evdev_fd = open(EVDEV_NAME, O_RDWR | O_NOCTTY | O_NDELAY);
- if(evdev_fd == -1) {
- perror("unable open evdev interface:");
- return;
- }
- fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK);
- #endif
-
- ts = ts_setup(NULL, 1);
- if (!ts) {
- perror("ts_setup");
-
- return;
-
- //exit(1);
- }
- evdev_root_x = 0;
- evdev_root_y = 0;
- evdev_button = LV_INDEV_STATE_REL;
- }
- // 4:修改读取代码
- bool evdev_read(lv_indev_data_t * data)
- {
- #if 0
- struct input_event in;
- while(read(evdev_fd, &in, sizeof(struct input_event)) > 0) {
- if(in.type == EV_REL) {
- if(in.code == REL_X)
- #if EVDEV_SWAP_AXES
- evdev_root_y += in.value;
- #else
- evdev_root_x += in.value;
- #endif
- else if(in.code == REL_Y)
- #if EVDEV_SWAP_AXES
- evdev_root_x += in.value;
- #else
- evdev_root_y += in.value;
- #endif
- } else if(in.type == EV_ABS) {
- if(in.code == ABS_X)
- #if EVDEV_SWAP_AXES
- evdev_root_y = in.value;
- #else
- evdev_root_x = in.value;
- #endif
- else if(in.code == ABS_Y)
- #if EVDEV_SWAP_AXES
- evdev_root_x = in.value;
- #else
- evdev_root_y = in.value;
- #endif
- } else if(in.type == EV_KEY) {
- if(in.code == BTN_MOUSE || in.code == BTN_TOUCH) {
- if(in.value == 0)
- evdev_button = LV_INDEV_STATE_REL;
- else if(in.value == 1)
- evdev_button = LV_INDEV_STATE_PR;
- }
- }
- }
- #endif
- // tslib
- struct ts_sample samp;
- int ret;
- /* 修改自tslib ts_print.c */
-
- while (ts_read(ts, &samp, 1) == 1) {
- printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure);
-
-
-
-
- #if EVDEV_SWAP_AXES
- evdev_root_x = samp.y;
- evdev_root_y = samp.x;
- #else
- evdev_root_x = samp.x;
- evdev_root_y = samp.y;
- #endif
-
-
- if(samp.pressure == 0)
- evdev_button = LV_INDEV_STATE_REL; //抬起
- else if(samp.pressure == 255)
- evdev_button = LV_INDEV_STATE_PR;
- }
-
-
- /*Store the collected data*/
- #if EVDEV_SCALE
- data->point.x = map(evdev_root_x, 0, EVDEV_SCALE_HOR_RES, 0, LV_HOR_RES);
- data->point.y = map(evdev_root_y, 0, EVDEV_SCALE_VER_RES, 0, LV_VER_RES);
- #else
- #if EVDEV_CALIBRATE
- data->point.x = map(evdev_root_x, EVDEV_HOR_MIN, EVDEV_HOR_MAX, 0, LV_HOR_RES);
- data->point.y = map(evdev_root_y, EVDEV_VER_MIN, EVDEV_VER_MAX, 0, LV_VER_RES);
- #else
- data->point.x = evdev_root_x;
- data->point.y = evdev_root_y;
- #endif
- #endif
- data->state = evdev_button;
- if(data->point.x < 0)
- data->point.x = 0;
- if(data->point.y < 0)
- data->point.y = 0;
- if(data->point.x >= LV_HOR_RES)
- data->point.x = LV_HOR_RES - 1;
- if(data->point.y >= LV_VER_RES)
- data->point.y = LV_VER_RES - 1;
- return false;
- }
复制代码
五. 修改main.c
main.c里有很多都是模拟器用的,需要删掉。这里直接用linux fb。
整个代码是比较容易看懂的:
- #include "lvgl/lvgl.h"
- #include "lv_drivers/display/fbdev.h"
- #include "lv_drivers/indev/evdev.h"
- #include <unistd.h>
- #include "lv_examples/lv_apps/demo/demo.h"
- #include "lv_examples/lv_tests/lv_test_theme/lv_test_theme_1.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 internalgraphical buffer to the frame buffer*/
- lv_disp_drv_register(&disp_drv);
- /*Create a "Hello world!" label*/
- // lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
- // lv_label_set_text(label, "Hello world!");
- // lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
- lv_indev_drv_t indev_drv;
- lv_indev_drv_init(&indev_drv);/*Basic initialization*/
- evdev_init();
- indev_drv.type=LV_INDEV_TYPE_POINTER;/*See below.*/
- indev_drv.read=evdev_read;/*See below.*/
- lv_indev_drv_register(&indev_drv);/*Register the driver in LittlevGL*/
- //demo_create();
- lv_test_theme_1(lv_theme_night_init(210, NULL));
- /*Handle LitlevGL tasks (tickless mode)*/
- while(1) {
- lv_tick_inc(5);
- lv_task_handler();
- usleep(1000);
- }
- return 0;
- }
复制代码
最后编译:
运行截图:
上传一个附件用作参考。
整个工程较大,附件只包含需要修改的文件:main.c,evdev.c,Makefile,lv_conf.h,lv_drv_conf.h,lv_ex_conf.h。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|