Locations of HID descriptors, USB types, etc.. for Teensy LC

Edit: I'm marking this as sort-of-solved. I still don't know if my project will work, but I can trace the path back through boards.txt to usb_desc.h and understand where all the parts are now, which is what I wanted from this post. Thanks!

I'm trying to work from an older guide on creating a custom controller for Teensy 3, but I'd like to adapt it to Teensy LC and the modern IDE. I'm running on Windows 10.

The guide is here.

So questions about new locations and the new IDE:

  • Where are the relevant files stored for LC? usb_desc.h, usb_desc.c, usb_customdevice, etc. The guide points to /Arduino/hardware/teensy/cores/teensy 3/.
  • What file is edited to make classes accessible to the Arduino environment? Is it still usb_inst.cpp? In which directory?
  • WProgram.h I saw that mentioned as a deprecated file... but does arduino.h work identically? can i just drop whatever the original instruction was in there?
  • How do I make the Arduino environment use the new descriptions? In the guide, it's Arduino/hardware/teensy/boards.txt.

Any guidance is appreciated.

Edit:

OK. Some minimal progress so far...

It looks like the syntax in boards.txt has changed. I don't know if this is right, but at least it's reflected in the IDE menu.

teensyLC.menu.usb.arcade=Wedcade Controller
teensyLC.menu.usb.arcade.build.usbtype=-DUSB_ARCADE
teensyLC.menu.usb.arcade.fake_serial=teensy_gateway

Now I'm getting the error "macros names must be identifiers"

Arduino: 1.8.10 (Windows 10), TD: 1.48, Board: "Teensy LC, Wedcade Controller, 48 MHz, Smallest Code, US English"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\bxlplk\Documents\Arduino\libraries -fqbn=teensy:avr:teensyLC:usb=arcade,speed=48,opt=osstd,keys=en-us -vid-pid=0000_0000 -ide-version=10810 -build-path C:\Users\bxlplk\AppData\Local\Temp\arduino_build_515937 -warnings=none -build-cache C:\Users\bxlplk\AppData\Local\Temp\arduino_cache_594003 -verbose C:\Users\bxlplk\Documents\Arduino\Teensy\sketch_dec01a\sketch_dec01a.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\bxlplk\Documents\Arduino\libraries -fqbn=teensy:avr:teensyLC:usb=arcade,speed=48,opt=osstd,keys=en-us -vid-pid=0000_0000 -ide-version=10810 -build-path C:\Users\bxlplk\AppData\Local\Temp\arduino_build_515937 -warnings=none -build-cache C:\Users\bxlplk\AppData\Local\Temp\arduino_cache_594003 -verbose C:\Users\bxlplk\Documents\Arduino\Teensy\sketch_dec01a\sketch_dec01a.ino
Using board 'teensyLC' from platform in folder: C:\Program
Using core 'teensy3' from platform in folder: C:\Program
Detecting libraries used...
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=148 -DARDUINO=10810 -DF_CPU=48000000 -D-DUSB_ARCADE -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\bxlplk\\AppData\\Local\\Temp\\arduino_build_515937\\sketch\\sketch_dec01a.ino.cpp" -o nul
Error while detecting libraries included by C:\Users\bxlplk\AppData\Local\Temp\arduino_build_515937\sketch\sketch_dec01a.ino.cpp
Generating function prototypes...
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=148 -DARDUINO=10810 -DF_CPU=48000000 -D-DUSB_ARCADE -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\bxlplk\\AppData\\Local\\Temp\\arduino_build_515937\\sketch\\sketch_dec01a.ino.cpp" -o "C:\\Users\\bxlplk\\AppData\\Local\\Temp\\arduino_build_515937\\preproc\\ctags_target_for_gcc_minus_e.cpp"
<command-line>:0:1: error: macro names must be identifiers

Error compiling for board Teensy LC.

This is for every program with TeensyLC, Wedcade. Even:

