[MSF] FightStick (TeensyLC XINPUT Controller) – 5

Xinput usb option

Adding Xinput to USB Menu


This was where the project took an evil turn. It took all of 15 minutes to load up the joystick example and fill it with my own code. The complications came when trying to create a device not previously defined in the teensyduino libraries. I am used to libraries and examples that show you what to define and what to include. Where I can make copies in the project directory of anything I need. The arduino IDE is all about doing things in the background with no user intervention. This makes it terribly hard to make changes for just individual projects. This entire process creates a situation where, hopefully I stay up to date with teensyduino releases. I am replacing libraries within the installation which means I replace new functionality if I don’t keep up with releases. But this section isn’t about my hatred for the arduino environment and ideologies.

This is my first arduino IDE project and I was absolutely lost. The great thing about the internet was that someone was there to help me out. I found that help from Kenton Hamaluik‘s project where he makes a teensy joystick for his wedding arcade. Reading his post showed me that we needed to add a menu item that when selected defined a statement that we would continue to check for to include code. The first step is to edit the file boards.txt, which is located in the sub-folder hardware\teensy\avr\ of your arduino installation.

Boards_1

teensyLC.menu.usb.xinput=[MSF] Shoryuken! (XINPUT DEVICE)
teensyLC.menu.usb.xinput.build.usbtype=USB_XINPUT
teensyLC.menu.usb.xinput.fake_serial=teensy_gateway

We need to add 3 simple lines to insert our device into the TeensyLC usb menu. Scroll down to right around line 321, then insert the 3 lines shown above the line that says “No USB”. You can theoretically put the entry anywhere in the menu, but I felt at the bottom would be best. Now the Xinput device type has been added to the menu and when selected defines USB_XINPUT as the usb type.

We still need to add a couple of pieces of code so that the correct headers are loaded and objects defined. The first piece of code we need to add is to the file called usb_inst.cpp. We need to tell the compiler that if USB_XINPUT is defined that it should created an instance of usb_xinput_class labeled XInput. I put the code below in at line 75:

usb_inst_orig_1

#ifdef USB_XINPUT
  usb_xinput_class XInput;
#endif

Finally to wrap this portion up, all we have left to do is include usb_xinput.h in the file Wprogram.h. We will discuss usb_xinput.h and its counterpart, usb_xinput.c, in a later section. All you need to know for now is that these two files contain the libraries we use to bridge our code with the standard USB code provided by teensyduino. I stuffed this include into line 32 of wprogram.h as follows:

wprogram_h_1

#include "usb_xinput.h"
Table of Contents

2 thoughts on “[MSF] FightStick (TeensyLC XINPUT Controller) – 5”

  1. Hi there!

    This seems to be the holy grail for Windows Joystick support. Thank you very much for sharing it.

    Unfortunately it does not work in my environment.

    If I just copy your files from GitHub into my folders, I get the compilations errors

    C:\Users\VIRTUA~2\AppData\Local\Temp\build1856689795118684437.tmp/core.a(usb_dev.c.o): In function `usb_rx_memory’:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_dev.c:645: undefined reference to `usb_endpoint_config_table’
    C:\Users\VIRTUA~2\AppData\Local\Temp\build1856689795118684437.tmp/core.a(usb_dev.c.o): In function `usb_setup’:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_dev.c:280: undefined reference to `usb_descriptor_list’
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_dev.c:280: undefined reference to `usb_endpoint_config_table’
    C:\Users\VIRTUA~2\AppData\Local\Temp\build1856689795118684437.tmp/core.a(usb_dev.c.o): In function `usb_isr’:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_dev.c:862: undefined reference to `usb_descriptor_list’
    C:\Users\VIRTUA~2\AppData\Local\Temp\build1856689795118684437.tmp/core.a(usb_dev.c.o): In function `usb_init’:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/usb_dev.c:937: undefined reference to `usb_init_serialnumber’
    collect2.exe: error: ld returned 1 exit status
    Error compiling.

    I have investigated and came up with the idea to include the following into my usb_dev.h:

    #include “usb_desc.c”

    If I do that it seems to go a step further when compiling, however I get the errors at the end of this post. So I am not sure that my include statment is correct.

    I am suspecting a version issue.

    I am using Teensyduino 1.25-beta2. (Older Versions do not work with Windows 10)

    What version have you been developing on?

    Did you test this with above version by any chance?

    Care to investigate this problem? 🙂

    Thank you very much!

    Kind regards

    Roman

    complete output of errorlog when trying to compile:

    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.c:40:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_joystick.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_keyboard.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_mem.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_midi.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_mouse.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_rawhid.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_seremu.c:33:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_serial.c:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_xinput.c:1:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: missing braces around initializer [-Wmissing-braces]
    0xB2, 0x03, 0x58, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x78, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00,
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:923:3: warning: (near initialization for ‘usb_string_xinput_security_descriptor.wString’) [-Wmissing-braces]
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:36:0,
    from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_flightsim.cpp:31:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:910:9: warning: multi-character character constant [-Wmultichar]
    MANUFACTURER_NAME
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:905:1: error: too many initializers for ‘uint16_t [0] {aka short unsigned int [0]}’
    };
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:911:1: error: too many initializers for ‘uint16_t [0] {aka short unsigned int [0]}’
    };
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:916:1: error: too many initializers for ‘uint16_t [0] {aka short unsigned int [0]}’
    };
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:921:1: error: too many initializers for ‘uint16_t [0] {aka short unsigned int [0]}’
    };
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:935:3: error: too many initializers for ‘usb_string_descriptor_struct’
    };
    ^
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.c:937:6: error: previous declaration of ‘void usb_init_serialnumber()’ with ‘C++’ linkage
    void usb_init_serialnumber(void)
    ^
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_flightsim.cpp:31:0:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_dev.h:52:32: error: conflicts with new declaration with ‘C’ linkage
    void usb_init_serialnumber(void);
    ^
    Error compiling.

    1. The massive amount of spam I normally get in the form of comments on here buried your question. You can always email if you have questions like this. I will try to find time to look into this issue. I am on windows 10 now as well and can go through reinstalling the teensy stuff and following my own tutorial. If this is a version issue I will see what I can do. This is a good example of why I am not a fan of the arduino environment and addons like this.

Leave a Reply

Your email address will not be published. Required fields are marked *