From 3d2b28b1a1df017559a470c0029a86052985fe3f Mon Sep 17 00:00:00 2001 From: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com> Date: Tue, 10 Nov 2026 18:32:06 +0000 Subject: [PATCH 1/4] Common: S2 OEM controller state + PABotBase2 NS2 message headers (CC-side copies) --- .../NintendoSwitch2_OemController_State.cpp | 159 ++++++++ .../NintendoSwitch2_OemController_State.h | 338 ++++++++++++++++++ .../PABotBase2_Controller_NS2_OemController.h | 95 +++++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 4 files changed, 595 insertions(+) create mode 100644 Common/ControllerStates/NintendoSwitch2_OemController_State.cpp create mode 100644 Common/ControllerStates/NintendoSwitch2_OemController_State.h create mode 100644 Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h diff --git a/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp b/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp new file mode 100644 index 0000000000..6a9e43f631 --- /dev/null +++ b/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp @@ -0,0 +1,159 @@ +/* Nintendo Switch 2 - OEM Controller State + * + * From: https://github.com/PokemonAutomation/ + * + */ + + +#include +#include "NintendoSwitch2_OemController_State.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch2{ + + +// Every input report payload is exactly 63 bytes on the wire +// (64 over USB including the report ID byte). +static_assert(sizeof(OemController_State0x05) == 63, "Report 0x05 must be 63 bytes"); +static_assert(sizeof(OemController_State0x07) == 63, "Report 0x07 must be 63 bytes"); +static_assert(sizeof(OemController_State0x08) == 63, "Report 0x08 must be 63 bytes"); +static_assert(sizeof(OemController_State0x09) == 63, "Report 0x09 must be 63 bytes"); +static_assert(sizeof(OemController_State0x0A) == 63, "Report 0x0A must be 63 bytes"); + + +const OemController_RumbleState OemController_RumbleState_NEUTRAL_STATE = { + // Zero amplitude is silent. + .left = {}, + .right = {}, +}; + + +const OemController_RumbleStateGC OemController_RumbleStateGC_NEUTRAL_STATE = { + .motor = {}, +}; + + +const OemController_State0x05 OemController_State0x05_NEUTRAL_STATE = { + .counter = 0, + .buttons = {}, + .unknown_0x08 = {}, + .left_stick = {0x00, 0x08, 0x80}, + .right_stick = {0x00, 0x08, 0x80}, + .optical = {}, + .unknown_0x18 = 0, + .magnetometer = {}, + .battery_voltage_mv = 0, + .charging_state = 0, + .battery_current = 0, + .unknown_0x24 = {}, + .unknown_0x29 = 0, + .motion = {}, + .left_trigger = 0, + .right_trigger = 0, + .reserved = 0, +}; + + +bool OemController_State0x05_equals( + const OemController_State0x05* state0, + const OemController_State0x05* state1 +){ + return memcmp(state0, state1, sizeof(OemController_State0x05)) == 0; +} + + +const OemController_State0x07 OemController_State0x07_NEUTRAL_STATE = { + .counter = 0, + .power_info = 0, + .buttons0 = 0, + .buttons1 = 0, + .unknown_0x04 = 0x07, + .stick = {0x00, 0x08, 0x80}, + .unknown_0x08 = 0, + .optical = {}, + .motion_length = 0, + .motion_data = {}, + .reserved = {}, +}; + + +bool OemController_State0x07_equals( + const OemController_State0x07* state0, + const OemController_State0x07* state1 +){ + return memcmp(state0, state1, sizeof(OemController_State0x07)) == 0; +} + + +const OemController_State0x08 OemController_State0x08_NEUTRAL_STATE = { + .counter = 0, + .power_info = 0, + .buttons0 = 0, + .buttons1 = 0, + .unknown_0x04 = 0x07, + .stick = {0x00, 0x08, 0x80}, + .unknown_0x08 = 0, + .optical = {}, + .nfc_state = 0, + .motion_length = 0, + .motion_data = {}, + .reserved = {}, +}; + + +bool OemController_State0x08_equals( + const OemController_State0x08* state0, + const OemController_State0x08* state1 +){ + return memcmp(state0, state1, sizeof(OemController_State0x08)) == 0; +} + + +const OemController_State0x09 OemController_State0x09_NEUTRAL_STATE = { + .counter = 0, + .power_info = 0, + .buttons = {}, + .left_stick = {0x00, 0x08, 0x80}, + .right_stick = {0x00, 0x08, 0x80}, + .unknown_0x0B = 0x30, + .nfc_state = 0, + .headset_audio_state = 0, + .motion_length = 0, + .motion_data = {}, + .reserved = {}, +}; + + +bool OemController_State0x09_equals( + const OemController_State0x09* state0, + const OemController_State0x09* state1 +){ + return memcmp(state0, state1, sizeof(OemController_State0x09)) == 0; +} + + +const OemController_State0x0A OemController_State0x0A_NEUTRAL_STATE = { + .counter = 0, + .power_info = 0, + .buttons = {}, + .left_stick = {0x00, 0x08, 0x80}, + .right_stick = {0x00, 0x08, 0x80}, + .unknown_0x0B = 0x30, + .left_trigger = 0, + .right_trigger = 0, + .motion_length = 0, + .motion_data = {}, + .reserved = {}, +}; + + +bool OemController_State0x0A_equals( + const OemController_State0x0A* state0, + const OemController_State0x0A* state1 +){ + return memcmp(state0, state1, sizeof(OemController_State0x0A)) == 0; +} + + +} +} diff --git a/Common/ControllerStates/NintendoSwitch2_OemController_State.h b/Common/ControllerStates/NintendoSwitch2_OemController_State.h new file mode 100644 index 0000000000..fb35cfc7b1 --- /dev/null +++ b/Common/ControllerStates/NintendoSwitch2_OemController_State.h @@ -0,0 +1,338 @@ +/* Nintendo Switch 2 - OEM Controller State + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_NintendoSwitch2_OemController_State_H +#define PokemonAutomation_NintendoSwitch2_OemController_State_H + +#include +#include + +// The report payloads place 16-bit fields on odd byte offsets, so the +// report structs are packed to keep a byte-exact wire layout. +#pragma pack(push, 1) + +namespace PokemonAutomation{ +namespace NintendoSwitch2{ + + + +// +// Notes +// +// Every S2 controller has two input report formats: +// +// - 0x05 (common): one shape for every controller type. This is the +// "grip" format - what a charging grip presents for a docked Joy-Con 2 +// L+R pair, and the stable alternate used by PC tools. All controllers +// can produce it. +// - Native side reports 0x07/0x08/0x09/0x0A (Joy-Con 2 L, Joy-Con 2 R, +// Pro Controller 2, NSO GameCube): the power-on default for a +// standalone controller of that type, and what the console uses for it. +// +// The host picks the format with command 0x03 sub 0x0A over USB (the +// controller streams the selected report; power-up default is the native +// side report for that controller type). Over BLE both formats exist as +// separate GATT characteristics (0x05 at handle 0x000a, native at +// 0x000e) and the host subscribes to whichever it wants via the CCCs; +// the 0x03 sub 0x0A value in the known-good BLE startup sequence is +// 0x09 even for Joy-Con 2, so it is not a literal report ID there. +// +// All structs below are the 63-byte report payloads WITHOUT the USB +// report ID byte (BLE notifications omit it; USB reports prepend it). +// Multi-byte fields are little-endian on the wire. Sticks are packed +// 12-bit: X = b0 | ((b1 & 0x0f) << 8); Y = (b1 >> 4) | (b2 << 4); +// neutral is ~0x800 but the true center comes from the controller's +// flash calibration. +// + +// +// Console <-> Controller +// + + +// 16-byte LRA frame per motor (HD rumble). The Pro Controller 2 drives +// both frames; a Joy-Con 2 drives the single frame for its side; the +// NSO GameCube controller uses a separate 4-byte motor format +// (OemController_RumbleStateGC). The internal packing (two +// frequency/amplitude pairs) is partially opaque; zero amplitude is +// silent. +struct OemController_RumbleState{ + uint8_t left[16]; + uint8_t right[16]; +}; + +extern const OemController_RumbleState OemController_RumbleState_NEUTRAL_STATE; + + +// NSO GameCube controller motor (4-byte packed frame, output report 0x03). +struct OemController_RumbleStateGC{ + uint8_t motor[4]; +}; + +extern const OemController_RumbleStateGC OemController_RumbleStateGC_NEUTRAL_STATE; + + +// +// Report 0x05 (common input report - all controller types) +// + + +struct OemController_State0x05_Optical{ + uint16_t position_x; // absolute position (Joy-Con 2 only; zeros elsewhere) + uint16_t position_y; + uint16_t status0; // low byte tracks the native coveredness/lift-off byte + uint16_t status1; // lift-off distance?; semantics open +}; + +struct OemController_State0x05_Magnetometer{ + int16_t x; // 0.15 uT/LSB (feature bit 7) + int16_t y; + int16_t z; +}; + +struct OemController_State0x05_Motion{ + uint32_t timestamp; // microseconds (some controllers report it incorrectly) + int16_t temperature; // deviation from 25C (1/126.9 C/LSB) + int16_t accel_x; // default FSR +/-8G (8.0/32767 G/LSB) + int16_t accel_y; + int16_t accel_z; + int16_t gyro_x; // default FSR +/-2000dps (2000.0/32767 dps/LSB) + int16_t gyro_y; + int16_t gyro_z; +}; + +// The fast-path input fields of report 0x05: the buttons, sticks, and +// the GameCube analog triggers. It does not embed in +// OemController_State0x05 (the triggers sit after the motion block, so +// the fields are not contiguous on the wire); the remaining 0x05 fields +// only update on full-state commands. +struct OemController_State0x05_Buttons{ + uint8_t buttons[4]; + uint8_t left_stick[3]; + uint8_t right_stick[3]; + uint8_t left_trigger; + uint8_t right_trigger; +}; + +struct OemController_State0x05{ + uint32_t counter; + + // 4 button bytes (MSB -> LSB): + // byte0: ZR R SL-R SR-R A B X Y + // byte1: C Capture Home Lstickclick Rstickclick Plus Minus + // byte2: ZL L SL-L SR-L Left Right Up Down + // byte3: - - - Headset - - GL GR + uint8_t buttons[4]; + + uint8_t unknown_0x08[2]; + uint8_t left_stick[3]; + uint8_t right_stick[3]; + + OemController_State0x05_Optical optical; + + uint8_t unknown_0x18; + + OemController_State0x05_Magnetometer magnetometer; + + uint16_t battery_voltage_mv; + uint8_t charging_state; // rises and settles on 0x34 when charging, 0x20 when full + uint16_t battery_current; // encoding unknown (feature bit 5) + uint8_t unknown_0x24[5]; + uint8_t unknown_0x29; // always 0x01 + + OemController_State0x05_Motion motion; + + uint8_t left_trigger; // NSO GameCube only + uint8_t right_trigger; // NSO GameCube only + uint8_t reserved; +}; + +extern const OemController_State0x05 OemController_State0x05_NEUTRAL_STATE; + +bool OemController_State0x05_equals( + const OemController_State0x05* state0, + const OemController_State0x05* state1 +); + + +// +// Report 0x07 (Joy-Con 2 Left native) +// + + +struct OemController_State0x07_Optical{ + int16_t delta_x; + int16_t delta_y; + uint8_t coveredness; // ~0xff uncovered/lifted, ~0x00 resting on a surface +}; + +struct OemController_State0x07{ + uint8_t counter; + uint8_t power_info; // [0] ext power, [1] charging, [2:5] level, [6:7] reserved + uint8_t buttons0; // MSB->LSB: Lstickclick Minus ZL L | Up Left Right Down + uint8_t buttons1; // MSB->LSB: SL SR | - - - - - | Capture + uint8_t unknown_0x04; // observed 0x07 + uint8_t stick[3]; + uint8_t unknown_0x08; + OemController_State0x07_Optical optical; + uint8_t motion_length; // 0x28 ordinary / 0x1e compact / 0x00 + uint8_t motion_data[40]; + uint8_t reserved[8]; +}; + +extern const OemController_State0x07 OemController_State0x07_NEUTRAL_STATE; + +bool OemController_State0x07_equals( + const OemController_State0x07* state0, + const OemController_State0x07* state1 +); + + +// +// Report 0x08 (Joy-Con 2 Right native) +// +// Same as 0x07 with an extra NFC state byte (the Right Joy-Con carries +// the NFC reader) between the optical block and the motion length. +// + + +struct OemController_State0x08{ + uint8_t counter; + uint8_t power_info; + uint8_t buttons0; // MSB->LSB: Rstickclick Plus ZR R | X Y A B + uint8_t buttons1; // MSB->LSB: SL SR | C | - - - | Home + uint8_t unknown_0x04; // observed 0x07 + uint8_t stick[3]; + uint8_t unknown_0x08; + OemController_State0x07_Optical optical; + uint8_t nfc_state; // 0x00-0x07, 0x00 = idle + uint8_t motion_length; + uint8_t motion_data[40]; + uint8_t reserved[7]; +}; + +extern const OemController_State0x08 OemController_State0x08_NEUTRAL_STATE; + +bool OemController_State0x08_equals( + const OemController_State0x08* state0, + const OemController_State0x08* state1 +); + + +// +// Report 0x09 (Pro Controller 2 native) +// + + +struct OemController_State0x09{ + uint8_t counter; + uint8_t power_info; + uint8_t buttons[3]; + // MSB->LSB, byte0: Rstickclick Plus ZR R | X Y A B + // MSB->LSB, byte1: Lstickclick Minus ZL L | Up Left Right Down + // MSB->LSB, byte2: - - - C GL GR Capture Home + uint8_t left_stick[3]; + uint8_t right_stick[3]; + uint8_t unknown_0x0B; // 0x38 if feature bit 5 is set, otherwise 0x30 + uint8_t nfc_state; // 0x00-0x07, 0x00 = idle + uint8_t headset_audio_state; // 0x07/0x0F headset, 0x05/0x0D headphones, 0x00 otherwise + uint8_t motion_length; // 0x28 ordinary / 0x1e compact / 0x00 + uint8_t motion_data[40]; + uint8_t reserved[8]; +}; + +extern const OemController_State0x09 OemController_State0x09_NEUTRAL_STATE; + +bool OemController_State0x09_equals( + const OemController_State0x09* state0, + const OemController_State0x09* state1 +); + + +// +// Report 0x0A (NSO GameCube native) +// + + +struct OemController_State0x0A{ + uint8_t counter; + uint8_t power_info; + uint8_t buttons[3]; + // MSB->LSB, byte0: Rstickclick Plus R Z | X Y A B + // MSB->LSB, byte1: Lstickclick Minus L ZL | Up Left Right Down + // MSB->LSB, byte2: - - - C | - - | Capture Home + uint8_t left_stick[3]; + uint8_t right_stick[3]; + uint8_t unknown_0x0B; // 0x38 if feature bit 5 is set, otherwise 0x30 + uint8_t left_trigger; + uint8_t right_trigger; + uint8_t motion_length; + uint8_t motion_data[40]; + uint8_t reserved[8]; +}; + +extern const OemController_State0x0A OemController_State0x0A_NEUTRAL_STATE; + +bool OemController_State0x0A_equals( + const OemController_State0x0A* state0, + const OemController_State0x0A* state1 +); + + +// +// Motion payload (inside the native reports) +// +// motion_data[] holds the raw payload selected by motion_length: +// +// - 0x28 (40 B, "ordinary"): bit-packed scheduler time, quaternion +// (smallest-three, 21-bit components, 2-bit omitted-component +// selector) plus explicit accelerometer (three samples, mixed +// 14/13-bit) and gyroscope (two samples, 15-bit) values on a ~48.75 ms +// cadence with non-uniform internal timing. +// - 0x1e (30 B, "compact"): quaternion (25-bit components) plus 16-bit +// acceleration on a ~250 Hz cadence over USB. +// +// The two formats use DIFFERENT quaternion codecs (the BLE and USB +// compact forms also differ from each other), and several interleaved +// bits are semantically unresolved, so the payload is kept raw here. +// Field-level decoding is a CC-side concern; see the S2 protocol +// analysis (Docs/Switch2/S2-Protocol-Analysis.md) and the linux-switch2 +// PROTOCOL.md sections 20-27 for the bit maps. +// + + + +// +// Controller <-> CC +// + + +struct OemController_Status{ + // Bit 0: Connected + // Bit 1: Ready + // Bit 2: Paired + uint8_t status; + + uint8_t player_lights; + + // The controller's BLE address (the S2 stores the host's address, + // so this is the base's own address for reconnection purposes). + uint8_t paired_mac_address[6]; +}; + +enum class DisconnectReason{ + HOST_SHUTDOWN, + CONNECTION_REJECTED, +}; + + + +} +} + +#pragma pack(pop) + +#endif diff --git a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h new file mode 100644 index 0000000000..5eef881d70 --- /dev/null +++ b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h @@ -0,0 +1,95 @@ +/* PABotBase2 NS2 OEM Controller + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PABotBase2_Controller_NS2_OemController_H +#define PokemonAutomation_PABotBase2_Controller_NS2_OemController_H + +#include "../../ControllerStates/NintendoSwitch2_OemController_State.h" +#include "../PABotBase2_MessageProtocol.h" + +#pragma pack(push, 1) + +namespace PokemonAutomation{ +namespace PABotBase2{ + + + +// +// Report format +// +// The S1 normalized all of its OEM targets to report 0x30; the S2 +// normalizes to report 0x05 - the one input report format every S2 +// controller type can produce (the "grip" format). The S2 host selects +// it on the physical controller (command 0x03 sub 0x0A over USB, the +// 0x000a characteristic over BLE), so the 0x05 report bytes pass through +// the firmware unmodified from the physical controller to the target. +// + + +// +// Flash access on the physical S2 (S2 command 0x02). +// +// Reads cap at 0x50 bytes over USB and 0x4F over BLE; the handler +// enforces the smaller of the two for the session in use. +// + + +#define PABB2_MESSAGE_REQ_NS2_OEM_CONTROLLER_READ_FLASH 0xa0 +#define PABB2_MESSAGE_REQ_NS2_OEM_CONTROLLER_WRITE_FLASH 0xa1 +struct Message_NS2_OemController_Flash : MessageHeader{ + uint32_t controller_type; + uint32_t address; + uint8_t bytes; +}; + + +// +// Target output +// + + +// Echoed to the CC when the game writes the target's rumble output +// report (report 0x01 / 0x02 / 0x03). The GC's 4-byte motor and the +// Joy-Con 2's single 16-byte LRA frame both fit in the state struct. +#define PABB2_MESSAGE_INFO_NS2_OEM_CONTROLLER_RUMBLE 0xa2 +struct Message_Feedback_NS2_OemController_Rumble : MessageHeader{ + NintendoSwitch2::OemController_RumbleState data; +}; + + +// +// Target input +// +// Note: the full-state message is 69 bytes (4 header + 2 ms + 63 report), +// which is above the current PABB2_MAX_INCOMING_MESSAGE_SIZE of 64 - raise +// the board cap when the S2 targets are wired in. +// + + +// Fast path: buttons + sticks + GameCube triggers (12 bytes). The +// remaining 0x05 fields (counter, optical, magnetometer, battery, motion) +// are untouched by this command. +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS 0xa3 +struct Message_Command_NS2_OemController_Buttons : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x05_Buttons buttons; +}; + + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE 0xa4 +struct Message_Command_NS2_OemController_FullState : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x05 state; +}; + + + +} +} + +#pragma pack(pop) + +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e3a854eb06..91cb9ef0c4 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -14,6 +14,8 @@ file(GLOB CORE_LIBRARY_SOURCES ../3rdParty-Core/miniz-3.1.1/miniz.c ../3rdParty-Core/miniz-3.1.1/miniz.h ../Common/Compiler.h + ../Common/ControllerStates/NintendoSwitch2_OemController_State.cpp + ../Common/ControllerStates/NintendoSwitch2_OemController_State.h ../Common/ControllerStates/NintendoSwitch_OemController_State.cpp ../Common/ControllerStates/NintendoSwitch_OemController_State.h ../Common/ControllerStates/NintendoSwitch_WiredController_State.h @@ -185,6 +187,7 @@ file(GLOB CORE_LIBRARY_SOURCES ../Common/CRC32/pabb_CRC32.h ../Common/PABotBase2/Controllers/PABotBase2_Controller_HID_Keyboard.h ../Common/PABotBase2/Controllers/PABotBase2_Controller_NS1_OemController.h + ../Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h ../Common/PABotBase2/Controllers/PABotBase2_Controller_NS_WiredController.h ../Common/PABotBase2/PABotBase2_MessageProtocol.h ../Common/PABotBase2/PABotBase2CC_MessageDumper.cpp From cacf8cdf6a0ab2a0e8bb6a97a620135aef1fee18 Mon Sep 17 00:00:00 2001 From: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com> Date: Tue, 10 Nov 2026 19:21:27 +0000 Subject: [PATCH 2/4] Common: NS2 serial messages - per-CID native report formats (sync with Firmware #56) --- .../NintendoSwitch2_OemController_State.h | 24 +++++ .../PABotBase2_Controller_NS2_OemController.h | 98 +++++++++++++++---- 2 files changed, 103 insertions(+), 19 deletions(-) diff --git a/Common/ControllerStates/NintendoSwitch2_OemController_State.h b/Common/ControllerStates/NintendoSwitch2_OemController_State.h index fb35cfc7b1..89e534747a 100644 --- a/Common/ControllerStates/NintendoSwitch2_OemController_State.h +++ b/Common/ControllerStates/NintendoSwitch2_OemController_State.h @@ -169,6 +169,11 @@ struct OemController_State0x07_Optical{ uint8_t coveredness; // ~0xff uncovered/lifted, ~0x00 resting on a surface }; +struct OemController_State0x07_Buttons{ + uint8_t buttons[2]; + uint8_t stick[3]; +}; + struct OemController_State0x07{ uint8_t counter; uint8_t power_info; // [0] ext power, [1] charging, [2:5] level, [6:7] reserved @@ -199,6 +204,11 @@ bool OemController_State0x07_equals( // +struct OemController_State0x08_Buttons{ + uint8_t buttons[2]; + uint8_t stick[3]; +}; + struct OemController_State0x08{ uint8_t counter; uint8_t power_info; @@ -227,6 +237,12 @@ bool OemController_State0x08_equals( // +struct OemController_State0x09_Buttons{ + uint8_t buttons[3]; + uint8_t left_stick[3]; + uint8_t right_stick[3]; +}; + struct OemController_State0x09{ uint8_t counter; uint8_t power_info; @@ -257,6 +273,14 @@ bool OemController_State0x09_equals( // +struct OemController_State0x0A_Buttons{ + uint8_t buttons[3]; + uint8_t left_stick[3]; + uint8_t right_stick[3]; + uint8_t left_trigger; + uint8_t right_trigger; +}; + struct OemController_State0x0A{ uint8_t counter; uint8_t power_info; diff --git a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h index 5eef881d70..f7616b46fb 100644 --- a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h +++ b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h @@ -20,20 +20,30 @@ namespace PABotBase2{ // // Report format // -// The S1 normalized all of its OEM targets to report 0x30; the S2 -// normalizes to report 0x05 - the one input report format every S2 -// controller type can produce (the "grip" format). The S2 host selects -// it on the physical controller (command 0x03 sub 0x0A over USB, the -// 0x000a characteristic over BLE), so the 0x05 report bytes pass through -// the firmware unmodified from the physical controller to the target. +// Each S2 target CID presents its real controller's input report format, +// matching the real controller's behavior: +// +// PABB_CID_NintendoSwitch2_WiredController (0x1010, grip/combined) 0x05 +// PABB_CID_NintendoSwitch2_WiredProController / _WirelessProController 0x09 +// PABB_CID_NintendoSwitch2_WiredLeftJoycon / _WirelessLeftJoycon 0x07 +// PABB_CID_NintendoSwitch2_WiredRightJoycon / _WirelessRightJoycon 0x08 +// +// (The NSO GameCube's 0x0A is available to a future GC CID.) The target +// streams that format by default and implements 0x03/0x0A so the host +// can switch it to 0x05, as a real S2 does. The serial messages below +// carry the 63-byte report for the CID's format verbatim - the CC fills +// the matching struct and the firmware passes the bytes through without +// translation. The 40-byte native motion payload is bit-packed with a +// different codec per format, so it is generated on the CC side. // // // Flash access on the physical S2 (S2 command 0x02). // -// Reads cap at 0x50 bytes over USB and 0x4F over BLE; the handler -// enforces the smaller of the two for the session in use. +// The controller allows 0x50-byte reads over USB and 0x4F over BLE; the +// 72-byte serial message cap limits the payload to 68 bytes, so the CC +// steps the address for longer regions. // @@ -63,29 +73,79 @@ struct Message_Feedback_NS2_OemController_Rumble : MessageHeader{ // // Target input // -// Note: the full-state message is 69 bytes (4 header + 2 ms + 63 report), -// which is above the current PABB2_MAX_INCOMING_MESSAGE_SIZE of 64 - raise -// the board cap when the S2 targets are wired in. +// Per report format: a fast-path buttons message (buttons + sticks, and +// the GameCube triggers where the format has them) and a full-state +// message (the complete 63-byte report). The full-state messages are +// 69 bytes: they fit the 72-byte incoming message cap and, at the 96 +// byte packet cap, travel as a single RSC packet. // -// Fast path: buttons + sticks + GameCube triggers (12 bytes). The -// remaining 0x05 fields (counter, optical, magnetometer, battery, motion) -// are untouched by this command. -#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS 0xa3 -struct Message_Command_NS2_OemController_Buttons : MessageHeader{ +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS_0X05 0xa3 +struct Message_Command_NS2_OemController_Buttons0x05 : MessageHeader{ uint16_t milliseconds; NintendoSwitch2::OemController_State0x05_Buttons buttons; }; - -#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE 0xa4 -struct Message_Command_NS2_OemController_FullState : MessageHeader{ +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE_0X05 0xa4 +struct Message_Command_NS2_OemController_FullState0x05 : MessageHeader{ uint16_t milliseconds; NintendoSwitch2::OemController_State0x05 state; }; +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS_0X07 0xa5 +struct Message_Command_NS2_OemController_Buttons0x07 : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x07_Buttons buttons; +}; + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE_0X07 0xa6 +struct Message_Command_NS2_OemController_FullState0x07 : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x07 state; +}; + + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS_0X08 0xa7 +struct Message_Command_NS2_OemController_Buttons0x08 : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x08_Buttons buttons; +}; + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE_0X08 0xa8 +struct Message_Command_NS2_OemController_FullState0x08 : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x08 state; +}; + + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS_0X09 0xa9 +struct Message_Command_NS2_OemController_Buttons0x09 : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x09_Buttons buttons; +}; + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE_0X09 0xaa +struct Message_Command_NS2_OemController_FullState0x09 : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x09 state; +}; + + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_BUTTONS_0X0A 0xab +struct Message_Command_NS2_OemController_Buttons0x0A : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x0A_Buttons buttons; +}; + +#define PABB2_MESSAGE_CMD_NS2_OEM_CONTROLLER_FULL_STATE_0X0A 0xac +struct Message_Command_NS2_OemController_FullState0x0A : MessageHeader{ + uint16_t milliseconds; + NintendoSwitch2::OemController_State0x0A state; +}; + + } } From 6cdcc84b3422705d3e49f830cbcdae0896d1d95b Mon Sep 17 00:00:00 2001 From: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com> Date: Wed, 11 Nov 2026 02:06:36 +0000 Subject: [PATCH 3/4] Common: S2 states - drop counter/power_info (firmware-filled), sync NS2 header sizes --- .../NintendoSwitch2_OemController_State.cpp | 24 ++++++------------ .../NintendoSwitch2_OemController_State.h | 25 ++++++++++--------- .../PABotBase2_Controller_NS2_OemController.h | 17 +++++++------ 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp b/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp index 6a9e43f631..3d5d46572b 100644 --- a/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp +++ b/Common/ControllerStates/NintendoSwitch2_OemController_State.cpp @@ -12,13 +12,14 @@ namespace PokemonAutomation{ namespace NintendoSwitch2{ -// Every input report payload is exactly 63 bytes on the wire -// (64 over USB including the report ID byte). -static_assert(sizeof(OemController_State0x05) == 63, "Report 0x05 must be 63 bytes"); -static_assert(sizeof(OemController_State0x07) == 63, "Report 0x07 must be 63 bytes"); -static_assert(sizeof(OemController_State0x08) == 63, "Report 0x08 must be 63 bytes"); -static_assert(sizeof(OemController_State0x09) == 63, "Report 0x09 must be 63 bytes"); -static_assert(sizeof(OemController_State0x0A) == 63, "Report 0x0A must be 63 bytes"); +// The wire payload is 63 bytes; the structs hold the CC-filled portion +// (the firmware appends the counter / power-info prefix and the USB +// report ID byte): 59 bytes for 0x05, 61 for the native reports. +static_assert(sizeof(OemController_State0x05) == 59, "Report 0x05 state must be 59 bytes"); +static_assert(sizeof(OemController_State0x07) == 61, "Report 0x07 state must be 61 bytes"); +static_assert(sizeof(OemController_State0x08) == 61, "Report 0x08 state must be 61 bytes"); +static_assert(sizeof(OemController_State0x09) == 61, "Report 0x09 state must be 61 bytes"); +static_assert(sizeof(OemController_State0x0A) == 61, "Report 0x0A state must be 61 bytes"); const OemController_RumbleState OemController_RumbleState_NEUTRAL_STATE = { @@ -34,7 +35,6 @@ const OemController_RumbleStateGC OemController_RumbleStateGC_NEUTRAL_STATE = { const OemController_State0x05 OemController_State0x05_NEUTRAL_STATE = { - .counter = 0, .buttons = {}, .unknown_0x08 = {}, .left_stick = {0x00, 0x08, 0x80}, @@ -63,8 +63,6 @@ bool OemController_State0x05_equals( const OemController_State0x07 OemController_State0x07_NEUTRAL_STATE = { - .counter = 0, - .power_info = 0, .buttons0 = 0, .buttons1 = 0, .unknown_0x04 = 0x07, @@ -86,8 +84,6 @@ bool OemController_State0x07_equals( const OemController_State0x08 OemController_State0x08_NEUTRAL_STATE = { - .counter = 0, - .power_info = 0, .buttons0 = 0, .buttons1 = 0, .unknown_0x04 = 0x07, @@ -110,8 +106,6 @@ bool OemController_State0x08_equals( const OemController_State0x09 OemController_State0x09_NEUTRAL_STATE = { - .counter = 0, - .power_info = 0, .buttons = {}, .left_stick = {0x00, 0x08, 0x80}, .right_stick = {0x00, 0x08, 0x80}, @@ -133,8 +127,6 @@ bool OemController_State0x09_equals( const OemController_State0x0A OemController_State0x0A_NEUTRAL_STATE = { - .counter = 0, - .power_info = 0, .buttons = {}, .left_stick = {0x00, 0x08, 0x80}, .right_stick = {0x00, 0x08, 0x80}, diff --git a/Common/ControllerStates/NintendoSwitch2_OemController_State.h b/Common/ControllerStates/NintendoSwitch2_OemController_State.h index 89e534747a..30b0fb49ee 100644 --- a/Common/ControllerStates/NintendoSwitch2_OemController_State.h +++ b/Common/ControllerStates/NintendoSwitch2_OemController_State.h @@ -40,8 +40,19 @@ namespace NintendoSwitch2{ // the 0x03 sub 0x0A value in the known-good BLE startup sequence is // 0x09 even for Joy-Con 2, so it is not a literal report ID there. // -// All structs below are the 63-byte report payloads WITHOUT the USB -// report ID byte (BLE notifications omit it; USB reports prepend it). +// All structs below are the report payload MINUS the fields the +// firmware fills in - the same "header" information the S1 states omit: +// +// - 0x05: 4-byte report counter at the start (struct is 59 bytes, +// 63 on the wire) +// - Native reports: 1-byte counter + 1-byte power info at the start +// ([0] ext power, [1] charging, [2:5] battery level, [6:7] reserved) +// (struct is 61 bytes, 63 on the wire) +// +// The USB report ID byte is also added by the firmware (BLE +// notifications omit it; USB reports prepend it). The unknown_0xNN +// field names below keep their on-wire offsets. +// // Multi-byte fields are little-endian on the wire. Sticks are packed // 12-bit: X = b0 | ((b1 & 0x0f) << 8); Y = (b1 >> 4) | (b2 << 4); // neutral is ~0x800 but the true center comes from the controller's @@ -118,8 +129,6 @@ struct OemController_State0x05_Buttons{ }; struct OemController_State0x05{ - uint32_t counter; - // 4 button bytes (MSB -> LSB): // byte0: ZR R SL-R SR-R A B X Y // byte1: C Capture Home Lstickclick Rstickclick Plus Minus @@ -175,8 +184,6 @@ struct OemController_State0x07_Buttons{ }; struct OemController_State0x07{ - uint8_t counter; - uint8_t power_info; // [0] ext power, [1] charging, [2:5] level, [6:7] reserved uint8_t buttons0; // MSB->LSB: Lstickclick Minus ZL L | Up Left Right Down uint8_t buttons1; // MSB->LSB: SL SR | - - - - - | Capture uint8_t unknown_0x04; // observed 0x07 @@ -210,8 +217,6 @@ struct OemController_State0x08_Buttons{ }; struct OemController_State0x08{ - uint8_t counter; - uint8_t power_info; uint8_t buttons0; // MSB->LSB: Rstickclick Plus ZR R | X Y A B uint8_t buttons1; // MSB->LSB: SL SR | C | - - - | Home uint8_t unknown_0x04; // observed 0x07 @@ -244,8 +249,6 @@ struct OemController_State0x09_Buttons{ }; struct OemController_State0x09{ - uint8_t counter; - uint8_t power_info; uint8_t buttons[3]; // MSB->LSB, byte0: Rstickclick Plus ZR R | X Y A B // MSB->LSB, byte1: Lstickclick Minus ZL L | Up Left Right Down @@ -282,8 +285,6 @@ struct OemController_State0x0A_Buttons{ }; struct OemController_State0x0A{ - uint8_t counter; - uint8_t power_info; uint8_t buttons[3]; // MSB->LSB, byte0: Rstickclick Plus R Z | X Y A B // MSB->LSB, byte1: Lstickclick Minus L ZL | Up Left Right Down diff --git a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h index f7616b46fb..c3dfedf2bc 100644 --- a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h +++ b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h @@ -31,10 +31,12 @@ namespace PABotBase2{ // (The NSO GameCube's 0x0A is available to a future GC CID.) The target // streams that format by default and implements 0x03/0x0A so the host // can switch it to 0x05, as a real S2 does. The serial messages below -// carry the 63-byte report for the CID's format verbatim - the CC fills -// the matching struct and the firmware passes the bytes through without -// translation. The 40-byte native motion payload is bit-packed with a -// different codec per format, so it is generated on the CC side. +// carry the report minus the fields the firmware fills in (the report +// counter, the power-info byte on the native reports, and the USB +// report ID byte) - the CC fills the matching state struct and the +// firmware passes those bytes through without translation. The 40-byte +// native motion payload is bit-packed with a different codec per format, +// so it is generated on the CC side. // @@ -75,9 +77,10 @@ struct Message_Feedback_NS2_OemController_Rumble : MessageHeader{ // // Per report format: a fast-path buttons message (buttons + sticks, and // the GameCube triggers where the format has them) and a full-state -// message (the complete 63-byte report). The full-state messages are -// 69 bytes: they fit the 72-byte incoming message cap and, at the 96 -// byte packet cap, travel as a single RSC packet. +// message (the complete state payload: 59 bytes for 0x05, 61 for the +// native reports). The full-state messages are 65/67 bytes: they fit +// the 72-byte incoming message cap and, at the 96 byte packet cap, +// travel as a single RSC packet. // From 2a4c3a133c754b6b8c284ae90ddb0b6b9f94a30c Mon Sep 17 00:00:00 2001 From: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com> Date: Wed, 11 Nov 2026 02:20:41 +0000 Subject: [PATCH 4/4] Common: S2 _Buttons exact-prefix sync (with Firmware #56) --- .../NintendoSwitch2_OemController_State.h | 21 ++++++++++++------- .../PABotBase2_Controller_NS2_OemController.h | 13 ++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Common/ControllerStates/NintendoSwitch2_OemController_State.h b/Common/ControllerStates/NintendoSwitch2_OemController_State.h index 30b0fb49ee..5bfefb2810 100644 --- a/Common/ControllerStates/NintendoSwitch2_OemController_State.h +++ b/Common/ControllerStates/NintendoSwitch2_OemController_State.h @@ -115,17 +115,17 @@ struct OemController_State0x05_Motion{ int16_t gyro_z; }; -// The fast-path input fields of report 0x05: the buttons, sticks, and -// the GameCube analog triggers. It does not embed in -// OemController_State0x05 (the triggers sit after the motion block, so -// the fields are not contiguous on the wire); the remaining 0x05 fields -// only update on full-state commands. +// The fast-path input fields of report 0x05: an exact prefix of +// OemController_State0x05 (buttons, the unknown pair, sticks), so the +// firmware can memcpy it over the head of the state. The GameCube +// analog triggers sit after the motion block, so no contiguous prefix +// can reach them - the GC target uses report 0x0A, where they are part +// of the 0x0A buttons prefix. struct OemController_State0x05_Buttons{ uint8_t buttons[4]; + uint8_t unknown_0x08[2]; uint8_t left_stick[3]; uint8_t right_stick[3]; - uint8_t left_trigger; - uint8_t right_trigger; }; struct OemController_State0x05{ @@ -178,8 +178,10 @@ struct OemController_State0x07_Optical{ uint8_t coveredness; // ~0xff uncovered/lifted, ~0x00 resting on a surface }; +// Exact prefix of OemController_State0x07. struct OemController_State0x07_Buttons{ uint8_t buttons[2]; + uint8_t unknown_0x04; uint8_t stick[3]; }; @@ -211,8 +213,10 @@ bool OemController_State0x07_equals( // +// Exact prefix of OemController_State0x08. struct OemController_State0x08_Buttons{ uint8_t buttons[2]; + uint8_t unknown_0x04; uint8_t stick[3]; }; @@ -242,6 +246,7 @@ bool OemController_State0x08_equals( // +// Exact prefix of OemController_State0x09. struct OemController_State0x09_Buttons{ uint8_t buttons[3]; uint8_t left_stick[3]; @@ -276,10 +281,12 @@ bool OemController_State0x09_equals( // +// Exact prefix of OemController_State0x0A. struct OemController_State0x0A_Buttons{ uint8_t buttons[3]; uint8_t left_stick[3]; uint8_t right_stick[3]; + uint8_t unknown_0x0B; uint8_t left_trigger; uint8_t right_trigger; }; diff --git a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h index c3dfedf2bc..7d5c9bb8a4 100644 --- a/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h +++ b/Common/PABotBase2/Controllers/PABotBase2_Controller_NS2_OemController.h @@ -75,12 +75,13 @@ struct Message_Feedback_NS2_OemController_Rumble : MessageHeader{ // // Target input // -// Per report format: a fast-path buttons message (buttons + sticks, and -// the GameCube triggers where the format has them) and a full-state -// message (the complete state payload: 59 bytes for 0x05, 61 for the -// native reports). The full-state messages are 65/67 bytes: they fit -// the 72-byte incoming message cap and, at the 96 byte packet cap, -// travel as a single RSC packet. +// Per report format: a fast-path buttons message and a full-state +// message. The buttons struct is an exact prefix of the full state +// (buttons + sticks + the format's unknown byte(s), and the GameCube +// triggers where the 0x0A format has them contiguously), so the firmware +// updates the cached state with a single memcpy. The full-state messages +// are 65/67 bytes: they fit the 72-byte incoming message cap and, at the +// 96 byte packet cap, travel as a single RSC packet. //