基于Freescale Android4.2.2 max11801 的10寸电阻屏校准方法总结

作者:[email protected]

时间:2014-5-6

 

关键字:Freescale , Android JB , max11801 , 电阻屏 , 校准

 

背景:

         当下,在Android4.2.2 上基本全部用的都是电容式的触摸屏了,所以Google和其他定制厂商也陆续在自己的Android版本中去掉了电阻屏校准这部分代码,飞思卡尔的Android 4.2.2也不例外,但在其Android 4.0.4上都还有ts_calibrator的电阻屏校准程序,我们下面的要介绍的方法就是把这个 ts_calibrator 移植到Android 4.2.2 上。

 

准备:

ts_calibrator.zip

max11801_ts.idc

<文件夹下还有相关改动文件的源文件,如果平台相同,可以偷懒哟>

 

移植步骤:

1、 将  ts_calibrator.zip 解包至  “${androidroot}/system/core/”  下。 
2、 修改  “${androidroot}/system/core/init/init.c” ,  参考如下

diff --git a/system/core/init/init.c b/system/core/init/init.c
index 8a4fc52..483391c 100755
--- a/system/core/init/init.c
+++ b/system/core/init/init.c
@@ -77,6 +77,7 @@ static char bootmode[32];
 static char hardware[32];
 static unsigned revision = 0;
 static char qemu[32];
+static char calibration;
 
 #ifdef HAVE_SELINUX
 static int selinux_enabled = 1;
@@ -623,8 +624,12 @@ static void import_kernel_nv(char *name, int for_emulator)
 {
     char *value = strchr(name, '=');
     int name_len = strlen(name);
-
-    if (value == 0) return;
+    /* zeng */
+    if (value == 0) {
+	if (!strcmp(name, "calibration"))
+	    calibration = 1;
+	return;
+    }
     *value++ = 0;
     if (name_len == 0) return;
 
@@ -703,6 +708,11 @@ static void export_kernel_boot_props(void)
         property_set("ro.factorytest", "2");
     else
         property_set("ro.factorytest", "0");
+    /* zeng */
+    if (calibration)
+        property_set("ro.calibration", "1");
+    else
+        property_set("ro.calibration", "0");
 }
 
 static void process_kernel_cmdline(void)

3、修改  “${androidroot}/kernel_imx/”  下的文件,  参考如下 

diff --git a/kernel_imx/arch/arm/mach-mx6/board-mx6q_sabresd.c b/kernel_imx/arch/arm/mach-mx6/board-mx6q_sabresd.c
index f0d64a8..1946187 100644
--- a/kernel_imx/arch/arm/mach-mx6/board-mx6q_sabresd.c
+++ b/kernel_imx/arch/arm/mach-mx6/board-mx6q_sabresd.c
@@ -201,7 +201,7 @@ static struct clk *sata_clk;
 static struct clk *clko;
 static int mma8451_position = 3;
 static int mag3110_position = 1;
-static int max11801_mode = 1;
+static int max11801_mode = 0;
 static int caam_enabled;
 
 extern char *gp_reg_id;
diff --git a/kernel_imx/drivers/input/touchscreen/max11801_ts.c b/kernel_imx/drivers/input/touchscreen/max11801_ts.c
index a1ac2d2..df27d15 100755
--- a/kernel_imx/drivers/input/touchscreen/max11801_ts.c
+++ b/kernel_imx/drivers/input/touchscreen/max11801_ts.c
@@ -108,6 +108,18 @@ struct i2c_client *max11801_client;
 unsigned int max11801_workmode;
 u8 aux_buf[AUX_BUFSIZE];
 
