Rework DS4 structs based on linux kernel hid driver

This commit is contained in:
Frederik Walk 2023-11-26 09:58:33 +01:00
parent e8c3e5d697
commit 3d217e5729
3 changed files with 17 additions and 53 deletions

View File

@ -13,7 +13,7 @@
extern "C" {
#endif
// https://www.psdevwiki.com/ps4/DS4-USB
// https://github.com/torvalds/linux/blob/master/drivers/hid/hid-playstation.c
typedef struct __attribute((packed, aligned(1))) {
uint8_t report_id;
uint8_t lx;
@ -25,24 +25,23 @@ typedef struct __attribute((packed, aligned(1))) {
uint8_t buttons3;
uint8_t lt;
uint8_t rt;
uint16_t timestamp;
uint8_t battery;
uint16_t sensor_timestamp;
uint8_t sensor_temperature;
uint16_t gyrox;
uint16_t gyroy;
uint16_t gyroz;
int16_t accelx;
int16_t accely;
int16_t accelz;
uint8_t unknown1[5];
uint8_t extension;
uint8_t unknown2[2];
uint8_t touchpad_event_active;
uint8_t touchpad_counter;
uint8_t touchpad1_touches;
uint8_t touchpad1_position[3];
uint8_t touchpad2_touches;
uint8_t touchpad2_position[3];
uint8_t unknown3[21];
uint8_t _reserved1[5];
uint8_t battery;
uint8_t peripheral;
uint8_t _reserved2;
uint8_t touch_report_count;
uint8_t touch_report1[9];
uint8_t touch_report2[9];
uint8_t touch_report3[9];
uint8_t _reserved3[3];
} hid_ps4_report_t;
extern const tusb_desc_device_t ps4_tatacon_desc_device;

View File

@ -48,7 +48,7 @@ enum {
#define USBD_PS4_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
const uint8_t ps4_desc_cfg[] = {
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_LANGUAGE, USBD_PS4_DESC_LEN, 0, USBD_MAX_POWER_MAX),
TUD_HID_INOUT_DESCRIPTOR(USBD_ITF_HID, USBD_STR_PS4, 0, 507, 0x03, 0x84, CFG_TUD_HID_EP_BUFSIZE, 1),
TUD_HID_INOUT_DESCRIPTOR(USBD_ITF_HID, USBD_STR_PS4, 0, 483, 0x03, 0x84, CFG_TUD_HID_EP_BUFSIZE, 1),
};
const uint8_t ps4_desc_hid_report[] = {
@ -289,18 +289,6 @@ const uint8_t ps4_desc_hid_report[] = {
0x09, 0x56, // Usage (0x56)
0x95, 0x02, // Report Count (2)
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x85, 0xE0, // Report ID (-32)
0x09, 0x57, // Usage (0x57)
0x95, 0x02, // Report Count (2)
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x85, 0xB3, // Report ID (-77)
0x09, 0x55, // Usage (0x55)
0x95, 0x3F, // Report Count (63)
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x85, 0xB4, // Report ID (-76)
0x09, 0x55, // Usage (0x55)
0x95, 0x3F, // Report Count (63)
0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
};

View File

@ -138,7 +138,6 @@ usb_report_t InputState::getPS3InputReport() {
usb_report_t InputState::getPS4InputReport() {
static uint8_t report_counter = 0;
static uint8_t last_timestamp = 0;
memset(&m_ps4_report, 0, sizeof(m_ps4_report));
@ -171,35 +170,13 @@ usb_report_t InputState::getPS4InputReport() {
m_ps4_report.lt = (drum.ka_left.triggered ? 0xFF : 0);
m_ps4_report.rt = (drum.ka_right.triggered ? 0xFF : 0);
// Used for gyro/accel, so we don't need to be precise here.
m_ps4_report.timestamp = last_timestamp;
m_ps4_report.battery = 0 | (1 << 4) | 11;
m_ps4_report.gyrox = 0;
m_ps4_report.gyroy = 0;
m_ps4_report.gyroz = 0;
m_ps4_report.accelx = 0;
m_ps4_report.accely = 0;
m_ps4_report.accelz = 0;
m_ps4_report.extension = 0x01;
m_ps4_report.touchpad_event_active = 0;
m_ps4_report.touchpad_counter = 0;
m_ps4_report.touchpad1_touches = (1 << 7);
m_ps4_report.touchpad2_touches = (1 << 7);
m_ps4_report.unknown3[1] = 0x80;
m_ps4_report.unknown3[5] = 0x80;
m_ps4_report.unknown3[10] = 0x80;
m_ps4_report.unknown3[14] = 0x80;
m_ps4_report.unknown3[19] = 0x80;
m_ps4_report.battery = 0 | (1 << 4) | 11; // Cable connected and fully charged
m_ps4_report.peripheral = 0x01;
m_ps4_report.touch_report_count = 0;
// This method actually gets called more often than the report is sent,
// so counters are not consecutive ... let's see if this turns out to
// be a problem.
last_timestamp += 188;
report_counter++;
if (report_counter > (UINT8_MAX >> 2)) {
report_counter = 0;