Teensy 3.6 Joystick USB_desc.c

Status
Not open for further replies.

Guigui56

Member
Hello,

i'm trying to create a joystick using my Teensy 3.6... When using default "12" size joystick, everythings work fine. But this joystick is declared with more axes than i need and a 10 bit resolution (0-1023).

What i would have is a 2 axes joystick (X and Y) with a 16bit resolution (0-65535 value) and 32 buttons.

Trying to get this done, i've ended with this par of code to include in the "usb_desc.c" file. But when selected, i've got a compliation error : 'class usb_joystick_class' has no member named 'X' (X is the X axis, wand the main code works well, when using defualt joystick setting.

So the error is in my .c file, here is the stuff that i've added :

Code:
#ifdef JOYSTICK_INTERFACE

#if JOYSTICK_SIZE == 9
//  32 buttons   4
//    2 axes      4
//    4 pov       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, 0x20,                     // Report Count (32)
        0x05, 0x09,                     // Usage Page (Button)
        0x19, 0x01,                     // Usage Minimum (Button #1)
        0x29, 0x20,                     // Usage Maximum (Button #32)
        0x81, 0x02,                     // Input (variable,absolute)
        0x05, 0x01,                     // Usage Page (Generic Desktop)
        0x09, 0x01,                     // Usage (Pointer)
        0xA1, 0x00,                     // Collection ()
        0x15, 0x00,                     // Logical Minimum (0)
        0x27, 0xFF, 0xFF, 0, 0,         // Logical Maximum (65535)
        0x75, 0x10,                     // Report Size (16)
        0x95, 2,                       // Report Count (2)
        0x09, 0x30,                     // Usage (X)
        0x09, 0x31,                     // Usage (Y)
        0x81, 0x02,                     // Input (variable,absolute)
        0xC0,                           // End Collection
        0x15, 0x00,                     // Logical Minimum (0)
        0x25, 0x07,                     // Logical Maximum (7)
        0x35, 0x00,                     // Physical Minimum (0)
        0x46, 0x3B, 0x01,               // Physical Maximum (315)
        0x75, 0x04,                     // Report Size (4)
        0x95, 0x02,                     // Report Count (1)
        0x65, 0x14,                     // Unit (20)
        0x05, 0x01,                     // Usage Page (Generic Desktop)
        0x09, 0x39,                     // Usage (Hat switch)
        0x81, 0x42,                     // Input (variable,absolute,null_state)
        0xC0                            // End Collection
};

#elif JOYSTICK_SIZE == 12
....

I've spent some time on this without results... any help is welcome :) and merry christmas !
 
First, an error about 'class usb_joystick_class' has no member named 'X' means there's an error in usb_joystick.h, not this descriptor data you've shown.

Looking briefly at this data, I see only 8.5 bytes (32 bits for buttons, 32 bits for axes, 4 bits for hat switch). You probably will need to add 4 more bits. Using constant bits is fine, but the HID drivers on Windows and other platforms expect the report to add up to a multiple of 8 bits.
 
First, an error about 'class usb_joystick_class' has no member named 'X' means there's an error in usb_joystick.h, not this descriptor data you've shown.

Looking briefly at this data, I see only 8.5 bytes (32 bits for buttons, 32 bits for axes, 4 bits for hat switch). You probably will need to add 4 more bits. Using constant bits is fine, but the HID drivers on Windows and other platforms expect the report to add up to a multiple of 8 bits.

Well, didn't touch anything in the "usb_joystick.h" so the issue is clearly comming from the "usb_desc.c" file.. need to fine a way to add those missing bits. Really stuck right now :(
 
Following Paul's direction into "usb_joystick.h" it seems that file should be touched with a fitting "#if JOYSTICK_SIZE == 9" added. There is no clause for "#if JOYSTICK_SIZE == 9" - only 12 and 64, so those code sections are idef'd out and nothing replaces them.
 
need to fine a way to add those missing bits. Really stuck right now :(

Look at keyboard_report_desc in that file. It has 8 constant bits in the middle of its report descriptor. Just copy those 3 lines and change the size to 4 bits.

Of course, once you tell Windows to expect a 9 byte report, you must transmit exactly 9 bytes. It will ignore any packets with different sizes then you specified in the report descriptor.
 
Status
Not open for further replies.
Back
Top