12/08/2013

OLinuXino A13: touchscreen support in Linux


Take From blog http://www.dimrobotics.com/2013/06/olinuxino-a13-touchscreen-support-in.html

OLinuXino A13: touchscreen support in Linux

One of the first problems we had with OLinuxIno-A13 board is the touchscreen support. The manual was published on the official Olimex blog, but source packages had updated, so old solution didn't give an effect. After some experiments, we solved this problem. Here is a full step-by-step manual how to get the device works well under Debian.


Required:
  • installed xorg-dev, xserver-xorg-dev, x11proto-core-dev, git, make, automake:
    aptitude install xorg-dev xserver-xorg-dev x11proto-core-dev git automake make
  • tslib sources - get it from Github:
    git clone https://github.com/kergoth/tslib.git
  • xf86-input-tslib sources - from Debian Git repository:
    git clone git://git.debian.org/git/collab-maint/xf86-input-tslib

Now it's time to build this stuff. (All commands are performed as root).

tslib


tslib is a library that allows programmer to use data from touchscreens. It is only API, but not a driver for Xorg (there is xf86-input-tslib package for this).

It works well for most of different touchscreens without any changes. But, suddenly, Olinuxino's touchscreen is an exception, and we need to patch original library.

First, download tslib source code and go to its directory:

# git clone https://github.com/kergoth/tslib.git
# cd tslib

Download and apply the patch using GNU patch utility:

# wget https://raw.github.com/webconn/OLINUXINO/master/SOFTWARE/A13/TOUCHSCREEN/tslib.patch
# patch -p0 < tslib.patch

Configure, make and install:

# autoreconf -vi
# ./configure --prefix=/usr
# make
# make install

Then, let's load a kernel module and check touchscreen:

# modprobe sun4i-ts
# dmesg | grep sun4i-ts

If it's all right, there will be some messages in dmesg like this:

[    9.010000] sun4i-ts.c: sun4i_ts_init: start ...
[    9.020000] sun4i-ts: tp_screen_size is 5 inch.
[    9.030000] sun4i-ts: tp_regidity_level is 5.
[    9.030000] sun4i-ts: tp_press_threshold_enable is 0.
[    9.040000] sun4i-ts: rtp_sensitive_level is 15.
[    9.050000] sun4i-ts: rtp_exchange_x_y_flag is 0.
[    9.060000] sun4i-ts.c: sun4i_ts_probe: start...
[    9.080000] input: sun4i-ts as /devices/platform/sun4i-ts/input/input1
[    9.100000] sun4i-ts.c: sun4i_ts_probe: end

Highlighted 1 there is a number of touchscreen event device. Later we will get a raw data from device using the path /dev/input/event1 (change higlighted number to your).

To load this kernel module automatically, add a line into /etc/modules:

# echo sun4i-ts >> /etc/modules
 Now let's check the touchscreen in use. We need to export some environment variables which contains basic configuration for library. Do not forget to change highlighted number:

# export TSLIB_TSEVENTTYPE=raw
# export TSLIB_CONSOLEDEVICE=none
# export TSLIB_FBDEVICE=/dev/fb0
# export TSLIB_TSDEVICE=/dev/input/event1
# export TSLIB_CALIBFILE=/usr/etc/pointercal
# export TSLIB_CONFFILE=/usr/etc/ts.conf
# export TSLIB_PLUGINDIR=/usr/lib/ts

Next, configure raw input module of the tslib. Open /usr/etc/ts.conf and uncomment the line which contains "module_raw input".

After this, we should make a test. Let's calibrate the touchscreen and try to do something with it.

# ts_calibrate
# ts_test

To get out from ts_test, you should press "Quit" button on the screen, or use Ctrl+C in emergency case (if screen is not calibrated or configured successfully).

To load configuration variables while system is loading, write these lines into /etc/environment file (check highlighted number):
 
TSLIB_TSEVENTTYPE=raw
TSLIB_CONSOLEDEVICE=none
TSLIB_FBDEVICE=/dev/fb0
TSLIB_TSDEVICE=/dev/input/event1
TSLIB_CALIBFILE=/etc/pointercal
TSLIB_CONFFILE=/usr/etc/ts.conf
TSLIB_PLUGINDIR=/usr/lib/ts

Now we need to modify and install xf86-input-tslib driver.

xf86-input-tslib


xf86-input-tslib allows us to use tslib device like our touchscreen as pointer device.

This driver is old a bit, so while it works with newer Xorg server, it faluts, because xf86InputSetScreen function is removed from Xorg, but driver tries to call it. I had just removed this call from driver's source code and the problem was solved.

Download source code, go to its directory:

# git clone git://git.debian.org/git/collab-maint/xf86-input-tslib
# cd xf86-input-tslib

Get and apply required patches (including my solution):

# wget https://raw.github.com/webconn/OLINUXINO/master/SOFTWARE/A13/TOUCHSCREEN/1-xf86tslib-sigfault.patch https://raw.github.com/webconn/OLINUXINO/master/SOFTWARE/A13/TOUCHSCREEN/xf86-input-tslib-port-ABI-12-r48.patch https://github.com/webconn/OLINUXINO/blob/master/SOFTWARE/A13/TOUCHSCREEN/xf86tslib-xorg-update.patch
# patch -p0 < 1-xf86tslib-sigfault.patch
# patch -p0 < xf86-input-tslib-port-ABI-12-r48.patch
# patch -p0 < xf86tslib-xorg-update.patch

Configure, make and install:

# ./configure --prefix=/usr
# make
# make install

Now describe the device as InputClass of Xorg in your xorg.conf (or in /usr/share/X11/xorg.conf.d/20-ts.conf as I did):

Section "InputClass"
    Identifier "Sun4i-Touchscreen"
    MatchDevicePath "/dev/input/event*"
    MatchProduct "sun4i-ts"
    Driver "tslib"
EndSection


If you had successfully calibrated and tested the touchscreen, when you start X server by

# startx

the screen should work well. Also it should work when X server is launched by desktop manager (ex. LightDM).

P.S. This solution is tested at Olinuxino A13 with Debian GNU/Linux 7.0 (wheezy). Last commit of tslib was 158ee49, version of xf86-input-tslib was 0.0.6.

댓글 없음: