tslib移植到fl440開發板

************************************************************************************************************************

操作系統:CentOS

開發板:fl440

**********************************************************************************************************************

1.簡介:

tslib背景:

            在採用觸摸屏的移動終端中,觸摸屏性能的調試是個重要問題之一,因爲電磁噪聲的緣故,觸摸屏容易存在點擊不準確、有抖動等問題。

tslib是一個開源的程序,能夠爲觸摸屏驅動獲得的採樣提供諸如濾波、去抖、校準等功能,通常作爲觸摸屏驅動的適配層,爲上層的應用提供了一個統一的接口。

2.下載並解壓tslib-1.4.tar.gz 

windows下下載http://download.csdn.net/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_calibratets_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.遇到的問題

問題1:

解決:第一行告訴tsliblinux的輸入設備讀取數據,需要用到input這個模塊,也就是input.so文件,這個文件我是放
在/apps/tslib/lib/ts目錄下的,所以在配置TSLIB_PLUGINDIR時,路徑要設置爲/apps/tslib/lib/ts 如下圖:

第二行導致"No raw modules loaded."的原因有兩個:
注意:一.是ts.conf中沒有指定module_raw,自帶的ts.conf的所有module_raw都被註釋掉了,所以應該打開至少一個module_raw選項 
      二.是你沒有正確配置TSLIB_PLUGINDIRtslib從你指定的目錄中沒有找到plugin需要的模塊文件,
       請檢查你的路徑和文件
ps:1.TSLIB_PLUGINDIR一定要配置正確,讓tslib能夠找到模塊文件。
      其他參數分別控制觸摸點的連續下壓、變化寬度、軌跡變化和線性校準。
     2.修改系統配置後,一定要重啓纔會生效!!!
問題2:

解決:在進行系統環境配置,指定動態庫路徑時,路勁設置出錯,我的動態庫是放在apps/tslib/lib/目錄下的,
所以要這樣設置:export LD_LIBRARY_PATH=/lib:/usr/lib:/apps/tslib/lib
問題3.

     解決:沒有修改內核裏面drivers/input/touchscreen/s3c2410_ts.c源代碼!在執行./ts_calibrate時。系統也會提示

selected device is not a touchscreen I understand,






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章