hansemro / kc1-linux

Documentation of mainline Linux on First Generation Kindle Fire
GNU General Public License v2.0
4 stars 0 forks source link

Add touchscreen support to device tree #29

Open hansemro opened 3 years ago

hansemro commented 3 years ago

Resources:

ILITEK 2107QS001K touchscreen controller:

hansemro commented 3 years ago

arch/arm/boot/dts/omap4-kc1.dts

&i2c2 {
    ...
    touchscreen@41 {
        compatible = "ilitek,ili210x";
        reg = <0x41>;
        interrupt-parent = <&gpio2>;
        interrupts = <3 IRQ_TYPE_EDGE_FALLING /* gpio_35 TOUCH_IRQ_1 */
            4 IRQ_TYPE_EDGE_FALLING /* gpio_36 TOUCH_IRQ_2 */
            >;
        reset-gpios = <&gpio1 18 GPIO_ACTIVE_LOW>; /* gpio_18; configuration uncertain */
    };
    ...
};
mj-sakellaropoulos commented 3 years ago

Change compatible to "ilitek,ili210x" and the driver will load.

There are some errors though:

~ # ls /dev/input/
by-path  event0
~ # dmesg | grep ili
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 129412
[    4.222412] i2c-core: driver [ili210x_i2c] registered
[    8.899566] ili210x_i2c 1-0041: probe
[    8.899566] ili210x_i2c 1-0041: GPIO lookup for consumer reset
[    8.909698] ili210x_i2c 1-0041: using device tree for GPIO lookup
[    9.083251] i2c i2c-1: client [ili210x] registered with bus id 1-0041
[   10.416076] ili210x_i2c 1-0041: ili210x_read_reg failed: -16
[   10.429809] ili210x_i2c 1-0041: Unable to get touch data: -16
[   11.466674] ili210x_i2c 1-0041: ili210x_read_reg failed: -16
[   11.472686] ili210x_i2c 1-0041: Unable to get touch data: -16

xinput:

~ # xinput
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ILI210x Touchscreen                       id=6    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]

And I can confirm that it is not working under X11

xinput --map-to-output 6 "DPI-1"
hansemro commented 3 years ago

https://github.com/hansemro/kernel_omap_otter-common/blob/84763bbf0a9138cb0ba7b42411cd8d0405c1c684/drivers/input/touchscreen/ilitek.c#L914

Looks like VAUX3 regulator is for touchscreen

hansemro commented 3 years ago

@mj-sakellaropoulos Can you replace/add GPIO 104 for reset?

reset-gpios = <&gpio1 18 GPIO_ACTIVE_LOW
    &gpio3 8 GPIO_ACTIVE_LOW
    >;
hansemro commented 3 years ago

I am not totally convinced that the reset is active low btw. It just happened to be in one of the ilitek examples.

mj-sakellaropoulos commented 3 years ago

I will try that too. I set VAUX3 to always on but it's still getting disabled As soon as VAUX3 is disabled we get ilitek errors

[   27.658447] g_cdc gadget: acm ttyGS0 serial state 0000
[   27.659027] gs_close: ttyGS0 (22c130d3,70c60c71) done!
[   27.659545] gs_open: start ttyGS0
[   27.659545] gs_open: ttyGS0 (22c130d3,a90e9dc6)
[   27.682830] g_cdc gadget: acm ttyGS0 serial state 0003
[   35.708587] g_cdc gadget: acm ttyGS0 req21.22 v0000 i0002 l0
[   35.709899] g_cdc gadget: acm ttyGS0 req21.22 v0003 i0002 l0
[   35.710388] g_cdc gadget: acm ttyGS0 req21.20 v0000 i0002 l7
[   35.710906] g_cdc gadget: acm ttyGS0 req21.22 v0000 i0002 l0
[   39.517517] VAUX3_6030: disabling
[   39.525329] VDAC: disabling
[   39.528411] VANA: disabling
[   39.529357] vwl1271: disabling
[   40.562103] ili210x_i2c 1-0041: ili210x_read_reg failed: -16
[   40.562194] ili210x_i2c 1-0041: Unable to get touch data: -16
[   41.591918] ili210x_i2c 1-0041: ili210x_read_reg failed: -16
[   41.591918] ili210x_i2c 1-0041: Unable to get touch data: -16
[   42.632110] ili210x_i2c 1-0041: ili210x_read_reg failed: -16

OK I managed to set VAUX3 to enabled for real this time, no more ilitek errors

[    6.038635] VAUX3_6030: 1000 <--> 3000 mV at 1200 mV, enabled
hansemro commented 3 years ago

Can you cat the new input device and get touch data?

Also, set vaux3 to 3V


&vaux3 {
    regulator-min-microvolt = <3000000>;
    regulator-max-microvolt = <3000000>;
};
mj-sakellaropoulos commented 3 years ago

Something is stopping the driver probe

I can see an entry in /sys/class/input/input0

but no /dev/input

there are no errors

Also, set vaux3 to 3V

Oh the 1v would explain it

mj-sakellaropoulos commented 3 years ago

Ok, VAUX3 set to 3v0, and reset GPIO is as described above

[    6.050262] VAUX3_6030: Bringing 1200000uV into 3000000-3000000uV
[    6.060516] VAUX3_6030: ramp_delay not set
[    6.068267] VAUX3_6030: 3000 mV, enabled

Nothing in /dev/input, no errors and ili210 driver is not probing ilitek is gone from xinput list:

/ # xinput
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
/ #
/ # dmesg | grep i2c-1
[    6.264434] i2c i2c-1: GPIO lookup for consumer scl
[    6.269592] i2c i2c-1: using device tree for GPIO lookup
[    6.303222] i2c i2c-1: using lookup tables for GPIO lookup
[    6.309020] i2c i2c-1: No GPIO consumer scl found
[    6.314086] i2c i2c-1: GPIO lookup for consumer sda
[    6.314086] i2c i2c-1: using device tree for GPIO lookup
[    6.352783] i2c i2c-1: using lookup tables for GPIO lookup
[    6.358581] i2c i2c-1: No GPIO consumer sda found
[    6.524475] input: ILI210x Touchscreen as /devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0
/ # dmesg | grep ili2
[    6.366333] ili210x_i2c 1-0041: GPIO lookup for consumer reset
[    6.372528] ili210x_i2c 1-0041: using device tree for GPIO lookup
/ #
mj-sakellaropoulos commented 3 years ago

The issue is that the probe function is never executed (I used to see this printk), which is strange because it was working before (? maybe that was my imagination, either way - probe is not working)

Also the way dev_err works, I would have seen it

For instance, this is the only occurence of "input" in the dmesg

[    6.524475] input: ILI210x Touchscreen as /devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0

Afaik, probe function is executed by the kernel once it finds the matching compatible = ilitek,ili210x in the devicetree, it looks up what driver is needed for it and the calls the probe function specified by this

mj-sakellaropoulos commented 3 years ago

Could have something to do with udev or other userspace issues at this point since there are no errors.