+/**
+ * calibration array refers to
+ * (delta_x[0], delta_x[1], delta_x[2], delta_y[0], delta_y[1], delta_y[2], delta).
+ * Which generated by calibration service.
+ * In this driver when we got touch pointer (x', y') from PMIC ADC,
+ * we calculate the display pointer (x,y) by:
+ * x = (delta_x[0] * x' + delta_x[1] * y' + delta_x[2]) / delta;
+ * y = (delta_y[0] * x' + delta_y[1] * y' + delta_y[2]) / delta;
+ */
+static int calibration[7];
+module_param_array(calibration, int, NULL, S_IRUGO | S_IWUSR);
+
 static int max11801_dcm_write_command(struct i2c_client *client, int command)
 {
 	return i2c_smbus_write_byte(client, command);
@@ -169,9 +181,28 @@ static int max11801_write_reg(struct i2c_client *client, int addr, int data)
 
 static void calibration_pointer(int *x_orig, int *y_orig)
 {
-	int  y;
+	int  x, y;
 	y = MAX11801_MAX_Y - *y_orig;
 	*y_orig = y;
+
+	if (calibration[6] != 0) {
+		x = calibration[0] * *x_orig +
+			calibration[1] * *y_orig +
+			calibration[2];
+		x /= calibration[6];
+		if (x < 0)
+			x = 0;
+		y = calibration[3] * *x_orig +
+			calibration[4] * *y_orig +
+			calibration[5];
+		y /= calibration[6];
+		if (y < 0)
+			y = 0;
+		*x_orig = x;
+		*y_orig = y;
+	}
+
+	/* printk("x: %d , y: %d\n", *x_orig, *y_orig); */
 }
 
 static irqreturn_t max11801_ts_interrupt(int irq, void *dev_id)

4、拷贝  max11801_ts.idc  到  “${androidroot}/device/fsl/common/input/”  ,  修改 “${androidroot}/device/fsl/”  下文件,参考如下 

diff --git a/device/fsl/imx6/etc/init.rc b/device/fsl/imx6/etc/init.rc
index 41e7995..ac56ad4 100755
--- a/device/fsl/imx6/etc/init.rc
+++ b/device/fsl/imx6/etc/init.rc
@@ -398,6 +398,8 @@ on boot
     setprop dalvik.vm.jniopts warnonly
 
     class_start core
+    class_start tscal
+on property:service.calibrate.exit=1
     class_start main
 
 on property:sys.boot_completed=1
@@ -544,6 +546,12 @@ service bootanim /system/bin/bootanimation
     disabled
     oneshot
 
+service calibrate /system/bin/logwrapper /sbin/ts_calibrator
+    class tscal
+    user root
+    group root
+    oneshot
+
 service dbus /system/bin/dbus-daemon --system --nofork
     class main
     socket dbus stream 660 bluetooth bluetooth

	 
diff --git a/device/fsl/imx6/imx6.mk b/device/fsl/imx6/imx6.mk
index ac0ce25..c5438fb 100644
--- a/device/fsl/imx6/imx6.mk
+++ b/device/fsl/imx6/imx6.mk
@@ -290,6 +290,7 @@ PRODUCT_COPY_FILES +=	\
 	device/fsl/common/input/eGalax_Touch_Screen.idc:system/usr/idc/HannStar_P1003_Touchscreen.idc \
 	device/fsl/common/input/eGalax_Touch_Screen.idc:system/usr/idc/Novatek_NT11003_Touch_Screen.idc \
 	device/fsl/common/input/CTA_Touch_Screen.idc:system/usr/idc/CTA_Touch_Screen.idc \
+	device/fsl/common/input/max11801_ts.idc:system/usr/idc/max11801_ts.idc \
 	device/fsl/common/input/Vantron_CB_Keyboard.kl:system/usr/keylayout/gpio-keys.kl \
 	device/fsl/imx6/etc/init.rc:root/init.rc \
 	device/fsl/imx6/etc/apns-conf.xml:system/etc/apns-conf.xml \

diff --git a/device/fsl/sabresd_6dq/BoardConfig.mk b/device/fsl/sabresd_6dq/BoardConfig.mk
index 716282b..b73f6fc 100755
--- a/device/fsl/sabresd_6dq/BoardConfig.mk
+++ b/device/fsl/sabresd_6dq/BoardConfig.mk
@@ -93,7 +93,7 @@ $(error "TARGET_USERIMAGES_USE_UBIFS and TARGET_USERIMAGES_USE_EXT4 config open
 endif
 endif
 
-BOARD_KERNEL_CMDLINE := console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,CLAA070WP03,if=RGB666,fbpix=RGB32 ldb=sep1 video=mxcfb1:off video=mxcfb2:off fbmem=16M fb0base=0x27b00000 vmalloc=400M androidboot.console=ttymxc0 androidboot.hardware=freescale
+BOARD_KERNEL_CMDLINE := calibration console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,H101IV024,if=RGB666,fbpix=RGB32 ldb=sep1 video=mxcfb1:off video=mxcfb2:off fbmem=16M fb0base=0x27b00000 vmalloc=400M androidboot.console=ttymxc0 androidboot.hardware=freescale
 
 ifeq ($(TARGET_USERIMAGES_USE_UBIFS),true)
 #UBI boot command line.
@@ -117,6 +117,9 @@ NUM_FRAMEBUFFER_SURFACE_BUFFERS := 3
 
 # agan
 PREBUILT_3G_MODEM_RIL :=true
+# zeng
+TARGET_TS_CALIBRATION :=true
+TARGET_TS_DEVICE := "max11801_ts"
 
 TARGET_BOOTLOADER_CONFIG := 6q:mx6q_sabresd_android_config 6dl:mx6dl_sabresd_android_config

‘BOARD_KERNEL_CMDLINE ’中添加 ’ calibration ‘可开启ts_calibrator校准程序。


校准原理

ts_calibrator 校准后生成 /data/system/calibration,同时会拷贝到 /sys/module/max11801_ts/parameters/calibration,其中 /sys/module/max11801_ts/parameters/calibration中的参数又会传递给触摸屏驱动使用。

如下:

drivers/input/touchscreen/max11801_ts.c 修改部分中的module_param_array(calibration,int, NULL, S_IRUGO | S_IWUSR) 引用了/sys/module/max11801_ts/parameters/calibration中的参数。

 

注意事项

1、校准时要删除calibration文件

    rm /data/system/calibration

2、${androidroot} 自己的android源码目录


参考文档

imx53* 飞思卡尔 启用触摸屏校准


你可能感兴趣的:(kernel,android)