2014年4月8日 星期二

Linux touchscreen with tslib

Linux touchscreen 的工作分為兩大部份

1.Touchscreen driver
  通常透過SPI interface與Touchscreen A/D controller取得座標及觸控事件/壓力.
  我手邊的device是TI TSC2046 A/D controller. 座標及觸控壓力資料為12bits.
  User space則透過input device讀取資料,例如 /dev/input/event0.

2.Touchscreen library
  User space讀取到touchscreen 的資料還需要經過處理才能使用,
  例如轉換為銀幕的座標位置,濾除錯誤的資料(noise)等. 
  tslib這個library已經有這些模組功能.
  透過tslib, Graphic user interface 可以取得相對應座標的touchscreen 動作完成UI反應.

tslib

取得tslib
git clone https://github.com/kergoth/tslib.git

編譯

cd tslib

./autogen.sh

CC=mipsel-linux-uclibc-gcc AR=mipsel-linux-uclibc-ar ./configure --host=mipsel-linux --target=mipsel-linux --prefix=/usr/local/MIPSEL_UCLIBC --cache-file=/dev/null

make
make install

tslib在target的安裝位置

/phone/lib/libts-1.0.so.0.0.0
/phone/lib/ts/dejitter.so  
/phone/lib/ts/input.so    
/phone/lib/ts/linear.so    
/phone/lib/ts/pthres.so    
/phone/lib/ts/variance.so
/phone/etc/ts.conf
/phone/bin/ts_calibrate
/phone/bin/ts_print

tslib 模組

1.Variance filter - 過濾隨機的噪音資料.
2.Dejitter - 平均化X及Y軸的資料.
3.Linear - 轉換touchscreen座標至銀幕座標.

tslib ts.conf 內容

# Uncomment if you wish to use the linux input layer event interface
module_raw input

# Uncomment if you're using a Sharp Zaurus SL-5500/SL-5000d
# module_raw collie

# Uncomment if you're using a Sharp Zaurus SL-C700/C750/C760/C860
# module_raw corgi

# Uncomment if you're using a device with a UCB1200/1300/1400 TS interface
# module_raw ucb1x00

# Uncomment if you're using an HP iPaq h3600 or similar
# module_raw h3600

# Uncomment if you're using a Hitachi Webpad
# module_raw mk712

# Uncomment if you're using an IBM Arctic II
# module_raw arctic2

module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear

tslib 環境變數

tslib根據以下的環境變數取得模組及設定檔案(ts.conf / pointercal), ㄧ定要正確設定.

export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CONFFILE=/phone/etc/ts.conf
export TSLIB_PLUGINDIR=/phone/lib/ts
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CALIBFILE=/phone/etc/pointercal 

tslib 校正(ts_calibrate)

執行 /phone/bin/ts_calibrate
依 左上, 右上, 右下, 左下, 中間 的順序觸控 touchscreen 就完成校正.
校正資料會儲存在/phone/etc/pointercal 

tslib 測試(ts_print)

執行 ts_print 會讀取/phone/etc/pointercal, 在 console 上顯示目前觸控的銀幕座標





2 則留言:

  1. 你好, 請問是否方便 email 聯絡您, 有關 TI DSP 的事情 ? 謝謝.

    回覆刪除