world leader in high performance signal processing
Trace: » tslib

Touchscreen Library

The touchscreen library (tslib) is an abstraction layer for touchscreen panel events, as well as a filter stack for the manipulation of those events (such as jitter smoothing and calibration transform). It provides the user space API to interacting with touchscreens under Linux. It is the only method supported anymore for accessing touchscreen devices. The upstream homepage can be found at http://tslib.berlios.de/.

Building

uClinux-dist

The tslib package can be enabled under your user/vendor settings in the uClinux distribution.

Library Configuration  --->
  [*] Build tslib

You should also enable the test program to assist in debugging if you're setting things up for the first time.

Blackfin test programs  --->
  [*] Input event device test

Kernel

There are two things to enable in the Linux kernel. First, you need the common code for the event interface. Then you need the specific driver for the touchscreen device you're using.

Here is the common configuration options. If you build it as a module, you will need to run modprobe evdev at runtime.

Device Drivers  --->
  Input device support  --->
    [*] Generic input layer (needed for keyboard, mouse, ...)
    <*>   Event interface

The touchscreen drivers will be in the same place. Enable the driver for the device you're using.

Device Drivers  --->
  Input device support  --->
    [*] Touchscreens  --->
      <*> Whatever hardware you are using ...

Runtime Config

Before you can use the touchscreen, you need to export a few environment variables. You may want to put these into a file so you can easily source it at runtime.

root:~> cat /etc/tslib.env
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CONSOLEDEVICE=none
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_TSDEVICE=/dev/input/event2
root:~> . /etc/tslib.env

Calibration

Before you start using the touchscreen, you should calibrate it. This can be easily accomplished with the ts_calibrate application. Just follow the on-screen directions.

root:~> ts_calibrate
xres = 480, yres = 272
Took 11 samples...
Top left : X = 3545 Y = 3184
Took 6 samples...
Top right : X =  538 Y = 3193
Took 7 samples...
Bot right : X =  551 Y =  876
Took 7 samples...
Bot left : X = 3555 Y =  866
Took 8 samples...
Center : X = 2034 Y = 2036
499.785706 -0.126435 -0.000629
287.218597 -0.000235 -0.074219
Calibration constants: 32753956 -8286 -41 18823158 -15 -4863 65536

Testing

Once you're up and running and you've loaded all the right drivers, we can check to make sure things are OK.

Device Nodes

Make sure you have some event input device nodes.

root:~> ls -al /dev/input/
drw-r--r--    2 root     root            0 Jan  1 00:03 .
drwxr-xr-x    5 root     root            0 Jan  1 00:03 ..
crw-rw-r--    1 root     root      13,  64 Jan  1 00:03 event0
crw-rw-r--    1 root     root      13,  65 Jan  1 00:03 event1
crw-rw-r--    1 root     root      13,  66 Jan  1 00:03 event2

You may have just one event node, or you may have many. To figure out what node represents what, check sysfs:

root:~> find /sys/class/input/ -name name -print -exec cat {} \;
/sys/class/input/input0/name
bf54x-keys
/sys/class/input/input1/name
AD7877 Touchscreen

Event Test

Assuming you enabled the input event test application, you can run it to test the hardware. After you give it the right path to the event device, start using the touchscreen. The application should decode the input immediately.

root:~> event_test /dev/input/event2
Input driver version is 1.0.0
Input device ID: bus 0x0 vendor 0x0 product 0x0 version 0x0
Input device name: "AD7877 Touchscreen"
Supported events:
  Event type 0 (Reset)
    Event code 0 (Reset)
    Event code 3 (Absolute)
  Event type 3 (Absolute)
    Event code 0 (X)
      Value      0
      Min        0
      Max     4095
    Event code 1 (Y)
      Value      0
      Min        0
      Max     4095
    Event code 24 (Pressure)
      Value      0
      Min        0
      Max     1000
Testing ... (interrupt to exit)
Event: time 272.783714, type 3 (Absolute), code 0 (X), value 3879
Event: time 272.783722, type 3 (Absolute), code 1 (Y), value 390
Event: time 272.783725, type 3 (Absolute), code 24 (Pressure), value 392
Event: time 272.783728, type 0 (Reset), code 0 (Reset), value 0
Event: time 272.826906, type 3 (Absolute), code 0 (X), value 3883
Event: time 272.826912, type 3 (Absolute), code 1 (Y), value 387
Event: time 272.826915, type 3 (Absolute), code 24 (Pressure), value 375
Event: time 272.826917, type 0 (Reset), code 0 (Reset), value 0
Event: time 272.870104, type 3 (Absolute), code 0 (X), value 3884
Event: time 272.870111, type 3 (Absolute), code 1 (Y), value 385
Event: time 272.870113, type 3 (Absolute), code 24 (Pressure), value 370
Event: time 272.870116, type 0 (Reset), code 0 (Reset), value 0
Event: time 272.913306, type 3 (Absolute), code 0 (X), value 3883
Event: time 272.913314, type 3 (Absolute), code 24 (Pressure), value 365
Event: time 272.913317, type 0 (Reset), code 0 (Reset), value 0

Using In Applications

Many libraries already include tslib support. Consult the page for that package for more information.