fhoedemakers / pico-infonesPlus

NES Emulator with SD card and menu support for the Raspberry PI Pico, Pico 2 and other RP2040/RP2350 based microcontrollers. Play your games from SD card on a HDMI display.
GNU General Public License v3.0
247 stars 27 forks source link

Support another USB Gamepad #26

Open kpbicka opened 1 year ago

kpbicka commented 1 year ago

Hi. How to add support USB gamepad with Product ID: 0x0011 Vendor ID: 0x0079

Thanks

fhoedemakers commented 1 year ago

What is the brand and type of this gamepad?

kpbicka commented 1 year ago

What is the brand and type of this gamepad?

with such identifiers, several names are produced, but specifically in my case it is called Defenderimage

kpbicka commented 1 year ago

What is the brand and type of this gamepad?

no any ideas?)

fhoedemakers commented 1 year ago

Hi, I don't have that specific gamepad, so i cannot test it.

Last week i tried adding different other USB gamepads, (8BitDO, XBox, Nintendo WII Switch, etc). Must of them were not detected at all by the TinyUsb driver, for those who were detected, the tuh_hid_report_received_cb() callback was not executed, so the data from the controller could not be read. So even if i have that specific controller at hand, chances it will work are slim.

Maybe i'm doing something wrong here. The TinyUsb documentation is very limited.

I'll do some more testing when i have time for it.

Frank

hetii commented 1 year ago

Hello dear. I'm also in the middle of adding new pad for this project. In my case it looks like below, and it's wireless. obraz

This controller report itself under ubuntu like: obraz

Then tinyusb driver also not enumerate it as a HID device. This is due the fact that in hidh_open of src/class/hid/hid_host.c tinnyusb library the bInterfaceClass is asserted and expected to have value 0x05. In my case for this controller it's 0xff Indicate that we have a deal with vendor specific controller. Then discover this PR https://github.com/hathach/tinyusb/pull/1647 indicated that vendor specific driver is some sort in refactoring stage and not fully done yet in tinnyusb, but based on this PR I start creating own driver.

Meantime in this process I notice that pico sdk 1.4.0 use old tinnyusb library in version 0.12.0. So now after a bit of work I successfully use tinnyusb in version 0.15.0 and code from above PR. In this point my gamepad is just attached but additional work need to be done to handle endpoint and process data.

As I have blurry idea how this should be done finally I also discover example called bare_api

After adding it to this project and ignoring checking of if (desc_itf->bInterfaceClass == TUSB_CLASS_HID) in parse_config_descriptor I was able to register endpoint of my controller and got events from it when pressing buttons ;)

Now about tusb_config.h.
To use tinnyusb in version 0.15.0 you need to have #define TUSB_OPT_MUTEX 1 otherwise pico hangs when new usb device is plugged.

Then #define CFG_TUH_API_EDPT_XFER 1 is required to use bare_api example.

Now, i'm not sure why, but when I plug my pad into pico, the idVendor and idProduct is have values 0x045e:0x028e instead of 054c:0cda, you can see that below: obraz

So my work is still in progress and I imagine that we can add support for regular keyboards for those who don't have pads and wanna to just test this project.

I also wonder if all that usb enumeration parts can be handled by second core of pico as the screen blinks when new usb device is attached.

If you have any suggestion about my vendor specific pad or how would you see that implemented at the end (by bare api or vendor driver) please let me know and don't hesitate to contact me.

Best Regards.

fhoedemakers commented 1 year ago

Hi, Thanks for your message.

Meantime in this process I notice that pico sdk 1.4.0 use old tinnyusb library in version 0.12.0. So now after a bit of work I successfully use tinnyusb in version 0.15.0 and code from above PR. In this point my gamepad is just attached but additional work need to be done to handle endpoint and process data.

The latest version of the emulator now uses pico sdk 1.5 with tinyusb version 0.15 The memory issues when using the 1.5 SDK are resolved by removing an unused nes mapper. So there is no need anymore to use the 1.4 SDK. see #7

I also wonder if all that usb enumeration parts can be handled by second core of pico as the screen blinks when new usb device is attached.

The second core is already used for screen handling. Maybe it can be added, but not sure.

If you have any suggestion about my vendor specific pad or how would you see that implemented at the end (by bare api or vendor driver) please let me know and don't hesitate to contact me.

Sounds great, Would be nice to make it more generic, so xbox, switch and 8bitdo controllers could also work. see my comment in this issue

Regards,

Frank