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

hid_host_example.c does not collect data from generic devices (ie. wired PS4 controller) (IDFGH-12808) #13784

Open
3 tasks done
BotSpace opened this issue May 12, 2024 · 5 comments
Labels
Status: Opened Issue is new

Comments

@BotSpace
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

My goal is to have my ESP32-S2 act as a USB host for my wired PS4 controller. I'm using windows 10, VS code, and ESP-IDF v5.2.1. I'm using UART for flashing and monitoring, leaving the USB peripheral free to act as USB Host. I have created a project that is an unmodified copy of hid_host_example.c.

After flashing and monitoring, I plug in a wired mouse to the USB peripheral, shake it a bit, and disconnect it:

Waiting for the device to reconnect..
I (128226) example: HID Device, protocol 'KEYBOARD' CONNECTED
I (128226) example: HID Device, protocol 'MOUSE' CONNECTED
I (128226) example: HID Device, protocol 'NONE' CONNECTED

Mouse
X: -00006       Y: 000322       | | |
Generic
E (240326) USBH: Device 1 gone
I (240326) example: HID Device, protocol 'KEYBOARD' DISCONNECTED
I (240326) example: HID Device, protocol 'MOUSE' DISCONNECTED
I (240336) example: HID Device, protocol 'NONE' DISCONNECTED

The mouse connection works in that the mouse state is printed to the terminal in real time as expected. There seems to be some erroneous info messages but otherwise it works.

Then I connect the PS4 controller and do my hardest to provide input.

I (385816) example: HID Device, protocol 'NONE' CONNECTED
E (398406) USBH: Device 1 gone
I (398406) example: HID Device, protocol 'NONE' DISCONNECTED
E (401006) HUB: Root port reset failed

The S2 sees the HID device but despite my efforts, no data is read to the terminal. When I unplug the PS4 controller, that is reported.

The PS4 controller is known good, when I plug it into my PC it shows up in device manager and I can see inputs using the windows game controller utility.

I have spent the better part of the last 2 days reading the Device Class Definition for Human Interface Devices (HID) but am completely stumped. Any advice is appriciated!

@espressif-bot espressif-bot added the Status: Opened Issue is new label May 12, 2024
@github-actions github-actions bot changed the title hid_host_example.c does not collect data from generic devices (ie. wired PS4 controller) hid_host_example.c does not collect data from generic devices (ie. wired PS4 controller) (IDFGH-12808) May 12, 2024
@peter-marcisovsky
Copy link
Collaborator

Hi @BotSpace
Could you please provide us a USB descriptor of the PS4 controller you are using?
Thank you.

@BotSpace
Copy link
Author

My controller is a PS4 SADES PS-403 (C200?). I don't have too much experience with HID but this is what I found by connecting the controller to my laptop and sniffing that connection with Wireshark. I based my results from this information. The results are mostly similar, except for the bcdHID 1.17 field and both bEndpointAddresses

Device Descriptor

0x12,        // bLength
0x01,        // bDescriptorType (Device)
0x00, 0x02,  // bcdUSB 2.00
0x00,        // bDeviceClass (Use class information in the Interface Descriptors)
0x00,        // bDeviceSubClass 
0x00,        // bDeviceProtocol 
0x40,        // bMaxPacketSize0 64
0x4C, 0x05,  // idVendor 0x054C
0xC4, 0x05,  // idProduct 0x05C4
0x00, 0x01,  // bcdDevice 1.00
0x01,        // iManufacturer (String Index)
0x02,        // iProduct (String Index)
0x00,        // iSerialNumber (String Index)
0x01,        // bNumConfigurations 1

Configuration Descriptor

0x09,        // bLength
0x02,        // bDescriptorType (Configuration)
0x29, 0x00,  // wTotalLength 41
0x01,        // bNumInterfaces 1
0x01,        // bConfigurationValue
0x00,        // iConfiguration (String Index)
0xC0,        // bmAttributes Self Powered
0xFA,        // bMaxPower 500mA

0x09,        // bLength
0x04,        // bDescriptorType (Interface)
0x00,        // bInterfaceNumber 0
0x00,        // bAlternateSetting
0x02,        // bNumEndpoints 2
0x03,        // bInterfaceClass
0x00,        // bInterfaceSubClass
0x00,        // bInterfaceProtocol
0x00,        // iInterface (String Index)

0x09,        // bLength
0x21,        // bDescriptorType (HID)
0x00, 0x01,  // bcdHID 1.17
0x00,        // bCountryCode
0x01,        // bNumDescriptors
0x22,        // bDescriptorType[0] (HID)
0xD3, 0x01,  // wDescriptorLength[0] 467

0x07,        // bLength
0x05,        // bDescriptorType (Endpoint)
0x83,        // bEndpointAddress (IN/D2H)
0x03,        // bmAttributes (Interrupt)
0x40, 0x00,  // wMaxPacketSize 64
0x05,        // bInterval 5 (unit depends on device speed)

0x07,        // bLength
0x05,        // bDescriptorType (Endpoint)
0x02,        // bEndpointAddress (OUT/H2D)
0x03,        // bmAttributes (Interrupt)
0x40, 0x00,  // wMaxPacketSize 64
0x05,        // bInterval 5 (unit depends on device speed)

@Marcel-1
Copy link

Marcel-1 commented Jun 7, 2024

This is exactly what I am trying todo as well. Have you made any progress on this that you would share?

@BotSpace
Copy link
Author

BotSpace commented Jun 8, 2024

Honestly I have been pretty frustrated trying to hook a wired gamepad up to an ESP32-S2. Espressif advertises the USB-OTG Host capabilities of the S2 which has been out for 5 years, but if you are trying to host for any device that is not a keyboard or mouse you seem pretty screwed to find a working example.

I gave up on ESP-IDF and turned to Arduino, where there you are still hard pressed to find working examples. Part of the problem is that I feel like there are four or five different forks of TinyUSB, each with their own quirks and spotty examples. I tried one or two but had little success with those either.

This is compounded by the fact that I believe tinyUSB is still broken on the esp32-S3 in some ways.

I have had my only success with this project by badjeff (we love badjeff) which he says is based off of esp-idf, but it what way I do not understand. There is very little in common between his code and the modern esp-idf example. And even then Jeff's work only works with some of my PS controllers, but not all of them. I have tried to add more with little success.

I suppose I shouldn't be too quick to hold it against espressif. As part of this project I have spent many hours trying to learn and understand USB and I have found it to be an order of magnitude more complex than the serial/i2s/spi/can protocols I am more familiar with. It seems like what makes controllers different is not just the format of the data they report, but even the sequence of messages needed to get them to spit out data.

I now have more respect for modern operating systems that can handle so many gamepads from different manufactures.

So yea in the end I gave up on ESP-IDF and TinyUSB after toying with both for many hours, and am basing my MVP off Jeff's work.

Perhaps someone will come along and tell me about what I missed with ESP-IDF or TinyUSB. I would welcome that in that case, but for now I am somewhat miffed.

@Marcel-1
Copy link

Marcel-1 commented Jun 9, 2024

Thank you for the feedback and your experience. I'm currently going through the same exercise as you did to understand and modify ESP-IDF example. I have been experimenting with ChatGPT to help me write some code for this but so far haven't been successful. If I do get this to work I will help you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

4 participants