硬件:imx6 ads7846电阻屏
系统:android7.1
LCD显示屏的坐标原点为左上角(800,600),触摸屏的坐标原点为右下角(xmin,ymin)
1.通过驱动打印原始的坐标值
static void ads7846_report_state(struct ads7846 *ts)
获取坐标原点和最大值分别为(xmin,ymin)(xmax,ymax)
u16 ymin=480,ymax=3520;
u16 xmin=270,xmax=3750;
2.坐标变换,经过坐标变换使LCD的坐标原点和触摸屏的坐标原点重合
#define LCD_X 800
#define LCD_Y 600
x = LCD_X*(x-xmin)/(xmax-xmin);
y = LCD_Y-LCD_Y*(y-ymin)/(ymax-ymin);
input_report_abs(input, ABS_X, x);
input_report_abs(input, ABS_Y, y);
3.配置文件
getevent获取触摸屏的input device name
add device 3: /dev/input/event1
name: “ADS7846_Touchscreen”
增加配置文件
device/fsl/imx6/imx6.mk
device/fsl/common/input/eGalax_Touch_Screen.idc:system/usr/idc/ADS7846_Touchscreen.idc
内容为
touch.deviceType = touchScreen
touch.orientationAware = 1
touch.size.calibration = none
touch.orientation.calibration = none
5.dtsi
+&ecspi2 {
+ fsl,spi-num-chipselects = <1>;
+ cs-gpios = <&gpio2 26 GPIO_ACTIVE_LOW>;
+ pinctrl-names = "default";
+ pinctrl-0 = <&pinctrl_ecspi2>;
+ status = "okay";
+
+ tsc2046: tsc2046@0 {
+ pinctrl-names = "default";
+ pinctrl-0 = <&tsc2046_irq_pins>;
+ status = "okay";
+ spi-max-frequency = <50000>;
+ reg = <0>;
+ compatible = "ti,tsc2046";
+ interrupt-parent = <&gpio4>;
+ interrupts = <10 2>;
+ pendown-gpio = <&gpio4 10 0>;
+ irq = <&gpio4 10 GPIO_ACTIVE_LOW>;
+
+
+ ti,x-min = /bits/ 16 <0>;
+ ti,x-max = /bits/ 16 <800>;
+ ti,y-min = /bits/ 16 <0>;
+ ti,y-max = /bits/ 16 <600>;
+ ti,x-plate-ohms = /bits/ 16 <500>;
+ ti,y-plate-ohms = /bits/ 16 <400>;
+ ti,pressure-max = /bits/ 16 <255>;
+
+
+ };
+};
+ pinctrl_ecspi2: ecspi2grp {
+ fsl,pins = <
+ MX6QDL_PAD_EIM_RW__GPIO2_IO26 0x100b1
+ MX6QDL_PAD_EIM_CS1__ECSPI2_MOSI 0x100b1
+ MX6QDL_PAD_EIM_OE__ECSPI2_MISO 0x100b1
+ MX6QDL_PAD_EIM_CS0__ECSPI2_SCLK 0x100b1
+ >;
+ };
+
+ tsc2046_irq_pins: tsc2046_irq_pinsgrp {
+ fsl,pins = <
+ MX6QDL_PAD_KEY_COL2__GPIO4_IO10 0x1b0b1
+
+ >;
+ };