void setup() {

}

void loop() {

}

Change this line:

avisgut:

teensyLC.menu.usb.arcade.build.usbtype=-DUSB_ARCADE

to:

teensyLC.menu.usb.arcade.build.usbtype=USB_ARCADE

and the error should be fixed.

Note that you need to restart the Arduino IDE before changes to boards.txt take effect.

Just in case you're curious about the problem. If you look at the command that caused the error:

"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=148 -DARDUINO=10810 -DF_CPU=48000000 -D-DUSB_ARCADE -DLAYOUT_US_ENGLISH "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\bxlplk\\AppData\\Local\\Temp\\arduino_build_515937\\sketch\\sketch_dec01a.ino.cpp" -o "C:\\Users\\bxlplk\\AppData\\Local\\Temp\\arduino_build_515937\\preproc\\ctags_target_for_gcc_minus_e.cpp"

You can see where the command line macros are defined using the -D flag. This is the problematic one:

-D-DUSB_ARCADE

So it is trying to create a macro named "-DUSB_ARCADE", which is not a valid C++ identifier. The problem is that the recipe in platform.txt for this command looks like:

recipe.preproc.macros="{compiler.path}{build.toolchain}{build.command.g++}" -E -CC -x c++ -w {compiler.cpp.flags} {build.flags.common} {build.flags.cpp} {build.flags.cpu} {build.flags.defs} -DARDUINO={runtime.ide.version} -DF_CPU={build.fcpu} -D{build.usbtype} -DLAYOUT_{build.keylayout} {includes} "{source_file}" -o "{preprocessed_file_path}"

where build.usbtype is defined in boards.txt. So you can see that the recipe already provides the -D flag, so it should not also be in the definition of build.usbtype in boards.txt. Likely in the old version of Teensyduino used for the original "Wedcade" project, the recipe had something like {build.define0} alone in the recipe, which did require the -D flag to be part of the property definition in boards.txt.

Thanks, that was really informative.

Would you be interested in advising me on the next stage?

Before I got your reply, I decided to scrap creating my own controller and build directly off the included examply in the Teensyduino library. I figured that would be a less challenging task that an updating older code. I tried adding things, subtracting things, but I always was running into the same problem -- Windows 10 would not recognize it as a game controller at all (it didn't show up in "Setup USB Game Controllers").

Backed into a corner, I decided to try a one-button joystick. The example has conveniently given some elifs for different configuration based on the report size in usb_desc.h. After editing the JOYSTICK_SIZE to 1, I dropped this into the appropriate section of usb_desc.c:

#elif JOYSTICK_SIZE == 1
static uint8_t joystick_report_desc[] = {
0x05, 0x01, //Usage Page (Generic Desktop)
0x09, 0x04, //Usage (Joystick)
0xA1, 0x01, //Collection (Application)
0x15, 0x00, //Logical Minimum 0
0x25, 0x01, //Logical Maximum 1
0x75, 0x01, //Report Size (1)
0x95, 0x01, //Report Count (1)
0x05, 0x09, //Usage Page (Button)
0x19, 0x01, //Usage_Minimum (Button 1)
0x29, 0x01, //Usage Maximum (Button 1)
0x81, 0x02, //Input (Data, Var, Abs)
0x95, 0x01, //Report Count (1) (filler)
0x75, 0x07, //Report Size (7)
0x81, 0x03, //Input (Cnst, Var, Abs)
0xC0 // End Collection
};
Everything else in usb_desc.h, .c, etc. have remained exactly the same. Since there are no statements anywhere else regarding JOYSTICK_SIZE, I assume they don't need to be updated(?).

I made some perfunctory updates to joystick.h but haven't invested much time in it since I'm not sure it impacts Windows recognizing it. I've got it to where it compiles and that's it. I'm not looking to get it working right now, just recognized.

If you have an idea as to the missing puzzle piece here, I'd sure appreciate it.