您尚未登录。

楼主 #1 2019-04-02 10:43:38

Jmhh247
会员
注册时间: 2018-12-21
已发帖子: 262
积分: 262

笔记-编译LittlevGL GUI demo支持tslib

前提,已经准备好交叉编译工具链和tslib,我用的是buildroot制作好的。

一、下载lvgl模拟器源码:

git clone https://github.com/littlevgl/pc_simulator.git
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;
}

最后编译:

time make 

运行截图:

FluxBB bbcode 测试

FluxBB bbcode 测试

FluxBB bbcode 测试


上传一个附件用作参考。

整个工程较大,附件只包含需要修改的文件:main.c,evdev.c,Makefile,lv_conf.h,lv_drv_conf.h,lv_ex_conf.h。

lvgl-port-bak.rar

离线

楼主 #9 2019-08-13 10:35:57

Jmhh247
会员
注册时间: 2018-12-21
已发帖子: 262
积分: 262

Re: 笔记-编译LittlevGL GUI demo支持tslib

804715358@qq.com 说:

楼主,您好,ts = ts_setup(NULL, 1);这个函数在哪里实现的,我这里用您的配置报错

1. 这个函数就是tslib自己的API

在tslib.h里面可以看到

TSAPI struct tsdev *ts_setup(const char *dev_name, int nonblock);

正常情况下,只要在应用程序里包含 tslib.h头文件,并且链接了tslib的库,就可以用这些API了。


2. 关于配置报错。这些配置的前提是,tslib已经移植好,可以正常工作。

你需要确认tslib是否能正常工作。(我也是新手,用的是buildroot自动编译好的tslib,本篇笔记不涉及tslib编译。。。)

离线

楼主 #10 2019-08-13 10:37:59

Jmhh247
会员
注册时间: 2018-12-21
已发帖子: 262
积分: 262

Re: 笔记-编译LittlevGL GUI demo支持tslib

804715358@qq.com 说:

我的tslib是1.1的没有这个函数,现在换成最新的了,但是一直报错,环境变量设置应该没有问题,1.1可以完美运行的,但是1.4报错./usr/local/tslib/bin/ts_test: can't load library 'libts.so.0',急啊,晕哥大神指点下

我用的版本是tslib-1.11。

离线

楼主 #13 2019-10-23 19:17:50

Jmhh247
会员
注册时间: 2018-12-21
已发帖子: 262
积分: 262

Re: 笔记-编译LittlevGL GUI demo支持tslib

应该是版本不一样了,发帖的时候是V5.3,现在是V6.0,导致一些文件不一样了。


官方已经有linux-fb版了,可以直接clone这个:https://github.com/littlevgl/lv_linux_frame_buffer,加上这里的tslib修改就可以了。(官方这个我还没用过~)


a32425262 说:

一步一步按照上面的来,出现了以下错误

In file included from /workdir/littlevgl/pc_simulator/lvgl/src/lv_core/lv_group.h:19:0,
                 from /workdir/littlevgl/pc_simulator/lvgl/src/lv_core/lv_group.c:9:
/workdir/littlevgl/pc_simulator/lvgl/src/lv_core/../../../lv_conf.h:388:10: fatal error: lvgl/lv_conf_checker.h: No such file or directory
 #include "lvgl/lv_conf_checker.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [lv_group.o] Error 1

real    0m0.340s
user    0m0.052s
sys     0m0.048s

离线

楼主 #22 2020-04-20 08:50:03

Jmhh247
会员
注册时间: 2018-12-21
已发帖子: 262
积分: 262

Re: 笔记-编译LittlevGL GUI demo支持tslib

这个帖子里面有: https://whycan.cn/t_561.html

另,版主不合适啊,楼主就好。。。


felix_zhou1618 说:

版主 tslib 与 buildroot 哪里可以下载了

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn