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

Thread: Looking for Teensy USB Joystick Libraries

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    1

    Looking for Teensy USB Joystick Libraries

    I'm building some sim racing pedals and I'm working in VS Code with a Teensy 4.1. I'd like to import the joystick library used in this example (https://www.pjrc.com/teensy/td_joystick.html) but I'm having trouble finding the library itself. Could somebody please point me in the right direction?

    Thanks a bunch.

    Chris

  2. #2

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,026
    The USB Joystick code is built into Teensyduino installs. It is enabled when you choose a USB type that includes Joysticks.

    That is it is in the ...\cores\teensy4\joystick.c (and .h)
    But again this code is not brought in unless the build is such that JOYSTICK_INTERFACE is defined as the header file and the like start off with:
    Code:
    #if defined(JOYSTICK_INTERFACE)
    And these get typically set in usb_desc.h file depending on stuff passed in to the build and choose the USB type of : Keyboard + mouse + joystick
    The build will go through with: -DUSB_HID
    (from boards.txt)

    If you look in usb_desc.h for the section: #elif defined(USB_HID)
    Line 240 in mine you will see it will define JOYSTICK_INTERFACE plus several other things.
    Note other places need this as well, for example the usb_desc.c which will setup the USB descriptor and the like.

    But how this translates to platform IO? Not sure, I don't typically use it.

  4. #4
    Member
    Join Date
    Aug 2018
    Location
    Brisbane, Australia
    Posts
    48
    Quote Originally Posted by KurtE View Post
    But how this translates to platform IO? Not sure, I don't typically use it.
    For PlatformIO, all you need to do is define the desired USB Features in a build flag as described in the the documentation.
    https://docs.platformio.org/en/lates...l#usb-features

  5. #5
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    278
    in platform io the usable flags are:
    Code:
    USB_HID                  | Keyboard + Mouse + Joystick
    USB_SERIAL_HID           | Serial + Keyboard + Mouse + Joystick
    USB_FLIGHTSIM_JOYSTICK   | Flight Sim Controls + Joystick

Posting Permissions

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