#pragma once #include #include "tusb.h" #ifdef __cplusplus extern "C" { #endif #define DINPUT_VID 0x1234 #define DINPUT_PID 0x1000 typedef struct __attribute__((packed)) { uint8_t lx; /* Left Stick X: 0..255 (128 center) -> Usage X (0x30) */ uint8_t ly; /* Left Stick Y: 0..255 (128 center) -> Usage Y (0x31) */ uint8_t rx; /* Right Stick X: 0..255 (128 center) -> Usage Z (0x32) */ uint8_t ry; /* Right Stick Y: 0..255 (128 center) -> Usage Rx (0x33) */ uint8_t lt; /* Left Trigger: 0..255 (0 released) -> Usage Ry (0x34) */ uint8_t rt; /* Right Trigger: 0..255 (0 released) -> Usage Rz (0x35) */ uint8_t hat; /* Hat Switch: 0..7 directions, 8 centered */ uint32_t buttons; /* 32 buttons bitmask (D-pad 12-15, System 16, Share 17) */ } dinput_report_t; /* Standard 32-button, 6-axis, Hat Switch DirectInput Gamepad Report Descriptor */ static const uint8_t dinput_hid_report_descriptor[] = { 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) 0x09, 0x05, // Usage (Game Pad) 0xA1, 0x01, // Collection (Application) 0x15, 0x00, // Logical Minimum (0) 0x26, 0xFF, 0x00, // Logical Maximum (255) 0x75, 0x08, // Report Size (8) 0x95, 0x06, // Report Count (6 axes) 0x09, 0x30, // Usage (X) - Left Stick X 0x09, 0x31, // Usage (Y) - Left Stick Y 0x09, 0x32, // Usage (Z) - Right Stick X 0x09, 0x33, // Usage (Rx) - Right Stick Y 0x09, 0x34, // Usage (Ry) - Left Trigger 0x09, 0x35, // Usage (Rz) - Right Trigger 0x81, 0x02, // Input (Data,Var,Abs) 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) 0x25, 0x07, // Logical Maximum (7) 0x46, 0x3B, 0x01, // Physical Maximum (315) 0x65, 0x14, // Unit (System: English Rotation, Degrees) 0x75, 0x04, // Report Size (4) 0x95, 0x01, // Report Count (1) 0x09, 0x39, // Usage (Hat switch) 0x81, 0x42, // Input (Data,Var,Abs,Null State) 0x65, 0x00, // Unit (None) 0x75, 0x04, // Report Size (4) 0x95, 0x01, // Report Count (1) - padding 0x81, 0x01, // Input (Const,Array,Abs) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x75, 0x01, // Report Size (1) 0x95, 0x20, // Report Count (32 buttons) 0x05, 0x09, // Usage Page (Button) 0x19, 0x01, // Usage Minimum (0x01) 0x29, 0x20, // Usage Maximum (0x20) 0x81, 0x02, // Input (Data,Var,Abs) 0xC0 // End Collection }; #ifdef __cplusplus } #endif