Răsfoiți Sursa

switch2: Send full init sequence from real hardware

Vicki Pfau 4 luni în urmă
părinte
comite
70bfdd013a
1 a modificat fișierele cu 42 adăugiri și 7 ștergeri
  1. 42 7
      src/joystick/hidapi/SDL_hidapi_switch2.c

+ 42 - 7
src/joystick/hidapi/SDL_hidapi_switch2.c

@@ -333,9 +333,42 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
     }
     ctx->interface_claimed = true;
 
-    const unsigned char INIT_DATA[] = {
-        0x03, 0x91, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00,
-        0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+    const struct {
+        Uint8 size;
+        const Uint8 *data;
+    } init_sequence[] = {
+        { 8, (Uint8[]) { // Unknown purpose
+            0x7, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+        }},
+        { 8, (Uint8[]) { // Unknown purpose
+            0x16, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+        }},
+        { 12, (Uint8[]) { // Set feature output bit mask
+            0x0c, 0x91, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00
+        }},
+        { 8, (Uint8[]) { // Unknown purpose
+            0x11, 0x91, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0,
+        }},
+        { 28, (Uint8[]) { // Set rumble data?
+            0x0a, 0x91, 0x00, 0x08, 0x00, 0x14, 0x00, 0x00,
+            0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+            0xff, 0x35, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00
+        }},
+        { 12, (Uint8[]) { // Enable feature output bits
+            0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00
+        }},
+        { 8, (Uint8[]) { // Unknown purpose
+            0x10, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+        }},
+        { 8, (Uint8[]) { // Enable rumble
+            0x01, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
+        }},
+        { 16, (Uint8[]) { // Start output
+            0x03, 0x91, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00,
+            0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+        }},
+        { 0, NULL }, // Sentinel
     };
     unsigned char flash_read_command[] = {
         0x02, 0x91, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00,
@@ -343,11 +376,13 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
     };
     unsigned char calibration_data[0x50] = {0};
 
-    res = SendBulkData(ctx, INIT_DATA, sizeof(INIT_DATA));
-    if (res < 0) {
-        return SDL_SetError("Couldn't send initialization data: %d\n", res);
+    for (int i = 0; init_sequence[i].size; i++) {
+        res = SendBulkData(ctx, init_sequence[i].data, init_sequence[i].size);
+        if (res < 0) {
+            return SDL_SetError("Couldn't send initialization data: %d\n", res);
+        }
+        RecvBulkData(ctx, calibration_data, 0x40);
     }
-    RecvBulkData(ctx, calibration_data, 0x40);
 
     // Wait for initialization to complete
     SDL_Delay(1);