PaulStoffregen / USBHost_t36

USB Host Library for Teensy 3.6 and 4.0
167 stars 86 forks source link

HIDDeviceInfo - Structure prints the HID Report descriptor #96

Closed KurtE closed 2 years ago

KurtE commented 2 years ago

@PaulStoffregen @mjs513,

As I mentioned in a thread today, I have been wanting to print out additional information about a HID device. Before I would use Linux, and plug in a device and use USBHID-dump plus another few commands to print out a structured ouput. But that second app is no longer in Ubuntu releases since about 18.04... So decided to try to use our own sketches to provide this type of output.

I added two methods to the USBHIDParser class to allow caller code to query it for the Report Descriptor data as well as the length.

I then added code to the example sketch HIDDeviceInfo that when one of my HIDDumper classes is claimed it asks for the descriptor data and tries to do a structured listing of it.

This hopefully will help users to be able to provide enough data to better integrate different HID Devices.

Some debug output from a Keyboard I plugged in

HIDDumpController Claim: 4d9:a06b usage: 10080HID Report Descritor (0x20009790) size: 81
  05 01 // Usage Page(1) - Generic Desktop
  09 80 // Usage(80) -(?)
  A1 01 // Collection(1) top Usage(10080)
    85 02   // Report ID(2)
    19 81   // Usage Minimum(81) - (System Power Down)
    29 83   // Usage Maximum(83) - (System Wake Up)
    15 00   // Logical Minimum(0)
    25 01   // Logical maximum(1)
    75 01   // Report Size(1)
    95 03   // Report Count(3)
    81 02   // Input(2)
    95 05   // Report Count(5)
    81 01   // Input(1)
    C0  // End Collection
  05 0C // Usage Page(c) - Consumer
  09 01 // Usage(1) -(Consumer Controls)
  A1 01 // Collection(1) top Usage(c0000)
    85 03   // Report ID(3)
    19 00   // Usage Minimum(0) - (?)
    2A FF 02    // Usage Maximum(2ff) - (?)
    15 00   // Logical Minimum(0)
    26 FF 7F    // Logical maximum(7fff)
    95 01   // Report Count(1)
    75 10   // Report Size(10)
    81 00   // Input(0)
    C0  // End Collection
  06 00 FF  // Usage Page(ff00) - Vendor Defined
  09 01 // Usage(1) -
  A1 01 // Collection(1) top Usage(ff000000)
    85 06   // Report ID(6)
    15 00   // Logical Minimum(0)
    26 FF 00    // Logical maximum(ff)
    09 2F   // Usage(2f) -
    75 08   // Report Size(8)
    95 03   // Report Count(3)
    81 02   // Input(2)
    09 30   // Usage(30) -
    95 07   // Report Count(7)
    B1 02   // Feature(2)
    C0  // End Collection
 - Yes
HIDDumpController Claim: 4d9:a06b usage: c0001 - NO (Usage: 10080)
HIDDumpController Claim: 4d9:a06b usage: c0001HID Report Descritor (0x20009790) size: 81
  05 01 // Usage Page(1) - Generic Desktop
  09 80 // Usage(80) -(?)
  A1 01 // Collection(1) top Usage(10080)
    85 02   // Report ID(2)
    19 81   // Usage Minimum(81) - (System Power Down)
    29 83   // Usage Maximum(83) - (System Wake Up)
    15 00   // Logical Minimum(0)
    25 01   // Logical maximum(1)
    75 01   // Report Size(1)
    95 03   // Report Count(3)
    81 02   // Input(2)
    95 05   // Report Count(5)
    81 01   // Input(1)
    C0  // End Collection
  05 0C // Usage Page(c) - Consumer
  09 01 // Usage(1) -(Consumer Controls)
  A1 01 // Collection(1) top Usage(c0000)
    85 03   // Report ID(3)
    19 00   // Usage Minimum(0) - (?)
    2A FF 02    // Usage Maximum(2ff) - (?)
    15 00   // Logical Minimum(0)
    26 FF 7F    // Logical maximum(7fff)
    95 01   // Report Count(1)
    75 10   // Report Size(10)
    81 00   // Input(0)
    C0  // End Collection
  06 00 FF  // Usage Page(ff00) - Vendor Defined
  09 01 // Usage(1) -
  A1 01 // Collection(1) top Usage(ff000000)
    85 06   // Report ID(6)
    15 00   // Logical Minimum(0)
    26 FF 00    // Logical maximum(ff)
    09 2F   // Usage(2f) -
    75 08   // Report Size(8)
    95 03   // Report Count(3)
    81 02   // Input(2)
    09 30   // Usage(30) -
    95 07   // Report Count(7)
    B1 02   // Feature(2)
    C0  // End Collection
 - Yes