/ # udevadm info -q all -p /sys/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0
P: /devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0
E: ABS=2608000 3
E: DEVPATH=/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0
E: EV=b
E: ID_INPUT=1
E: ID_INPUT_TOUCHSCREEN=1
E: ID_PATH=platform-48072000.i2c
E: ID_PATH_TAG=platform-48072000_i2c
E: KEY=400 0 0 0 0 0 0 0 0 0 0
E: MODALIAS=input:b0018v0000p0000e0000-e0,1,3,k14A,ra0,1,2F,35,36,39,mlsfw
E: NAME="ILI210x Touchscreen"
E: PRODUCT=18/0/0/0
E: PROP=2
E: SUBSYSTEM=input
E: USEC_INITIALIZED=14343343
udeven info recursive ``` / # udevadm info -q all -a -p /sys/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0 Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0': KERNEL=="input0" SUBSYSTEM=="input" DRIVER=="" ATTR{uniq}=="" ATTR{properties}=="2" ATTR{phys}=="" ATTR{inhibited}=="0" ATTR{name}=="ILI210x Touchscreen" looking at parent device '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041': KERNELS=="1-0041" SUBSYSTEMS=="i2c" DRIVERS=="ili210x_i2c" ATTRS{name}=="ili210x" looking at parent device '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1': KERNELS=="i2c-1" SUBSYSTEMS=="i2c" DRIVERS=="" ATTRS{name}=="OMAP I2C adapter" looking at parent device '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c': KERNELS=="48072000.i2c" SUBSYSTEMS=="platform" DRIVERS=="omap_i2c" ATTRS{driver_override}=="(null)" looking at parent device '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module': KERNELS=="48072000.target-module" SUBSYSTEMS=="platform" DRIVERS=="ti-sysc" ATTRS{driver_override}=="(null)" looking at parent device '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0': KERNELS=="48000000.interconnect:segment@0" SUBSYSTEMS=="platform" DRIVERS=="simple-pm-bus" ATTRS{driver_override}=="(null)" looking at parent device '/devices/platform/ocp/48000000.interconnect': KERNELS=="48000000.interconnect" SUBSYSTEMS=="platform" DRIVERS=="simple-pm-bus" ATTRS{driver_override}=="(null)" looking at parent device '/devices/platform/ocp': KERNELS=="ocp" SUBSYSTEMS=="platform" DRIVERS=="simple-pm-bus" ATTRS{driver_override}=="(null)" looking at parent device '/devices/platform': KERNELS=="platform" SUBSYSTEMS=="" DRIVERS=="" / # ```
udevadm test ``` / # udevadm test /sys/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0 calling: test version 3.2.10 This program is for debugging only, it does not run any program specified by a RUN key. It may show incorrect results, because some values may be different, or not available at a simulation run. /etc/udev/hwdb.bin does not exist, please run udevadm hwdb --update Load module index timestamp of '/etc/udev/rules.d' changed Reading rules file: /usr/lib/udev/rules.d/10-dm.rules Reading rules file: /usr/lib/udev/rules.d/11-dm-lvm.rules Reading rules file: /usr/lib/udev/rules.d/11-dm-mpath.rules Reading rules file: /usr/lib/udev/rules.d/11-dm-parts.rules Reading rules file: /usr/lib/udev/rules.d/13-dm-disk.rules Reading rules file: /etc/udev/rules.d/50-firmware.rules Reading rules file: /lib/udev/rules.d/50-udev-default.rules Reading rules file: /usr/lib/udev/rules.d/56-multipath.rules Reading rules file: /lib/udev/rules.d/60-block.rules Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules Reading rules file: /lib/udev/rules.d/60-drm.rules Reading rules file: /lib/udev/rules.d/60-evdev.rules Reading rules file: /lib/udev/rules.d/60-input-id.rules Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules Reading rules file: /lib/udev/rules.d/60-persistent-input.rules Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules Reading rules file: /lib/udev/rules.d/60-sensor.rules Reading rules file: /lib/udev/rules.d/60-serial.rules Reading rules file: /run/udev/rules.d/61-dev-root-link.rules Reading rules file: /lib/udev/rules.d/64-btrfs.rules Reading rules file: /usr/lib/udev/rules.d/66-kpartx.rules Reading rules file: /usr/lib/udev/rules.d/68-del-part-nodes.rules Reading rules file: /lib/udev/rules.d/70-joystick.rules Reading rules file: /lib/udev/rules.d/70-mouse.rules Reading rules file: /lib/udev/rules.d/70-touchpad.rules Reading rules file: /lib/udev/rules.d/75-net-description.rules Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules Reading rules file: /lib/udev/rules.d/78-sound-card.rules Reading rules file: /lib/udev/rules.d/80-drivers.rules Reading rules file: /usr/lib/udev/rules.d/80-libinput-device-groups.rules Reading rules file: /lib/udev/rules.d/84-nm-drivers.rules Reading rules file: /lib/udev/rules.d/85-nm-unmanaged.rules Reading rules file: /usr/lib/udev/rules.d/90-libinput-fuzz-override.rules Reading rules file: /lib/udev/rules.d/90-nm-thunderbolt.rules Reading rules file: /usr/lib/udev/rules.d/95-dm-notify.rules Reading rules file: /lib/udev/rules.d/95-upower-csr.rules Reading rules file: /lib/udev/rules.d/95-upower-hid.rules Reading rules file: /lib/udev/rules.d/95-upower-hidpp.rules Reading rules file: /lib/udev/rules.d/95-upower-wup.rules Reading rules file: /usr/lib/udev/rules.d/99-triggerhappy.rules rules contain 49152 bytes tokens (4096 * 12 bytes), 13776 bytes strings 2324 strings (28885 bytes), 1606 de-duplicated (15828 bytes), 719 trie nodes used IMPORT builtin 'hwdb' /lib/udev/rules.d/50-udev-default.rules:14 IMPORT builtin 'hwdb' returned non-zero IMPORT builtin 'input_id' /lib/udev/rules.d/60-input-id.rules:5 capabilities/ev raw kernel attribute: b capabilities/abs raw kernel attribute: 2608000 3 capabilities/rel raw kernel attribute: 0 capabilities/key raw kernel attribute: 400 0 0 0 0 0 0 0 0 0 0 properties raw kernel attribute: 2 test_key: checking bit block 0 for any keys; found=0 test_key: checking bit block 32 for any keys; found=0 test_key: checking bit block 64 for any keys; found=0 test_key: checking bit block 96 for any keys; found=0 test_key: checking bit block 128 for any keys; found=0 test_key: checking bit block 160 for any keys; found=0 test_key: checking bit block 192 for any keys; found=0 test_key: checking bit block 224 for any keys; found=0 IMPORT builtin 'hwdb' /lib/udev/rules.d/60-input-id.rules:6 IMPORT builtin 'hwdb' returned non-zero IMPORT builtin 'path_id' /lib/udev/rules.d/60-persistent-input.rules:35 RUN 'kmod load $env{MODALIAS}' /lib/udev/rules.d/80-drivers.rules:5 RUN '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' /usr/lib/udev/rules.d/99-triggerhappy.rules:4 created db file '/run/udev/data/+input:input0' for '/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0' ABS=2608000 3 ACTION=add DEVPATH=/devices/platform/ocp/48000000.interconnect/48000000.interconnect:segment@0/48072000.target-module/48072000.i2c/i2c-1/1-0041/input/input0 EV=b ID_INPUT=1 ID_INPUT_TOUCHSCREEN=1 ID_PATH=platform-48072000.i2c ID_PATH_TAG=platform-48072000_i2c KEY=400 0 0 0 0 0 0 0 0 0 0 MODALIAS=input:b0018v0000p0000e0000-e0,1,3,k14A,ra0,1,2F,35,36,39,mlsfw NAME="ILI210x Touchscreen" PRODUCT=18/0/0/0 PROP=2 SUBSYSTEM=input USEC_INITIALIZED=14343343 run: 'kmod load input:b0018v0000p0000e0000-e0,1,3,k14A,ra0,1,2F,35,36,39,mlsfw' run: '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' Unload module index ```
mj-sakellaropoulos commented 3 years ago

From your 5.11.x kernel config: evdev is set to m

...
#
# Input device support
#
CONFIG_INPUT=y
# CONFIG_INPUT_LEDS is not set
# CONFIG_INPUT_FF_MEMLESS is not set
# CONFIG_INPUT_SPARSEKMAP is not set
# CONFIG_INPUT_MATRIXKMAP is not set

#
# Userland interfaces
#
CONFIG_INPUT_MOUSEDEV=m
# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
CONFIG_INPUT_MOUSEDEV_SCREEN_Y=600
# CONFIG_INPUT_JOYDEV is not set
CONFIG_INPUT_EVDEV=m
CONFIG_INPUT_EVBUG=m
...

But the module is not present in rootfs

I remember now, I recompiled my kernel with evdev = Y and /dev/input/... should appear

As it is right now, there is no way to modprobe evdev

hansemro commented 3 years ago

I manually add modules to /lib/modules/5.XX.X

I need to charge my device for about an hour, so I can't test right now.

mj-sakellaropoulos commented 3 years ago

OK! It's working now!! Totally missed the modules.tar.gz from before.

Coordinates in X11 seem way off / non-repeatable so far

omap4-kc1.dts.txt

# apk add evtest
# evtest
Event: time 1619986510.665575, -------------- SYN_REPORT ------------
Event: time 1619986510.785276, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1619986510.785276, -------------- SYN_REPORT ------------
Event: time 1619986510.865535, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 159
Event: time 1619986510.865535, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 35850
Event: time 1619986510.865535, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 32772
Event: time 1619986510.865535, -------------- SYN_REPORT ------------
Event: time 1619986510.940929, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1619986510.940929, -------------- SYN_REPORT ------------
Event: time 1619986510.995883, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 160
Event: time 1619986510.995883, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 64261
Event: time 1619986510.995883, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 30213
Event: time 1619986510.995883, -------------- SYN_REPORT ------------
Event: time 1619986511.107689, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1619986511.107689, -------------- SYN_REPORT ------------
Event: time 1619986511.162429, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 161
Event: time 1619986511.162429, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 15114
Event: time 1619986511.162429, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 11524
Event: time 1619986511.162429, -------------- SYN_REPORT ------------
/ # echo 1-0041 > /sys/bus/i2c/drivers/ili210x_i2c/unbind
/ # i2cdump 1 0x41
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1, address 0x41, mode byte
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
10: 00 00 00 00 80 80 00 00 00 00 00 00 00 00 00 00    ....??..........
20: 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ?...............
30: 00 00 00 XX XX XX XX XX XX XX XX XX XX XX XX XX    ...XXXXXXXXXXXXX
40: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
50: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
70: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
80: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
90: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
a0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
b0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
c0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
d0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
e0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
f0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX

Note : using i2ctools crashes the controller

Is there a datasheet out there for this controller ?

hansemro commented 3 years ago

Is there a datasheet out there for this controller ?

I couldn't find any for 210x series

ILI2117A

mj-sakellaropoulos commented 3 years ago

Seems like all the datasheets available on the internet are missing protocol / register descriptions

hansemro commented 3 years ago

Finally got around to test it and touchscreen seems like a pretty good random number generator to me.

mj-sakellaropoulos commented 3 years ago

😂🤣 yeah....

hansemro commented 3 years ago

Here is downstream log btw:

3.4.48 evtest
    Event code 48 (ABS_MT_TOUCH_MAJOR)
      Value      0
      Min        0
      Max      255
    Event code 53 (ABS_MT_POSITION_X)
      Value      0
      Min        0
      Max     2305
    Event code 54 (ABS_MT_POSITION_Y)
      Value      0
      Min        0
      Max     3969
    Event code 57 (ABS_MT_TRACKING_ID)
      Value      0
      Min        0
      Max        2
    Event code 58 (ABS_MT_PRESSURE)
      Value      0
      Min        0
      Max      255
Properties:
Testing ... (interrupt to exit)
Event: time 4542.860915, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.860945, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.860945, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 837
Event: time 4542.860976, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1236
Event: time 4542.860976, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.860976, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.860976, -------------- SYN_REPORT ------------
Event: time 4542.868056, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.868056, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.868086, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 838
Event: time 4542.868086, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1236
Event: time 4542.868086, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.868117, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.868117, -------------- SYN_REPORT ------------
Event: time 4542.883680, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.883711, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.883711, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 842
Event: time 4542.883741, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1235
Event: time 4542.883741, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.883741, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.883741, -------------- SYN_REPORT ------------
Event: time 4542.891523, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.891523, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.891523, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 849
Event: time 4542.891554, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1234
Event: time 4542.891554, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.891554, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.891584, -------------- SYN_REPORT ------------
Event: time
Event: time 4542.907179, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1234
Event: time 4542.907179, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.907179, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.907210, -------------- SYN_REPORT ------------
Event: time 4542.922713, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.922743, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.922804, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 875
Event: time 4542.922804, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1236
Event: time 4542.922804, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.922804, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.922835, -------------- SYN_REPORT ------------
Event: time 4542.938368, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.938399, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.938460, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 889
Event: time 4542.938460, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1240
Event: time 4542.938490, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.938490, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.938490, -------------- SYN_REPORT ------------
Event: time 4542.953963, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4542.953993, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4542.954024, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 950
Event: time 4542.954054, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1332
Event: time 4542.954054, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4542.954054, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.954085, -------------- SYN_REPORT ------------
Event: time 4542.969557, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4542.969588, -------------- SYN_REPORT ------------
Event: time 4543.735856, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4543.735886, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4543.735886, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 982
Event: time 4543.735917, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1425
Event: time 4543.735917, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4543.735917, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4543.735917, -------------- SYN_REPORT ------------
Event: time 4543.750840, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4543.750871, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4543.750871, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 984
Event: time 4543.750901, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1424
Event: time 4543.750901, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4543.750901, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4543.750901, -------------- SYN_REPORT ------------
Event: time 4543.766435, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4543.766465, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4543.766526, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 986
Event: time 4543.766526, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1422
Event: time 4543.766526, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4543.766557, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4543.766557, -------------- SYN_REPORT ------------
Event: time 4543.782121, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4543.782151, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4543.782212, type 3 (EV_ABS
Event: time 4543.782243, -------------- SYN_REPORT ------------
Event: time 4543.789903, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4543.789933, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4543.789933, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 993
Event: time 4543.789933, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1397
Event: time 4543.789964, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4543.789964, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4543.789964, -------------- SYN_REPORT ------------
Event: time 4543.813340, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4543.813371, -------------- SYN_REPORT ------------
Event: time 4544.633655, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4544.633686, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4544.633716, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 1229
Event: time 4544.633716, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 2203
Event: time 4544.633716, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4544.633747, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4544.633747, -------------- SYN_REPORT ------------
Event: time 4544.648975, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4544.648975, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4544.648975, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 1230
Event: time 4544.648975, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 2202
Event: time 4544.648975, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4544.648975, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4544.648975, -------------- SYN_REPORT ------------
Event: time 4544.672535, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4544.672535, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4544.672565, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 1229
Event: time 4544.672565, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 2202
Event: time 4544.672565, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4544.672565, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4544.672565, -------------- SYN_REPORT ------------
Event: time 4544.689960, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4544.689991, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4544.689991, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 1228
Event: time 4544.689991, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 2202
Event: time 4544.689991, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4544.689991, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4544.689991, -------------- SYN_REPORT ------------
Event: time 4544.697284, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4544.697284, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4544.697315, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 1164
Event: time 4544.697315, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 2221
Event: time 4544.697315, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4544.697315, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4544.697315, -------------- SYN_REPORT ------------
Event: time 4544.711567, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4544.711567, -------------- SYN_REPORT ------------
Event: time 4545.321889, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4545.321951, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4545.321951, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 953
Event: time 4545.321951, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1139
Event: time 4545.321981, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4545.321981, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4545.321981, -------------- SYN_REPORT ------------
Event: time 4545.352438, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4545.352468, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4545.352529, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 953
Event: time 4545.352529, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1140
Event: time 4545.352560, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4545.352560, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4545.352560, -------------- SYN_REPORT ------------
Event: time 4545.368093, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4545.368124, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4545.368154, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 951
Event: time 4545.368154, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1141
Event: time 4545.368185, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4545.368185, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4545.368185, -------------- SYN_REPORT ------------
Event: time 4545.375845, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 4545.375845, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 5
Event: time 4545.375875, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 898
Event: time 4545.375875, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1153
Event: time 4545.375875, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 20
Event: time 4545.375875, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4545.375906, -------------- SYN_REPORT ------------
Event: time 4545.391470, ++++++++++++++ SYN_MT_REPORT ++++++++++++
Event: time 4545.391470, -------------- SYN_REPORT ------------
^Camazon-otter:/usr/share/X11/xorg.conf.d# xinput
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ilitek_i2c                                id=7    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ twl6030_pwrbutton                         id=6    [slave  keyboard (3)]
5.11.0 evtest info
amazon-otter:~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:  ILI210x Touchscreen
Select the device event number [0-0]: 0
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "ILI210x Touchscreen"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 330 (BTN_TOUCH)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value   9737
      Min        0
      Max    65535
    Event code 1 (ABS_Y)
      Value  31235
      Min        0
      Max    65535
    Event code 47 (ABS_MT_SLOT)
      Value      0
      Min        0
      Max        1
    Event code 53 (ABS_MT_POSITION_X)
      Value      0
      Min        0
      Max    65535
    Event code 54 (ABS_MT_POSITION_Y)
      Value      0
      Min        0
      Max    65535
    Event code 57 (ABS_MT_TRACKING_ID)
      Value      0
      Min        0
      Max    65535
Properties:
  Property type 1 (INPUT_PROP_DIRECT)
mj-sakellaropoulos commented 3 years ago

I'm working on getting it working via raw i2c in python. That will take a little while

hansemro commented 3 years ago
3.4.48 dmesg
[    2.388854] ilitek_init
[    2.429412] ilitek_i2c_probe, i2c new style format
[    2.434509] ilitek_i2c_probe, IRQ: 0xC3
[    2.434539] ilitek_i2c_register_device, add i2c device, success
[    2.440826] ilitek_i2c_register_device, client.addr: 0x41
[    2.446563] ilitek_i2c_register_device, client.adapter: 0xDE192CA8
[    2.453124] ilitek_i2c_register_device, client.driver: 0xC085057C
[    2.476501] ilitek_i2c_read_tp_info, firmware version 10.2.4.0
[    2.499877] ilitek_i2c_read_tp_info, protocol version: 1.2
[    2.523437] ilitek_i2c_read_tp_info, max_x: 3968, max_y: 2304, ch_x: 30, ch_y: 18
[    2.531402] ilitek_i2c_read_tp_info, max_tp: 2, max_btn: 0
[    2.537384] input: ilitek_i2c as /devices/platform/omap_i2c.2/i2c-2/2-0041/input/input0
[    2.545989] ilitek_i2c_register_device, register input device, success
[    2.553100] ilitek_i2c_register_device, request irq, success
[    2.559143] ilitek_init, register chrdev(247, 0)
hansemro commented 3 years ago

On downstream kernels, touch data continues to be polled after the finger is on the screen. In contrast, mainline driver polls data once when the finger is on/off the screen.

mj-sakellaropoulos commented 3 years ago

Data looks "good" (not random) when obtained manually

sudo apk add python3
sudo apk add py3_pip
sudo pip3 install smbus2
# Run this script as root
import sys
import time
from smbus2 import SMBus, i2c_msg
# import gpio

I2C_BUS_NUMBER = 1
I2C_CHIP_ADDR = 0x41

ILI210X_DATA_SIZE = 64
ILI210X_CMD_READ_TOUCHDATA = 0x10
ILI210X_REG_PANEL_INFO = 0x20
ILI210X_REG_CALIBRATE = 0xcc

i2c_raw_val = 0

def reset_ili210x():
    print("Not implemented")

def init_i2c():
    return SMBus(I2C_BUS_NUMBER)

def read_touch_data(bus):
    write = i2c_msg.write(I2C_CHIP_ADDR, [ILI210X_CMD_READ_TOUCHDATA])
    read = i2c_msg.read(I2C_CHIP_ADDR, ILI210X_DATA_SIZE)
    bus.i2c_rdwr(write, read)
    return list(read)

def main():
    i2c = init_i2c()
    while(True):
        b = read_touch_data(i2c)
        print(b[0:8])
        time.sleep(0.5)
    i2c.close()

if __name__ == "__main__":
    sys.exit(main())
~ $ sudo python3 i2c.py
[sudo] password for user:
[1, 185, 7, 201, 4, 26, 13, 244]
[1, 174, 7, 203, 4, 26, 13, 244]
[1, 182, 7, 204, 4, 26, 13, 244]
[1, 182, 7, 204, 4, 26, 13, 244]
[1, 178, 7, 203, 4, 26, 13, 244]
[1, 180, 7, 204, 4, 26, 13, 244]
[1, 179, 7, 202, 4, 26, 13, 244]
[1, 241, 7, 10, 3, 26, 13, 244]
[1, 239, 7, 236, 1, 26, 13, 244]
[1, 239, 7, 235, 1, 26, 13, 244]
[1, 239, 7, 246, 1, 26, 13, 244]
[1, 242, 7, 254, 1, 26, 13, 244]
[1, 241, 7, 0, 2, 26, 13, 244]
[1, 240, 7, 8, 2, 26, 13, 244]
[1, 241, 7, 5, 2, 26, 13, 244]
[1, 243, 7, 4, 2, 26, 13, 244]
[1, 243, 7, 7, 2, 26, 13, 244]
[1, 242, 7, 7, 2, 26, 13, 244]
[1, 43, 8, 26, 2, 26, 13, 244]
[1, 219, 12, 165, 2, 26, 13, 244]
[1, 96, 13, 184, 2, 26, 13, 244]
[1, 102, 13, 191, 2, 26, 13, 244]
...
hansemro commented 3 years ago

Great work on the script. Just added a few more commands and interpreted touch data

# Run this script as root
import sys
import time
from smbus2 import SMBus, i2c_msg
# import gpio

I2C_BUS_NUMBER = 1
I2C_CHIP_ADDR = 0x41

ILI210X_DATA_SIZE = 64
ILI210X_CMD_READ_TOUCHDATA = 0x10
ILI210X_CMD_PANEL_INFO = 0x20
ILI210X_CMD_CALIBRATE = 0xcc
ILI210X_CMD_GET_FIRMWARE_VERSION = 0x40
ILI210X_CMD_GET_PROTOCOL_VERSION = 0x42

i2c_raw_val = 0

def reset_ili210x():
    print("Not implemented")

def init_i2c():
    return SMBus(I2C_BUS_NUMBER)

def read_panel_info(bus):
    write = i2c_msg.write(I2C_CHIP_ADDR, [ILI210X_CMD_PANEL_INFO])
    read = i2c_msg.read(I2C_CHIP_ADDR, ILI210X_DATA_SIZE)
    bus.i2c_rdwr(write, read)
    return list(read)

def read_firmware_ver(bus):
    write = i2c_msg.write(I2C_CHIP_ADDR, [ILI210X_CMD_GET_FIRMWARE_VERSION])
    read = i2c_msg.read(I2C_CHIP_ADDR, 4*8)
    bus.i2c_rdwr(write, read)
    return list(read)

def read_protocol_ver(bus):
    write = i2c_msg.write(I2C_CHIP_ADDR, [ILI210X_CMD_GET_PROTOCOL_VERSION])
    read = i2c_msg.read(I2C_CHIP_ADDR, 2*8)
    bus.i2c_rdwr(write, read)
    return list(read)

def read_touch_data(bus):
    write = i2c_msg.write(I2C_CHIP_ADDR, [ILI210X_CMD_READ_TOUCHDATA])
    read = i2c_msg.read(I2C_CHIP_ADDR, ILI210X_DATA_SIZE)
    bus.i2c_rdwr(write, read)
    return list(read)

def main():
    i2c = init_i2c()
    res = read_panel_info(i2c)
    fw_ver = read_firmware_ver(i2c)
    prot_ver = read_protocol_ver(i2c)
    print("Max touch point: ", res[6])
    print("Max button number: ", res[7])
    print("y_max: ", res[1]*256 + res[0])
    print("x_max: ", res[3]*256 + res[2])
    print("y_ch: ", res[4])
    print("x_ch: ", res[5])
    print("Firmware version: ", fw_ver[0], ".", fw_ver[1], ".", fw_ver[2], ".", fw_ver[3])
    print("Protocol version: ", prot_ver[0], ".", prot_ver[1])
    while(True):
        b = read_touch_data(i2c)
        y0 = b[2]*256+b[1]
        x0 = b[4]*256+b[3]
        y1 = b[6]*256+b[5]
        x1 = b[8]*256+b[7]
        print("state: ", b[0], " x0: ", x0, " y0: ", y0, " x1: ", x1, " y1: ", y1)
        time.sleep(0.2)
    i2c.close()

if __name__ == "__main__":
    sys.exit(main())
Sample test
amazon-otter:~# python3 touch_test.py
Max touch point:  2
Max button number:  2
y_max:  3968
x_max:  2304
y_ch:  30
x_ch:  18
Firmware version:  10 . 2 . 4 . 0
Protocol version:  1 . 2
state:  0  x0:  1064  y0:  2315  x1:  1064  y1:  2315
state:  0  x0:  1064  y0:  2315  x1:  1064  y1:  2315
state:  0  x0:  1064  y0:  2315  x1:  1064  y1:  2315
state:  0  x0:  1064  y0:  2315  x1:  1064  y1:  2315
state:  0  x0:  1064  y0:  2315  x1:  1064  y1:  2315
state:  0  x0:  1064  y0:  2315  x1:  1064  y1:  2315
state:  1  x0:  1908  y0:  2271  x1:  1064  y1:  2315
state:  1  x0:  1905  y0:  2291  x1:  1064  y1:  2315
state:  1  x0:  1905  y0:  2288  x1:  1064  y1:  2315
state:  1  x0:  1922  y0:  2297  x1:  1064  y1:  2315
state:  3  x0:  1938  y0:  2306  x1:  1435  y1:  2844
state:  3  x0:  1937  y0:  2306  x1:  1444  y1:  2843
state:  3  x0:  1923  y0:  2302  x1:  1444  y1:  2839
state:  3  x0:  1916  y0:  2300  x1:  1446  y1:  2837
state:  3  x0:  1914  y0:  2299  x1:  1447  y1:  2836
state:  3  x0:  1911  y0:  2299  x1:  1447  y1:  2835
state:  3  x0:  1909  y0:  2299  x1:  1451  y1:  2836
state:  3  x0:  1911  y0:  2299  x1:  1447  y1:  2839
state:  2  x0:  1584  y0:  2707  x1:  1473  y1:  2841
state:  2  x0:  1478  y0:  2838  x1:  1478  y1:  2838
state:  2  x0:  1481  y0:  2839  x1:  1481  y1:  2839
state:  2  x0:  1480  y0:  2838  x1:  1480  y1:  2838
state:  2  x0:  1479  y0:  2838  x1:  1479  y1:  2838
state:  2  x0:  1478  y0:  2837  x1:  1478  y1:  2837
state:  3  x0:  1821  y0:  2319  x1:  1483  y1:  2839
state:  3  x0:  1826  y0:  2316  x1:  1482  y1:  2840
state:  3  x0:  1827  y0:  2317  x1:  1482  y1:  2840
state:  1  x0:  1838  y0:  2321  x1:  1447  y1:  2850
state:  1  x0:  1841  y0:  2323  x1:  1447  y1:  2849
state:  1  x0:  1843  y0:  2326  x1:  1447  y1:  2849
state:  1  x0:  1845  y0:  2326  x1:  1447  y1:  2849
state:  1  x0:  1844  y0:  2326  x1:  1447  y1:  2849
state:  1  x0:  1854  y0:  2329  x1:  1447  y1:  2849
state:  3  x0:  1858  y0:  2332  x1:  1328  y1:  2945
state:  3  x0:  1846  y0:  2326  x1:  1331  y1:  2940
state:  3  x0:  1846  y0:  2326  x1:  1331  y1:  2938
state:  2  x0:  1722  y0:  2481  x1:  1343  y1:  2943
state:  2  x0:  1372  y0:  2949  x1:  1372  y1:  2949
state:  2  x0:  1369  y0:  2948  x1:  1369  y1:  2948
state:  2  x0:  1371  y0:  2948  x1:  1371  y1:  2948
state:  2  x0:  1376  y0:  2949  x1:  1376  y1:  2949
state:  3  x0:  1698  y0:  2409  x1:  1378  y1:  2948
state:  3  x0:  1717  y0:  2405  x1:  1387  y1:  2950
state:  1  x0:  1730  y0:  2415  x1:  1366  y1:  2950
state:  1  x0:  1734  y0:  2422  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947
state:  0  x0:  1740  y0:  2401  x1:  1358  y1:  2947

state 0 : no fingers state 1 : first finger only state 2 : second finger only state 3 : two fingers

mj-sakellaropoulos commented 3 years ago

Update : SDL2 demo reading the raw values from i2c

old demo ![image](https://user-images.githubusercontent.com/36081545/116902044-ad2c2780-ac08-11eb-8c76-47f2891a7536.png)
demo proper coords ![image](https://user-images.githubusercontent.com/36081545/116912956-e53a6700-ac16-11eb-9503-90b3c2d38372.png)
demo multitouch ![image](https://user-images.githubusercontent.com/36081545/116915557-297b3680-ac1a-11eb-8131-d2e15057c39c.png)
hansemro commented 3 years ago

With CONFIG_DEBUG_DRIVERS set, I am able to see driver error (dev_err) statements:

Bad example:

[    3.166687] bus: 'i2c': add driver ili210x_i2c
[    3.166870] i2c-core: driver [ili210x_i2c] registered
[    3.973571] bus: 'i2c': driver_probe_device: matched device 1-0041 with driver ili210x_i2c
[    3.973571] bus: 'i2c': really_probe: probing driver ili210x_i2c with device 1-0041
[    3.973663] ili210x_i2c 1-0041: no pinctrl handle
[    3.973663] ili210x_i2c 1-0041: probe
[    3.974365] ili210x_i2c 1-0041: GPIO lookup for consumer reset
[    3.974365] ili210x_i2c 1-0041: using device tree for GPIO lookup
[    4.117309] driver: 'ili210x_i2c': driver_bound: bound to device '1-0041'
[    4.117309] ili210x_i2c 1-0041: Dropping the link to 48057000.gpio
[    4.117309] ili210x_i2c 1-0041: Dropping the link to 4a310000.gpio
[    4.117675] ili210x_i2c 1-0041: Dropping the link to 48055000.gpio
[    4.118316] bus: 'i2c': really_probe: bound device 1-0041 to driver ili210x_i2c
[    4.118377] i2c i2c-1: client [ili210x] registered with bus id 1-0041

Kernel testing 1: https://github.com/hansemro/linux/commit/04ebf3827e99845affca908fb71ea2ced0953019

Observations:

mj-sakellaropoulos commented 3 years ago

Here's my current progress : https://github.com/mj-sakellaropoulos/linux-omap4-kc1/commit/9b6063fba66faca00f770b7dff7e2b6106fcc021

I changed the coordinates to little endian, now the values seem to be really scaled down, but cursor is moving mostly right otherwise

BIT(finger) operation was causing most events to be ignored - I had to remove that in the python port too

Update: Can confirm values in evtest are correct - only problem now is X11 coordinate transform

hansemro commented 3 years ago

Can confirm those changes fixes polling issue from before with good data for both fingers.

hansemro commented 3 years ago

only problem now is X11 coordinate transform

I wonder if this is because resolution field is not specified for ili210x_chip

mj-sakellaropoulos commented 3 years ago

I've been trying to set it manually by following https://wiki.archlinux.org/title/Calibrating_Touchscreen

Using those formulas, it's slightly better but still scaled down - I'm thinking something else is messing with the resolution

I wonder if this is because resolution field is not specified for ili210x_chip

That could explain it

mj-sakellaropoulos commented 3 years ago

Oh yeah, they are assuming symetrical resolution ?! image

command 0x20 panel info is never used, so there is no way they are getting the right values for max x/y

hansemro commented 3 years ago

This seems to fix scaling issue

    input_set_abs_params(input, ABS_MT_POSITION_X, 0, 3968, 0, 0);
    input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 2304, 0, 0);
hansemro commented 3 years ago

command 0x20 panel info is never used, so there is no way they are getting the right values for max x/y

I was going to write a function to handle this, but I am not sure if other ili210x chips work the same way... For now, we can have a patch take care of things for kindle

mj-sakellaropoulos commented 3 years ago

I was going to write a function to handle this

I'm trying my hand at it now, no guarantee of 3968x2304 touch resolution on all devices - I have a feeling this might get modified by the calibration command (by android?) / different firmwares / etc

mj-sakellaropoulos commented 3 years ago

Update : It's working , https://github.com/mj-sakellaropoulos/linux-omap4-kc1/commit/b0c4503fadd3a0a3f7569f7bf56a47d3a1c5e8e3

I'm not a C developer, so there might be glaring/dumb mistakes but at least it works 😅

What isn't working : Actual "Click" event, can move cursor - but can't click anything , this is a regression because even in the broken state before, I was able to click and drag

Also : ignore changes to device tree - apparently I still needed DSI = ok on 5.11 branch for some reason...

hansemro commented 3 years ago

Also : ignore changes to device tree - apparently I still needed DSI = ok on 5.11 branch for some reason...

I actually do need dsi1/2 enabled as well. Something about working with a dirty tree messed things up... So that's been sorted and I will update the device tree shortly.

hansemro commented 3 years ago

Actual "Click" event, can move cursor - but can't click anything

Can you check the events and confirm that it follows the multitouch protocol? https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt

mj-sakellaropoulos commented 3 years ago

The click isn't working because I commented out the BIT(finger) thing, when that function returns false it signifies a click. It's just that the logic that was there already is invalid. (?)

Can you check the events and confirm that it follows the multitouch protocol?

Checking now

mj-sakellaropoulos commented 3 years ago

Can you check the events and confirm that it follows the multitouch protocol?

I think it does follow the protocol , just the events are not triggered in any logical way ? And it's buggy (With BIT(finger) enabled), normally the cursor and events wont track a single touch/drag, but you can glitch it by doing a two-point touch and only releasing one touch. This is intermittent

Also, it's useful to compile the ili210x driver as a module, which can be quickly recompiled and hot-loaded over ssh

hansemro commented 3 years ago
static bool ili210x_touchdata_to_coords(const u8 *touchdata, ...
...
{
    if (touchdata[0] & BIT(finger))
        return false;
...
}

The if statement is definitely not right. When a finger is detected, it will skip interpreting coordinates from touchdata. This is the opposite of what should happen.

After negating the result, we can track finger 1 and actually tap/drag things.

if (!(touchdata[0] & BIT(finger)))
        return false;

output

hansemro commented 3 years ago

Also, it's useful to compile the ili210x driver as a module, which can be quickly recompiled and hot-loaded over ssh

Excellent tip.

mj-sakellaropoulos commented 3 years ago

Can confirm, this is working as it should !

hansemro commented 3 years ago

Polling rate is much slower than downstream, so I am looking into that right now.

Not ideal, but setting ILI2XXX_POLL_PERIOD to 0 makes the touchscreen much smoother.

hansemro commented 3 years ago

It is funny how ili212x_touchdata_to_coords has the negation... Maybe there are not many people with ili210x IC to test?

mj-sakellaropoulos commented 3 years ago

I'm wondering if it's down to firmware or chip variant...

hansemro commented 3 years ago

active low states? Possible, but it could just be a typo that has been overlooked and untested. There is not enough documentation to argue one way or the other so I will call it a typo.

mj-sakellaropoulos commented 3 years ago

So then, is this issue resolved? Or do we still need right click ? 😂

hansemro commented 3 years ago

That doesn't appear to be implemented by the driver...

mj-sakellaropoulos commented 3 years ago

That doesn't appear to be implemented by the driver...

Hmmmm....

Maybe something like this on userspace side could be an option : https://github.com/PeterCxy/evdev-right-click-emulation

Also a suggestion : install the xinput_calibrator package for easy calibration

hansemro commented 3 years ago

Also a suggestion : install the xinput_calibrator package for easy calibration

Can we use this to calibrate the touchscreen without setting the resolution field?