Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: How-to: Clean Custom USB Mode?

  1. #1
    Junior Member
    Join Date
    Apr 2018

    How-to: Clean Custom USB Mode?


    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?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    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.

  3. #3
    Junior Member
    Join Date
    Apr 2018
    Thanks Paul. I guess I'll have to stick to copy + paste for the foreseeable future

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts