- 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.
118 lines
4.7 KiB
C
118 lines
4.7 KiB
C
#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
|
|
};
|