Repository navigation
iOS: Switch 2 Pro Controller over CoreBluetooth - #645
oliverames wants to merge 8 commits into
Conversation
|
Hardware validation is tracked in #646: pairing/wake behaviour, button and stick mapping, rumble, optional motion axes and two-controller play. |
a287a51 to
a273fd6
Compare
e8cea74 to
ef2bfca
Compare
d34e448 to
6b053d2
Compare
6b053d2 to
90d97cc
Compare
90d97cc to
9cf0b25
Compare
|
Added launcher-side connection management for Switch 2 controllers (58456b23):
The guide text is limited to what the transport supports today: it only advertises the Pro Controller 2 (product 0x2069); Joy-Con 2 and the NSO GameCube pad share the protocol but are not connected by DmSwitch2BLE yet. Verification: the app builds clean as a Release device build including the new UI and BLE code (build_smoke), the settings/docs checks and the macOS launcher-storage check pass (16 tests), and Launcher.swift typechecks against the iPhone SDK. A simulator launch is not possible in this environment because this Xcode's simulator SDK lacks MetalFX, which the render layer imports. |
58456b2 to
51d1f77
Compare
|
Polish pass on the launcher section (8071937d), applying Apple's current SwiftUI and accessibility guidance straight from Xcode 27.3's shipped references (swiftui-specialist, accessibility-voiceover-specialist, the Liquid Glass guide):
Verification: the launcher typechecks clean for arm64-apple-ios26.0 against the iPhone SDK and the macOS launcher-storage check passes. |
|
Added Joy-Con 2 (solo and as a pair) and the NSO GameCube pad to the iOS transport (a2973e6d), so the launcher's controller list and connection settings cover all four Switch 2 controller forms:
A pad (one slot) can also hold the pairs across reconnects: a half joins the lone opposite half, and a pad that loses one half keeps playing as the surviving half's sideways pad. Verification: |
|
Follow-up on the four safe integrable pieces from switch2mac's feature survey (1758bf6a):
The Joy-Con 2 mouse mode and anything display-instrument-shaped stays out deliberately (per the survey comment): mouse mode is bench-verify-first, and instruments with no game consumer would be decoration. Verification: the protocol test grew to 49 checks (charge, current, temperature and the threshold parameter against hand-built reports in the recorded shape); 17 tests pass, the launcher typechecks for arm64-apple-ios26.0, and the app builds clean as a Release device build. |
1758bf6 to
77aacb6
Compare
iOS has no GameController or HID driver for a Nintendo Switch 2 Pro Controller: it is a proprietary BLE GATT device, so games see no pad at all. DmSwitch2BLE.m is a CoreBluetooth central for it: advertisement filter, handshake (info, stick calibration, player LEDs, feature mask), 63-byte input reports, a command queue, the Apple-host keep-alive and HD rumble. It feeds the existing dm_pad_set_player slot table, motion and haptics paths, so a BLE controller competes for players with GameController pads and hides the touch gamepad like one. Protocol credit: Peter Sharma's Finally the Controller Works (https://github.com/Peterksharma/switch2mac) publishes the protocol notes and CoreBluetooth implementation this port follows, and credits ndeadly/switch2_controller_research, trevlars/switch2-controllers-linux (MIT), Nadeflore/switch2-controllers and the wider Switch 2 RE community. The installed 0.2.0 binary was checked in Ghidra for the same frame, report offsets, feature command and UUIDs. Pro Controller 2 only. No SMP, and iOS exposes no public local Bluetooth address for the application-layer 0x15 bond, so the controller must advertise in pairing mode (Sync) or be woken while scanning; DM_SW2_BOND_MAC is the opt-in path for a known host address. Motion is opt-in (DM_SW2_MOTION=1) because the Switch 2 IMU scale and axis order are not measured yet. NSBluetoothAlwaysUsageDescription and CoreBluetooth are added to the iOS project. Tests: t_switch2 (protocol: framing, advertisement, reports, button map, bilateral calibration, rumble packing) and the BLE rumble route in t_haptics_apple. Not yet verified on a device.
…AD_GL, DM_PAD_GR)
…ion lists connected Pro Controller 2 pads with their player slot, serial, battery and connection state, scan and stop controls, test rumble, disconnect buttons and a pairing guide; the stick deadzone (DM_SW2_DEADZONE) and the experimental motion input (DM_SW2_MOTION) become settings in Controls (feat-switch2-pro)
…gle in Controls switches the controller's HD rumble alongside the game's own rumble settings (feat-switch2-pro)
…essibility guidance — decorative symbols and the scanning spinner are hidden from VoiceOver, the colour-only connection dot announces its state, the guide's pages are their own view types, the pairing sheet is presented by the section, the scan controls take the framed style like the row's other buttons, and the idle line reads Ready to connect (feat-switch2-pro)
…sideways) or as a pair (one pad, its sticks split L/R, motion from the right half) and the NSO GameCube pad (analog triggers as digital holds, its motor lane never written, which powers the pad off); the pad a player holds is one slot, so a pair's two halves join as one controller, and its rumble follows the console's left-low right-high split; the tests keep the recorded Joy-Con reports and the pad and motion rules (feat-switch2-pro) The Joy-Con 2 rules come from JakePre's hardware-verified PR 1346 (dm/host/switch2_proto.h, its tests' recorded reports carried over as dm/ios/tests/switch2_ios.c); the NSO GameCube's product id, analog triggers and motor-lane rule are from switch2mac's published protocol notes (§1, §5, §7) and are not confirmed on our own hardware yet, and its built-in rumble presets (0x0A/0x02) stay unused until their payloads are published.
…er LEDs chase one at a time and the motors pulse for four seconds, loud enough to be known among four dark ones) and a charging bolt beside the battery (the report's signed current, + charging); the reports' charge state, battery current and IMU die temperature are parsed (temperature in the verbose sample line), and the NSO GameCube pad's trigger hold threshold becomes DM_SW2_GC_TRIGGER, a Controls setting (feat-switch2-pro)
77aacb6 to
d6972a0
Compare
|
Thanks for this, @oliverames. Your work on the protocol came first, and it helped shape #1267. Switch 2 controller support has now landed through #1267: one protocol header and one CoreBluetooth transport in So I won't land this PR, and I'm closing it:
What #645 has that |
What and why
Symptom: with a Nintendo Switch 2 Pro Controller, an iOS game sees no controller at all: no npad appears and the touch gamepad stays on screen. The controller works on a Mac through the bridge app.
Cause: iOS has no GameController or HID driver for it. It is a proprietary BLE GATT device with Nintendo's own service and characteristics, so the OS never publishes it.
Change:
dm/ios/Sources/DmSwitch2BLE.mis a CoreBluetooth central for the Pro Controller 2. It filters Nintendo's manufacturer data, performs the handshake (info, stick calibration, player LEDs,0xA7feature mask), decodes the 63-byte input reports, keeps the link alive with a 1 Hz player-LED write, and sends HD-rumble packets. It feeds the existingdm_pad_set_playerslot table,dm_motion_set_hidandhaptics_apple.m, so a BLE controller competes for players with GameController pads, hides the touch gamepad, and gets each player's game rumble. The pure protocol lives indm_switch2_proto.h;t_switch2.cchecks framing, advertisement parsing, reports, the button map, bilateral stick calibration and rumble packing, andt_haptics_applechecks the BLE rumble route. The finding is in docs/reference/services.md;docs_symptoms.pywas run.Protocol credit: this is a port of the protocol notes and CoreBluetooth implementation published by Peter Sharma in Finally the Controller Works. That project credits the wider Switch 2 reverse-engineering community, including ndeadly/switch2_controller_research, trevlars/switch2-controllers-linux (MIT), Nadeflore/switch2-controllers, coffincolors and darthcloud/BlueRetro. The installed 0.2.0 binary was opened in Ghidra and checked for the same frame, report offsets, feature command and UUIDs before porting.
Scope: this adds a device class and is just over the ~1,000-line guidance in CONTRIBUTING. If you would rather review it in pieces, I can split the transport (
DmSwitch2BLE.m), the protocol header plus tests, and the haptics/slot integration into separate PRs.Limits/open:
0x15bond. The controller must be in pairing mode (hold Sync) or woken while scanning;DM_SW2_BOND_MACis the opt-in path for a known host address. An OS-held connection can hide it from apps.DM_SW2_MOTION=1): the Switch 2 IMU scale and axis order are inferred from the Switch Pro map, not measured. Rumble strength/frequency and the 40-count stick deadzone (DM_SW2_DEADZONE) need device tuning.Checked
Fixed the rumble tail so silent packets stop after 120 ms instead of renewing the deadline indefinitely. A fixture runs the production Objective-C maintenance method with a stub peripheral: it fails on the previous implementation and passes with the fix. The protocol suite and iOS SDK syntax check also pass.
Tests:
t_switch2builds and passes on this head (make -C dm/host/tests GAME=<id> build/t_switch2). It did NOT build before this push, so an earlier version of this description that reported it passing was wrong: it usedDS2_PID_PRO_CONTROLLER_2(the header definesDS2_PID_PRO_2), calledds2_motor_packetwithout itsblocksargument, and asserted the old no-calibration stick scale (full deflection at 2048) after the default range was narrowed to 1200 from the centre. The fix is folded into the commit that added the test, with a new one-block (Joy-Con 2) check.t_haptics_appleandt_pad_applepass after the rebase onto main. The full host suite was last run before the rebase and has not been re-run on this head.python3 -m unittest dm.tools.tests.test_docs dm.tools.tests.test_env_switches: 11/11 and OK.iOS compile and link:
GAME=01007EF00011E000 python3 dm/ios/tools/build_smoke.py --output /tmp/ios-smoke-switch2→ BUILD SUCCEEDED (the synthetic production project, includingDmSwitch2BLE.mand CoreBluetooth).DmSwitch2BLE.m,DmGamepad.mandhaptics_apple.malso compile cleanly for iOS 26 with-Wall -Wextra.Games run, with title ID and version: none. Not device-tested.
Devices and OS: none. The protocol tests are hardware-independent.
scripts/regress.py check --games: not run (iOS-only front-end code; no shared host or shader path).Measurements before and after: not a performance change (one BLE scan while the game runs; scanning stops at 8 controllers and on resign-active).
Front ends
None: no front end has to act on this. The change is the iOS front end's own code (
DmGamepad.m, the newDmSwitch2BLE.m), env switches and settings rows, which git shows;front.handpad_hid.hare unchanged.Docs
docs/reference/<subsystem>.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)dmsh_chain.py --headerwas run anddm/gfx/nvn/dmsh_chain.his part of the change. Not applicable: no chain tool changed.Rebased onto main bd979ce; conflicts resolved in dm/ios/Sources/DmGamepad.m, docs/env_switches.tsv, docs/settings.md.
Behaviour to check after the rebase:
dm_pad_external_claimtakes a player slot immediately, so a Switch 2 pad joins at once even withDM_PAD_PRESS_TO_JOIN=1; main's press-to-join applies only to GameController pads.