Embedded Linux Encounters

A peek in to the world of Embedded Linux and stuff

  • Linux is addictive, I'm hooked!

         Geek@WastingTime>

Making TsLib work in Android

Posted by Vaisakh P S On 7:47 AM 0 comments


For my initial porting of Android, I had to work on a PXA270 board with a WM9713 Codec IC. So here are the steps that I followed to make touch screen working properly. Initially, touchscreen values were not accepting properly by Android even though ts_calibrate and ts_test were working properly.

Modifying Touch Drivers
Modify the WM97XX and WM9713 driver to report pen down event properly to the event system.
diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
index 781ee83..055db86 100644
--- a/drivers/input/touchscreen/wm9713.c
+++ b/drivers/input/touchscreen/wm9713.c
@@ -14,6 +14,7 @@
* option) any later version.
*
*/
+#define DEBUG

#include

#include

@@ -54,7 +55,7 @@ MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
* This is used to increase the range of values returned by the adc
* when measureing touchpanel pressure.
*/
-static int pil;
+static int pil = 1;
module_param(pil, int, 0);
MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");

@@ -395,7 +396,6 @@ err:
static int wm9713_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
{
int rc;
-
if (coord) {
rc = wm9713_poll_coord(wm, data);
if (rc != RC_VALID)


diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
index d589ab0..6859078 100644
--- a/drivers/input/touchscreen/wm97xx-core.c
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -34,7 +34,7 @@
* - Support for async sampling control for noisy LCDs.
*
*/
-
+#define DEBUG
#include

#include

#include

@@ -392,7 +392,8 @@ static int wm97xx_init_pen_irq(struct wm97xx *wm)

return 0;
}

static int wm97xx_read_samples(struct wm97xx *wm)
{
struct wm97xx_data data;
@@ -410,6 +411,7 @@ static int wm97xx_read_samples(struct wm97xx *wm)
wm->pen_is_down = 0;
dev_dbg(wm->dev, "pen up\n");
input_report_abs(wm->input_dev, ABS_PRESSURE, 0);
+ input_report_key(wm->input_dev, BTN_TOUCH, wm->pen_is_down);
input_sync(wm->input_dev);
} else if (!(rc & RC_AGAIN)) {
/* We need high frequency updates only while
@@ -427,13 +429,30 @@ static int wm97xx_read_samples(struct wm97xx *wm)
}

} else if (rc & RC_VALID) {
input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
+ wm->pen_is_down = 1;
+ input_report_key(wm->input_dev, BTN_TOUCH, wm->pen_is_down);
input_sync(wm->input_dev);
wm->pen_is_down = 1;
wm->ts_reader_interval = wm->ts_reader_min_interval;
@@ -630,9 +649,11 @@ static int wm97xx_probe(struct device *dev)
wm->input_dev->open = wm97xx_ts_input_open;
wm->input_dev->close = wm97xx_ts_input_close;
set_bit(EV_ABS, wm->input_dev->evbit);
+ set_bit(EV_KEY, wm->input_dev->evbit);
set_bit(ABS_X, wm->input_dev->absbit);
set_bit(ABS_Y, wm->input_dev->absbit);
set_bit(ABS_PRESSURE, wm->input_dev->absbit);
+ set_bit(BTN_TOUCH, wm->input_dev->keybit);
input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
abs_x[2], 0);
input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],


Use TsLib
Compile tslib using buildroot or something else and run it on the board with the parameters set:
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/lib/ts

After running ts_calibrate you will obtain 'pointercal' file with the corrections that needed to be applied for touchscreen values.






Modify Kernel Code
Change the kernel configuration to enable the following functionalities:

# Power management options
#
CONFIG_PM=y
CONFIG_PM_DEBUG=y
CONFIG_PM_VERBOSE=y
CONFIG_CAN_PM_TRACE=y
CONFIG_PM_SLEEP=y
CONFIG_SUSPEND=y
CONFIG_PM_TEST_SUSPEND=y
CONFIG_SUSPEND_FREEZER=y
CONFIG_HAS_WAKELOCK=y
CONFIG_HAS_EARLYSUSPEND=y
CONFIG_WAKELOCK=y
CONFIG_WAKELOCK_STAT=y
CONFIG_USER_WAKELOCK=y
CONFIG_EARLYSUSPEND=y

CONFIG_ANDROID_PMEM=y
CONFIG_ANDROID_TIMED_GPIO=y
CONFIG_BINDER_IPC=y

CONFIG_LOW_MEMORY_KILLER=y
CONFIG_LOGGER=y
CONFIG_ANDROID_RAM_CONSOLE=y
CONFIG_ANDROID_RAM_CONSOLE_ENABLE_VERBOSE=y
Modify Android Code
Apply the following patch to the Android Input management code. Copy the pointrecal file that you obtained from ts_calibrate to /system/etc/pointrecal
diff --git a/services/java/com/android/server/InputDevice.java b/services/java/com/android/server/InputDevice.java
index 6eb6242..f1ed013 100644
--- a/services/java/com/android/server/InputDevice.java
+++ b/services/java/com/android/server/InputDevice.java
@@ -22,6 +22,9 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.WindowManagerPolicy;

+import java.io.FileInputStream;
+import java.util.StringTokenizer;
+
public class InputDevice {
static final boolean DEBUG_POINTERS = false;
static final boolean DEBUG_HACKS = false;
@@ -29,8 +32,10 @@ public class InputDevice {
/** Amount that trackball needs to move in order to generate a key event. */
static final int TRACKBALL_MOVEMENT_THRESHOLD = 6;

+ static final String CALIBRATION_FILE = "/system/etc/pointercal";
+
/** Maximum number of pointers we will track and report. */
- static final int MAX_POINTERS = 10;
+ static final int MAX_POINTERS = 2;

final int id;
final int classes;
@@ -39,6 +44,7 @@ public class InputDevice {
final AbsoluteInfo absY;
final AbsoluteInfo absPressure;
final AbsoluteInfo absSize;
+ final TransformInfo tInfo;

long mKeyDownTime = 0;
int mMetaKeysState = 0;
@@ -595,15 +601,29 @@ public class InputDevice {
final AbsoluteInfo absSize = device.absSize;
for (int i=0; i 0) {
+ int i;
+ for (i = 0 ; i < len =" i;" st =" new" t =" new" x1 =" Integer.parseInt(" y1 =" Integer.parseInt(" z1 =" Integer.parseInt(" x2 =" Integer.parseInt(" y2 =" Integer.parseInt(" z2 =" Integer.parseInt(" s =" Integer.parseInt(" tinfo =" t;" debug =" false;" debug_virtual_keys =" false;" debug_pointers =" false;" debug_pointers =" true;" bad_touch_hack =" true;" bad_touch_hack =" false;" excluded_devices_path = "etc/excluded-input-devices.xml" max_processes =" 2;" max_processes =" 10;">

There you have it a calibrated touchscreen working in Android.

I was able to make this work because of lot of work I found online in discussion forums and blogs. Here are the reference to their work:

  • http://groups.google.com/group/android-internals/browse_thread/thread/25a8ccefeb362fd1/8705c88c4b68ab8a?#8705c88c4b68ab8a
  • http://groups.google.com/group/android-porting/browse_thread/thread/fd1bb870ce8d7b2d/45be0fd8eb43d59a?#45be0fd8eb43d59a
  • http://groups.google.com/group/android-porting/browse_thread/thread/211d654dbd0f3f99/2d34279ae278f135?lnk=gst&q=touch+calibration#2d34279ae278f135
  • http://groups.google.com/group/android-porting/browse_thread/thread/fb64af66b1f877fa/8708ab0ea2b9b545?hl=en&lnk=gst&q=touch+screen+top+bar#
  • http://groups.google.com/group/android-porting/browse_thread/thread/9ea3b46fe87d1e3/589c7c6ebd238755?lnk=gst&q=touch+calibration#
  • http://groups.google.com/group/android-porting/browse_thread/thread/9ea3b46fe87d1e3/589c7c6ebd238755?lnk=gst&q=touch+calibration#
  • http://www.opentom.org/Tslib
  • http://androidzaurus.seesaa.net/article/96581331.html

  • Categories: , ,

    0 Response for the "Making TsLib work in Android"

    Post a Comment