Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huion RTP-700 wrong device match and aspect ratio after firmware update #784

Open
1 task done
maruseu opened this issue Oct 14, 2024 · 13 comments
Open
1 task done

Comments

@maruseu
Copy link

maruseu commented Oct 14, 2024

  • Device name: Huion RTP-700

  • Device model identifier: RTP-700

  • libwacom version: 2.13.0-1

  • I understand that libwacom does affect whether the device works (see Troubleshooting)

Bug description

The graphics tablet doesn't show up in GNOME Settings after an update to its firmware.
The names that show up in evtest are

HUION Huion Tablet_RTP_700 Pen
HUION Huion Tablet_RTP_700

In lsusb:

Bus 005 Device 004: ID 256c:0064 HUION Huion Tablet_RTP_700

I dont know how to edit the .tablet's DeviceMatch to properly support it but I just removed the name from the match and that made it show up in the settings program however when i use the "keep aspect ratio" option it is corrected to a wrong aspect ratio. The tablet is physically 23:14 and when using "keep aspect ratio" on a 16:9 monitor the active area becomes 23:8 (or 16:5.6).

@whot
Copy link
Member

whot commented Oct 16, 2024

Hooray. The update probably changed the firmware version that we need to identify the tablet since Huion thinks it's fun to have multiple devices use the same USB product ids.

Can you run https://github.com/whot/huion-switcher please and let us know what the output of that is? Thanks.

@maruseu
Copy link
Author

maruseu commented Oct 16, 2024

Thank you for your work. It outputs:

HUION_FIRMWARE_ID="HUION_T19k_220310"
HUION_MAGIC_BYTES="130348da00688800ff1fd81303060001043c3e"

@whot
Copy link
Member

whot commented Oct 21, 2024

weird, that seems to be the same firmware id as before, see the data/huion-rtp-700.tablet file1. What does libwacom-list-local-devices say?

Footnotes

  1. concidentally, that one hasn't been reviewed by anyone with the device, it'd be great if you could update it!

@maruseu
Copy link
Author

maruseu commented Oct 21, 2024

In an unmodified system

/dev/input/event5 is a tablet but not supported by libwacom
/dev/input/event6 is a tablet but not supported by libwacom
Failed to find any devices known to libwacom.

With the aforementioned workaround

devices:
- name: 'Huion RTP-700'
  bus: 'usb'
  vid: '0x256c'
  pid: '0x0064'
  nodes: 
  - /dev/input/event11: 'HUION Huion Tablet_RTP_700 Pen'
  - /dev/input/event12: 'HUION Huion Tablet_RTP_700'
  styli:
   - id: 0xffffd
     name: 'General Pen with no Eraser'
     type: 'general'
     axes: ['x', 'y' , 'pressure']
     buttons: 2
     erasers: []

Im not sure if it is related but I also noticed the top pen button started acting as flipping the pen instead of a button, this pen has no eraser and libwacom correctly reports as such. Before the firmware update both buttons worked as buttons.

