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.