************************************************************************************************************************
操作系统:CentOS
开发板:fl440
**********************************************************************************************************************
1.简介:
tslib背景:
在采用触摸屏的移动终端中,触摸屏性能的调试是个重要问题之一,因为电磁噪声的缘故,触摸屏容易存在点击不准确、有抖动等问题。
tslib是一个开源的程序,能够为触摸屏驱动获得的采样提供诸如滤波、去抖、校准等功能,通常作为触摸屏驱动的适配层,为上层的应用提供了一个统一的接口。
2.下载并解压tslib-1.4.tar.gz
windows下下载http://download.youkuaiyun.com/detail/scholar_fish/4167788,然后上传到linux服务器上!
[zoulei@CentOS ~]$ tar -zxvf tslib-1.4.tar.gz
3.安装
[zoulei@CentOS ~]$cd tslib/
[zoulei@CentOS tslib]$./autogen.sh
********************************************************************************************
说明:这个时候如果直接运行autogen.sh这个文件的话,会出现如下错误:
configure.ac:24: error: possibly undefined macro: AC_DISABLE_STATIC
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:25: error: possibly undefined macro: AC_ENABLE_SHARED
configure.ac:26: error: possibly undefined macro: AC_LIBTOOL_DLOPEN
configure.ac:27: error: possibly undefined macro: AC_PROG_LIBTOOL
autoreconf: /usr/bin/autoconf failed with exit status: 1
原因是没有安装 automake,libtool这两个 工具,于是要安装这两个工具!
***************************************************************************************************
[zoulei@CentOS tslib]$sudo yum install -y automake
[zoulei@CentOS tslib]$sudo yum install -y libtool
[zoulei@CentOS tslib]$ ls
acinclude.m4 autom4te.cache CVS NEWS tslib.pc.in
aclocal.m4 ChangeLog etc plugins
AUTHORS configure INSTALL README
autogen-clean.sh configure.ac m4 src
autogen.sh COPYING Makefile.am tests
*********************************************************************************************
ps:1执行autogen.sh脚本文件后,系统会自动生成一个configure配置文件,这时候再执行./configure
文件时将生成Makefile
2. 执行./configure --prefix=(你自己的安装目录)--host=arm-linux ac_cv_func_malloc_0_nonnull=yes CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
*******************************************************************************************************************
[zoulei@CentOS tslib]$mkdir tslib
[zoulei@CentOS tslib]$cd tslib/
[zoulei@CentOS tslib]$pwd
/home/zoulei/tslib/tslib
[zoulei@CentOS tslib]$./configure --prefix=/home/zoulei/tslib /tslib --host=arm-linux ac_cv_func_malloc_0_nonnull=yes CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
[zoulei@CentOS tslib]$make
[zoulei@CentOS tslib]$make install
[zoulei@CentOS tslib]$ls
bin etc include lib
[zoulei@CentOS tslib]$ tar -czf tslib.tar.gz tslib
***********************************************************************************************
ps:这时候会生成bin etc include lib 4个文件,然后将这四个文件打包传到开发板上,进入apps目录
直接将压缩包传到apps目录下,然后直接解压!
***********************************************************************************************
4.开发板上操作
>: cd apps
>: tftp -gr tslib.tar.gz 192.168.1.2
tslib.tar.gz 100% |*******************************| 63738 0:00:00 ETA
>: tar -xzf tslib.tar.gz
>: ls
tslib tslib .tar.gz
>: cd tslib/
>: ls
bin etc include lib
ps:这时候要设置一下系统环境配置
>:vi /etc/profile
接着进入vi apps/tslib/bin/ts.conf 修改配置文件
在末尾加入module_raw input 你也可以释放被注释掉的module_raw input
5.修改源代码
[zoulei@CentOS linux-3.0]$ vim drivers/input/touchscreen/s3c2410_ts.c
--- s3c2410_ts1.c 2017-04-19 05:13:12.216013784 -0700
+++ s3c2410_ts.c 2017-04-19 05:14:36.973013655 -0700
@@ -118,14 +118,18 @@
if (ts.count == (1 << ts.shift)) {
ts.xp >>= ts.shift;
ts.yp >>= ts.shift;
+
+ printk("%s: X=%lu,Y=%lu,count=%d\n",
+ __func__, ts.xp, ts.yp, ts.count);//modify by zoulei 2017.04.19
- dev_dbg(ts.dev, "%s: X=%lu, Y=%lu, count=%d\n",
- __func__, ts.xp, ts.yp, ts.count);
+ /*dev_dbg(ts.dev, "%s: X=%lu, Y=%lu, count=%d\n",
+ __func__, ts.xp, ts.yp, ts.count);*/
input_report_abs(ts.input, ABS_X, ts.xp);
input_report_abs(ts.input, ABS_Y, ts.yp);
input_report_key(ts.input, BTN_TOUCH, 1);
+ input_report_abs(ts.input, ABS_PRESSURE, 1);//add by zoulei
input_sync(ts.input);
ts.xp = 0;
@@ -140,6 +144,7 @@
ts.count = 0;
input_report_key(ts.input, BTN_TOUCH, 0);
+ input_report_abs(ts.input, ABS_PRESSURE, 0);//add by zoulei
input_sync(ts.input);
writel(WAIT4INT | INT_DOWN, ts.io + S3C2410_ADCTSC);
@@ -314,11 +319,13 @@
}
ts.input = input_dev;
- ts.input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ ts.input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT(EV_SYN);//modify by zoulei
ts.input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
input_set_abs_params(ts.input, ABS_X, 0, 0x3FF, 0, 0);
input_set_abs_params(ts.input, ABS_Y, 0, 0x3FF, 0, 0);
-
+ input_set_abs_params(ts.input, ABS_PRESSURE, 0, 1, 0, 0);/*add by zoulei*/
+
ts.input->name = "S3C24XX TouchScreen";
ts.input->id.bustype = BUS_HOST;
ts.input->id.vendor = 0xDEAD;
*****************************************************************************************************************************
说明:在tslib/plugins目录下,input-raw.c源码里面有一个check_fd函数,这个函数是为了检测设备是否为触摸屏,首先tslib通过EVIOCGVERSION来获取驱动的版本号,然后再通过EVIOCGBIT来判断设备是否为触摸屏,最后获取触摸屏的X轴(ABS_X),Y轴(ABS_Y),以及压力(ABS_PRESSURE)。其中只要有一项内容不正确,tslib都会认为该设备不是触摸屏,而打印出“selected device is not a touchscreen I understand”错误。所以,当我们用手指触摸触摸屏时不出错,就需要修改s3c2410_ts.c!
通过查看linux-3.0中的触摸屏驱动文件s3c2410_ts.c,发现系统没有给出ABS_PRESSURE,因此为了与tslib一致,linux-3.0要加上ABS_PRESSURE内容。在touch_timer_fire函数中的第一input_sync(ts.input);前添加下面函数:input_report_abs(ts.input, ABS_PRESSURE, 1);(内核将压力值上报给tslib)
在该函数中的第二input_sync(ts.input);前添加:
input_report_abs(ts.input, ABS_PRESSURE, 0);
在s3c2410ts_probe函数内的ts.input->name = "S3C24XX TouchScreen";语句前添加:
input_set_abs_params(ts.input, ABS_PRESSURE, 0, 1, 0, 0);
********************************************************************************************************************************************
通过上面的修改,就可以使 tslib 能够正确识别出开发板的触摸屏,执行 ts_calibrate 和 ts_test 命令可以成功的显示校准信息!
6.测试
触摸屏模时,开发板会显示如下信息:(前提是你在触摸之前要写个测试程序,测试程序并且在运行)
>: touch_timer_fire: X=465,Y=772,count=4
touch_timer_fire: X=468,Y=761,count=4
touch_timer_fire: X=470,Y=765,count=4
touch_timer_fire: X=469,Y=773,count=4
touch_timer_fire: X=468,Y=768,count=4
touch_timer_fire: X=469,Y=769,count=4
touch_timer_fire: X=471,Y=766,count=4
touch_timer_fire: X=471,Y=771,count=4
touch_timer_fire: X=470,Y=764,count=4
touch_timer_fire: X=471,Y=769,count=4
touch_timer_fire: X=470,Y=767,count=4
touch_timer_fire: X=471,Y=769,count=4
touch_timer_fire: X=469,Y=774,count=4
touch_timer_fire: X=470,Y=771,count=4
>: cd
>: cd apps/tslib/bin/
>: ls
ts_calibrate ts_harvest ts_print ts_print_raw ts_test
>: ./ts_calibrate
xres = 480, yres = 27
Took 10 samples...
Top left : X = 545 Y = 733
Took 1 samples...
Top right : X = 542 Y = 554
Took 1 samples...
Bot right : X = 519 Y = 541
Took 18 samples...
Bot left : X = 566 Y = 517
Took 14 samples...
Center : X = 703 Y = 598
1035.643555 -0.380085 -0.980438
510.537109 0.032967 -0.668516
Calibration constants: 67871936 -24909 -64254 33458560 2160 -43811 65536
***************************************************************************************************************
说明:执行后屏幕上,依次出现5个点,依次点击进行校准,校准完毕后,在/etc下会产生pointercal文件,供其他用户使用,ts_calibrate是一个应用程序
*********************************************************************************************************************
>: ./ts_test
touch_timer_fire: X=727,Y=580,count=4
touch_timer_fire: X=723,Y=562,count=4
52.518706: 190 146 1
touch_timer_fire: X=722,Y=559,count=4
52.528737: 203 154 1
touch_timer_fire: X=722,Y=561,count=4
52.538663: 208 157 1
touch_timer_fire: X=723,Y=561,count=4
52.548520: 207 157 1
52.558477: 212 159 1
52.565143: 210 159 0
*****************************************************************************************************************
说明;./ts_test 检测一下校正的结果,屏幕上出现两个按钮,分别为,Drag时,光标随着手指移动,另一个Draw是在屏幕上画画
屏幕最上方会出现二个按钮,分别为“Drag”、“Draw”,默认是第一个,因此,用触摸笔点击任何一处,十字光标便会到那里。
**********************************************************************************************************************
>: ./ts_print_raw
touch_timer_fire: X=777,Y=616,count=4
91.711468: 777 616 1touch_timer_fire: X=777,Y=621,count=4
touch_timer_fire: X=777,Y=608,count=4
91.716543: 777 621 1touch_timer_fire: X=777,Y=607,count=4
touch_timer_fire: X=777,Y=597,count=4
91.721495: 777 608 1touch_timer_fire: X=777,Y=605,count=4
91.726557:touch_timer_fire: X=777,Y=592,count=4
777 607 touch_timer_fire: X=777,Y=605,count=4
1
91.731481: touch_timer_fire: X=776,Y=600,count=4
777 597 touch_timer_fire: X=776,Y=603,count=4
1
91.736554: touch_timer_fire: X=777,Y=597,count=4
777 605 1
91.741555: 777 592 1
91.746561: 777 605 1
91.751522: 776 600 1
91.756495: 776 603 1
91.761493: 777 597 1
91.765179: 0 0 0
91.765281: 777 597 0
**********************************************************************************************
说明:./ts_print_raw 将屏幕坐标的原始数据打印出来
******************************************************************************************
如果执行以上文件能成功的在开发板上显示信息,则说明tslib移植成功了!
7.遇到的问题
selected device is not a touchscreen I understand,