HIDDumpController Claim: 4d9:a06b usage: 10006HID Report Descritor (0x20009e50) size: 37
  05 01 // Usage Page(1) - Generic Desktop
  09 06 // Usage(6) -(Keyboard)
  A1 01 // Collection(1) top Usage(10000)
    05 07   // Usage Page(7) - Keycode
    19 E0   // Usage Minimum(e0) - (Left Control)
    29 E7   // Usage Maximum(e7) - (Right)
    15 00   // Logical Minimum(0)
    25 01   // Logical maximum(1)
    75 01   // Report Size(1)
    95 08   // Report Count(8)
    81 02   // Input(2)
    19 00   // Usage Minimum(0) - (Keycode 0)
    29 6F   // Usage Maximum(6f) - (Keycode 111)
    15 00   // Logical Minimum(0)
    25 01   // Logical maximum(1)
    75 01   // Report Size(1)
    95 70   // Report Count(70)
    81 02   // Input(2)
    C0  // End Collection
 - Yes
KurtE commented 2 years ago

Forgot to mention the thread: https://forum.pjrc.com/threads/70824-USB-host-Teensy-4-1-with-Wacom-Intuos5

PaulStoffregen commented 2 years ago

is this ready to merge?

KurtE commented 2 years ago

It could be any time,

Although I have some changes locally for helping debug some more.

The Logitech G Wireless mouse - sets up a Keyboard with 64 byte packets... Which the messages appear to be killing the system.

I have a hack right now that allows the USBHIDParser class optionally claim (BOOT) keyboards which it appears to be making the code work better.

But I am thinking instead of HID Parser allowing to grab all keyboards... Instead, I am thinking of adding a: maybe a new keyboard class like: HIDKeyboard(), that works with HID input.
Also have a PID/VID table that the HID Parser would check to see if it should claim a BOOT/Keyboard or not.

We have run into this a few times with like the GIGABYTE keyboard.

Hopefully later today or tomorrow should have version to try.

PaulStoffregen commented 2 years ago

Please commit whatever else should be part of this improved printing and then I'll merge it.

I have an unopened Gigabyte Force K83 keyboard that's been sitting here next to my USB host stuff for over a year. Is that the one which causes problems?

KurtE commented 2 years ago

I pushed up the current stuff. I don't believe it is depending on other changes that I am testing.

I now do have code in place where the is a list of keyboards to process as HID device.
I have the HID code being able to detect it.

I have some code in place to take a list of keyboards to support by HID, and the USBHIDParser code will now claim it, and the KeyboardController will not.

Next up either extend keyboard and/or add new class to handle these.

Yes I do have a Gigabyte one that we resolved earlier forcing into boot mode. Once I finish this may try seeing if it work better with HID parser.

KurtE commented 2 years ago

@PaulStoffregen @mjs513 -

I went ahead and pushed up the WIP on allowing a Keyboard to be claimed by the HID Parser instead of Keyboard.

This so far is allowing the underlying Mouse object to run. Before it would more or less die if the mouse had not been used for a few minutes. I have been running this version with a Mouse/Keyboard forwarder sketch (not part of any github project)

This however does not fix the HUB issue. If I start up another slot with keyboard, the whole thing hangs with the several of the QH lists creating loops and hanging.

Note: I also checked in a slightly updated version of the print_qh_list that does a more thorough check for loops. It also will bail if it prints out over 32 items in a list.

If you prefer, I could pull this stuff back out. But this should allow the one forum member to make progress with their mouse.

So now should be a good time to merge