Waveshare 10.1 (H) touchscreen with android

Post Reply
dlugaz
Posts: 1
Joined: Thu Sep 12, 2019 7:50 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Waveshare 10.1 (H) touchscreen with android

Unread post by dlugaz » Thu Sep 12, 2019 9:10 pm

Hi!
I wanted to share my struggles with Waveshare 10.1 H device. I've been working for a few days to get waveshare 10.1 inch (h) touchscreen working with android 6.0.1. and I've managed to do it. Maybe someone will use it

WARNING:

This is really an ugly hack - I modify a hid-generic input device driver just so a quirky touchscreen would work.
This will cause some other devices such as usb mouse to STOP working with android!

This is just a quick fix, If you have an idea how to make it better and permament, please write it down below


So after some basic diagnosic I've found out:

1. Hardkernel added waveshare do kernel driver hid-multitouch. However this driver is incompatibile with this device! That's why kernel doesn't call this module when this device is connected:
dmesg shows:

Code: Select all

[  909.411691@0] usb 1-1.3: new full-speed USB device number 5 using dwc_otg
[  909.516216@0] input: waveshare HDMI/VGA/AV RTD2660H Viedo Board as /devices/dwc2_b/usb1/1-1/1-1.3/1-1.3:1.0/0003:0483:5710.0002/input/input5
[  909.524229@0] hid-generic 0003:0483:5710.0002: input: USB HID v1.00 Mouse [waveshare HDMI/VGA/AV RTD2660H Viedo Board] on usb-dwc2_b-1.3/input0
so it's registered under hid-generic, not hid-multitouch. I unbinded it from hid-generic and binded to hid-multitouch:

Code: Select all

1|root@odroidc2:/ # echo -n "0003:0483:5710.0002" > /sys/bus/hid/drivers/hid-generic/unbind
1|root@odroidc2:/ # echo -n "0003:0483:5710.0002" > /sys/bus/hid/drivers/hid-multitouch/bind
but dmesg said:

Code: Select all

[  909.411691@0] usb 1-1.3: new full-speed USB device number 5 using dwc_otg
[  909.516216@0] input: waveshare HDMI/VGA/AV RTD2660H Viedo Board as /devices/dwc2_b/usb1/1-1/1-1.3/1-1.3:1.0/0003:0483:5710.0002/input/input5
[  909.524229@0] hid-generic 0003:0483:5710.0002: input: USB HID v1.00 Mouse [waveshare HDMI/VGA/AV RTD2660H Viedo Board] on usb-dwc2_b-1.3/input0
[ 4494.153911@0] hid-multitouch 0003:0483:5710.0002: No inputs registered, leaving
[ 4494.155578@0] hid-multitouch 0003:0483:5710.0002: device has no listeners, quitting

2. But! hid-generic registered this driver and it's shown under /dev/input/eventX and I'm able to read events with:

Code: Select all

adb shell
getevent
add device 1: /dev/input/event3
  name:     "waveshare HDMI/VGA/AV RTD2660H Viedo Board"
could not get driver version for /dev/input/mouse1, Not a typewriter
add device 2: /dev/input/event4
  name:     "cec_input"
add device 3: /dev/input/event1
  name:     "vt-input"
could not get driver version for /dev/input/mice, Not a typewriter
add device 4: /dev/input/event2
  name:     "odroid-encoder"
could not get driver version for /dev/input/mouse0, Not a typewriter
add device 5: /dev/input/event0
  name:     "aml_keypad"
3. Ok, so it exists under linux kernel, but doesn't work with android. I checked what events it registers with:

Code: Select all

130|root@odroidc2:/ # getevent -lp
add device 1: /dev/input/event3
  name:     "waveshare HDMI/VGA/AV RTD2660H Viedo Board"
  events:
    KEY (0001): BTN_MOUSE
    ABS (0003): ABS_X                 : value 0, min 0, max 10000, fuzz 0, flat 0, resolution 0
                ABS_Y                 : value 0, min 0, max 10000, fuzz 0, flat 0, resolution 0
    MSC (0004): MSC_SCAN
  input props:
    <none>
