A few posts back I was whining heavily about the gyrations it was taking to get an arcade emulator running well on a Raspberry Pi.  This had nothing at all to do with the cpu capability of the Pi (especially since upgrading to a Pi 2), but was all about the nightmares of Linux configuration, and to some extent, the less than stellar support for Linux by the makers of the arcade control hardware.

The guy who runs the joystick company had convinced me to send back the stick’s circuit board so that it could be upgraded (one time process) to support user-reflashable firmware and better Linux support: no need to recompile a custom kernel and all that.  Well, it took a month for the round trip to England and back, but it did as he advertised. But of course, there’s a catch.  The new firmware uses a completely different technique to upload the joystick control maps than the old firmware version. 

This is where it gets technical and ugly: the old version sent USB control setup packets to the default control channel, while the new one uses HID output reports to the third of three separate endpoints and HID interfaces.  Worse, the guy who wrote the original Linux utility was no longer available to lend assistance.

I know a fair amount about USB, but this went way deeper than I was used to. I also hadn’t monkeyed with any C or C++ in a LONG time.  I had to download and read significant hunks of the USB spec, the hid spec, and some pretty sparse documentation for some abandoned Linux libraries, and restructure and rewrite some decent hunks of the original app.

Shortening this long story, in a few hours of tinkering on and off over the course of about a day, I was able to completely upgrade the original app to enumerate the correct HID interface, navigate the path to the correct report descriptor, and output the correct sequences of bytes to successfully reconfigure the stick on demand. At the same time, I preserved the original logic for anyone using the older stick firmware and made the whole thing completely transparent to the user, while at the same time adding more robust error checking and fixing one or two other small nits.

Then I wrapped the whole thing back up and posted it to github. 🙂 Not too shabby for this longtime program manager.  I have to say, it’s been teaching the APCS class for the last two years that has given me the confidence in my own coding skills again to tackle stuff like this.  Yes, my degree was in CS, but that was almost 25 years ago and boy, those muscles were a bit rusty.