- 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.
138 lines
5.1 KiB
C
138 lines
5.1 KiB
C
#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
|