Wednesday, August 31, 2011

Touchscreen calibration in Android

Another how-to. This time about touchscreen calibration for Android.

We assume you already have your touchscreen driver for your dev board and you've tested it with Android getevent (or the evtest tool) and you're sure it's giving the right coordinates to user space.

Next step before really using it is calibration ... which is real pain in the a** because Android doesn't provide a calibration tool. For the purpose we are going to use ts_lib.

To clone ts_lib package ported for Android use:
$ git clone git://

Then build it as normal Android package with "mm" (I assume you already know how to build Android... If no checkout this link for basics).
Copy all output files from the build to their corresponding places in the target dev board.

To create calibration file for the touchscreen boot the board, export the following environment variables

export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/system/etc/ts.conf
export TSLIB_CALIBFILE=/system/etc/pointercal
export TSLIB_PLUGINDIR=/system/lib
export TSLIB_FBDEVICE=/dev/graphics/fb0
 (see also in ts_lib sources)

and then run the newly built ts_calibrate tool.

Now we must apply this patch to make Android use the calibration file we created.

Rebuild Android services and you custom touchscreen must now work properly :) Hope it was useful!

P.S. the above was tested on Android Eclair with resistive touchscreen.