Skip to content

iOS: Switch 2 Pro Controller over CoreBluetooth - #645

Closed
oliverames wants to merge 8 commits into
seedds:mainfrom
oliverames:feat-switch2-pro
Closed

oliverames wants to merge 8 commits into
seedds:mainfrom
oliverames:feat-switch2-pro

Conversation

@oliverames

@oliverames oliverames commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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.m is a CoreBluetooth central for the Pro Controller 2. It filters Nintendo's manufacturer data, performs the handshake (info, stick calibration, player LEDs, 0xA7 feature 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 existing dm_pad_set_player slot table, dm_motion_set_hid and haptics_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 in dm_switch2_proto.h; t_switch2.c checks framing, advertisement parsing, reports, the button map, bilateral stick calibration and rumble packing, and t_haptics_apple checks the BLE rumble route. The finding is in docs/reference/services.md; docs_symptoms.py was 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:

  • Pro Controller 2 only; Joy-Con 2 and the NSO GameCube pad are recognised and ignored (other stick/trigger rules).
  • No SMP, and iOS exposes no public local Bluetooth address for the application-layer 0x15 bond. The controller must be in pairing mode (hold Sync) or woken while scanning; DM_SW2_BOND_MAC is the opt-in path for a known host address. An OS-held connection can hide it from apps.
  • Hardware validation (pairing/wake, mapping, rumble, motion, two controllers) and its evidence checklist: iOS: validate the Switch 2 Pro Controller on hardware (PR #645) #646.
  • Motion is opt-in (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_switch2 builds 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 used DS2_PID_PRO_CONTROLLER_2 (the header defines DS2_PID_PRO_2), called ds2_motor_packet without its blocks argument, 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_apple and t_pad_apple pass 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, including DmSwitch2BLE.m and CoreBluetooth). DmSwitch2BLE.m, DmGamepad.m and haptics_apple.m also 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 new DmSwitch2BLE.m), env switches and settings rows, which git shows; front.h and pad_hid.h are unchanged.

Docs

  • The finding is in its docs/reference/<subsystem>.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change. Not applicable: no chain tool changed.
  • No game files, keys or data extracted from a game in the change or the attachments

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_claim takes a player slot immediately, so a Switch 2 pad joins at once even with DM_PAD_PRESS_TO_JOIN=1; main's press-to-join applies only to GameController pads.

@oliverames

Copy link
Copy Markdown
Contributor Author

Hardware validation is tracked in #646: pairing/wake behaviour, button and stick mapping, rumble, optional motion axes and two-controller play.

@oliverames
oliverames force-pushed the feat-switch2-pro branch 2 times, most recently from a287a51 to a273fd6 Compare October 29, 2026 18:43
@oliverames oliverames mentioned this pull request Nov 2, 2026
1 of 3 tasks
@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) docs Documentation labels Nov 3, 2026
@oliverames

Copy link
Copy Markdown
Contributor Author

Added launcher-side connection management for Switch 2 controllers (58456b23):

  • A new "Nintendo Switch 2 Controllers" section in the launcher lists connected Pro Controller 2 pads with their player slot, serial, battery percent/level icon and connection state, and a scan/stop control (scanning starts automatically when the section appears).
  • Each pad gets Test Rumble (the HD rumble self-test) and Disconnect buttons.
  • A three-page pairing guide covers Sync-button pairing, waking a remembered pad, and forgetting the controller in iOS Bluetooth settings so the app can connect.
  • Two existing env switches are now launcher settings in Controls: DM_SW2_DEADZONE (0-120 raw counts, default 40) and DM_SW2_MOTION (experimental six-axis input, off by default). docs/settings.md and docs/env_switches.tsv updated accordingly.

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.

@oliverames

