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

Thread: Teensy 3.2 custom USB Type

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    9

    Teensy 3.2 custom USB Type

    I have a project that needs data sent from a PC to my Teensy where the Teensy itself is acting as Keyboard/Mouse/Joystick. So it looks like I need a RawHID on top of Keyboard/Mouse/Joystick.
    Right now I'm using that "All of the Above"/USB_EVERYTHING configuration which should do just fine for the development phase but ultimately, for production environment, I would like to include only RawHID/Keyboard/Mouse/Joystick.
    I'm fairly confident I could get it done by coming up with my own usb_desc.h configuration but how to I go implementing this while making sure it can easily be in working order on a new PC installation for instance? It would obviously also need to survive Arduino and Teensydruino upgrades.
    Can I somehow create my own "USB Type" without having to edit files from Teensydruino SDK?
    Are there recommended good practices for that sort of things?

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,935
    The only way I know how to do something like this is to edit the Teensyduino files... Note: I personally have never done a complete setup to add a USB type here. But the steps I would take to do it in a clean way, and maybe if done fully you could get Paul to accept it and add it to official release, would be something like:

    I would edit the boards.txt that was installed as part of Arduino Teensy install: <where Arduino is installed>\hardware\teensy\avr\boards.txt
    For each board type would add a new USB type... Maybe something like:
    Code:
    ...
    teensy31.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick
    teensy31.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID
    teensy31.menu.usb.rawhidhid=Raw HID + Keyboard + Mouse + Joystick
    teensy31.menu.usb.rawhidhid.build.usbtype=USB_RAWHID_HID
    teensy31.menu.usb.rawhidhid.fake_serial=teensy_gateway
    teensy31.menu.usb.midi=MIDI
    ...
    Note: You should make the same changes for each of the Teensy boards in the boards.txt... Not sure if needed to do for 2.x boards, but should probably do for all 3.x boards.

    Then when you restart Arduino IDE and select the board type 3.2, and then look at USB Type, there should be a new entry: Raw HID + Keyboard + Mouse + Joystick

    When you build with this setting it will add a different define. So for example in this case there should be -DUSB_RAWHID_HID should be passed to compiler.

    Now you need to edit the core code to handle this new define:

    Some of the places you would need to edit include: <where Arduino is installed>\hardware\teensy\avr\cores\teensy3\usb_d esc.h

    You need to create a section for this new define... You can probably either start from the USB_SERIAL_HID section or from the USB_EVERYTHING section and either change the appropriate settings, like Product name, and either change or remove Interfaces...

    That may be the only file needed to change... Not sure, would have to try it out to see... And again I have not done this!

  3. #3
    Junior Member
    Join Date
    Jan 2018
    Posts
    9
    I feared that was the way to go.
    However I could not find boards.txt and platform.txt in Teensy core:
    https://github.com/PaulStoffregen/cores

    Also it would be nice if we could dynamically add and remove HID devices rather than hard coding them at compile time.
    Would that be possible as far as USB specs are concerned?
    For instance I vaguely recall that RawHID needed runtime init on Arduino Micro.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,935
    As for boards.txt - Not sure where @Paul keeps these as I have not found them on github.... My assumption is if you come up with a version of this that he thinks is appropriate, you could send it to him in email...

    As for dynamic being possible... I think there was a very recent thread that someone asked this and I believe Paul answered something along the line, it would be possible but there is no current support for it and it might be a lot of work...

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,084
    So far I haven't put Teensyduino's boards.txt and platform.txt on github.

    There are actually 3 different versions of these files built into the Teensyduino installer, so there isn't just 1 authoritative copy to put onto a repository. If you install into the 2 oldest versions of Arduino we support, you'll find these 2 files are different. Arduino has kept changing the format, especially with new stuff for their 1.9 betas. Luckily the recent changes haven't caused backwards compatibility, at least for the features Teensy uses.

    So these 2 files are "special" in the Teensyduino build process, together with several scripts I use to analyze which Java JDK they used, to confirm my build process gives an exact binary Java bytecode match on all 5 platforms, to merge my patches and to adapt things for the differences between the many years span of Arduino versions Teensy supports. The honest reality is those scripts and all that Arduino version adapting stuff is terribly messy. I'm not particularly proud of how it looks, and kinda not so inclined to such a mess onto github.

    But these files 2 files are pretty simple, if you can understand Arduino's format. Hopefully editing them within your copy of Arduino isn't too hard? If anyone wants changes to be merged into the next version of Teensyduino, that's the sort of thing we'd discuss here on the forum, not github issues.

Posting Permissions

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