After reading Android documentation https://source.android.com/devices/input/touch-devices I've found out that:

Code: Select all

Single-touch devices use the following Linux input events:

    ABS_X: (REQUIRED) Reports the X coordinate of the tool.
    ABS_Y: (REQUIRED) Reports the Y coordinate of the tool.
   (...)
    BTN_TOUCH: (REQUIRED) Indicates whether the tool is touching the device.
Then problem is that the device registers BTN_MOUSE instead of BTN_TOUCH. This is problem with USBHID device descriptor, but I made an UGLY hack in linux kernel driver to check if this is the case.
1. Clone kernel source as in here https://wiki.odroid.com/odroid-c2/softw ... ing_kernel
2. Change BTN_MOUSE to BTN_TOUCH in file
linux/drivers/hid/hid-input.c :

Code: Select all

--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -522,7 +522,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
 
                switch (field->application) {
                case HID_GD_MOUSE:
-               case HID_GD_POINTER:  code += BTN_MOUSE; break;
+               case HID_GD_POINTER:  code += BTN_TOUCH; break;
                case HID_GD_JOYSTICK:
                                if (code <= 0xf)
                                        code += BTN_JOYSTICK;
@@ -538,7 +538,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
                default:
                        switch (field->physical) {
                        case HID_GD_MOUSE:
-                       case HID_GD_POINTER:  code += BTN_MOUSE; break;
+                       case HID_GD_POINTER:  code += BTN_TOUCH; break;
                        case HID_GD_JOYSTICK: code += BTN_JOYSTICK; break;
                        case HID_GD_GAMEPAD:  code += BTN_GAMEPAD; break;
                        default:              code += BTN_MISC;

3. Compile, load kernel:

Code: Select all

make odroidc2_defconfig
make clean
make -j4 Image modules dtbs
adb shell
reboot bootloader
fastboot flash boot arch/arm64/boot/Image
4. Make an idc file. idc = input device config.

Code: Select all

# Copyright (C) 2011 The Android-x86 Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Basic Parameters
touch.deviceType = touchScreen
#touch.orientationAware = 1

# Touch Size
touch.touchSize.calibration = default

# Tool Size
touch.toolSize.calibration = default

# Pressure
touch.pressure.calibration = default

# Size
touch.size.calibration = default

# Orientation
touch.orientation.calibration = none

device.internal = 0

!!!!!!!!!!!!!!!!!!!!!!
Name it: Vendor_0483_Product_5710.idc
Also check with lsusb if your device has the same Vendor and Product codes

Code: Select all

root@odroidc2:/ # lsusb
Bus 001 Device 002: ID 05e3:0610
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 001 Device 003: ID 0403:6015
Bus 001 Device 005: ID 0483:5710 <------------- this is my device
!!!!!!!!!!!!!!!!!!!!!!
and copy it to /usr/idc/
I just take the SD card out and copy it on my PC.

THE END. Boot Odroid C2 and now waveshare 10.1 H screen works.
getevent -lp:

Code: Select all

root@odroidc2:/ # getevent -lp
add device 1: /dev/input/event3
  name:     "waveshare HDMI/VGA/AV RTD2660H Viedo Board"
  events:
    KEY (0001): BTN_TOUCH
    ABS (0003): ABS_X                 : value 7636, min 0, max 10000, fuzz 0, flat 0, resolution 0
                ABS_Y                 : value 4966, min 0, max 10000, fuzz 0, flat 0, resolution 0
    MSC (0004): MSC_SCAN
  input props:
    <none>
dumpsys input:

Code: Select all

 
 Event Hub State:
    7: waveshare HDMI/VGA/AV RTD2660H Viedo Board
      Classes: 0x80000004
      Path: /dev/input/event3
      Descriptor: b8c0a3ecccd403c6acf8d2c84659e8548e85a24e
      Location: usb-dwc2_b-1.3/input0
      ControllerNumber: 0
      UniqueId: 49813F733936
      Identifier: bus=0x0003, vendor=0x0483, product=0x5710, version=0x0100
      KeyLayoutFile:
      KeyCharacterMapFile:
      ConfigurationFile: /system/usr/idc/Vendor_0483_Product_5710.idc
      HaveKeyboardLayoutOverlay: false
      
Input Reader State:
  Device 7: waveshare HDMI/VGA/AV RTD2660H Viedo Board
    Generation: 23
    IsExternal: true
    HasMic:     false
    Sources: 0x0000d002
    KeyboardType: 0
    Motion Ranges:
      X: source=0x0000d002, min=0.000, max=1023.000, flat=0.000, fuzz=0.000, resolution=0.000
      Y: source=0x0000d002, min=0.000, max=599.000, flat=0.000, fuzz=0.000, resolution=0.000
      PRESSURE: source=0x0000d002, min=0.000, max=1.000, flat=0.000, fuzz=0.000, resolution=0.000
    Touch Input Mapper:
      Parameters:
        GestureMode: spots
        DeviceType: touchScreen
        AssociatedDisplay: hasAssociatedDisplay=true, isExternal=true
        OrientationAware: true
      Raw Touch Axes:
        X: min=0, max=10000, flat=0, fuzz=0, resolution=0
        Y: min=0, max=10000, flat=0, fuzz=0, resolution=0
        Pressure: unknown range
        TouchMajor: unknown range
        TouchMinor: unknown range
        ToolMajor: unknown range
        ToolMinor: unknown range
        Orientation: unknown range
        Distance: unknown range
        TiltX: unknown range
        TiltY: unknown range
        TrackingId: unknown range
        Slot: unknown range
      Calibration:
        touch.size.calibration: none
        touch.pressure.calibration: none
        touch.orientation.calibration: none
        touch.distance.calibration: none
        touch.coverage.calibration: none
      Affine Transformation:
        X scale: 1.000
        X ymix: 0.000
        X offset: 0.000
        Y xmix: 0.000
        Y scale: 1.000
        Y offset: 0.000
      Viewport: displayId=0, orientation=0, logicalFrame=[0, 0, 1024, 600], physicalFrame=[0, 0, 1024, 600], deviceSize=[1024, 600]
      SurfaceWidth: 1024px
      SurfaceHeight: 600px
      SurfaceLeft: 0
      SurfaceTop: 0
      SurfaceOrientation: 0
      Translation and Scaling Factors:
        XTranslate: 0.000
        YTranslate: 0.000
        XScale: 0.102
        YScale: 0.060
        XPrecision: 9.767
        YPrecision: 16.668
        GeometricScale: 0.081
        PressureScale: 0.000
        SizeScale: 0.000
        OrientationScale: 0.000
        DistanceScale: 0.000
        HaveTilt: false
        TiltXCenter: 0.000
        TiltXScale: 0.000
        TiltYCenter: 0.000
        TiltYScale: 0.000
      Last Raw Button State: 0x00000000
      Last Raw Touch: pointerCount=0
      Last Cooked Button State: 0x00000000
      Last Cooked Touch: pointerCount=0
      Stylus Fusion:
        ExternalStylusConnected: true
        External Stylus ID: -1
        External Stylus Data Timeout: 9223372036854775807
      External Stylus State:
        When: 9223372036854775807
        Pressure: 0.000000
        Button State: 0x00000000
        Tool Type: 0


TODO:
We can also change the Android InputReader and EventHub code to detect BTN_MOUSE as touchscreen, but I haven't done it because recompilation of android takes much more time. This may be a better solution.
We can add a separate driver for this device
We can add a QUIRK definition to linux kernel, only for this device.

User avatar
odroid
Site Admin
Posts: 32104
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 115 times
Been thanked: 287 times
Contact:

Re: Waveshare 10.1 (H) touchscreen with android

Unread post by odroid » Mon Sep 16, 2019 1:39 pm

Thank you for sharing a very detail instruction.

If your touchscreen controller is compatible with the standard multi-touch protocol, just changing this parameter to "true" in boot.ini file might be enough to activate a proper input driver.

Code: Select all

# disable vu7
setenv disable_vu7 "false"

Post Reply

Return to “Android”

Who is online

Users browsing this forum: No registered users and 0 guests