Copy link
Copy Markdown
Contributor Author

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):

  • VoiceOver: the decorative SF Symbols (controller icons, battery glyph, scanning spinner, page icon) are now hidden with accessibilityHidden(true), and the colour-only connection dot announces "Connected" / "Present, not connected" so the state is not carried by colour alone.
  • Structure: the pairing guide's pages are now their own View structs (GuidePage), matching the guidance that every separately rendered region should be its own invalidation boundary, and the sheet is presented from the section rather than from a button inside it.
  • Row controls: the Scan and Stop buttons take the same framed style as the row's other buttons; the idle line now reads "Ready to connect".
  • Button styles: judged against the Liquid Glass guidance and left as standard .bordered/.borderedProminent — those styles are for content floating over media; inside an inset-grouped settings list the standard styles stay correct.

Verification: the launcher typechecks clean for arm64-apple-ios26.0 against the iPhone SDK and the macOS launcher-storage check passes.

@oliverames

Copy link
Copy Markdown
Contributor Author

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:

  • Joy-Con 2 (L, 0x2067 / R, 0x2066): one half alone is a sideways pad (rail buttons as L / R, its stick the left stick); a left and a right together form one Pro-style pad on one player slot, the left's stick the left stick and the right's the right, motion from the right half, and the rumble follows the console's left-low / right-high split. The right unit's stick data reports in the right field but is calibrated from the stick-1 slots (a Joy-Con has none for its Reported at slot 2). These rules and the per-form motion maps follow JakePre's hardware-verified PR 1346; that PR's recorded Joy-Con reports are now kept in this PR's tests (dm/ios/tests/switch2_ios.c, 45 checks on the reported bytes, the pad shapes and the motion maps).
  • NSO GameCube pad (0x2073): input with its analog triggers (report offsets 0x3C/0x3D) acting as digital holds above a quarter travel, as the console maps them onto digital ZL/ZR; per switch2mac's protocol notes §7 the pad's motor characteristic powers it off if written, so it is never written and the pad stays silent; the built-in presets (0x0A/0x02) are not used until their payloads are published. Input rules are from switch2mac's published protocol (not yet confirmed on our own hardware).

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: dm/ios/tests/test_switch2_ios.py (45 checks, no BLE needed), the launcher settings/docs checks and the macOS launcher-storage check (17 tests), the launcher Swift typechecks against the iPhone SDK, and the full app builds clean as a Release device build (build_smoke). Hardware-tested caveat: the GameCube's input comes from switch2mac's published protocol and has not been confirmed on hardware here; the Joy-Con rules carry PR 1346's recorded evidence.

@oliverames

oliverames commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Follow-up on the four safe integrable pieces from switch2mac's feature survey (1758bf6a):

  • Find on every pad row: each controller's player LEDs chase one at a time (a quarter turn every 150 ms) and the HD motors pulse for four seconds, so a controller can be picked out among four dark ones. It runs on the existing 50 ms maintenance tick, covers pairs and full pads alike through the pad dispatch, and skips the motor write on a GameCube pad as always.
  • Charging state in the controller list: every report already carries the signed battery current (the feature mask enables it at 0x20; positive = charging), so the launcher row shows a bolt beside the battery.
  • The reports' other environment fields are now parsed: charge state (0x21), battery current (0x22, shown above) and the IMU die temperature (0x2E, degrees C = 25 + raw/127), and every 90th verbose sample logs current and temperature.
  • The NSO GameCube pad's trigger hold threshold is a setting: DM_SW2_GC_TRIGGER, a Controls slider in report counts 0-255, default 64 (was a hard-coded constant).

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.

seedds and others added 7 commits November 7, 2026 14:41
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.
…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)
@seedds

seedds commented Nov 9, 2026

Copy link
Copy Markdown
Owner

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 dm/host (switch2_proto.h, pad_switch2_apple.m), shared by the Mac and iOS the way haptics_apple.m is, with pairing in the host and no launcher UI. JakePre has the iOS wiring on top of it (38 lines, tested on an iPhone 16) and will open it as a small PR.

So I won't land this PR, and I'm closing it:

What #645 has that main doesn't is the NSO GameCube controller. If you'd like to add it, please open a small PR on the shared transport, written from the protocol notes and run on a real pad, and say in it what you ran. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants