SDL: Add support for "standard" Switch 2 report formats

From c6153337a700b1881ab17e033d499e4a47a9b33b Mon Sep 17 00:00:00 2001
From: Vicki Pfau <[EMAIL REDACTED]>
Date: Mon, 16 Nov 2026 22:01:09 -0800
Subject: [PATCH] Add support for "standard" Switch 2 report formats

While all first party controllers support a "unified" format with a simpler
IMU data format, the Switch 2 itself only ever uses the device-specific
report formats, and some third-party (e.g. NYXI Hyperion 3) controllers
don't support the unified format.

The device-specific format has a much more complex IMU format that differs
between wired and wireless. This only implements the wired format, as we
don't support it over Bluetooth yet.
---
 src/joystick/hidapi/SDL_hidapi_switch2.c | 690 +++++++++++++++++++----
 1 file changed, 593 insertions(+), 97 deletions(-)

diff --git a/src/joystick/hidapi/SDL_hidapi_switch2.c b/src/joystick/hidapi/SDL_hidapi_switch2.c
index 4085ec194bc46..e84a2f273075b 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch2.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch2.c
@@ -74,6 +74,15 @@ enum
     SDL_GAMEPAD_NUM_SWITCH2_GAMECUBE_BUTTONS
 };
 
+enum
+{
+    SDL_GAMEPAD_SWITCH2_REPORT_UNIFIED = 0x05,
+    SDL_GAMEPAD_SWITCH2_REPORT_JOYCON_LEFT = 0x07,
+    SDL_GAMEPAD_SWITCH2_REPORT_JOYCON_RIGHT = 0x08,
+    SDL_GAMEPAD_SWITCH2_REPORT_PRO = 0x09,
+    SDL_GAMEPAD_SWITCH2_REPORT_GAMECUBE = 0x0A,
+};
+
 typedef struct
 {
     Uint16 neutral;
@@ -127,6 +136,7 @@ typedef struct
     Uint64 sensor_ticks;
     Uint64 sensor_ts_coeff;
     float gyro_coeff;
+    float last_quat[4];
 
     bool player_lights;
     int player_index;
@@ -419,14 +429,6 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
         (Uint8[]) { // Enable grip buttons on charging grip
             0x8, 0x91, 0x0, 0x2, 0x0, 0x4, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0,
         },
-        (Uint8[]) { // Set report format
-            0x03, 0x91, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00,
-            0x05, 0x00, 0x00, 0x00
-        },
-        (Uint8[]) { // Start output
-            0x03, 0x91, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00,
-            0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-        },
         NULL, // Sentinel
     };
 
@@ -505,6 +507,39 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
         RecvBulkData(ctx, calibration_data, 0x40);
     }
 
+    Uint8 set_report_format[] = {
+        0x03, 0x91, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00,
+        SDL_GAMEPAD_SWITCH2_REPORT_UNIFIED, 0x00, 0x00, 0x00
+    };
+    switch (device->product_id) {
+    case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+        set_report_format[8] = SDL_GAMEPAD_SWITCH2_REPORT_JOYCON_LEFT;
+        break;
+    case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+        set_report_format[8] = SDL_GAMEPAD_SWITCH2_REPORT_JOYCON_RIGHT;
+        break;
+    case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+        set_report_format[8] = SDL_GAMEPAD_SWITCH2_REPORT_PRO;
+        break;
+    case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
+        set_report_format[8] = SDL_GAMEPAD_SWITCH2_REPORT_GAMECUBE;
+        break;
+    }
+    res = SendBulkData(ctx, set_report_format, 12);
+    if (res < 0) {
+        return SDL_SetError("Couldn't send set report format data: %d\n", res);
+    }
+    RecvBulkData(ctx, calibration_data, 0x40);
+
+    res = SendBulkData(ctx, (Uint8[]) { // Start output
+        0x03, 0x91, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00,
+        0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    } , 16);
+    if (res < 0) {
+        return SDL_SetError("Couldn't send start data: %d\n", res);
+    }
+    RecvBulkData(ctx, calibration_data, 0x40);
+
     return true;
 }
 