1. concidentally, that one hasn't been reviewed by anyone with the device, it'd be great if you could update it! [↩](#user-content-fnref-1-1a60bc734014950f0ecbe24617af631f)

Everything looks correct, except the size is 11x6.9 inches. I sent the sysinfo in linuxwacom/wacom-hid-descriptors#420

whot added a commit to whot/libwacom that referenced this issue Oct 22, 2024
@whot
Copy link
Member

whot commented Oct 22, 2024

Everything looks correct, except the size is 11x6.9 inches.

Thanks! -> #802

The graphics tablet doesn't show up in GNOME Settings after an update to its firmware.

to confirm: this used to work? right not it looks like the hid-uclogic kernel driver doesn't support it and we don't have a udev-hid-bpf entry for it yet - and that one would require huion-switcher (see #718, same story).

@maruseu
Copy link
Author

maruseu commented Oct 22, 2024

Yes it used to work, including the keep aspect option correctly changing the aspect ratio. I didn't have to use huion-switcher or perform any additional setup.
I'm currently talking to the huion support in hopes of downgrading the firmware so we can compare it later

whot added a commit to whot/libwacom that referenced this issue Oct 24, 2024
whot added a commit that referenced this issue Oct 27, 2024
@whot
Copy link
Member

whot commented Oct 29, 2024

alright, so an outline of how things work, maybe that helps narrow down what changed.

The Huion devices (that I have seen) provide multiple HID devices, some of which are emulation nodes (e.g. the pad button send key events) so that the tablet works OOTB without any driver support. One HID device is the one that reports all data through a vendor collection but the device needs to be switched to that mode (see huion-switcher) before that device sends events. Once that's done the other nodes stop sending events until the device is unplugged.

hid-recorder should show you those different devices.

For many older devices the kernel hid_uclogic kernel module did this, at least for a whole set of devices - where hid_uclogic module applies to a device the HID reports will be changed by the driver.

For unhandled (and newer) devices the kernel does nothing, instead you need to use huion-switcher to switch to raw mode and then a BPF file through udev-hid-bpf to change the HID report descriptors so the data isn't in some proprietary vendor protocol but is recognised by the kernel.

That's the kernel level.

In user-space libwacom tries to detect the device and libinput/gnome rely on this to some degree to allow for configuration. However... Huion re-uses PIDs so the only way libwacom can differentiate between devices is to use the firmare ID prefix (HUION_T19k). However, that prefix is only set by the hid-uclogic module or by huion-switcher via it's udev rule/udev properties.

In other words: libwacom will not detect your device correctly, we have at current count 121 devices that may have the 0064 PID. The only way for libwacom to (ootb) detect it is if either the kernel module or huion-switcher apply.

So I don't have a good answer what's going on here but maybe the above may help narrow down what could've changed.

Attaching the hid-recorder output for all hidraw nodes on this device here should also help, maybe I can reproduce locally.

@maruseu
Copy link
Author

maruseu commented Oct 29, 2024

Sorry if i forget something im not sure if i understood all that but before using huion-switcher i get these 3 nodes, the second one has pen events and pen button events but not tablet button events

# Available devices:
# /dev/hidraw0:     ELAN Touchscreen
# /dev/hidraw1:     HUION Huion Tablet_RTP_700
# /dev/hidraw2:     HUION Huion Tablet_RTP_700
# /dev/hidraw3:     HUION Huion Tablet_RTP_700
# Select the device event number [0-9]: 1
# HUION Huion Tablet_RTP_700
# Report descriptor length: 18 bytes
# 0x06, 0x00, 0xff,              // Usage Page (Vendor Defined Page FF00)     0
# 0x09, 0x01,                    // Usage (Vendor Usage 0x01)                 3
# 0xa1, 0x01,                    // Collection (Application)                  5
# 0x85, 0x08,                    //   Report ID (8)                           7
# 0x75, 0x58,                    //   Report Size (88)                        9
# 0x95, 0x01,                    //   Report Count (1)                        11
# 0x09, 0x01,                    //   Usage (Vendor Usage 0x01)               13
# 0x81, 0x02,                    //   Input (Data,Var,Abs)                    15
# 0xc0,                          // End Collection                            17
R: 18 06 00 ff 09 01 a1 01 85 08 75 58 95 01 09 01 81 02 c0
N: HUION Huion Tablet_RTP_700
I: 3 256c 64
# Report descriptor:
# ------- Input Report ------- 
#   Report ID: 8
#   | Report size: 96 bits
#   | Bits:   8..=95  | Usage: ff00/0001: Vendor Defined Usage ff00 / 0001            | Logical Range:     0..=0     
##############################################################################
# Recorded events below in format:
# E: <seconds>.<microseconds> <length-in-bytes> [bytes ...]
#
# Current time: 18:08:46
# Available devices:
# /dev/hidraw0:     ELAN Touchscreen
# /dev/hidraw1:     HUION Huion Tablet_RTP_700
# /dev/hidraw2:     HUION Huion Tablet_RTP_700
# /dev/hidraw3:     HUION Huion Tablet_RTP_700
# Select the device event number [0-9]: 2
# HUION Huion Tablet_RTP_700
# Report descriptor length: 93 bytes
# 0x05, 0x0d,                    // Usage Page (Digitizers)                   0
# 0x09, 0x02,                    // Usage (Pen)                               2
# 0xa1, 0x01,                    // Collection (Application)                  4
# 0x85, 0x0a,                    //   Report ID (10)                          6
# 0x09, 0x20,                    //   Usage (Stylus)                          8
# 0xa1, 0x01,                    //   Collection (Application)                10
# 0x09, 0x42,                    //     Usage (Tip Switch)                    12
# 0x09, 0x44,                    //     Usage (Barrel Switch)                 14
# 0x09, 0x45,                    //     Usage (Eraser)                        16
# 0x09, 0x3c,                    //     Usage (Invert)                        18
# 0x15, 0x00,                    //     Logical Minimum (0)                   20
# 0x25, 0x01,                    //     Logical Maximum (1)                   22
# 0x75, 0x01,                    //     Report Size (1)                       24
# 0x95, 0x06,                    //     Report Count (6)                      26
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  28
# 0x09, 0x32,                    //     Usage (In Range)                      30
# 0x75, 0x01,                    //     Report Size (1)                       32
# 0x95, 0x01,                    //     Report Count (1)                      34
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  36
# 0x81, 0x03,                    //     Input (Cnst,Var,Abs)                  38
# 0x05, 0x01,                    //     Usage Page (Generic Desktop)          40
# 0x09, 0x30,                    //     Usage (X)                             42
# 0x09, 0x31,                    //     Usage (Y)                             44
# 0x55, 0x0d,                    //     Unit Exponent (-3)                    46
# 0x65, 0x33,                    //     Unit (EnglishLinear: in³)             48
# 0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               50
# 0x35, 0x00,                    //     Physical Minimum (0)                  53
# 0x46, 0x00, 0x08,              //     Physical Maximum (2048)               55
# 0x75, 0x10,                    //     Report Size (16)                      58
# 0x95, 0x02,                    //     Report Count (2)                      60
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  62
# 0x05, 0x0d,                    //     Usage Page (Digitizers)               64
# 0x09, 0x30,                    //     Usage (Tip Pressure)                  66
# 0x26, 0xff, 0x1f,              //     Logical Maximum (8191)                68
# 0x75, 0x10,                    //     Report Size (16)                      71
# 0x95, 0x01,                    //     Report Count (1)                      73
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  75
# 0x09, 0x3d,                    //     Usage (X Tilt)                        77
# 0x09, 0x3e,                    //     Usage (Y Tilt)                        79
# 0x15, 0x81,                    //     Logical Minimum (-127)                81
# 0x25, 0x7f,                    //     Logical Maximum (127)                 83
# 0x75, 0x08,                    //     Report Size (8)                       85
# 0x95, 0x02,                    //     Report Count (2)                      87
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  89
# 0xc0,                          //   End Collection                          91
# 0xc0,                          // End Collection                            92
R: 93 05 0d 09 02 a1 01 85 0a 09 20 a1 01 09 42 09 44 09 45 09 3c 15 00 25 01 75 01 95 06 81 02 09 32 75 01 95 01 81 02 81 03 05 01 09 30 09 31 55 0d 65 33 26 ff 7f 35 00 46 00 08 75 10 95 02 81 02 05 0d 09 30 26 ff 1f 75 10 95 01 81 02 09 3d 09 3e 15 81 25 7f 75 08 95 02 81 02 c0 c0
N: HUION Huion Tablet_RTP_700
I: 3 256c 64
# Report descriptor:
# ------- Input Report ------- 
#   Report ID: 10
#   | Report size: 80 bits
#   | Bit:    8       | Usage: 000d/0042: Digitizers / Tip Switch                     | Logical Range:     0..=1     
#   | Bit:    9       | Usage: 000d/0044: Digitizers / Barrel Switch                  | Logical Range:     0..=1     
#   | Bit:   10       | Usage: 000d/0045: Digitizers / Eraser                         | Logical Range:     0..=1     
#   | Bit:   11       | Usage: 000d/003c: Digitizers / Invert                         | Logical Range:     0..=1     
#   | Bit:   12       | Usage: 000d/003c: Digitizers / Invert                         | Logical Range:     0..=1     
#   | Bit:   13       | Usage: 000d/003c: Digitizers / Invert                         | Logical Range:     0..=1     
#   | Bit:   14       | Usage: 000d/0032: Digitizers / In Range                       | Logical Range:     0..=1     
#   | Bit:   15       | ######### Padding                                             
#   | Bits:  16..=31  | Usage: 0001/0030: Generic Desktop / X                         | Logical Range:     0..=32767 | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  32..=47  | Usage: 0001/0031: Generic Desktop / Y                         | Logical Range:     0..=32767 | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  48..=63  | Usage: 000d/0030: Digitizers / Tip Pressure                   | Logical Range:     0..=8191  | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  64..=71  | Usage: 000d/003d: Digitizers / X Tilt                         | Logical Range:  -127..=127   | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  72..=79  | Usage: 000d/003e: Digitizers / Y Tilt                         | Logical Range:  -127..=127   | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
##############################################################################
# Recorded events below in format:
# E: <seconds>.<microseconds> <length-in-bytes> [bytes ...]
#
# Current time: 18:09:30
# Available devices:
# /dev/hidraw0:     ELAN Touchscreen
# /dev/hidraw1:     HUION Huion Tablet_RTP_700
# /dev/hidraw2:     HUION Huion Tablet_RTP_700
# /dev/hidraw3:     HUION Huion Tablet_RTP_700
# Select the device event number [0-9]: 3
# HUION Huion Tablet_RTP_700
# Report descriptor length: 40 bytes
# 0x05, 0x01,                    // Usage Page (Generic Desktop)              0
# 0x09, 0x06,                    // Usage (Keyboard)                          2
# 0xa1, 0x01,                    // Collection (Application)                  4
# 0x85, 0x03,                    //   Report ID (3)                           6
# 0x05, 0x07,                    //   Usage Page (Keyboard/Keypad)            8
# 0x19, 0xe0,                    //   UsageMinimum (224)                      10
# 0x29, 0xe7,                    //   UsageMaximum (231)                      12
# 0x15, 0x00,                    //   Logical Minimum (0)                     14
# 0x25, 0x01,                    //   Logical Maximum (1)                     16
# 0x75, 0x01,                    //   Report Size (1)                         18
# 0x95, 0x08,                    //   Report Count (8)                        20
# 0x81, 0x02,                    //   Input (Data,Var,Abs)                    22
# 0x05, 0x07,                    //   Usage Page (Keyboard/Keypad)            24
# 0x19, 0x00,                    //   UsageMinimum (0)                        26
# 0x29, 0xff,                    //   UsageMaximum (255)                      28
# 0x26, 0xff, 0x00,              //   Logical Maximum (255)                   30
# 0x75, 0x08,                    //   Report Size (8)                         33
# 0x95, 0x06,                    //   Report Count (6)                        35
# 0x81, 0x00,                    //   Input (Data,Arr,Abs)                    37
# 0xc0,                          // End Collection                            39
R: 40 05 01 09 06 a1 01 85 03 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 05 07 19 00 29 ff 26 ff 00 75 08 95 06 81 00 c0
N: HUION Huion Tablet_RTP_700
I: 3 256c 64
# Report descriptor:
# ------- Input Report ------- 
#   Report ID: 3
#   | Report size: 64 bits
#   | Bit:    8       | Usage: 0007/00e0: Keyboard/Keypad / Keyboard LeftControl      | Logical Range:     0..=1     
#   | Bit:    9       | Usage: 0007/00e1: Keyboard/Keypad / Keyboard LeftShift        | Logical Range:     0..=1     
#   | Bit:   10       | Usage: 0007/00e2: Keyboard/Keypad / Keyboard LeftAlt          | Logical Range:     0..=1     
#   | Bit:   11       | Usage: 0007/00e3: Keyboard/Keypad / Keyboard Left GUI         | Logical Range:     0..=1     
#   | Bit:   12       | Usage: 0007/00e4: Keyboard/Keypad / Keyboard RightControl     | Logical Range:     0..=1     
#   | Bit:   13       | Usage: 0007/00e5: Keyboard/Keypad / Keyboard RightShift       | Logical Range:     0..=1     
#   | Bit:   14       | Usage: 0007/00e6: Keyboard/Keypad / Keyboard RightAlt         | Logical Range:     0..=1     
#   | Bit:   15       | Usage: 0007/00e7: Keyboard/Keypad / Keyboard Right GUI        | Logical Range:     0..=1     
#   | Bits:  16..=63  | Usages:                                                       | Logical Range:     0..=255   
#   |                 | 0007/0000: <unknown>                                          
#   |                 | 0007/0001: Keyboard/Keypad / ErrorRollOver                    
#   |                 | 0007/0002: Keyboard/Keypad / POSTFail                         
#   |                 | 0007/0003: Keyboard/Keypad / ErrorUndefined                   
#   |                 | 0007/0004: Keyboard/Keypad / Keyboard A                       
#   |                 | ... use --full to see all usages                              
##############################################################################
# Recorded events below in format:
# E: <seconds>.<microseconds> <length-in-bytes> [bytes ...]
#
# Current time: 18:10:47

after huion-switcher , the first one has the pen and all button events raw-dev-hidraw1.txt

# Available devices:
# /dev/hidraw0:     ELAN Touchscreen
# /dev/hidraw1:     HUION Huion Tablet_RTP_700
# /dev/hidraw2:     HUION Huion Tablet_RTP_700
# /dev/hidraw3:     HUION Huion Tablet_RTP_700
# Select the device event number [0-9]: 1
# HUION Huion Tablet_RTP_700
# Report descriptor length: 18 bytes
# 0x06, 0x00, 0xff,              // Usage Page (Vendor Defined Page FF00)     0
# 0x09, 0x01,                    // Usage (Vendor Usage 0x01)                 3
# 0xa1, 0x01,                    // Collection (Application)                  5
# 0x85, 0x08,                    //   Report ID (8)                           7
# 0x75, 0x58,                    //   Report Size (88)                        9
# 0x95, 0x01,                    //   Report Count (1)                        11
# 0x09, 0x01,                    //   Usage (Vendor Usage 0x01)               13
# 0x81, 0x02,                    //   Input (Data,Var,Abs)                    15
# 0xc0,                          // End Collection                            17
R: 18 06 00 ff 09 01 a1 01 85 08 75 58 95 01 09 01 81 02 c0
N: HUION Huion Tablet_RTP_700
I: 3 256c 64
# Report descriptor:
# ------- Input Report ------- 
#   Report ID: 8
#   | Report size: 96 bits
#   | Bits:   8..=95  | Usage: ff00/0001: Vendor Defined Usage ff00 / 0001            | Logical Range:     0..=0     
##############################################################################
# Recorded events below in format:
# E: <seconds>.<microseconds> <length-in-bytes> [bytes ...]
#
# Current time: 18:32:24
# Available devices:
# /dev/hidraw0:     ELAN Touchscreen
# /dev/hidraw1:     HUION Huion Tablet_RTP_700
# /dev/hidraw2:     HUION Huion Tablet_RTP_700
# /dev/hidraw3:     HUION Huion Tablet_RTP_700
# Select the device event number [0-9]: 2
# HUION Huion Tablet_RTP_700
# Report descriptor length: 93 bytes
# 0x05, 0x0d,                    // Usage Page (Digitizers)                   0
# 0x09, 0x02,                    // Usage (Pen)                               2
# 0xa1, 0x01,                    // Collection (Application)                  4
# 0x85, 0x0a,                    //   Report ID (10)                          6
# 0x09, 0x20,                    //   Usage (Stylus)                          8
# 0xa1, 0x01,                    //   Collection (Application)                10
# 0x09, 0x42,                    //     Usage (Tip Switch)                    12
# 0x09, 0x44,                    //     Usage (Barrel Switch)                 14
# 0x09, 0x45,                    //     Usage (Eraser)                        16
# 0x09, 0x3c,                    //     Usage (Invert)                        18
# 0x15, 0x00,                    //     Logical Minimum (0)                   20
# 0x25, 0x01,                    //     Logical Maximum (1)                   22
# 0x75, 0x01,                    //     Report Size (1)                       24
# 0x95, 0x06,                    //     Report Count (6)                      26
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  28
# 0x09, 0x32,                    //     Usage (In Range)                      30
# 0x75, 0x01,                    //     Report Size (1)                       32
# 0x95, 0x01,                    //     Report Count (1)                      34
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  36
# 0x81, 0x03,                    //     Input (Cnst,Var,Abs)                  38
# 0x05, 0x01,                    //     Usage Page (Generic Desktop)          40
# 0x09, 0x30,                    //     Usage (X)                             42
# 0x09, 0x31,                    //     Usage (Y)                             44
# 0x55, 0x0d,                    //     Unit Exponent (-3)                    46
# 0x65, 0x33,                    //     Unit (EnglishLinear: in³)             48
# 0x26, 0xff, 0x7f,              //     Logical Maximum (32767)               50
# 0x35, 0x00,                    //     Physical Minimum (0)                  53
# 0x46, 0x00, 0x08,              //     Physical Maximum (2048)               55
# 0x75, 0x10,                    //     Report Size (16)                      58
# 0x95, 0x02,                    //     Report Count (2)                      60
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  62
# 0x05, 0x0d,                    //     Usage Page (Digitizers)               64
# 0x09, 0x30,                    //     Usage (Tip Pressure)                  66
# 0x26, 0xff, 0x1f,              //     Logical Maximum (8191)                68
# 0x75, 0x10,                    //     Report Size (16)                      71
# 0x95, 0x01,                    //     Report Count (1)                      73
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  75
# 0x09, 0x3d,                    //     Usage (X Tilt)                        77
# 0x09, 0x3e,                    //     Usage (Y Tilt)                        79
# 0x15, 0x81,                    //     Logical Minimum (-127)                81
# 0x25, 0x7f,                    //     Logical Maximum (127)                 83
# 0x75, 0x08,                    //     Report Size (8)                       85
# 0x95, 0x02,                    //     Report Count (2)                      87
# 0x81, 0x02,                    //     Input (Data,Var,Abs)                  89
# 0xc0,                          //   End Collection                          91
# 0xc0,                          // End Collection                            92
R: 93 05 0d 09 02 a1 01 85 0a 09 20 a1 01 09 42 09 44 09 45 09 3c 15 00 25 01 75 01 95 06 81 02 09 32 75 01 95 01 81 02 81 03 05 01 09 30 09 31 55 0d 65 33 26 ff 7f 35 00 46 00 08 75 10 95 02 81 02 05 0d 09 30 26 ff 1f 75 10 95 01 81 02 09 3d 09 3e 15 81 25 7f 75 08 95 02 81 02 c0 c0
N: HUION Huion Tablet_RTP_700
I: 3 256c 64
# Report descriptor:
# ------- Input Report ------- 
#   Report ID: 10
#   | Report size: 80 bits
#   | Bit:    8       | Usage: 000d/0042: Digitizers / Tip Switch                     | Logical Range:     0..=1     
#   | Bit:    9       | Usage: 000d/0044: Digitizers / Barrel Switch                  | Logical Range:     0..=1     
#   | Bit:   10       | Usage: 000d/0045: Digitizers / Eraser                         | Logical Range:     0..=1     
#   | Bit:   11       | Usage: 000d/003c: Digitizers / Invert                         | Logical Range:     0..=1     
#   | Bit:   12       | Usage: 000d/003c: Digitizers / Invert                         | Logical Range:     0..=1     
#   | Bit:   13       | Usage: 000d/003c: Digitizers / Invert                         | Logical Range:     0..=1     
#   | Bit:   14       | Usage: 000d/0032: Digitizers / In Range                       | Logical Range:     0..=1     
#   | Bit:   15       | ######### Padding                                             
#   | Bits:  16..=31  | Usage: 0001/0030: Generic Desktop / X                         | Logical Range:     0..=32767 | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  32..=47  | Usage: 0001/0031: Generic Desktop / Y                         | Logical Range:     0..=32767 | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  48..=63  | Usage: 000d/0030: Digitizers / Tip Pressure                   | Logical Range:     0..=8191  | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  64..=71  | Usage: 000d/003d: Digitizers / X Tilt                         | Logical Range:  -127..=127   | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
#   | Bits:  72..=79  | Usage: 000d/003e: Digitizers / Y Tilt                         | Logical Range:  -127..=127   | Physical Range:     0..=2048  | Unit: EnglishLinear: in³  
##############################################################################
# Recorded events below in format:
# E: <seconds>.<microseconds> <length-in-bytes> [bytes ...]
#
# Current time: 18:32:33
# Available devices:
# /dev/hidraw0:     ELAN Touchscreen
# /dev/hidraw1:     HUION Huion Tablet_RTP_700
# /dev/hidraw2:     HUION Huion Tablet_RTP_700
# /dev/hidraw3:     HUION Huion Tablet_RTP_700
# Select the device event number [0-9]: 3
# HUION Huion Tablet_RTP_700
# Report descriptor length: 40 bytes
# 0x05, 0x01,                    // Usage Page (Generic Desktop)              0
# 0x09, 0x06,                    // Usage (Keyboard)                          2
# 0xa1, 0x01,                    // Collection (Application)                  4
# 0x85, 0x03,                    //   Report ID (3)                           6
# 0x05, 0x07,                    //   Usage Page (Keyboard/Keypad)            8
# 0x19, 0xe0,                    //   UsageMinimum (224)                      10
# 0x29, 0xe7,                    //   UsageMaximum (231)                      12
# 0x15, 0x00,                    //   Logical Minimum (0)                     14
# 0x25, 0x01,                    //   Logical Maximum (1)                     16
# 0x75, 0x01,                    //   Report Size (1)                         18
# 0x95, 0x08,                    //   Report Count (8)                        20
# 0x81, 0x02,                    //   Input (Data,Var,Abs)                    22
# 0x05, 0x07,                    //   Usage Page (Keyboard/Keypad)            24
# 0x19, 0x00,                    //   UsageMinimum (0)                        26
# 0x29, 0xff,                    //   UsageMaximum (255)                      28
# 0x26, 0xff, 0x00,              //   Logical Maximum (255)                   30
# 0x75, 0x08,                    //   Report Size (8)                         33
# 0x95, 0x06,                    //   Report Count (6)                        35
# 0x81, 0x00,                    //   Input (Data,Arr,Abs)                    37
# 0xc0,                          // End Collection                            39
R: 40 05 01 09 06 a1 01 85 03 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 05 07 19 00 29 ff 26 ff 00 75 08 95 06 81 00 c0
N: HUION Huion Tablet_RTP_700
I: 3 256c 64
# Report descriptor:
# ------- Input Report ------- 
#   Report ID: 3
#   | Report size: 64 bits
#   | Bit:    8       | Usage: 0007/00e0: Keyboard/Keypad / Keyboard LeftControl      | Logical Range:     0..=1     
#   | Bit:    9       | Usage: 0007/00e1: Keyboard/Keypad / Keyboard LeftShift        | Logical Range:     0..=1     
#   | Bit:   10       | Usage: 0007/00e2: Keyboard/Keypad / Keyboard LeftAlt          | Logical Range:     0..=1     
#   | Bit:   11       | Usage: 0007/00e3: Keyboard/Keypad / Keyboard Left GUI         | Logical Range:     0..=1     
#   | Bit:   12       | Usage: 0007/00e4: Keyboard/Keypad / Keyboard RightControl     | Logical Range:     0..=1     
#   | Bit:   13       | Usage: 0007/00e5: Keyboard/Keypad / Keyboard RightShift       | Logical Range:     0..=1     
#   | Bit:   14       | Usage: 0007/00e6: Keyboard/Keypad / Keyboard RightAlt         | Logical Range:     0..=1     
#   | Bit:   15       | Usage: 0007/00e7: Keyboard/Keypad / Keyboard Right GUI        | Logical Range:     0..=1     
#   | Bits:  16..=63  | Usages:                                                       | Logical Range:     0..=255   
#   |                 | 0007/0000: <unknown>                                          
#   |                 | 0007/0001: Keyboard/Keypad / ErrorRollOver                    
#   |                 | 0007/0002: Keyboard/Keypad / POSTFail                         
#   |                 | 0007/0003: Keyboard/Keypad / ErrorUndefined                   
#   |                 | 0007/0004: Keyboard/Keypad / Keyboard A                       
#   |                 | ... use --full to see all usages                              
##############################################################################
# Recorded events below in format:
# E: <seconds>.<microseconds> <length-in-bytes> [bytes ...]
#
# Current time: 18:32:40

@whot
Copy link
Member

whot commented Nov 1, 2024

Right, so it's mostly the same behaviour as all the others. Note that since you don't have a BPF loaded right now the report descriptors do not change.

The goal of the BPFs is two-fold:

  • change the report descriptor of the vendor node (/dev/hidraw1 above) to something that's understandable.
  • fix the other two report descriptors and/or their events so they work reliably

So part of any confusion is probably because we're mangling two things together here but only one behavior happens at any time - depending which mode the tablet is in.

When you run huion-switcher it reads a USB string descriptor in the US English language ID, that's a normal read-only operation and usually does things like fetch the manufacturer ID. In Huion's case if you read the 200 string descriptor index it will switch into tablet mode and send everything through /dev/hidraw1 instead of the default firmware mode.

You don't get tablet button events because in default firmware mode the pad buttons emulate key events, again this is all expected.

So let's look at the first goal, change the rdesc: See the comment starting in line 26 in this bpf and the corresponding rdesc fixup in fixed_rdesc_vendor - the goal is to get this array for your device so the bits in the reports match the expected. There's a good chance you can just take that one and run with it, iirc the huion devices don't change much between tablets except for the logical min/max settings. But in the end that report descriptor says things like "we have value range 0-1 for a 1-bit field with the usages tip,stylus-button,stylus-button-2, and there's three of them". I.e. the first byte has 3 bits for those buttons followed by 4 bits padding and 1 bit to signal proximity. Then we have bytes 2+3 being the X coordinate, etc.

For the second goal we have fixed_rdesc_pen for the pen but I think this one only changes the eraser button to BTN_STYLUS2, the rest is basically the same as before. But it's easier to define the whole lot and memcpy it over toggling a few bits. Because this is all sorted in the rdesc, we have /* Nothing to do for the PEN_REPORT_ID, it's already mapped */ - the kernel will interpret the bits correctly in that report.

Then we have fixed_rdesc_pad which works a bit differently - it sets up a generic "pad" device that is detected by userspace as tablet pad (we need x/y and BTN_STYLUS for that to happen so the first bytes do that) with a wheel (doesn't apply to you so you can leave that as padding with Input(Const) instead and 6 (0x1 - 0x6) buttons. This HID descriptor says "there's one byte and it has usages 1-6 (simply numeric buttons)" but only one can be pressed at a time.

Then you look at HID_BPF_DEVICE_EVENT:

  • if the incoming event is from the firmware pad node we look at the incoming event, detect based on the key event in it which button it is and then create a pad report with that button in it. The current event is replaced with that pad report (the memcpy)
  • if the incoming event is from the vendor node we also generate a pad report that matches our fixed_rdesc_pad with the byte 4 and 5 set to the wheel/button data. Then we overwrite the current event with that fixed pad report.

For simplicity: if you start by copying all the bits for fixed_rdesc_vendor only then you should get your tablet to work once huion-switcher changes it to vendor mode. Ignore the rest for now.

edit: the RTP700 uses a shared PID so I don't think we can implement the generic handling anyway, we have to switch to vendor mode because that also gives us the firmware ID that we need to reliably detect this device. IOW any BPF for your device will only do the vendor version anyway.

@maruseu
Copy link
Author

maruseu commented Nov 1, 2024

Ok so I made these changes to the source code

12 - #define PID_INSPIROY_2_S 0x0064

24 - char EXPECTED_FIRMWARE_ID[] = "HUION_19k_";

299 - LogicalMinimum_i16(2)
300 - LogicalMaximum_i16(55880)

302 - PhysicalMaximum_i16(164)

306 - LogicalMinimum_i16(0)
307 - LogicalMaximum_i16(34920)

Compiled it and installed as per instructions in udev-hid-bpf's readme file and then installed with

sudo ./builddir/udev-hid-bpf install ./builddir/src/bpf/0010-Huion__Inspiroy-2-S.bpf.o

It works in vendor mode now. It fixed the barrel button being misidentified as eraser problem, buttons works but libwacom still doesnt detect it without modifying the .tablet and the aspect ratio option isn't doing anything at all now (though I can work around this by changing the value in line 307)

@whot
Copy link
Member

whot commented Nov 4, 2024

nice, good work on getting it to work - can you file a PR in udev-hid-bpf please? You'll need to file a user verification issue (see the issue template) in the fdo gitlab instance first so you can fork the repo there.

libwacom still doesnt detect it without modifying the .tablet

If you install huion-switcher with the udev rule it provides that should set the UNIQ udev property on the device on plug. This should then be picked up by libwacom - can you verify this?

$ udevadm info /sys/class/input/event123/ | grep UNIQ

(if not can you attach, not copy, the full udevadm info --export-db output please)

Note that this only works if triggered via udev since huion-switcher cannot retrospectively add a udev property to a device.

Arguably the RTP700 doesn't need the firmware match since it has its name in the string so we could reduce the device match to just:

DeviceMatch=usb|0256|0064|HUION Huion Tablet_RTP_700 Pen;usb|0256|0064|HUION Huion Tablet_RTP_700 Pad;

in which case it should get detected either way.

the aspect ratio option isn't doing anything at all

ftr, that option is implemented fully in the compositor, there is nothing libwacom can do to make this work. libwacom only says "this is an external tablet" and then the rest is implemented elsewhere. In the libwacom repo there's builddir/debug-device which shows you the full output of all libwacom APIs.

The logical min/max should specify the values that the device sends. The physical max is the width/height in mm. The goal is that the device presents itself correctly - any aspect ratio mapping fix is ok as temporary fix locally but please don't try to upstream that, as above it needs to be fixed in the compositor.

@maruseu
Copy link
Author

maruseu commented Nov 5, 2024

If you install huion-switcher with the udev rule it provides that should set the UNIQ udev property on the device on plug. This should then be picked up by libwacom - can you verify this?

My bad, it does match with the udev rule

Arguably the RTP700 doesn't need the firmware match since it has its name in the string so we could reduce the device match to just:

DeviceMatch=usb|0256|0064|HUION Huion Tablet_RTP_700 Pen;usb|0256|0064|HUION Huion Tablet_RTP_700 Pad;

It matches w/ the existing file, the correct DeviceMatch with names would be

DeviceMatch=usb|256c|0064|HUION Huion Tablet_RTP_700 Stylus;usb|256c|0064|HUION Huion Tablet_RTP_700;

@whot
Copy link
Member

whot commented Nov 5, 2024

fwiw if you use your BPF program from udev-hid-bpf!156 the device should come up as ... Pen, not Stylus (because Huion uses Usage_Dig_Stylus and we usually use Usage_Dig_Pen). The pad node should come up as ... Pad so to make this match either way we'll need all four in the DeviceMatch line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants