Tweaking Froyo for Nitrogen Part 1: touch support

Published on August 30, 2010

Archived Notice

This article has been archived and may contain broken links, photos and out-of-date information. If you have any questions, please Contact Us.

If you walked through the steps from the previous post, you'll now have a semi-working Froyo release. You should see the Android desktop, but if you're running on a 7" Chi Mei panel, you'll have some issues with the touch screen. You'll have some other issues as well, but let's tackle the touch screen first, since it will allow us to access the settings application to keep the screen turned on for more than a couple of minutes. To begin with, the problem stems from touch screen calibration and scaling, which happen through a few different parts:

  1. The Freescale touch screen driver has a 'caiibration' parameter that allows X and Y readings to be linear functions of the X and Y raw readings.
  2. The /sbin/ts_calibrator program prompts the user to touch three on-screen points to gather the calibration data, and
  3. Android's input system does scaling of the input readings based on the reported ranges of the input device.
To enable the /sbin/ts_calibrator program, you'll need to add the keyword calibration to the bootargs U-Boot environment variable. U-Boot> set bootargs $bootargs calibration U-Boot> savee && reset When invoked, ts_calibrator will prompt the user iff it doesn't find a valid calibration file in /data/system/calibration. In other words, it will run on first boot after changing bootargs. Once it has a set of calibration points, it will hand them off to the Freescale driver through /sys/module/mxc_ts/parameters/calibration: # cat /sys/module/mxc_ts/parameters/calibration 5120,-178688,4237312,-131712,5568,1183488,-159416 Once all of this happens, touch screen events are reported by the driver in actual screen coordinates instead of raw A/D readings. Now we get to the place where things get screwed up. In this code it appears that Android wants its' touch screen readings in X and Y offsets with a range driven by the number of bits of resolution. In other words, since our touch-screen controller has 10-bit resolution, Android interprets touches as if they were in the range of [0..1023] instead of [0..screen width] and [0..screen height] (absX.range and absY.range) variables each contain 1024). At the moment, I'm not clear on the origin of each of these pieces of code, so it's not clear which should be changed. As I see it, we can either patch the ts_calibrator program to scale things according to the resolution bits or we can patch Android to skip its' scaling. For no other reason than I found the it here first, I've chosen to patch the InputDevice.java.
diff --git a/services/java/com/android/server/InputDevice.java b/services/java/com/android/server/InputDevice.java
index 414b69f..5dfcccb 100644
--- a/services/java/com/android/server/InputDevice.java
+++ b/services/java/com/android/server/InputDevice.java
@@ -826,7 +826,7 @@ public class InputDevice {
             final AbsoluteInfo absY = device.absY;
             final AbsoluteInfo absPressure = device.absPressure;
             final AbsoluteInfo absSize = device.absSize;
-            for (int i=0; i < numPointers; i++) {
+            if (false) for (int i=0; i < numPointers; i++) {
                 final int j = i * MotionEvent.NUM_SAMPLE_DATA;
                 if (absX != null) {
This is probably also the smallest patch... Once patched, you'll need to copy out/target/product/imx51_bbg/system/* to /media/SYSTEM/. In the next installment, I'll go through some other tweaks for adding sound and removing services we don't yet have on board.