I have a generic USB controller from a Brazilian brand based on a Chinese layout (Shanwan) that, despite installing the driver that comes with the Retropie and correctly configuring the digital inputs, does not correctly map all axis of the analog sticks.

I would like to use this opportunity to learn more about device debug, USB driver creation and reverse engineering USB devices to contribute to the open source community in that matter.

I want to know which Linux tools, references and documentation can describe this process of making a custom driver and allow the reading of raw USB serial data to remap this raw outputs to a retropie-friendly output.


What you need to do if you want to learn about USB on a low level is read up on USB drivers in LDD3 and carefully study /drivers/usb/usb-skeleton.c in the Linux repository. You should also have a good idea about how the USB protocol is specified. USB in a Nutshell is a good place to start.

You can use dmesg to see the specifics of the USB controller from the kernel's perspective. You can then modify the usb-skeleton to handle that specific device. From there you will need to probe the endpoints of the device, and initially preferably map them to nodes in the /dev-system. Once that is done, you can use a user land program to read and write to the endpoints, trying to figure out exactly what they do. From that information you can then write a HID driver that interfaces your USB device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.