@@ -575,8 +610,8 @@ static bool HIDAPI_DriverSwitch2_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
 
     // Initialize the joystick capabilities
     if (!ctx->device->parent) {
-        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
-        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
+        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 800.0f);
+        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 800.0f);
     }
     switch (device->product_id) {
     case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
@@ -584,17 +619,17 @@ static bool HIDAPI_DriverSwitch2_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
         break;
     case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
         if (ctx->device->parent) {
-            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_L, 250.0f);
-            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_L, 250.0f);
+            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_L, 800.0f);
+            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_L, 800.0f);
         }
         joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH2_JOYCON_BUTTONS;
         break;
     case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
         if (ctx->device->parent) {
-            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
-            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
-            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_R, 250.0f);
-            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_R, 250.0f);
+            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 800.0f);
+            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 800.0f);
+            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO_R, 800.0f);
+            SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL_R, 800.0f);
         }
         joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH2_JOYCON_BUTTONS;
         break;
@@ -663,9 +698,8 @@ static bool HIDAPI_DriverSwitch2_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *de
     return true;
 }
 
-static void HandleGameCubeState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+static void HandleGameCubeUnifiedState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
-
     if (data[5] != ctx->last_state[5]) {
         SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
         SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[5] & 0x02) != 0));
@@ -752,7 +786,95 @@ static void HandleGameCubeState(Uint64 timestamp, SDL_Joystick *joystick, SDL_Dr
     );
 }
 
-static void HandleCombinedControllerStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+static void HandleGameCubeState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+    if (data[3] != ctx->last_state[3]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x04) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_RIGHT_TRIGGER, ((data[3] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_RIGHT_SHOULDER, ((data[3] & 0x20) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_START, ((data[3] & 0x40) != 0));
+    }
+
+    if (data[4] != ctx->last_state[4]) {
+        Uint8 hat = 0;
+
+        if (data[4] & 0x01) {
+            hat |= SDL_HAT_DOWN;
+        }
+        if (data[4] & 0x02) {
+            hat |= SDL_HAT_RIGHT;
+        }
+        if (data[4] & 0x04) {
+            hat |= SDL_HAT_LEFT;
+        }
+        if (data[4] & 0x08) {
+            hat |= SDL_HAT_UP;
+        }
+        SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_LEFT_TRIGGER, ((data[4] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_LEFT_SHOULDER, ((data[4] & 0x20) != 0));
+    }
+
+    if (data[5] != ctx->last_state[5]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_GUIDE, ((data[5] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_SHARE, ((data[5] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_GAMECUBE_C, ((data[5] & 0x10) != 0));
+    }
+
+    MapTriggerAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
+        ctx->left_trigger_zero,
+        data[13]
+    );
+    MapTriggerAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
+        ctx->right_trigger_zero,
+        data[14]
+    );
+
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTX,
+        &ctx->left_stick.x,
+        (float) (data[6] | ((data[7] & 0x0F) << 8)),
+        false
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTY,
+        &ctx->left_stick.y,
+        (float) ((data[7] >> 4) | (data[8] << 4)),
+        true
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHTX,
+        &ctx->right_stick.x,
+        (float) (data[9] | ((data[10] & 0x0F) << 8)),
+        false
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHTY,
+        &ctx->right_stick.y,
+        (float)((data[10] >> 4) | (data[11] << 4)),
+        true
+    );
+}
+
+static void HandleCombinedControllerUnifiedStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
     if (data[6] != ctx->last_state[6]) {
         SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[6] & 0x01) != 0));
@@ -805,7 +927,57 @@ static void HandleCombinedControllerStateL(Uint64 timestamp, SDL_Joystick *joyst
     );
 }
 
-static void HandleMiniControllerStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+static void HandleCombinedControllerStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+    if (data[3] != ctx->last_state[3]) {
+        Uint8 hat = 0;
+
+        if (data[3] & 0x01) {
+            hat |= SDL_HAT_DOWN;
+        }
+        if (data[3] & 0x02) {
+            hat |= SDL_HAT_RIGHT;
+        }
+        if (data[3] & 0x04) {
+            hat |= SDL_HAT_LEFT;
+        }
+        if (data[3] & 0x08) {
+            hat |= SDL_HAT_UP;
+        }
+        SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[3] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[3] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[3] & 0x80) != 0));
+    }
+
+    if (data[4] != ctx->last_state[4]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_SHARE, ((data[4] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE1, ((data[4] & 0x04) != 0));
+    }
+
+    Sint16 axis = (data[3] & 0x20) ? 32767 : -32768;
+    SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTX,
+        &ctx->left_stick.x,
+        (float) (data[6] | ((data[7] & 0x0F) << 8)),
+        false
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTY,
+        &ctx->left_stick.y,
+        (float) ((data[7] >> 4) | (data[8] << 4)),
+        true
+    );
+}
+
+static void HandleMiniControllerUnifiedStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
     if (data[6] != ctx->last_state[6]) {
         SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[6] & 0x01) != 0));
@@ -843,7 +1015,44 @@ static void HandleMiniControllerStateL(Uint64 timestamp, SDL_Joystick *joystick,
     );
 }
 
-static void HandleCombinedControllerStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+static void HandleMiniControllerStateL(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+    if (data[3] != ctx->last_state[3]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x04) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE1, ((data[3] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_LEFT_PADDLE2, ((data[3] & 0x20) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[3] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[3] & 0x80) != 0));
+    }
+
+    if (data[4] != ctx->last_state[4]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[4] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[4] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[4] & 0x80) != 0));
+    }
+
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTY,
+        &ctx->left_stick.x,
+        (float) (data[6] | ((data[7] & 0x0F) << 8)),
+        true
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTX,
+        &ctx->left_stick.y,
+        (float) ((data[7] >> 4) | (data[8] << 4)),
+        true
+    );
+}
+
+static void HandleCombinedControllerUnifiedStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
     if (data[5] != ctx->last_state[5]) {
         SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
@@ -885,7 +1094,46 @@ static void HandleCombinedControllerStateR(Uint64 timestamp, SDL_Joystick *joyst
     );
 }
 
-static void HandleMiniControllerStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+static void HandleCombinedControllerStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+    if (data[3] != ctx->last_state[3]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x04) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[3] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[3] & 0x80) != 0));
+    }
+
+    if (data[4] != ctx->last_state[4]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[4] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_C, ((data[4] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE1, ((data[4] & 0x04) != 0));
+    }
+
+    Sint16 axis = (data[3] & 0x20) ? 32767 : -32768;
+    SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHTX,
+        &ctx->left_stick.x,
+        (float) (data[6] | ((data[7] & 0x0F) << 8)),
+        false
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHTY,
+        &ctx->left_stick.y,
+        (float) ((data[7] >> 4) | (data[8] << 4)),
+        true
+    );
+}
+
+static void HandleMiniControllerUnifiedStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
     if (data[5] != ctx->last_state[5]) {
         SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[5] & 0x01) != 0));
@@ -923,7 +1171,45 @@ static void HandleMiniControllerStateR(Uint64 timestamp, SDL_Joystick *joystick,
     );
 }
 
-static void HandleSwitchProState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+static void HandleMiniControllerStateR(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+    if (data[3] != ctx->last_state[3]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x04) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE1, ((data[3] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_RIGHT_PADDLE2, ((data[3] & 0x20) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[3] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[3] & 0x80) != 0));
+    }
+
+    if (data[4] != ctx->last_state[4]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[4] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_JOYCON_C, ((data[4] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[4] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[4] & 0x80) != 0));
+    }
+
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTY,
+        &ctx->left_stick.x,
+        (float) (data[6] | ((data[7] & 0x0F) << 8)),
+        true
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTX,
+        &ctx->left_stick.y,
+        (float) ((data[7] >> 4) | (data[8] << 4)),
+        true
+    );
+}
+
+static void HandleSwitchProUnifiedState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
     Sint16 axis;
 
@@ -1010,6 +1296,90 @@ static void HandleSwitchProState(Uint64 timestamp, SDL_Joystick *joystick, SDL_D
     );
 }
 
+static void HandleSwitchProState(Uint64 timestamp, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
+{
+    Sint16 axis;
+
+    if (data[3] != ctx->last_state[3]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH, ((data[3] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST, ((data[3] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST, ((data[3] & 0x04) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH, ((data[3] & 0x08) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((data[3] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START, ((data[3] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((data[3] & 0x80) != 0));
+    }
+
+    if (data[4] != ctx->last_state[4]) {
+        Uint8 hat = 0;
+
+        if (data[4] & 0x01) {
+            hat |= SDL_HAT_DOWN;
+        }
+        if (data[4] & 0x02) {
+            hat |= SDL_HAT_RIGHT;
+        }
+        if (data[4] & 0x04) {
+            hat |= SDL_HAT_LEFT;
+        }
+        if (data[4] & 0x08) {
+            hat |= SDL_HAT_UP;
+        }
+        SDL_SendJoystickHat(timestamp, joystick, 0, hat);
+
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((data[4] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK, ((data[4] & 0x40) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((data[4] & 0x80) != 0));
+    }
+
+    if (data[5] != ctx->last_state[5]) {
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, ((data[5] & 0x01) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_SHARE, ((data[5] & 0x02) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_C, ((data[5] & 0x10) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_RIGHT_PADDLE, ((data[5] & 0x04) != 0));
+        SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SWITCH2_PRO_LEFT_PADDLE, ((data[5] & 0x08) != 0));
+    }
+
+    axis = (data[3] & 0x20) ? 32767 : -32768;
+    SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, axis);
+
+    axis = (data[4] & 0x20) ? 32767 : -32768;
+    SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, axis);
+
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTX,
+        &ctx->left_stick.x,
+        (float) (data[6] | ((data[7] & 0x0F) << 8)),
+        false
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_LEFTY,
+        &ctx->left_stick.y,
+        (float) ((data[7] >> 4) | (data[8] << 4)),
+        true
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHTX,
+        &ctx->right_stick.x,
+        (float) (data[9] | ((data[10] & 0x0F) << 8)),
+        false
+    );
+    MapJoystickAxis(
+        timestamp,
+        joystick,
+        SDL_GAMEPAD_AXIS_RIGHTY,
+        &ctx->right_stick.y,
+        (float)((data[10] >> 4) | (data[11] << 4)),
+        true
+    );
+}
+
 static void EncodeHDRumble(Uint16 high_freq, Uint16 high_amp, Uint16 low_freq, Uint16 low_amp, Uint8 rumble_data[5])
 {
     rumble_data[0] = (Uint8)(high_freq & 0xFF);
@@ -1095,97 +1465,223 @@ static bool UpdateRumble(SDL_DriverSwitch2_Context *ctx)
 static void HIDAPI_DriverSwitch2_HandleStatePacket(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_DriverSwitch2_Context *ctx, Uint8 *data, int size)
 {
     Uint64 timestamp = SDL_GetTicksNS();
+    float accel_data[3];
+    float gyro_data[3];
+    bool sensor_data_ok = false;
+    Uint64 sensor_timestamp_ns;
 
     if (size < 64) {
         // We don't know how to handle this report
         return;
     }
 
-    switch (device->product_id) {
-    case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
-        HandleGameCubeState(timestamp, joystick, ctx, data, size);
-        break;
-    case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
-        if (device->parent || ctx->vertical_mode) {
-            HandleCombinedControllerStateL(timestamp, joystick, ctx, data, size);
-        } else {
-            HandleMiniControllerStateL(timestamp, joystick, ctx, data, size);
-        }
-        break;
-    case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
-        if (device->parent || ctx->vertical_mode) {
-            HandleCombinedControllerStateR(timestamp, joystick, ctx, data, size);
-        } else {
-            HandleMiniControllerStateR(timestamp, joystick, ctx, data, size);
+    if (data[0] == SDL_GAMEPAD_SWITCH2_REPORT_UNIFIED) {
+        switch (device->product_id) {
+        case USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER:
+            HandleGameCubeUnifiedState(timestamp, joystick, ctx, data, size);
+            break;
+        case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_LEFT:
+            if (device->parent || ctx->vertical_mode) {
+                HandleCombinedControllerUnifiedStateL(timestamp, joystick, ctx, data, size);
+            } else {
+                HandleMiniControllerUnifiedStateL(timestamp, joystick, ctx, data, size);
+            }
+            break;
+        case USB_PRODUCT_NINTENDO_SWITCH2_JOYCON_RIGHT:
+            if (device->parent || ctx->vertical_mode) {
+                HandleCombinedControllerUnifiedStateR(timestamp, joystick, ctx, data, size);
+            } else {
+                HandleMiniControllerUnifiedStateR(timestamp, joystick, ctx, data, size);
+            }
+            break;
+        case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
+            HandleSwitchProUnifiedState(timestamp, joystick, ctx, data, size);
+            break;
+        default:
+            // FIXME: Need state handling implementation
+            break;
         }
-        break;
-    case USB_PRODUCT_NINTENDO_SWITCH2_PRO:
-        HandleSwitchProState(timestamp, joystick, ctx, data, size);
-        break;
-    default:
-        // FIXME: Need state handling implementation
-        break;
-    }
 
-    Uint32 sensor_timestamp = (Uint32) (data[0x2b] | (data[0x2c] << 8U) | (data[0x2d] << 16U) | (data[0x2e] << 24U));
-    if (sensor_timestamp) {
-        if (ctx->last_sensor_timestamp) {
-            ctx->sensor_ticks += (Uint32)(sensor_timestamp - ctx->last_sensor_timestamp);
-        } else {
-            ctx->sensor_ticks = sensor_timestamp;
-        }
-        ctx->last_sensor_timestamp = sensor_timestamp;
-    }
-    if (sensor_timestamp && !ctx->sensors_ready) {
-        ctx->sample_count++;
-        if (ctx->sample_count >= 5 && !ctx->first_sensor_timestamp) {
-            ctx->first_sensor_timestamp = sensor_timestamp;
-            ctx->sample_count = 0;
-        } else if (ctx->sample_count == 100) {
-            // Calculate timestamp coefficient
-            // Timestamp are normally microseconds but sometimes it's something else for no apparent reason
-            Uint64 coeff = 1000 * (Uint64)(sensor_timestamp - ctx->first_sensor_timestamp) / (ctx->sample_count * 4);
-            if ((coeff + 100000) / 200000 == 5) {
-                // Within 10% of 1000
-                ctx->sensor_ts_coeff = 10000;
-                ctx->gyro_coeff = 34.8f;
-                ctx->sensors_ready = true;
-            } else if (coeff != 0) {
-                ctx->sensor_ts_coeff = 10000000000 / coeff;
-                ctx->gyro_coeff = 40.0f;
-                ctx->sensors_ready = true;
+        Uint32 sensor_timestamp = (Uint32) (data[0x2b] | (data[0x2c] << 8U) | (data[0x2d] << 16U) | (data[0x2e] << 24U));
+        if (sensor_timestamp) {
+            if (ctx->last_sensor_timestamp) {
+                ctx->sensor_ticks += (Uint32)(sensor_timestamp - ctx->last_sensor_timestamp);
             } else {
-                // Didn't get a valid reading, try again
-                ctx->first_sensor_timestamp = 0;
-                ctx->sample_count = 0;
+                ctx->sensor_ticks = sensor_timestamp;
             }
+            ctx->last_sensor_timestamp = sensor_timestamp;
+        }
+        if (sensor_timestamp && !ctx->sensors_ready) {
+            ctx->sample_count++;
+            if (ctx->sample_count >= 5 && !ctx->first_sensor_timestamp) {
+                ctx->first_sensor_timestamp = sensor_timestamp;
+                ctx->sample_count = 0;
+            } else if (ctx->sample_count == 100) {
+                // Calculate timestamp coefficient
+                // Timestamp are normally microseconds but sometimes it's something else for no apparent reason
+                Uint64 coeff = 1000 * (sensor_timestamp - ctx->first_sensor_timestamp) / (ctx->sample_count * 4);
+                if ((coeff + 100000) / 200000 == 5) {
+                    // Within 10% of 1000
+                    ctx->sensor_ts_coeff = 10000;
+                    ctx->gyro_coeff = 34.8f;
+                    ctx->sensors_ready = true;
+                } else if (coeff != 0) {
+                    ctx->sensor_ts_coeff = 10000000000 / coeff;
+                    ctx->gyro_coeff = 40.0f;
+                    ctx->sensors_ready = true;
+                } else {
+                    // Didn't get a valid reading, try again
+                    ctx->first_sensor_timestamp = 0;
+                    ctx->sample_count = 0;
+                }
 
-            if (ctx->sensors_ready && !ctx->sensors_enabled) {
-                Uint8 set_features[] = {
-                        0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00
-                };
-                unsigned char reply[12] = {0};
+                if (ctx->sensors_ready && !ctx->sensors_enabled) {
+                    Uint8 set_features[] = {
+                            0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00
+                    };
+                    unsigned char reply[12] = {0};
 
-                SendBulkData(ctx, set_features, sizeof(set_features));
-                RecvBulkData(ctx, reply, sizeof(reply));
+                    SendBulkData(ctx, set_features, sizeof(set_features));
+                    RecvBulkData(ctx, reply, sizeof(reply));
+                }
             }
         }
-    }
-    if (ctx->sensors_enabled && sensor_timestamp && ctx->sensors_ready) {
-        Uint64 sensor_timestamp_ns = ctx->sensor_ticks * ctx->sensor_ts_coeff / 10;
-        float accel_data[3];
-        float gyro_data[3];
-        const float g = 9.80665f;
-        const float accel_scale = g * 8.f / INT16_MAX;
+        if (ctx->sensors_enabled && sensor_timestamp && ctx->sensors_ready) {
+            sensor_timestamp_ns = sensor_timestamp * ctx->sensor_ts_coeff / 10;
+            const float accel_scale = SDL_STANDARD_GRAVITY * 8.f / INT16_MAX;
+
+            accel_data[0] = (Sint16)(data[0x31] | (data[0x32] << 8)) * accel_scale;
+            accel_data[1] = (Sint16)(data[0x35] | (data[0x36] << 8)) * accel_scale;
+            accel_data[2] = (Sint16)(data[0x33] | (data[0x34] << 8)) * -accel_scale;
+
+            gyro_data[0] = (Sint16)(data[0x37] | (data[0x38] << 8)) * ctx->gyro_coeff / INT16_MAX - ctx->gyro_bias_x;
+            gyro_data[1] = (Sint16)(data[0x3b] | (data[0x3c] << 8)) * ctx->gyro_coeff / INT16_MAX - ctx->gyro_bias_z;
+            gyro_data[2] = (Sint16)(data[0x39] | (data[0x3a] << 8)) * -ctx->gyro_coeff / INT16_MAX + ctx->gyro_bias_y;
+            sensor_data_ok = true;
+        }
+    } else {
+        int motion_start = 15;
+        int sample;
+        int delta;
+        int quat_index;
+        float quat_data[4];
+        float diff_quat[4];
+        float norm;
+        Uint8 *motion_data;
+        const float accel_scale = (float) (SDL_STANDARD_GRAVIT

(Patch may be truncated, please check the link at the top of this post.)