Initial commit: MimiCon v1.0.0 - Universal Gamepad Mimic & Console Bridge
- Dual-Core Architecture: Dedicated 1000Hz USB gaming pipeline on Core 1 and BLE/Wi-Fi/Web telemetry on Core 0. - Multi-Input BLE Host: Parsers for Xbox Wireless, Google Stadia, 8BitDo (Ultimate/Pro2/SN30), and Generic HOGP gamepads. - Multi-Console USB Emulation: Nintendo Switch, PC DirectInput, PS3, PS4, Xbox 360 (libxsm3 cryptographic challenge-response), Original Xbox, and Couch Mouse/Keyboard. - Onboard Web Portal & Captive Portal: Real-time SVG gamepad visualizer, stick deadzone calibration, button combo remapping, and Wi-Fi manager. - Low-Latency Radio Management: Interactive SoftAP toggle to drop to 0-latency gaming mode. - Dual OTA Firmware Flashing: Browser-based wireless firmware updater and automated Python OTA script. - Strict Build Quality: Clean build under -Wall -Wextra with zero warnings or errors. - Versioning & Licensing: Semantic Versioning v1.0.0 and GNU GPLv3 with Commercial Restrictions.
This commit is contained in:
commit
69ebdb4331
59 files changed
+9633
No files matched your search
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#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
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Standard USB HID Composite Report Descriptor: Mouse (ID 1), Keyboard (ID 2), Media (ID 3) */
|
||||
static const uint8_t mouse_kb_hid_report_descriptor[] = {
|
||||
/* --- MOUSE (Report ID 1) --- */
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x02, /* Usage (Mouse) */
|
||||
0xA1, 0x01, /* Collection (Application) */
|
||||
0x85, 0x01, /* Report ID (1) */
|
||||
0x09, 0x01, /* Usage (Pointer) */
|
||||
0xA1, 0x00, /* Collection (Physical) */
|
||||
/* 5 Buttons: Left, Right, Middle, Back, Forward */
|
||||
0x05, 0x09, /* Usage Page (Button) */
|
||||
0x19, 0x01, /* Usage Minimum (Button 1) */
|
||||
0x29, 0x05, /* Usage Maximum (Button 5) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x95, 0x05, /* Report Count (5) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x81, 0x02, /* Input (Data, Variable, Absolute) */
|
||||
/* Padding (3 bits) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x03, /* Report Size (3) */
|
||||
0x81, 0x03, /* Input (Constant, Variable, Absolute) */
|
||||
/* X, Y Movement (-127 to 127) */
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x30, /* Usage (X) */
|
||||
0x09, 0x31, /* Usage (Y) */
|
||||
0x15, 0x81, /* Logical Minimum (-127) */
|
||||
0x25, 0x7F, /* Logical Maximum (127) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x95, 0x02, /* Report Count (2) */
|
||||
0x81, 0x06, /* Input (Data, Variable, Relative) */
|
||||
/* Wheel (-127 to 127) */
|
||||
0x09, 0x38, /* Usage (Wheel) */
|
||||
0x15, 0x81, /* Logical Minimum (-127) */
|
||||
0x25, 0x7F, /* Logical Maximum (127) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x81, 0x06, /* Input (Data, Variable, Relative) */
|
||||
0xC0, /* End Collection */
|
||||
0xC0, /* End Collection */
|
||||
|
||||
/* --- KEYBOARD (Report ID 2) --- */
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop) */
|
||||
0x09, 0x06, /* Usage (Keyboard) */
|
||||
0xA1, 0x01, /* Collection (Application) */
|
||||
0x85, 0x02, /* Report ID (2) */
|
||||
/* Modifiers (8 bits: Ctrl, Shift, Alt, GUI) */
|
||||
0x05, 0x07, /* Usage Page (Key Codes) */
|
||||
0x19, 0xE0, /* Usage Minimum (224) */
|
||||
0x29, 0xE7, /* Usage Maximum (231) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x95, 0x08, /* Report Count (8) */
|
||||
0x81, 0x02, /* Input (Data, Variable, Absolute) */
|
||||
/* Reserved byte */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x81, 0x03, /* Input (Constant) */
|
||||
/* Key array (6 keys) */
|
||||
0x95, 0x06, /* Report Count (6) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0xFF, /* Logical Maximum (255) */
|
||||
0x05, 0x07, /* Usage Page (Key Codes) */
|
||||
0x19, 0x00, /* Usage Minimum (0) */
|
||||
0x29, 0xFF, /* Usage Maximum (255) */
|
||||
0x81, 0x00, /* Input (Data, Array) */
|
||||
0xC0, /* End Collection */
|
||||
|
||||
/* --- CONSUMER CONTROL / MEDIA (Report ID 3) --- */
|
||||
0x05, 0x0C, /* Usage Page (Consumer) */
|
||||
0x09, 0x01, /* Usage (Consumer Control) */
|
||||
0xA1, 0x01, /* Collection (Application) */
|
||||
0x85, 0x03, /* Report ID (3) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x26, 0xFF, 0x03, /* Logical Maximum (0x03FF) */
|
||||
0x19, 0x00, /* Usage Minimum (0) */
|
||||
0x2A, 0xFF, 0x03, /* Usage Maximum (0x03FF) */
|
||||
0x75, 0x10, /* Report Size (16) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x81, 0x00, /* Input (Data, Array) */
|
||||
0xC0 /* End Collection */
|
||||
};
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t buttons; /* bit 0: Left, bit 1: Right, bit 2: Middle, bit 3: Back, bit 4: Forward */
|
||||
int8_t x; /* Relative X displacement */
|
||||
int8_t y; /* Relative Y displacement */
|
||||
int8_t wheel; /* Relative wheel roll */
|
||||
} mouse_report_payload_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t modifier;
|
||||
uint8_t reserved;
|
||||
uint8_t keycodes[6];
|
||||
} keyboard_report_payload_t;
|
||||
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "controller_state.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define OGX_VID 0x045E /* Microsoft Corp. */
|
||||
#define OGX_PID 0x0289 /* Xbox Controller S */
|
||||
|
||||
/* Digital Buttons (Byte 2 of report) */
|
||||
#define OGX_BTN_DPAD_UP (1U << 0)
|
||||
#define OGX_BTN_DPAD_DOWN (1U << 1)
|
||||
#define OGX_BTN_DPAD_LEFT (1U << 2)
|
||||
#define OGX_BTN_DPAD_RIGHT (1U << 3)
|
||||
#define OGX_BTN_START (1U << 4)
|
||||
#define OGX_BTN_BACK (1U << 5)
|
||||
#define OGX_BTN_L3 (1U << 6)
|
||||
#define OGX_BTN_R3 (1U << 7)
|
||||
|
||||
/**
|
||||
* @brief Original Xbox (OG Xbox) 20-byte controller input report.
|
||||
* Matches authentic XID specification and Linux xpad.c driver.
|
||||
*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t start_byte; /* 0x00 */
|
||||
uint8_t bLength; /* 0x14 (20 bytes) */
|
||||
uint8_t dpad_digital; /* Bit 0: D-Up, 1: D-Down, 2: D-Left, 3: D-Right, 4: Start, 5: Back, 6: L3, 7: R3 */
|
||||
uint8_t reserved; /* 0x00 */
|
||||
uint8_t a; /* A button pressure: 0 or 255 */
|
||||
uint8_t b; /* B button pressure: 0 or 255 */
|
||||
uint8_t x; /* X button pressure: 0 or 255 */
|
||||
uint8_t y; /* Y button pressure: 0 or 255 */
|
||||
uint8_t black; /* Black button pressure: 0 or 255 (mapped from RB) */
|
||||
uint8_t white; /* White button pressure: 0 or 255 (mapped from LB) */
|
||||
uint8_t lt; /* Left trigger analog: 0 - 255 */
|
||||
uint8_t rt; /* Right trigger analog: 0 - 255 */
|
||||
int16_t lx; /* Left stick X (-32768 to 32767) */
|
||||
int16_t ly; /* Left stick Y (-32768 to 32767, up is positive) */
|
||||
int16_t rx; /* Right stick X (-32768 to 32767) */
|
||||
int16_t ry; /* Right stick Y (-32768 to 32767, up is positive) */
|
||||
} ogx_report_t;
|
||||
|
||||
/* Device Descriptor */
|
||||
static const tusb_desc_device_t ogx_device_desc __attribute__((unused)) = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = 0x0110, /* USB 1.10 */
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = OGX_VID,
|
||||
.idProduct = OGX_PID,
|
||||
.bcdDevice = 0x0121,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
/* Configuration Descriptor (32 bytes) */
|
||||
static const uint8_t ogx_config_desc[32] __attribute__((unused)) = {
|
||||
/* Configuration Descriptor (9 bytes) */
|
||||
0x09, TUSB_DESC_CONFIGURATION, 32, 0x00, 1, 1, 0, 0x80, 50,
|
||||
|
||||
/* Interface Descriptor (9 bytes): Class 0x58 (Xbox), SubClass 0x42 (Controller), Protocol 0x00 */
|
||||
0x09, TUSB_DESC_INTERFACE, 0x00, 0x00, 0x02, 0x58, 0x42, 0x00, 0x00,
|
||||
|
||||
/* Endpoint 1 IN Descriptor (7 bytes): EP 0x81, Interrupt, Max Packet 32, Interval 4ms */
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x81, 0x03, 0x20, 0x00, 0x04,
|
||||
|
||||
/* Endpoint 2 OUT Descriptor (7 bytes): EP 0x02, Interrupt, Max Packet 32, Interval 4ms */
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x02, 0x03, 0x20, 0x00, 0x04,
|
||||
};
|
||||
|
||||
/* 16-byte XID Descriptor returned on GET_DESCRIPTOR with wValue=0x4200 */
|
||||
static const uint8_t ogx_xid_descriptor[16] __attribute__((unused)) = {
|
||||
0x10, /* bLength = 16 bytes */
|
||||
0x42, /* bDescriptorType = XID */
|
||||
0x00, 0x01, /* bcdXid = 0x0100 (v1.00) */
|
||||
0x01, /* bType = 0x01 (Game Controller) */
|
||||
0x02, /* bSubType = 0x02 (Controller S) */
|
||||
0x14, /* bMaxInputReportSize = 20 bytes (0x14) */
|
||||
0x06, /* bMaxOutputReportSize = 6 bytes (0x06) */
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF /* wAlternateProductIds[4] */
|
||||
};
|
||||
|
||||
/* String Descriptors */
|
||||
static const char *ogx_string_desc[4] __attribute__((unused)) = {
|
||||
(char[]){0x09, 0x04},
|
||||
"Microsoft Corporation",
|
||||
"Xbox Controller S",
|
||||
"000000000004"
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Build 20-byte OG Xbox report from normalized controller state.
|
||||
*/
|
||||
static inline void ogx_build_report(const controller_state_t *state, ogx_report_t *rep)
|
||||
{
|
||||
memset(rep, 0, sizeof(ogx_report_t));
|
||||
rep->start_byte = 0x00;
|
||||
rep->bLength = sizeof(ogx_report_t); /* 0x14 */
|
||||
|
||||
if (state->dpad_up) rep->dpad_digital |= OGX_BTN_DPAD_UP;
|
||||
if (state->dpad_down) rep->dpad_digital |= OGX_BTN_DPAD_DOWN;
|
||||
if (state->dpad_left) rep->dpad_digital |= OGX_BTN_DPAD_LEFT;
|
||||
if (state->dpad_right) rep->dpad_digital |= OGX_BTN_DPAD_RIGHT;
|
||||
if (state->btn_start) rep->dpad_digital |= OGX_BTN_START;
|
||||
if (state->btn_select) rep->dpad_digital |= OGX_BTN_BACK;
|
||||
if (state->btn_l3) rep->dpad_digital |= OGX_BTN_L3;
|
||||
if (state->btn_r3) rep->dpad_digital |= OGX_BTN_R3;
|
||||
|
||||
rep->a = state->btn_a ? 0xFF : 0x00;
|
||||
rep->b = state->btn_b ? 0xFF : 0x00;
|
||||
rep->x = state->btn_x ? 0xFF : 0x00;
|
||||
rep->y = state->btn_y ? 0xFF : 0x00;
|
||||
rep->black = state->btn_rb ? 0xFF : 0x00; /* RB -> Black button */
|
||||
rep->white = state->btn_lb ? 0xFF : 0x00; /* LB -> White button */
|
||||
|
||||
rep->lt = state->lt;
|
||||
rep->rt = state->rt;
|
||||
|
||||
rep->lx = state->lx;
|
||||
rep->ly = state->ly;
|
||||
rep->rx = state->rx;
|
||||
rep->ry = state->ry;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PS4_VID 0x054C /* Sony Interactive Entertainment */
|
||||
#define PS4_PID 0x05C4 /* DualShock 4 Wireless Controller (USB) */
|
||||
|
||||
/* DualShock 4 Buttons Bitmask */
|
||||
#define PS4_BTN_SQUARE (1 << 4)
|
||||
#define PS4_BTN_CROSS (1 << 5)
|
||||
#define PS4_BTN_CIRCLE (1 << 6)
|
||||
#define PS4_BTN_TRIANGLE (1 << 7)
|
||||
|
||||
#define PS4_BTN_L1 (1 << 0)
|
||||
#define PS4_BTN_R1 (1 << 1)
|
||||
#define PS4_BTN_L2 (1 << 2)
|
||||
#define PS4_BTN_R2 (1 << 3)
|
||||
#define PS4_BTN_SHARE (1 << 4)
|
||||
#define PS4_BTN_OPTIONS (1 << 5)
|
||||
#define PS4_BTN_L3 (1 << 6)
|
||||
#define PS4_BTN_R3 (1 << 7)
|
||||
|
||||
#define PS4_BTN_PS (1 << 0)
|
||||
#define PS4_BTN_TOUCHPAD (1 << 1)
|
||||
|
||||
/* D-Pad Hat Switch (Bits 0..3) */
|
||||
#define PS4_HAT_UP 0x00
|
||||
#define PS4_HAT_UP_RIGHT 0x01
|
||||
#define PS4_HAT_RIGHT 0x02
|
||||
#define PS4_HAT_DOWN_RIGHT 0x03
|
||||
#define PS4_HAT_DOWN 0x04
|
||||
#define PS4_HAT_DOWN_LEFT 0x05
|
||||
#define PS4_HAT_LEFT 0x06
|
||||
#define PS4_HAT_UP_LEFT 0x07
|
||||
#define PS4_HAT_CENTER 0x08
|
||||
|
||||
/* DualShock 4 USB Input Report (Report ID 0x01, exactly 64 bytes) */
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t report_id; /* 0x01 */
|
||||
uint8_t lx; /* 0..255, 128 center */
|
||||
uint8_t ly; /* 0..255, 128 center */
|
||||
uint8_t rx; /* 0..255, 128 center */
|
||||
uint8_t ry; /* 0..255, 128 center */
|
||||
uint8_t dpad_and_buttons1; /* Bits 0..3: Hat switch (0..7, 8 neutral); Bits 4..7: Square, Cross, Circle, Triangle */
|
||||
uint8_t buttons2; /* L1, R1, L2, R2, Share, Options, L3, R3 */
|
||||
uint8_t buttons3; /* Bit 0: PS Button, Bit 1: Touchpad Click, Bits 2..7: Packet counter */
|
||||
uint8_t lt; /* 0..255 Left Trigger analog */
|
||||
uint8_t rt; /* 0..255 Right Trigger analog */
|
||||
uint16_t timestamp; /* 188.43 kHz timer tick */
|
||||
uint8_t battery; /* Battery status (0x0B = 100% full, 0x1B = charging) */
|
||||
int16_t gyro_x;
|
||||
int16_t gyro_y;
|
||||
int16_t gyro_z;
|
||||
int16_t accel_x;
|
||||
int16_t accel_y;
|
||||
int16_t accel_z;
|
||||
uint8_t reserved[39];
|
||||
} ps4_report_t;
|
||||
|
||||
/* Official DualShock 4 USB HID Report Descriptor */
|
||||
static const uint8_t ps4_hid_report_descriptor[] = {
|
||||
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
|
||||
0x09, 0x05, // Usage (Game Pad)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
0x85, 0x01, // Report ID (1)
|
||||
0x09, 0x30, // Usage (X)
|
||||
0x09, 0x31, // Usage (Y)
|
||||
0x09, 0x32, // Usage (Z)
|
||||
0x09, 0x35, // Usage (Rz)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x04, // Report Count (4)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x09, 0x39, // Usage (Hat switch)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x25, 0x07, // Logical Maximum (7)
|
||||
0x35, 0x00, // Physical Minimum (0)
|
||||
0x46, 0x3B, 0x01, // Physical Maximum (315)
|
||||
0x65, 0x14, // Unit (Eng Rot:Degree)
|
||||
0x75, 0x04, // Report Size (4)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x81, 0x42, // Input (Data,Var,Abs,Null State)
|
||||
0x65, 0x00, // Unit (None)
|
||||
0x05, 0x09, // Usage Page (Button)
|
||||
0x19, 0x01, // Usage Minimum (0x01)
|
||||
0x29, 0x0E, // Usage Maximum (0x0E)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x25, 0x01, // Logical Maximum (1)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x95, 0x0E, // Report Count (14)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
|
||||
0x09, 0x20, // Usage (0x20)
|
||||
0x75, 0x06, // Report Size (6)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
|
||||
0x09, 0x33, // Usage (Rx)
|
||||
0x09, 0x34, // Usage (Ry)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x02, // Report Count (2)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
|
||||
0x09, 0x21, // Usage (0x21)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x36, // Report Count (54)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x85, 0x05, // Report ID (5)
|
||||
0x09, 0x22, // Usage (0x22)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x1F, // Report Count (31)
|
||||
0x91, 0x02, // Output (Data,Var,Abs)
|
||||
0xC0 // End Collection
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SWITCH_VID 0x0F0D /* HORI Co., Ltd. */
|
||||
#define SWITCH_PID 0x0092 /* POKKEN TOURNAMENT DX Pro Pad (Plug & Play on Switch/PC/PS3) */
|
||||
|
||||
/* Button Bitmasks for Switch */
|
||||
#define SWITCH_BTN_Y (1 << 0)
|
||||
#define SWITCH_BTN_B (1 << 1)
|
||||
#define SWITCH_BTN_A (1 << 2)
|
||||
#define SWITCH_BTN_X (1 << 3)
|
||||
#define SWITCH_BTN_L (1 << 4)
|
||||
#define SWITCH_BTN_R (1 << 5)
|
||||
#define SWITCH_BTN_ZL (1 << 6)
|
||||
#define SWITCH_BTN_ZR (1 << 7)
|
||||
#define SWITCH_BTN_MINUS (1 << 8)
|
||||
#define SWITCH_BTN_PLUS (1 << 9)
|
||||
#define SWITCH_BTN_LCLICK (1 << 10)
|
||||
#define SWITCH_BTN_RCLICK (1 << 11)
|
||||
#define SWITCH_BTN_HOME (1 << 12)
|
||||
#define SWITCH_BTN_CAPTURE (1 << 13)
|
||||
|
||||
#define SWITCH_HAT_UP 0
|
||||
#define SWITCH_HAT_UP_RIGHT 1
|
||||
#define SWITCH_HAT_RIGHT 2
|
||||
#define SWITCH_HAT_DOWN_RIGHT 3
|
||||
#define SWITCH_HAT_DOWN 4
|
||||
#define SWITCH_HAT_DOWN_LEFT 5
|
||||
#define SWITCH_HAT_LEFT 6
|
||||
#define SWITCH_HAT_UP_LEFT 7
|
||||
#define SWITCH_HAT_CENTER 8
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t buttons;
|
||||
uint8_t hat;
|
||||
uint8_t lx;
|
||||
uint8_t ly;
|
||||
uint8_t rx;
|
||||
uint8_t ry;
|
||||
uint8_t vendor;
|
||||
} switch_report_t;
|
||||
|
||||
/* Standard Switch Pokken Pad HID Report Descriptor */
|
||||
static const uint8_t switch_hid_report_descriptor[] = {
|
||||
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
|
||||
0x09, 0x05, // Usage (Game Pad)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x25, 0x01, // Logical Maximum (1)
|
||||
0x35, 0x00, // Physical Minimum (0)
|
||||
0x45, 0x01, // Physical Maximum (1)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x95, 0x10, // Report Count (16)
|
||||
0x05, 0x09, // Usage Page (Button)
|
||||
0x19, 0x01, // Usage Minimum (0x01)
|
||||
0x29, 0x10, // Usage Maximum (0x10)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
|
||||
0x25, 0x07, // Logical Maximum (7)
|
||||
0x46, 0x3B, 0x01, // Physical Maximum (315)
|
||||
0x75, 0x04, // Report Size (4)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x65, 0x14, // Unit (System: English Rotation)
|
||||
0x09, 0x39, // Usage (Hat switch)
|
||||
0x81, 0x42, // Input (Data,Var,Abs,Null State)
|
||||
0x65, 0x00, // Unit (None)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x81, 0x01, // Input (Const,Array,Abs)
|
||||
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
||||
0x46, 0xFF, 0x00, // Physical Maximum (255)
|
||||
0x09, 0x30, // Usage (X)
|
||||
0x09, 0x31, // Usage (Y)
|
||||
0x09, 0x32, // Usage (Z)
|
||||
0x09, 0x35, // Usage (Rz)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x04, // Report Count (4)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
|
||||
0x09, 0x20, // Usage (0x20)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x81, 0x02, // Input (Data,Var,Abs)
|
||||
0x0A, 0x21, 0x26, // Usage (0x2621)
|
||||
0x95, 0x08, // Report Count (8)
|
||||
0x91, 0x02, // Output (Data,Var,Abs)
|
||||
0xC0 // End Collection
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,569 @@
|
||||
#include "usb_gamepad.h"
|
||||
#include "switch_descriptors.h"
|
||||
#include "dinput_descriptors.h"
|
||||
#include "ogx_descriptors.h"
|
||||
#include "ps4_descriptors.h"
|
||||
#include "mouse_kb_descriptors.h"
|
||||
#include "xinput_device.h"
|
||||
#include "ble_hid_host.h"
|
||||
#include "status_led.h"
|
||||
#include "tinyusb.h"
|
||||
#include "tusb.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <string.h>
|
||||
|
||||
static const char *TAG = "USB_GAMEPAD";
|
||||
static console_mode_t s_active_mode = CONSOLE_MODE_SWITCH;
|
||||
static bool s_driver_installed = false;
|
||||
|
||||
static controller_state_t s_last_state;
|
||||
static portMUX_TYPE s_state_mutex = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
void usb_gamepad_get_last_state(controller_state_t *st)
|
||||
{
|
||||
if (!st) return;
|
||||
portENTER_CRITICAL(&s_state_mutex);
|
||||
memcpy(st, &s_last_state, sizeof(controller_state_t));
|
||||
portEXIT_CRITICAL(&s_state_mutex);
|
||||
}
|
||||
|
||||
/* Device Descriptors */
|
||||
static tusb_desc_device_t s_device_desc = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = SWITCH_VID,
|
||||
.idProduct = SWITCH_PID,
|
||||
.bcdDevice = 0x0100,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
/* String Descriptors */
|
||||
static const char *s_string_desc_switch[] = {
|
||||
(char[]){0x09, 0x04}, /* Supported language: English (0x0409) */
|
||||
"HORI CO.,LTD.", /* Manufacturer */
|
||||
"POKKEN TOURNAMENT DX Pro Pad", /* Product */
|
||||
"000000000001" /* Serial */
|
||||
};
|
||||
|
||||
static const char *s_string_desc_pc[] = {
|
||||
(char[]){0x09, 0x04},
|
||||
"Generic USB",
|
||||
"PC Game Controller",
|
||||
"000000000002"
|
||||
};
|
||||
|
||||
static const char *s_string_desc_ps3[] = {
|
||||
(char[]){0x09, 0x04},
|
||||
"Sony Computer Entertainment",
|
||||
"PS3 Game Controller",
|
||||
"000000000003"
|
||||
};
|
||||
|
||||
static const char *s_string_desc_ps4[] = {
|
||||
(char[]){0x09, 0x04},
|
||||
"Sony Interactive Entertainment",
|
||||
"Wireless Controller",
|
||||
"000000000004"
|
||||
};
|
||||
|
||||
/* Full Speed Configuration Descriptors (34 / 41 bytes) */
|
||||
static uint8_t s_config_desc_switch[34] = {
|
||||
/* Configuration Descriptor (9 bytes) */
|
||||
0x09, TUSB_DESC_CONFIGURATION, 34, 0x00, 1, 1, 0, 0x80, 50,
|
||||
/* Interface Descriptor (9 bytes) */
|
||||
0x09, TUSB_DESC_INTERFACE, 0, 0, 1, TUSB_CLASS_HID, 0, 0, 0,
|
||||
/* HID Descriptor (9 bytes) */
|
||||
0x09, 0x21, 0x11, 0x01, 0, 1, 0x22, (sizeof(switch_hid_report_descriptor) & 0xFF), ((sizeof(switch_hid_report_descriptor) >> 8) & 0xFF),
|
||||
/* Endpoint IN Descriptor (7 bytes) */
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x81, 0x03, 64, 0x00, 8
|
||||
};
|
||||
|
||||
static uint8_t s_config_desc_pc[34] = {
|
||||
0x09, TUSB_DESC_CONFIGURATION, 34, 0x00, 1, 1, 0, 0x80, 50,
|
||||
0x09, TUSB_DESC_INTERFACE, 0, 0, 1, TUSB_CLASS_HID, 0, 0, 0,
|
||||
0x09, 0x21, 0x11, 0x01, 0, 1, 0x22, (sizeof(dinput_hid_report_descriptor) & 0xFF), ((sizeof(dinput_hid_report_descriptor) >> 8) & 0xFF),
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x81, 0x03, 64, 0x00, 8
|
||||
};
|
||||
|
||||
static uint8_t s_config_desc_ps4[41] = {
|
||||
/* Configuration Descriptor (9 bytes) */
|
||||
0x09, TUSB_DESC_CONFIGURATION, 41, 0x00, 1, 1, 0, 0xC0, 250,
|
||||
/* Interface Descriptor (9 bytes) */
|
||||
0x09, TUSB_DESC_INTERFACE, 0, 0, 2, TUSB_CLASS_HID, 0, 0, 0,
|
||||
/* HID Descriptor (9 bytes) */
|
||||
0x09, 0x21, 0x11, 0x01, 0, 1, 0x22, (sizeof(ps4_hid_report_descriptor) & 0xFF), ((sizeof(ps4_hid_report_descriptor) >> 8) & 0xFF),
|
||||
/* Endpoint IN Descriptor (7 bytes) */
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x81, 0x03, 64, 0x00, 4,
|
||||
/* Endpoint OUT Descriptor (7 bytes) */
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x01, 0x03, 64, 0x00, 4
|
||||
};
|
||||
|
||||
static uint8_t s_config_desc_mouse_kb[34] = {
|
||||
0x09, TUSB_DESC_CONFIGURATION, 34, 0x00, 1, 1, 0, 0xA0, 50,
|
||||
0x09, TUSB_DESC_INTERFACE, 0, 0, 1, TUSB_CLASS_HID, 0, 0, 0,
|
||||
0x09, 0x21, 0x11, 0x01, 0, 1, 0x22, (sizeof(mouse_kb_hid_report_descriptor) & 0xFF), ((sizeof(mouse_kb_hid_report_descriptor) >> 8) & 0xFF),
|
||||
0x07, TUSB_DESC_ENDPOINT, 0x81, 0x03, 16, 0x00, 8
|
||||
};
|
||||
|
||||
static char const *s_string_desc_mouse_kb[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* 0: Language English */
|
||||
"Antigravity", /* 1: Manufacturer */
|
||||
"Couch Mouse & Keyboard", /* 2: Product */
|
||||
"1.0.0", /* 3: Serial */
|
||||
};
|
||||
|
||||
/* --- TinyUSB Application Callbacks --- */
|
||||
|
||||
uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance)
|
||||
{
|
||||
(void)instance;
|
||||
if (s_active_mode == CONSOLE_MODE_SWITCH) {
|
||||
return switch_hid_report_descriptor;
|
||||
} else if (s_active_mode == CONSOLE_MODE_PS4) {
|
||||
return ps4_hid_report_descriptor;
|
||||
} else if (s_active_mode == CONSOLE_MODE_MOUSE_KB) {
|
||||
return mouse_kb_hid_report_descriptor;
|
||||
} else if (s_active_mode == CONSOLE_MODE_XBOX360 || s_active_mode == CONSOLE_MODE_XBOXOG) {
|
||||
return NULL;
|
||||
} else {
|
||||
return dinput_hid_report_descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
static void build_switch_report(const controller_state_t *state, switch_report_t *rep)
|
||||
{
|
||||
memset(rep, 0, sizeof(switch_report_t));
|
||||
|
||||
/* Buttons */
|
||||
if (state->btn_y) rep->buttons |= SWITCH_BTN_Y;
|
||||
if (state->btn_b) rep->buttons |= SWITCH_BTN_B;
|
||||
if (state->btn_a) rep->buttons |= SWITCH_BTN_A;
|
||||
if (state->btn_x) rep->buttons |= SWITCH_BTN_X;
|
||||
if (state->btn_lb) rep->buttons |= SWITCH_BTN_L;
|
||||
if (state->btn_rb) rep->buttons |= SWITCH_BTN_R;
|
||||
if (state->btn_lt) rep->buttons |= SWITCH_BTN_ZL;
|
||||
if (state->btn_rt) rep->buttons |= SWITCH_BTN_ZR;
|
||||
if (state->btn_select) rep->buttons |= SWITCH_BTN_MINUS;
|
||||
if (state->btn_start) rep->buttons |= SWITCH_BTN_PLUS;
|
||||
if (state->btn_l3) rep->buttons |= SWITCH_BTN_LCLICK;
|
||||
if (state->btn_r3) rep->buttons |= SWITCH_BTN_RCLICK;
|
||||
if (state->btn_system) rep->buttons |= SWITCH_BTN_HOME;
|
||||
if (state->btn_share) rep->buttons |= SWITCH_BTN_CAPTURE;
|
||||
|
||||
/* Hat Switch (D-Pad) */
|
||||
if (state->dpad_up && state->dpad_right) rep->hat = SWITCH_HAT_UP_RIGHT;
|
||||
else if (state->dpad_down && state->dpad_right) rep->hat = SWITCH_HAT_DOWN_RIGHT;
|
||||
else if (state->dpad_down && state->dpad_left) rep->hat = SWITCH_HAT_DOWN_LEFT;
|
||||
else if (state->dpad_up && state->dpad_left) rep->hat = SWITCH_HAT_UP_LEFT;
|
||||
else if (state->dpad_up) rep->hat = SWITCH_HAT_UP;
|
||||
else if (state->dpad_right) rep->hat = SWITCH_HAT_RIGHT;
|
||||
else if (state->dpad_down) rep->hat = SWITCH_HAT_DOWN;
|
||||
else if (state->dpad_left) rep->hat = SWITCH_HAT_LEFT;
|
||||
else rep->hat = SWITCH_HAT_CENTER;
|
||||
|
||||
/* Sticks: 0..255, 128 center, Y axis inverted: 0 is top */
|
||||
rep->lx = (uint8_t)(((int32_t)state->lx + 32768) >> 8);
|
||||
rep->ly = (uint8_t)(((int32_t)32767 - state->ly) >> 8);
|
||||
rep->rx = (uint8_t)(((int32_t)state->rx + 32768) >> 8);
|
||||
rep->ry = (uint8_t)(((int32_t)32767 - state->ry) >> 8);
|
||||
rep->vendor = 0x00;
|
||||
}
|
||||
|
||||
static void build_dinput_report(const controller_state_t *state, dinput_report_t *rep)
|
||||
{
|
||||
memset(rep, 0, sizeof(dinput_report_t));
|
||||
|
||||
/* Sticks: X (lx), Y (ly), Rx (rx), Ry (ry) */
|
||||
rep->lx = (uint8_t)(((int32_t)state->lx + 32768) >> 8);
|
||||
rep->ly = (uint8_t)(((int32_t)32767 - state->ly) >> 8);
|
||||
rep->rx = (uint8_t)(((int32_t)state->rx + 32768) >> 8);
|
||||
rep->ry = (uint8_t)(((int32_t)32767 - state->ry) >> 8);
|
||||
|
||||
/* Triggers: Z (lt), Rz (rt) */
|
||||
rep->lt = state->lt;
|
||||
rep->rt = state->rt;
|
||||
|
||||
/* Hat: 0..7 directions, 8 neutral */
|
||||
if (state->dpad_up && state->dpad_right) rep->hat = 1;
|
||||
else if (state->dpad_right && state->dpad_down) rep->hat = 3;
|
||||
else if (state->dpad_down && state->dpad_left) rep->hat = 5;
|
||||
else if (state->dpad_left && state->dpad_up) rep->hat = 7;
|
||||
else if (state->dpad_up) rep->hat = 0;
|
||||
else if (state->dpad_right) rep->hat = 2;
|
||||
else if (state->dpad_down) rep->hat = 4;
|
||||
else if (state->dpad_left) rep->hat = 6;
|
||||
else rep->hat = 8;
|
||||
|
||||
/* Buttons bitmask: Standard Gamepad API ordering */
|
||||
if (state->btn_a) rep->buttons |= (1UL << 0);
|
||||
if (state->btn_b) rep->buttons |= (1UL << 1);
|
||||
if (state->btn_x) rep->buttons |= (1UL << 2);
|
||||
if (state->btn_y) rep->buttons |= (1UL << 3);
|
||||
if (state->btn_lb) rep->buttons |= (1UL << 4);
|
||||
if (state->btn_rb) rep->buttons |= (1UL << 5);
|
||||
if (state->btn_lt) rep->buttons |= (1UL << 6);
|
||||
if (state->btn_rt) rep->buttons |= (1UL << 7);
|
||||
if (state->btn_select) rep->buttons |= (1UL << 8);
|
||||
if (state->btn_start) rep->buttons |= (1UL << 9);
|
||||
if (state->btn_l3) rep->buttons |= (1UL << 10);
|
||||
if (state->btn_r3) rep->buttons |= (1UL << 11);
|
||||
/* Buttons 12-15: Standard D-Pad buttons */
|
||||
if (state->dpad_up) rep->buttons |= (1UL << 12);
|
||||
if (state->dpad_down) rep->buttons |= (1UL << 13);
|
||||
if (state->dpad_left) rep->buttons |= (1UL << 14);
|
||||
if (state->dpad_right) rep->buttons |= (1UL << 15);
|
||||
/* Buttons 16-17: System / Guide / Home and Share / Capture */
|
||||
if (state->btn_system) rep->buttons |= (1UL << 16);
|
||||
if (state->btn_share) rep->buttons |= (1UL << 17);
|
||||
}
|
||||
|
||||
static void build_ps4_report(const controller_state_t *state, ps4_report_t *rep)
|
||||
{
|
||||
static uint16_t timer_tick = 0;
|
||||
static uint8_t packet_counter = 0;
|
||||
|
||||
memset(rep, 0, sizeof(ps4_report_t));
|
||||
rep->report_id = 0x01;
|
||||
|
||||
/* Sticks: 0..255, 128 center, Y axis: 0 is top */
|
||||
rep->lx = (uint8_t)(((int32_t)state->lx + 32768) >> 8);
|
||||
rep->ly = (uint8_t)(((int32_t)32767 - state->ly) >> 8);
|
||||
rep->rx = (uint8_t)(((int32_t)state->rx + 32768) >> 8);
|
||||
rep->ry = (uint8_t)(((int32_t)32767 - state->ry) >> 8);
|
||||
|
||||
/* Hat Switch (D-Pad) */
|
||||
uint8_t hat = PS4_HAT_CENTER;
|
||||
if (state->dpad_up && state->dpad_right) hat = PS4_HAT_UP_RIGHT;
|
||||
else if (state->dpad_down && state->dpad_right) hat = PS4_HAT_DOWN_RIGHT;
|
||||
else if (state->dpad_down && state->dpad_left) hat = PS4_HAT_DOWN_LEFT;
|
||||
else if (state->dpad_up && state->dpad_left) hat = PS4_HAT_UP_LEFT;
|
||||
else if (state->dpad_up) hat = PS4_HAT_UP;
|
||||
else if (state->dpad_right) hat = PS4_HAT_RIGHT;
|
||||
else if (state->dpad_down) hat = PS4_HAT_DOWN;
|
||||
else if (state->dpad_left) hat = PS4_HAT_LEFT;
|
||||
|
||||
rep->dpad_and_buttons1 = hat & 0x0F;
|
||||
|
||||
/* Face buttons (Square, Cross, Circle, Triangle) */
|
||||
if (state->btn_x) rep->dpad_and_buttons1 |= PS4_BTN_SQUARE;
|
||||
if (state->btn_a) rep->dpad_and_buttons1 |= PS4_BTN_CROSS;
|
||||
if (state->btn_b) rep->dpad_and_buttons1 |= PS4_BTN_CIRCLE;
|
||||
if (state->btn_y) rep->dpad_and_buttons1 |= PS4_BTN_TRIANGLE;
|
||||
|
||||
/* Shoulder buttons & Menu */
|
||||
if (state->btn_lb) rep->buttons2 |= PS4_BTN_L1;
|
||||
if (state->btn_rb) rep->buttons2 |= PS4_BTN_R1;
|
||||
if (state->btn_lt) rep->buttons2 |= PS4_BTN_L2;
|
||||
if (state->btn_rt) rep->buttons2 |= PS4_BTN_R2;
|
||||
if (state->btn_select) rep->buttons2 |= PS4_BTN_SHARE;
|
||||
if (state->btn_start) rep->buttons2 |= PS4_BTN_OPTIONS;
|
||||
if (state->btn_l3) rep->buttons2 |= PS4_BTN_L3;
|
||||
if (state->btn_r3) rep->buttons2 |= PS4_BTN_R3;
|
||||
|
||||
/* System & Touchpad buttons */
|
||||
if (state->btn_system) rep->buttons3 |= PS4_BTN_PS;
|
||||
/* Map Share / Capture button to Touchpad Click */
|
||||
if (state->btn_share) rep->buttons3 |= PS4_BTN_TOUCHPAD;
|
||||
|
||||
/* Rolling packet counter */
|
||||
rep->buttons3 |= ((packet_counter++ & 0x3F) << 2);
|
||||
|
||||
/* Analog triggers (0..255) */
|
||||
rep->lt = state->lt;
|
||||
rep->rt = state->rt;
|
||||
|
||||
/* Timestamp and battery */
|
||||
rep->timestamp = timer_tick++;
|
||||
rep->battery = 0x0B; /* 100% full, cable connected */
|
||||
|
||||
/* Touchpad packet (finger not touching: bit 7 = 1) */
|
||||
rep->reserved[10] = 0x01;
|
||||
rep->reserved[11] = 0x80;
|
||||
rep->reserved[15] = 0x80;
|
||||
}
|
||||
|
||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
|
||||
{
|
||||
(void)instance;
|
||||
(void)report_id;
|
||||
(void)report_type;
|
||||
|
||||
controller_state_t current;
|
||||
portENTER_CRITICAL(&s_state_mutex);
|
||||
memcpy(¤t, &s_last_state, sizeof(controller_state_t));
|
||||
portEXIT_CRITICAL(&s_state_mutex);
|
||||
|
||||
if (s_active_mode == CONSOLE_MODE_SWITCH) {
|
||||
switch_report_t rep;
|
||||
build_switch_report(¤t, &rep);
|
||||
uint16_t copy_len = (reqlen < sizeof(rep)) ? reqlen : sizeof(rep);
|
||||
memcpy(buffer, &rep, copy_len);
|
||||
return copy_len;
|
||||
} else if (s_active_mode == CONSOLE_MODE_PS4) {
|
||||
ps4_report_t rep;
|
||||
build_ps4_report(¤t, &rep);
|
||||
uint16_t copy_len = (reqlen < sizeof(rep)) ? reqlen : sizeof(rep);
|
||||
memcpy(buffer, &rep, copy_len);
|
||||
return copy_len;
|
||||
} else {
|
||||
dinput_report_t rep;
|
||||
build_dinput_report(¤t, &rep);
|
||||
uint16_t copy_len = (reqlen < sizeof(rep)) ? reqlen : sizeof(rep);
|
||||
memcpy(buffer, &rep, copy_len);
|
||||
return copy_len;
|
||||
}
|
||||
}
|
||||
|
||||
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
|
||||
{
|
||||
(void)instance;
|
||||
(void)report_id;
|
||||
if (report_type == HID_REPORT_TYPE_OUTPUT && buffer && bufsize > 0) {
|
||||
if (s_active_mode == CONSOLE_MODE_PS3) {
|
||||
/* PS3 DualShock 3 Output Report:
|
||||
* Byte 2 = Right small motor (0 or 1 on/off)
|
||||
* Byte 4 = Left large motor (0-255)
|
||||
*/
|
||||
if (bufsize >= 5) {
|
||||
uint8_t light = buffer[2] ? 255 : 0;
|
||||
uint8_t heavy = buffer[4];
|
||||
ble_hid_host_send_rumble(heavy, light);
|
||||
}
|
||||
} else if (s_active_mode == CONSOLE_MODE_PC_DINPUT) {
|
||||
/* PC Generic Output Report: [heavy, light] */
|
||||
if (bufsize >= 2) {
|
||||
ble_hid_host_send_rumble(buffer[0], buffer[1]);
|
||||
}
|
||||
} else if (s_active_mode == CONSOLE_MODE_PS4) {
|
||||
/* PS4 DualShock 4 Output Report (Report ID 0x05):
|
||||
* If buffer[0] == 0x05:
|
||||
* buffer[4] = Light / small motor (0-255)
|
||||
* buffer[5] = Heavy / large motor (0-255)
|
||||
* buffer[6] = Lightbar Red (0-255)
|
||||
* buffer[7] = Lightbar Green (0-255)
|
||||
* buffer[8] = Lightbar Blue (0-255)
|
||||
*/
|
||||
size_t off = (buffer[0] == 0x05) ? 1 : 0;
|
||||
if (bufsize >= off + 8) {
|
||||
uint8_t light = buffer[off + 3];
|
||||
uint8_t heavy = buffer[off + 4];
|
||||
ble_hid_host_send_rumble(heavy, light);
|
||||
|
||||
uint8_t r = buffer[off + 5];
|
||||
uint8_t g = buffer[off + 6];
|
||||
uint8_t b = buffer[off + 7];
|
||||
if (r > 0 || g > 0 || b > 0) {
|
||||
status_led_flash_color(r, g, b, 2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Background task ensuring reports are constantly streamed to prevent uninitialized host reads */
|
||||
static void usb_stream_task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
if (tud_mounted()) {
|
||||
controller_state_t current;
|
||||
portENTER_CRITICAL(&s_state_mutex);
|
||||
memcpy(¤t, &s_last_state, sizeof(controller_state_t));
|
||||
portEXIT_CRITICAL(&s_state_mutex);
|
||||
|
||||
if (s_active_mode == CONSOLE_MODE_XBOX360) {
|
||||
xinput_in_report_t rep;
|
||||
xinput_device_build_report(¤t, &rep);
|
||||
xinput_device_send_report(&rep);
|
||||
} else if (s_active_mode == CONSOLE_MODE_XBOXOG) {
|
||||
ogx_report_t rep;
|
||||
ogx_build_report(¤t, &rep);
|
||||
ogx_device_send_report(&rep, sizeof(rep));
|
||||
} else if (tud_hid_ready()) {
|
||||
if (s_active_mode == CONSOLE_MODE_SWITCH) {
|
||||
switch_report_t rep;
|
||||
build_switch_report(¤t, &rep);
|
||||
tud_hid_report(0, &rep, sizeof(rep));
|
||||
} else if (s_active_mode == CONSOLE_MODE_PS4) {
|
||||
ps4_report_t rep;
|
||||
build_ps4_report(¤t, &rep);
|
||||
tud_hid_report(0, &rep, sizeof(rep));
|
||||
} else if (s_active_mode == CONSOLE_MODE_MOUSE_KB) {
|
||||
/* Mouse movement calculation */
|
||||
int16_t lx = current.lx;
|
||||
int16_t ly = current.ly;
|
||||
int8_t dx = 0, dy = 0;
|
||||
if (abs(lx) > 3000) {
|
||||
int val = (lx > 0 ? (lx - 3000) : (lx + 3000)) / 2200;
|
||||
if (val > 120) val = 120;
|
||||
if (val < -120) val = -120;
|
||||
dx = (int8_t)val;
|
||||
}
|
||||
if (abs(ly) > 3000) {
|
||||
int val = -(ly > 0 ? (ly - 3000) : (ly + 3000)) / 2200;
|
||||
if (val > 120) val = 120;
|
||||
if (val < -120) val = -120;
|
||||
dy = (int8_t)val;
|
||||
}
|
||||
|
||||
int8_t wheel = 0;
|
||||
int16_t ry = current.ry;
|
||||
if (abs(ry) > 6000) {
|
||||
wheel = (ry > 0 ? 1 : -1) * (abs(ry) > 18000 ? 2 : 1);
|
||||
}
|
||||
|
||||
uint8_t btns = 0;
|
||||
if (current.btn_a || current.btn_lt || current.btn_lb) btns |= 0x01; /* Left Click */
|
||||
if (current.btn_b || current.btn_rt || current.btn_rb) btns |= 0x02; /* Right Click */
|
||||
if (current.btn_l3 || current.btn_x) btns |= 0x04; /* Middle Click */
|
||||
|
||||
mouse_report_payload_t m_rep = {
|
||||
.buttons = btns,
|
||||
.x = dx,
|
||||
.y = dy,
|
||||
.wheel = wheel
|
||||
};
|
||||
tud_hid_report(1, &m_rep, sizeof(m_rep));
|
||||
|
||||
/* Keyboard / Navigation keys */
|
||||
keyboard_report_payload_t k_rep = {0};
|
||||
uint8_t k_idx = 0;
|
||||
if (current.dpad_up && k_idx < 6) k_rep.keycodes[k_idx++] = 0x52; /* Up Arrow */
|
||||
if (current.dpad_down && k_idx < 6) k_rep.keycodes[k_idx++] = 0x51; /* Down Arrow */
|
||||
if (current.dpad_left && k_idx < 6) k_rep.keycodes[k_idx++] = 0x50; /* Left Arrow */
|
||||
if (current.dpad_right && k_idx < 6) k_rep.keycodes[k_idx++] = 0x4F; /* Right Arrow */
|
||||
if (current.btn_y && k_idx < 6) k_rep.keycodes[k_idx++] = 0x28; /* Enter */
|
||||
if (current.btn_select && k_idx < 6) k_rep.keycodes[k_idx++] = 0x2C; /* Space */
|
||||
if (current.btn_start && k_idx < 6) k_rep.keycodes[k_idx++] = 0x29; /* Escape */
|
||||
|
||||
static uint8_t s_last_k_keys[6] = {0};
|
||||
if (memcmp(s_last_k_keys, k_rep.keycodes, 6) != 0) {
|
||||
memcpy(s_last_k_keys, k_rep.keycodes, 6);
|
||||
tud_hid_report(2, &k_rep, sizeof(k_rep));
|
||||
}
|
||||
} else {
|
||||
dinput_report_t rep;
|
||||
build_dinput_report(¤t, &rep);
|
||||
tud_hid_report(0, &rep, sizeof(rep));
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Public API --- */
|
||||
|
||||
esp_err_t usb_gamepad_init(console_mode_t initial_mode)
|
||||
{
|
||||
s_active_mode = initial_mode;
|
||||
|
||||
/* Initialize last state to neutral */
|
||||
portENTER_CRITICAL(&s_state_mutex);
|
||||
controller_state_reset(&s_last_state);
|
||||
portEXIT_CRITICAL(&s_state_mutex);
|
||||
|
||||
tinyusb_config_t tusb_cfg = {
|
||||
.device_descriptor = &s_device_desc,
|
||||
.string_descriptor = s_string_desc_pc,
|
||||
.string_descriptor_count = 4,
|
||||
.external_phy = false,
|
||||
.configuration_descriptor = s_config_desc_pc,
|
||||
};
|
||||
|
||||
if (s_active_mode == CONSOLE_MODE_SWITCH) {
|
||||
s_device_desc.idVendor = SWITCH_VID;
|
||||
s_device_desc.idProduct = SWITCH_PID;
|
||||
tusb_cfg.string_descriptor = s_string_desc_switch;
|
||||
tusb_cfg.configuration_descriptor = s_config_desc_switch;
|
||||
} else if (s_active_mode == CONSOLE_MODE_PS4) {
|
||||
s_device_desc.idVendor = PS4_VID;
|
||||
s_device_desc.idProduct = PS4_PID;
|
||||
tusb_cfg.string_descriptor = s_string_desc_ps4;
|
||||
tusb_cfg.configuration_descriptor = s_config_desc_ps4;
|
||||
} else if (s_active_mode == CONSOLE_MODE_MOUSE_KB) {
|
||||
s_device_desc.idVendor = 0x046D; /* Logitech */
|
||||
s_device_desc.idProduct = 0xC52B; /* Wireless Receiver */
|
||||
tusb_cfg.string_descriptor = s_string_desc_mouse_kb;
|
||||
tusb_cfg.configuration_descriptor = s_config_desc_mouse_kb;
|
||||
} else if (s_active_mode == CONSOLE_MODE_PS3) {
|
||||
s_device_desc.idVendor = 0x054C; /* Sony PS3 */
|
||||
s_device_desc.idProduct = 0x0268;
|
||||
tusb_cfg.string_descriptor = s_string_desc_ps3;
|
||||
tusb_cfg.configuration_descriptor = s_config_desc_pc;
|
||||
} else if (s_active_mode == CONSOLE_MODE_XBOX360) {
|
||||
xinput_device_init();
|
||||
tusb_cfg.device_descriptor = &xinput_device_desc;
|
||||
tusb_cfg.configuration_descriptor = xinput_config_desc;
|
||||
tusb_cfg.string_descriptor = xinput_string_desc;
|
||||
tusb_cfg.string_descriptor_count = 5;
|
||||
} else if (s_active_mode == CONSOLE_MODE_XBOXOG) {
|
||||
ogx_device_init();
|
||||
tusb_cfg.device_descriptor = &ogx_device_desc;
|
||||
tusb_cfg.configuration_descriptor = ogx_config_desc;
|
||||
tusb_cfg.string_descriptor = ogx_string_desc;
|
||||
tusb_cfg.string_descriptor_count = 4;
|
||||
} else {
|
||||
s_device_desc.idVendor = DINPUT_VID;
|
||||
s_device_desc.idProduct = DINPUT_PID;
|
||||
tusb_cfg.string_descriptor = s_string_desc_pc;
|
||||
tusb_cfg.configuration_descriptor = s_config_desc_pc;
|
||||
}
|
||||
|
||||
esp_err_t err = tinyusb_driver_install(&tusb_cfg);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "TinyUSB install failed: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
s_driver_installed = true;
|
||||
ESP_LOGI(TAG, "USB Gamepad initialized in mode: %s (VID:0x%04X PID:0x%04X)",
|
||||
profile_manager_mode_name(s_active_mode),
|
||||
tusb_cfg.device_descriptor->idVendor,
|
||||
tusb_cfg.device_descriptor->idProduct);
|
||||
|
||||
static bool task_created = false;
|
||||
if (!task_created) {
|
||||
/* Pin real-time USB transmission to Core 1 (APP CPU) with high priority */
|
||||
xTaskCreatePinnedToCore(usb_stream_task, "usb_stream_task", 4096, NULL, 6, NULL, 1);
|
||||
task_created = true;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t usb_gamepad_change_mode(console_mode_t new_mode)
|
||||
{
|
||||
if (s_driver_installed) {
|
||||
ESP_LOGI(TAG, "Re-enumerating USB for new console profile...");
|
||||
tinyusb_driver_uninstall();
|
||||
s_driver_installed = false;
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
}
|
||||
return usb_gamepad_init(new_mode);
|
||||
}
|
||||
|
||||
bool usb_gamepad_is_mounted(void)
|
||||
{
|
||||
return tud_mounted();
|
||||
}
|
||||
|
||||
esp_err_t usb_gamepad_send_state(const controller_state_t *state)
|
||||
{
|
||||
if (!state) return ESP_ERR_INVALID_ARG;
|
||||
|
||||
portENTER_CRITICAL(&s_state_mutex);
|
||||
memcpy(&s_last_state, state, sizeof(controller_state_t));
|
||||
portEXIT_CRITICAL(&s_state_mutex);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "controller_state.h"
|
||||
#include "profile_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize USB Gamepad emulation with the specified console mode.
|
||||
*/
|
||||
esp_err_t usb_gamepad_init(console_mode_t initial_mode);
|
||||
|
||||
/**
|
||||
* @brief Reconfigure USB descriptors and re-enumerate for a new console mode.
|
||||
*/
|
||||
esp_err_t usb_gamepad_change_mode(console_mode_t new_mode);
|
||||
|
||||
/**
|
||||
* @brief Translate and send normalized controller state to the host console.
|
||||
*/
|
||||
esp_err_t usb_gamepad_send_state(const controller_state_t *state);
|
||||
|
||||
/**
|
||||
* @brief Check if USB device is mounted and ready to transmit reports.
|
||||
*/
|
||||
bool usb_gamepad_is_mounted(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,497 @@
|
||||
#include "xinput_device.h"
|
||||
#include "ogx_descriptors.h"
|
||||
#include "xsm3.h"
|
||||
#include "profile_manager.h"
|
||||
#include "ble_hid_host.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_mac.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void usb_gamepad_get_last_state(controller_state_t *st);
|
||||
|
||||
static const char *TAG = "XINPUT_DEV";
|
||||
|
||||
#define XINPUT_ENDPOINT_SIZE 32
|
||||
#define DESC_TYPE_VENDOR 0x21
|
||||
#define DESC_TYPE_SEC 0x41
|
||||
|
||||
/* Device Descriptor */
|
||||
const tusb_desc_device_t xinput_device_desc = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0xFF,
|
||||
.bDeviceSubClass = 0xFF,
|
||||
.bDeviceProtocol = 0xFF,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = XINPUT_VID, /* 0x045E */
|
||||
.idProduct = XINPUT_PID, /* 0x028E */
|
||||
.bcdDevice = 0x0114,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
/* Configuration Descriptor (153 bytes) - Authentic Xbox 360 Wired Controller */
|
||||
const uint8_t xinput_config_desc[153] = {
|
||||
// Configuration descriptor (9 bytes)
|
||||
0x09, 0x02, 0x99, 0x00, 0x04, 0x01, 0x00, 0xA0, 0xFA,
|
||||
|
||||
// ---- Interface 0: Gamepad (SubClass 0x5D, Protocol 0x01) ----
|
||||
0x09, 0x04, 0x00, 0x00, 0x02, 0xFF, 0x5D, 0x01, 0x00,
|
||||
0x11, 0x21, 0x00, 0x01, 0x01, 0x25, 0x81, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x13, 0x02, 0x08, 0x00, 0x00,
|
||||
0x07, 0x05, 0x81, 0x03, 0x20, 0x00, 0x04,
|
||||
0x07, 0x05, 0x02, 0x03, 0x20, 0x00, 0x08,
|
||||
|
||||
// ---- Interface 1: Audio (SubClass 0x5D, Protocol 0x03) ----
|
||||
0x09, 0x04, 0x01, 0x00, 0x04, 0xFF, 0x5D, 0x03, 0x00,
|
||||
0x1B, 0x21, 0x00, 0x01, 0x01, 0x01, 0x83, 0x40,
|
||||
0x01, 0x04, 0x20, 0x16, 0x85, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x16, 0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00,
|
||||
0x07, 0x05, 0x83, 0x03, 0x20, 0x00, 0x02,
|
||||
0x07, 0x05, 0x04, 0x03, 0x20, 0x00, 0x04,
|
||||
0x07, 0x05, 0x85, 0x03, 0x20, 0x00, 0x40,
|
||||
0x07, 0x05, 0x06, 0x03, 0x20, 0x00, 0x10,
|
||||
|
||||
// ---- Interface 2: Plugin Module (SubClass 0x5D, Protocol 0x02) ----
|
||||
0x09, 0x04, 0x02, 0x00, 0x01, 0xFF, 0x5D, 0x02, 0x00,
|
||||
0x09, 0x21, 0x00, 0x01, 0x01, 0x22, 0x86, 0x03, 0x00,
|
||||
0x07, 0x05, 0x86, 0x03, 0x20, 0x00, 0x10,
|
||||
|
||||
// ---- Interface 3: Security (SubClass 0xFD, Protocol 0x13), iInterface=4 ----
|
||||
0x09, 0x04, 0x03, 0x00, 0x00, 0xFF, 0xFD, 0x13, 0x04,
|
||||
0x06, 0x41, 0x00, 0x01, 0x01, 0x03,
|
||||
};
|
||||
|
||||
static char s_usb_serial[13] = "000000000000";
|
||||
|
||||
const char *xinput_string_desc[5] = {
|
||||
(char[]){0x09, 0x04},
|
||||
"\xa9Microsoft Corporation",
|
||||
"Xbox 360 Controller",
|
||||
s_usb_serial,
|
||||
"Xbox Security Method 3, Version 1.00, \xa9 2005 Microsoft Corporation. All rights reserved."
|
||||
};
|
||||
|
||||
/* State and Buffers */
|
||||
static uint8_t s_endpoint_in = 0xFF;
|
||||
static uint8_t s_endpoint_out = 0xFF;
|
||||
static uint8_t s_ep_in_buffer[XINPUT_ENDPOINT_SIZE];
|
||||
static uint8_t s_ep_out_buffer[XINPUT_ENDPOINT_SIZE];
|
||||
|
||||
typedef enum {
|
||||
XSM3_AUTH_STATE_IDLE = 0,
|
||||
XSM3_AUTH_STATE_RESPONDED = 2,
|
||||
XSM3_AUTH_STATE_AUTHENTICATED = 4,
|
||||
} xsm3_auth_state_t;
|
||||
|
||||
static volatile xsm3_auth_state_t s_xsm3_auth_state = XSM3_AUTH_STATE_IDLE;
|
||||
static uint8_t s_xsm3_identification[0x1D];
|
||||
static uint8_t s_xsm3_buf_82[0x22];
|
||||
static uint8_t s_xsm3_buf_87[0x16];
|
||||
static uint8_t s_xsm3_state_buf[2] = { 0x01, 0x00 };
|
||||
static bool s_identity_initialized = false;
|
||||
|
||||
static void init_xsm3_identity(void)
|
||||
{
|
||||
if (s_identity_initialized) return;
|
||||
|
||||
xsm3_initialise_state();
|
||||
|
||||
uint8_t mac[6];
|
||||
esp_efuse_mac_get_default(mac);
|
||||
snprintf(s_usb_serial, sizeof(s_usb_serial), "%02X%02X%02X%02X%02X%02X",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
memcpy(s_xsm3_identification, xsm3_id_data_ms_controller, sizeof(s_xsm3_identification));
|
||||
memcpy(&s_xsm3_identification[0x05], s_usb_serial, 12);
|
||||
|
||||
/* Calculate XOR checksum of packet starting at offset 5 */
|
||||
uint8_t packet_end = s_xsm3_identification[4] + 5;
|
||||
uint8_t checksum = 0;
|
||||
for (uint8_t i = 5; i < packet_end; ++i) {
|
||||
checksum ^= s_xsm3_identification[i];
|
||||
}
|
||||
s_xsm3_identification[0x1C] = checksum;
|
||||
|
||||
xsm3_set_identification_data(s_xsm3_identification);
|
||||
s_identity_initialized = true;
|
||||
|
||||
ESP_LOGI(TAG, "XSM3 Identity ready: Serial=%s Checksum=0x%02X", s_usb_serial, checksum);
|
||||
}
|
||||
|
||||
void xinput_device_init(void)
|
||||
{
|
||||
s_endpoint_in = 0xFF;
|
||||
s_endpoint_out = 0xFF;
|
||||
s_xsm3_auth_state = XSM3_AUTH_STATE_IDLE;
|
||||
memset(s_ep_in_buffer, 0, sizeof(s_ep_in_buffer));
|
||||
memset(s_ep_out_buffer, 0, sizeof(s_ep_out_buffer));
|
||||
|
||||
init_xsm3_identity();
|
||||
}
|
||||
|
||||
static bool xinput_deinit(void)
|
||||
{
|
||||
s_endpoint_in = 0xFF;
|
||||
s_endpoint_out = 0xFF;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void xinput_reset(uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
s_endpoint_in = 0xFF;
|
||||
s_endpoint_out = 0xFF;
|
||||
s_xsm3_auth_state = XSM3_AUTH_STATE_IDLE;
|
||||
}
|
||||
|
||||
static uint16_t xinput_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
|
||||
{
|
||||
/* Claim vendor-class interfaces: Xbox 360 (0xFF) and Original Xbox (0x58) */
|
||||
if (itf_desc->bInterfaceClass != 0xFF && itf_desc->bInterfaceClass != 0x58) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t drv_len = sizeof(tusb_desc_interface_t);
|
||||
uint8_t const *p_desc = tu_desc_next((uint8_t const*)itf_desc);
|
||||
|
||||
/* Original Xbox: Interface Class 0x58, SubClass 0x42 */
|
||||
if (itf_desc->bInterfaceClass == 0x58 && itf_desc->bInterfaceSubClass == 0x42) {
|
||||
for (uint8_t i = 0; i < itf_desc->bNumEndpoints; i++) {
|
||||
tusb_desc_endpoint_t const *ep_desc = (tusb_desc_endpoint_t const *)p_desc;
|
||||
if (TUSB_DESC_ENDPOINT != tu_desc_type(ep_desc)) break;
|
||||
TU_VERIFY(usbd_edpt_open(rhport, ep_desc), 0);
|
||||
if (tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
s_endpoint_in = ep_desc->bEndpointAddress;
|
||||
} else {
|
||||
s_endpoint_out = ep_desc->bEndpointAddress;
|
||||
}
|
||||
drv_len += sizeof(tusb_desc_endpoint_t);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
if (s_endpoint_out != 0xFF) {
|
||||
usbd_edpt_xfer(rhport, s_endpoint_out, s_ep_out_buffer, XINPUT_ENDPOINT_SIZE, false);
|
||||
}
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
return drv_len;
|
||||
}
|
||||
|
||||
/* Interface 0: Gamepad (0x5D/0x01) — open EP 0x81 (IN) & EP 0x02 (OUT) */
|
||||
if (itf_desc->bInterfaceSubClass == 0x5D && itf_desc->bInterfaceProtocol == 0x01) {
|
||||
if (p_desc[1] == DESC_TYPE_VENDOR) {
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
for (uint8_t i = 0; i < itf_desc->bNumEndpoints; i++) {
|
||||
tusb_desc_endpoint_t const *ep_desc = (tusb_desc_endpoint_t const *)p_desc;
|
||||
if (TUSB_DESC_ENDPOINT != tu_desc_type(ep_desc)) break;
|
||||
TU_VERIFY(usbd_edpt_open(rhport, ep_desc), 0);
|
||||
if (tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
s_endpoint_in = ep_desc->bEndpointAddress;
|
||||
} else {
|
||||
s_endpoint_out = ep_desc->bEndpointAddress;
|
||||
}
|
||||
drv_len += sizeof(tusb_desc_endpoint_t);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
if (s_endpoint_out != 0xFF) {
|
||||
usbd_edpt_xfer(rhport, s_endpoint_out, s_ep_out_buffer, XINPUT_ENDPOINT_SIZE, false);
|
||||
}
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
return drv_len;
|
||||
}
|
||||
|
||||
/* Interface 1: Audio (0x5D/0x03) — skip endpoints (stub) */
|
||||
if (itf_desc->bInterfaceSubClass == 0x5D && itf_desc->bInterfaceProtocol == 0x03) {
|
||||
if (p_desc[1] == DESC_TYPE_VENDOR) {
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
for (uint8_t i = 0; i < itf_desc->bNumEndpoints; i++) {
|
||||
drv_len += sizeof(tusb_desc_endpoint_t);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
return drv_len;
|
||||
}
|
||||
|
||||
/* Interface 2: Plugin (0x5D/0x02) — skip endpoints (stub) */
|
||||
if (itf_desc->bInterfaceSubClass == 0x5D && itf_desc->bInterfaceProtocol == 0x02) {
|
||||
if (p_desc[1] == DESC_TYPE_VENDOR) {
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
for (uint8_t i = 0; i < itf_desc->bNumEndpoints; i++) {
|
||||
drv_len += sizeof(tusb_desc_endpoint_t);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
return drv_len;
|
||||
}
|
||||
|
||||
/* Interface 3: Security (0xFD/0x13) — skip 0x41 descriptor, no EPs */
|
||||
if (itf_desc->bInterfaceSubClass == 0xFD && itf_desc->bInterfaceProtocol == 0x13) {
|
||||
if (p_desc[1] == DESC_TYPE_SEC) {
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
}
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
return drv_len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool xinput_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void)result;
|
||||
(void)xferred_bytes;
|
||||
if (ep_addr == s_endpoint_out) {
|
||||
console_mode_t current_mode = profile_manager_get_mode();
|
||||
if (current_mode == CONSOLE_MODE_XBOX360) {
|
||||
/* Xbox 360 Rumble Report: s_ep_out_buffer[0] == 0x00, s_ep_out_buffer[1] == 0x08 */
|
||||
if (s_ep_out_buffer[0] == 0x00 && s_ep_out_buffer[1] == 0x08) {
|
||||
uint8_t heavy = s_ep_out_buffer[3];
|
||||
uint8_t light = s_ep_out_buffer[4];
|
||||
ble_hid_host_send_rumble(heavy, light);
|
||||
}
|
||||
} else if (current_mode == CONSOLE_MODE_XBOXOG) {
|
||||
/* Original Xbox Rumble Report: s_ep_out_buffer[0] == 0x00, s_ep_out_buffer[1] == 0x06 */
|
||||
if (s_ep_out_buffer[0] == 0x00 && s_ep_out_buffer[1] == 0x06) {
|
||||
uint8_t heavy = s_ep_out_buffer[3];
|
||||
uint8_t light = s_ep_out_buffer[5];
|
||||
ble_hid_host_send_rumble(heavy, light);
|
||||
}
|
||||
}
|
||||
/* Re-prime OUT endpoint to receive rumble / LED packets */
|
||||
usbd_edpt_xfer(rhport, s_endpoint_out, s_ep_out_buffer, XINPUT_ENDPOINT_SIZE, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool xinput_control_handler(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
|
||||
{
|
||||
console_mode_t current_mode = profile_manager_get_mode();
|
||||
|
||||
/* Original Xbox XID control request handling */
|
||||
if (current_mode == CONSOLE_MODE_XBOXOG) {
|
||||
/* XID Descriptor Request: bRequest == 0x06 (GET_DESCRIPTOR) and wValue == 0x4200 */
|
||||
if (request->bRequest == 0x06 && request->wValue == 0x4200) {
|
||||
if (stage == CONTROL_STAGE_SETUP) {
|
||||
uint16_t len = (request->wLength < sizeof(ogx_xid_descriptor)) ? request->wLength : sizeof(ogx_xid_descriptor);
|
||||
return tud_control_xfer(rhport, request, (void *)ogx_xid_descriptor, len);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* GET_REPORT on control endpoint (bRequest == 0x01) */
|
||||
if (request->bRequest == 0x01 && (request->bmRequestType & 0x80)) {
|
||||
if (stage == CONTROL_STAGE_SETUP) {
|
||||
controller_state_t st;
|
||||
ogx_report_t rep;
|
||||
usb_gamepad_get_last_state(&st);
|
||||
ogx_build_report(&st, &rep);
|
||||
uint16_t len = (request->wLength < sizeof(rep)) ? request->wLength : sizeof(rep);
|
||||
return tud_control_xfer(rhport, request, &rep, len);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* SET_REPORT on control endpoint (bRequest == 0x09) */
|
||||
if (request->bRequest == 0x09 && !(request->bmRequestType & 0x80)) {
|
||||
return tud_control_status(rhport, request);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (current_mode != CONSOLE_MODE_XBOX360) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t type_bits = request->bmRequestType & 0x60;
|
||||
if (type_bits != 0x40 && type_bits != 0x20) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (request->bRequest) {
|
||||
case 0x81: /* GET Identification */
|
||||
if (stage == CONTROL_STAGE_SETUP) {
|
||||
ESP_LOGI(TAG, "XSM3: 0x81 GET_SERIAL (wLength=%d)", request->wLength);
|
||||
if (request->wLength >= 0x1D) {
|
||||
return tud_control_xfer(rhport, request, s_xsm3_identification, 0x1D);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case 0x82: /* OUT Challenge Init */
|
||||
if (stage == CONTROL_STAGE_SETUP && request->wLength >= 0x22) {
|
||||
return tud_control_xfer(rhport, request, s_xsm3_buf_82, 0x22);
|
||||
}
|
||||
if (stage == CONTROL_STAGE_DATA) {
|
||||
ESP_LOGI(TAG, "XSM3: 0x82 challenge init received, executing crypt...");
|
||||
xsm3_do_challenge_init(s_xsm3_buf_82);
|
||||
s_xsm3_auth_state = XSM3_AUTH_STATE_RESPONDED;
|
||||
}
|
||||
return true;
|
||||
|
||||
case 0x83: /* GET Challenge Response */
|
||||
if (stage == CONTROL_STAGE_SETUP) {
|
||||
if (s_xsm3_auth_state == XSM3_AUTH_STATE_RESPONDED) {
|
||||
ESP_LOGI(TAG, "XSM3: 0x83 sending init response (46 bytes)");
|
||||
uint16_t len = (request->wLength < 46) ? request->wLength : 46;
|
||||
bool ok = tud_control_xfer(rhport, request, xsm3_challenge_response, len);
|
||||
if (ok) s_xsm3_auth_state = XSM3_AUTH_STATE_IDLE;
|
||||
return ok;
|
||||
}
|
||||
if (s_xsm3_auth_state == XSM3_AUTH_STATE_AUTHENTICATED) {
|
||||
ESP_LOGI(TAG, "XSM3: 0x83 sending verify response (22 bytes)");
|
||||
uint16_t len = (request->wLength < 22) ? request->wLength : 22;
|
||||
bool ok = tud_control_xfer(rhport, request, xsm3_challenge_response, len);
|
||||
if (ok) s_xsm3_auth_state = XSM3_AUTH_STATE_IDLE;
|
||||
return ok;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
case 0x84: /* GET Keepalive */
|
||||
if (stage == CONTROL_STAGE_SETUP) {
|
||||
return tud_control_xfer(rhport, request, NULL, 0);
|
||||
}
|
||||
return true;
|
||||
|
||||
case 0x86: /* GET State */
|
||||
if (stage == CONTROL_STAGE_SETUP && request->wLength >= 2) {
|
||||
uint8_t state_val = (s_xsm3_auth_state == XSM3_AUTH_STATE_RESPONDED ||
|
||||
s_xsm3_auth_state == XSM3_AUTH_STATE_AUTHENTICATED)
|
||||
? 2 /* Ready */ : 1 /* Processing */;
|
||||
s_xsm3_state_buf[0] = state_val;
|
||||
s_xsm3_state_buf[1] = 0x00;
|
||||
return tud_control_xfer(rhport, request, s_xsm3_state_buf, 2);
|
||||
}
|
||||
return true;
|
||||
|
||||
case 0x87: /* OUT Challenge Verify */
|
||||
if (stage == CONTROL_STAGE_SETUP && request->wLength >= 0x16) {
|
||||
return tud_control_xfer(rhport, request, s_xsm3_buf_87, 0x16);
|
||||
}
|
||||
if (stage == CONTROL_STAGE_DATA) {
|
||||
ESP_LOGI(TAG, "XSM3: 0x87 verify received, authenticating...");
|
||||
xsm3_do_challenge_verify(s_xsm3_buf_87);
|
||||
s_xsm3_auth_state = XSM3_AUTH_STATE_AUTHENTICATED;
|
||||
ESP_LOGI(TAG, "XSM3: Controller authenticated successfully!");
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool xinput_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
|
||||
{
|
||||
return xinput_control_handler(rhport, stage, request);
|
||||
}
|
||||
|
||||
/* Intercept vendor-specific control requests dispatched directly from usbd.c */
|
||||
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
|
||||
{
|
||||
return xinput_control_handler(rhport, stage, request);
|
||||
}
|
||||
|
||||
static const usbd_class_driver_t s_xinput_class_driver = {
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
.name = "XINPUT",
|
||||
#else
|
||||
.name = NULL,
|
||||
#endif
|
||||
.init = xinput_device_init,
|
||||
.deinit = xinput_deinit,
|
||||
.reset = xinput_reset,
|
||||
.open = xinput_open,
|
||||
.control_xfer_cb = xinput_control_xfer_cb,
|
||||
.xfer_cb = xinput_xfer_cb,
|
||||
.xfer_isr = NULL,
|
||||
.sof = NULL
|
||||
};
|
||||
|
||||
/* Application class driver registration for TinyUSB */
|
||||
usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count)
|
||||
{
|
||||
*driver_count = 1;
|
||||
return &s_xinput_class_driver;
|
||||
}
|
||||
|
||||
void xinput_device_build_report(const controller_state_t *state, xinput_in_report_t *rep)
|
||||
{
|
||||
memset(rep, 0, sizeof(xinput_in_report_t));
|
||||
rep->report_id = 0x00;
|
||||
rep->report_size = sizeof(xinput_in_report_t);
|
||||
|
||||
/* Buttons 0: D-Pad, Start, Back, L3, R3 */
|
||||
if (state->dpad_up) rep->buttons0 |= XINPUT_BTN_DPAD_UP;
|
||||
if (state->dpad_down) rep->buttons0 |= XINPUT_BTN_DPAD_DOWN;
|
||||
if (state->dpad_left) rep->buttons0 |= XINPUT_BTN_DPAD_LEFT;
|
||||
if (state->dpad_right) rep->buttons0 |= XINPUT_BTN_DPAD_RIGHT;
|
||||
if (state->btn_start) rep->buttons0 |= XINPUT_BTN_START;
|
||||
if (state->btn_select) rep->buttons0 |= XINPUT_BTN_BACK;
|
||||
if (state->btn_l3) rep->buttons0 |= XINPUT_BTN_L3;
|
||||
if (state->btn_r3) rep->buttons0 |= XINPUT_BTN_R3;
|
||||
|
||||
/* Buttons 1: LB, RB, Guide, A, B, X, Y */
|
||||
if (state->btn_lb) rep->buttons1 |= XINPUT_BTN_LB;
|
||||
if (state->btn_rb) rep->buttons1 |= XINPUT_BTN_RB;
|
||||
if (state->btn_system) rep->buttons1 |= XINPUT_BTN_GUIDE;
|
||||
if (state->btn_a) rep->buttons1 |= XINPUT_BTN_A;
|
||||
if (state->btn_b) rep->buttons1 |= XINPUT_BTN_B;
|
||||
if (state->btn_x) rep->buttons1 |= XINPUT_BTN_X;
|
||||
if (state->btn_y) rep->buttons1 |= XINPUT_BTN_Y;
|
||||
|
||||
/* Triggers: 0..255 */
|
||||
rep->trigger_l = state->lt;
|
||||
rep->trigger_r = state->rt;
|
||||
|
||||
/* Joysticks: int16_t (-32768..32767).
|
||||
controller_state_t: Up is positive.
|
||||
XInput specification: Up is positive.
|
||||
*/
|
||||
rep->joystick_lx = state->lx;
|
||||
rep->joystick_ly = state->ly;
|
||||
rep->joystick_rx = state->rx;
|
||||
rep->joystick_ry = state->ry;
|
||||
}
|
||||
|
||||
bool xinput_device_send_report(const xinput_in_report_t *rep)
|
||||
{
|
||||
if (!tud_mounted() || s_endpoint_in == 0xFF) return false;
|
||||
if (usbd_edpt_busy(0, s_endpoint_in)) return false;
|
||||
|
||||
memcpy(s_ep_in_buffer, rep, sizeof(xinput_in_report_t));
|
||||
usbd_edpt_claim(0, s_endpoint_in);
|
||||
usbd_edpt_xfer(0, s_endpoint_in, s_ep_in_buffer, sizeof(xinput_in_report_t), false);
|
||||
usbd_edpt_release(0, s_endpoint_in);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ogx_device_init(void)
|
||||
{
|
||||
s_endpoint_in = 0xFF;
|
||||
s_endpoint_out = 0xFF;
|
||||
memset(s_ep_in_buffer, 0, sizeof(s_ep_in_buffer));
|
||||
memset(s_ep_out_buffer, 0, sizeof(s_ep_out_buffer));
|
||||
}
|
||||
|
||||
bool ogx_device_send_report(const void *rep, uint16_t len)
|
||||
{
|
||||
if (!tud_mounted() || s_endpoint_in == 0xFF) return false;
|
||||
if (usbd_edpt_busy(0, s_endpoint_in)) return false;
|
||||
|
||||
memcpy(s_ep_in_buffer, rep, len);
|
||||
usbd_edpt_claim(0, s_endpoint_in);
|
||||
usbd_edpt_xfer(0, s_endpoint_in, s_ep_in_buffer, len, false);
|
||||
usbd_edpt_release(0, s_endpoint_in);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "controller_state.h"
|
||||
#include "tusb.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define XINPUT_VID 0x045E /* Microsoft Corp. */
|
||||
#define XINPUT_PID 0x028E /* Xbox 360 Controller */
|
||||
|
||||
/* Buttons 0 Bitmask */
|
||||
#define XINPUT_BTN_DPAD_UP (1U << 0)
|
||||
#define XINPUT_BTN_DPAD_DOWN (1U << 1)
|
||||
#define XINPUT_BTN_DPAD_LEFT (1U << 2)
|
||||
#define XINPUT_BTN_DPAD_RIGHT (1U << 3)
|
||||
#define XINPUT_BTN_START (1U << 4)
|
||||
#define XINPUT_BTN_BACK (1U << 5)
|
||||
#define XINPUT_BTN_L3 (1U << 6)
|
||||
#define XINPUT_BTN_R3 (1U << 7)
|
||||
|
||||
/* Buttons 1 Bitmask */
|
||||
#define XINPUT_BTN_LB (1U << 0)
|
||||
#define XINPUT_BTN_RB (1U << 1)
|
||||
#define XINPUT_BTN_GUIDE (1U << 2)
|
||||
#define XINPUT_BTN_A (1U << 4)
|
||||
#define XINPUT_BTN_B (1U << 5)
|
||||
#define XINPUT_BTN_X (1U << 6)
|
||||
#define XINPUT_BTN_Y (1U << 7)
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t report_id; /* Always 0x00 */
|
||||
uint8_t report_size; /* Always 0x14 (20 bytes) */
|
||||
uint8_t buttons0; /* D-pad, Start, Back, L3, R3 */
|
||||
uint8_t buttons1; /* LB, RB, Guide, A, B, X, Y */
|
||||
uint8_t trigger_l; /* 0..255 */
|
||||
uint8_t trigger_r; /* 0..255 */
|
||||
int16_t joystick_lx; /* -32768..32767 */
|
||||
int16_t joystick_ly; /* -32768..32767 (Up is positive) */
|
||||
int16_t joystick_rx; /* -32768..32767 */
|
||||
int16_t joystick_ry; /* -32768..32767 (Up is positive) */
|
||||
uint8_t reserved[6];
|
||||
} xinput_in_report_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t report_id; /* 0x00 = Rumble, 0x01 = LED */
|
||||
uint8_t report_size; /* 0x08 */
|
||||
uint8_t led;
|
||||
uint8_t rumble_l; /* Heavy motor */
|
||||
uint8_t rumble_r; /* Light motor */
|
||||
uint8_t reserved[3];
|
||||
} xinput_out_report_t;
|
||||
|
||||
extern const tusb_desc_device_t xinput_device_desc;
|
||||
extern const uint8_t xinput_config_desc[153];
|
||||
extern const char *xinput_string_desc[5];
|
||||
|
||||
void xinput_device_init(void);
|
||||
void xinput_device_build_report(const controller_state_t *state, xinput_in_report_t *rep);
|
||||
bool xinput_device_send_report(const xinput_in_report_t *rep);
|
||||
|
||||
void ogx_device_init(void);
|
||||
bool ogx_device_send_report(const void *rep, uint16_t len);
|
||||
|
||||
/* TinyUSB Application Class Driver for XInput & XSM3 Security Handshake */
|
||||
usbd_class_driver_t const *xinput_device_get_class_driver(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user