How-to: Clean Custom USB Mode?

Status
Not open for further replies.

dmadison

New member
Hello!

I'm working on a custom controller project on the Teensy LC that uses XInput, taking cues from Zachery Littell's implementation here. Adding XInput support requires modifying a number of Teensy 3 core files:

  • WProgram.h: to include a custom XInput implementation header (usb_xinput.h).
  • usb_desc.c: overriding portions of the device descriptor and defining the config descriptor with an exact size.
  • usb_desc.h: adding USB macros for XInput (device class, VID, PID, num endpoints, etc.).
  • usb_inst.cpp creating USB XInput class instances.
It also requires a set of usb_xinput header & source files to define the API for sending / receiving XInput data from the control endpoints, and a few small additions to boards.txt to add the new USB mode for the relevant boards. I'm also thinking about adding a callback to handle the received data, which would require modifications to both usb_dev.h and usb_dev.c.

For another user to use this XInput implementation, as it's currently written, they would have to overwrite the relevant Teensy core files with these XInput equivalents. Since the modified files are direct replacements, the user's Teensyduino version must also match exactly or they risk breaking all of the USB modes. Predictably this is very messy and prone to issues. On top of that, maintaining these modified files is a mess because unrelated portions will change with Teensyduino updates.

Here's my question: How would I make it so this can be more easily packaged for distribution?

My assumption is that there would need to be some changes made to the Teensy cores to support custom USB descriptors / classes, though I don't know the ideal way to go about that. Perhaps custom macros in the relevant files that would be toggled on with a custom build recipe? At that point I'd assume I could define it as a custom board in the Arduino IDE and link back to the Teensyduino 3 core, which would avoid users having to copy + overwrite files.

Any thoughts?
 
The USB stack was written to have all the descriptors known at compile time. So editing the files in the only supported way so far.
 
Status
Not open for further replies.
Back
Top