feat(builder): the Switch 2 Pro Controller over Bluetooth (Windows) #3244
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3244
Loading…
Reference in a new issue
No description provided.
Delete branch "fofuxo/Longshot:feat/switch2-bluetooth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A Switch 2 Pro Controller over Bluetooth did nothing in Longshot: the builder's driver (
build_core::switch2) read itover USB only, and Windows has nothing a game can use for it over the air. It is not a Bluetooth HID device but a
Bluetooth LE peripheral with a GATT service of Nintendo's own, so pairing it in Windows' settings never makes it a
gamepad. Players used a bridge program and lost its motion sensor and rumble.
Now the builder takes it over Bluetooth too, with its sticks, buttons, gyroscope and rumble: hold the controller's SYNC
button with the game running and the builder pairs it with this PC; from then on any button wakes it. A controller
paired with a console stays the console's (the builder leaves it alone until SYNC is held). The NFC reader stays
USB only.
builder/crates/build-core/src/switch2/ble.rs(new): the protocol on its own (the advertisement's Nintendo data, whichcontroller is taken, the commands with byte 2 saying Bluetooth, an answer told from its acknowledgement, the pairing's
four commands, a report, the vibration payload), tested on canned bytes; and
os, the WinRT link: the advertisementwatcher, the GATT connection (session held first, the service looked up uncached, the 7.5 ms connection interval asked
for, the answer and input characteristics subscribed to), the command pipe and the vibration writes.
switch2.rs: the commands, the flash reads (subcommand 4 over the air), the calibration and the report are the USBones through the
Pipetrait, which now says which link it is; a second virtual pad and rumble thread for the air link(
SHARED[USB]/SHARED[BT], generic callbacks);ble_main, the link's thread.start-up changes what it sends there: before that start-up the cable asks the controller its own Bluetooth address
(command 0x15, subcommand 1 with no host given,
bluetooth_address), and that controller's air link alone is dropped(
CABLEDholds the address,on_cable); a button wakes it on Bluetooth again once the cable is pulled. AnotherSwitch 2 Pro Controller keeps its air link: one on each link is two players. A controller that does not say its
address is taken to be any (every air link let go while it is plugged in). Such a controller, still leaving its air
link, also drops the cable's first start-up commands, the features among them (it then streamed with no motion and
its trigger bits flickering): the USB start-up is sent again while commands go unanswered (
start_settled), and twounanswered in a row end a try at once, each costing the pipe's half second.
reads its address again whenever the watcher stops), and the advertisements heard wait in a bounded queue (16),
dropped past it while a controller is connected.
sharing the link), and at 12 ms one lost now and then left a gap felt in most Test vibration runs.
windows0.62.2 (already inCargo.lockthrough Slint's winit) with the Bluetooth,GATT, collections and streams features, Windows only.
The protocol is the community's: https://github.com/ndeadly/switch2_controller_research, and the GATT UUIDs, the
Bluetooth start-up, the pairing and the cable's dropped start-up as https://github.com/uayten/JoyShockLibrary4Unreal
measured and uses them (as does mkw-recomp, the source of the Bluetooth support the issue links). Nothing is copied:
the code is written here.
Fixes #2670. On top of #3239 (rumble strength over USB, merged): the air link takes its strength too, and
docs/dev/reference/input.md's rumble paragraph says USB or Bluetooth with #3239's text.Testing
Tested: Windows 11 Pro (build 26300), AMD Ryzen 9 5900X, NVIDIA GeForce RTX 3070 (driver 621.47), a Switch 2 Pro
Controller (firmware as shipped) over Bluetooth on the PC's own adapter (Intel Wireless Bluetooth on the
board, USB 8087:0025), and over USB. A runtime of this branch over
main's base (
dev.py rt), from a copy of my own profile:reconnected it with no SYNC. Log:
switch2: Switch 2 Pro Controller over Bluetooth (…): started (sticks calibrated at 2029 2092 / 2128 2100), the same centres the USB start reads;its reports over Bluetooth: 104 a second.Bluetooth; Test vibration over USB.
runs; at 8 ms, much more rarely (by feel).
a controller is on the cable: the cable has it) and the cable took it (over USB: started,reports arrive (ID 05, 64 bytes)); pulled, a buttonbrought it back on Bluetooth. Before the cable fix the same plug gave random inputs (the left trigger flickering every
5 to 10 ms, the menu opened) and no motion.
main@a2b7abf9, a runtime over the base7bc53f84: the cable said thecontroller's address, the same as its air link's (
the controller on the cable is 4044f7ed86cc on Bluetooth,over Bluetooth (4044f7ed86cc): started); plugged in twice and pulled twice, the cable took it (once the controllerdropped its air link itself, once
it is on the cable now: the cable has it) and a button brought it back over theair; buttons, sticks, Motion and Test vibration over Bluetooth with #3239's strength. Started with the PC's Bluetooth
switched off (
advertisements cannot be watched ... retrying), switched on in game: a button connected it, 109reports a second. Beside it a DualShock 4 and Joy-Cons (a pair as one, and single), four pads at once, each working.
HOS_SWITCH2_HD=1on the cable (#3239's still to test):HD rumble (RenHDrum), Test vibration at another pitchand no stronger or weaker by feel; hitting a wall, a long fall and falling into water each stopped with its effect,
none stuck.
cargo test -p build-core switch2: 16 passed (8 new: the cable's address question and which air link it lets go; the advertisement and what is taken, the commands and answers,the pairing, the vibration payload, the calibration over the air past each block's acknowledgement, a notification as
the USB report, a start-up dropped and sent again). Undoing the air link's flash read (
(cmd[2], cmd[3]) = (0x01, 0x04)) failsover_bluetooth_the_calibration_is_read_past_each_block_s_acknowledgement.cargo test -p build-core: 246 passed, 2 ignored on the rebased head (208 and 1 before it). Before the review:dev.py test-changed: the crates' tests and the Python checksthat read the changed files;
test_switch_table(the two rows' new text) andtest_cargo_lock_sourcespass.mise run teston Windows 11, with WinLibs' GCC and the checkout's llvm-mingw clang first on the PATH: 829 passed,52 skipped, 30 failed: the same 30 that fail on
main@7bc53f84in this environment, listed by cause in #3239'sTesting (the C compiler beside
{cxx}, glslang's file name, no spirv-val or llvm-mc, no symlink privilege, fixturesthat don't compile here, and five not looked into). None is in the code this changes.
test_driver_env_choose,test_guest_page_fast32andtest_mesh_fallback_layoutfailed once intest-changed, 24 at once, and pass in thefull run.
cargo clippy -p build-core --all-targets -- -D warnings: clean on the rebased head; rustfmt clean.Still to test:
play a while with rumble and Motion on, expecting the same, and the log's report rate near 100 a second or more (by
hand)
the second one's cable in lets go of its own air link alone (by hand; I have one)
with the game running): a button connects the controller with no restart (by hand; this PC's adapter is on the
board, tested switched off and on only)
Measurements
Nothing to measure: the driver runs on threads of its own in the builder, as the USB one does; with no Bluetooth LE adapter its thread asks Windows for one every 5 s and sleeps between. The cable's address question adds one command (half a second at most when unanswered, three tries) to a USB start-up.
Risks
player expects;
HOS_SWITCH2=0(the game's switches) still leaves the controller, on both links, to a bridge program.wireless headset during these tests.
start-ups and reports of their own.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Windows 11 Pro 26300, Ryzen 9 5900X, RTX 3070 (driver 621.47), a Switch 2 Pro Controller over Bluetooth on the PC's own adapter and over USB: a runtime of this branch over main's base, from a copy of my profile. Paired with SYNC, woken by a button after; buttons, sticks, Test vibration and Motion aiming over Bluetooth; cable and air in turn several times, the cable taking it and a button bringing it back over the air; 104 reports a second over Bluetooth.
WIP: feat(builder): the Switch 2 Pro Controller over Bluetooth (Windows)to feat(builder): the Switch 2 Pro Controller over Bluetooth (Windows)@rebase
I rebased this pull request onto
main(b6330a5b0b): the new head isa2906ec88c.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
3a3d79995ea2906ec88cRecommendation: Request changes. The Bluetooth driver prevents a separate Bluetooth controller from working whenever a USB controller is connected. Its advertisement queue can also grow throughout a long session.
Adds Windows Bluetooth LE support for the Switch 2 Pro Controller, including motion and rumble, using the existing virtual-pad path. The basic connection worked in the author's game run, but controller selection and resource handling need changes.
Blocking (1): must change before merging.
builder/crates/build-core/src/switch2.rs:1308: The cable flag suppresses every Bluetooth controller, including a different physical controller. (more on the line) Do: Identify the physical controller on each link and suppress or disconnect only the Bluetooth link belonging to the cabled device.Should fix (2): not blocking, but worth doing before merging.
builder/crates/build-core/src/switch2/ble.rs:247: The advertisement callback sends into an unbounded channel even while the Bluetooth thread is occupied with a controller. (more on the line) Do: Use a bounded or coalescing advertisement queue and discard redundant advertisements while a controller is connected.builder/crates/build-core/src/switch2.rs:1259: Bluetooth discovery exits permanently if no LE adapter is available at startup. (more on the line) Do: Retry adapter discovery while the driver is running, including after a radio or adapter change.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1, L2 and L3.Questions (1) (not confirmed from the code; they don't hold the recommendation)
builder/crates/build-core/src/switch2/ble.rs:45: Can a Switch 2 Pro Controller paired with another host advertise a manufacturer-data section containing the IDs but fewer than 16 bytes?Checks: they run again on this head; a failure shows on the pull request.
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested setup: the author reports pairing, reconnecting, buttons, sticks, motion and rumble working on Windows 11, with 104 reports per second. Other Bluetooth adapters remain untested.
Other systems: The Windows USB driver and its startup path also change; the author tested USB rumble and repeated cable handoffs. Linux does not compile the WinRT link. A different Bluetooth adapter and coexistence with a second controller need testing.
Switches: HOS_SWITCH2 remains on by default on Windows and now enables Bluetooth as well as USB; HOS_SWITCH2_HD remains off by default and now applies to Bluetooth too. Their table entries and documentation were updated.
Reviewed:
a2906ec88cagainstb6330a5b0b: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the commit and all changed code and documentation. Skimmed the lockfile change and recorded test results. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code, tests or project scripts were run. CI has not run on this head.
Overlaps and merge order: The description identifies Longshot#3239 as overlapping the input reference documentation; the second pull request to land needs that line rebased.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
@ -1129,0 +1256,4 @@use super::ble::{self, Take};use std::collections::{HashMap, HashSet};use std::time::{Duration, Instant};let Some(host) = ble::os::adapter() else {L3 (should fix): Bluetooth discovery exits permanently if no LE adapter is available at startup.
When: A player starts the game before plugging in a Bluetooth dongle; adapter() returns None and the thread returns, so holding SYNC after the dongle is connected does nothing until the game is restarted.
Do: Retry adapter discovery while the driver is running, including after a radio or adapter change.
@ -1129,0 +1305,4 @@Take::Pair => true,Take::Ours => false,};if CABLED.load(Ordering::SeqCst) || later.get(&address).is_some_and(|t| Instant::now() < *t) {L1 (blocking): The cable flag suppresses every Bluetooth controller, including a different physical controller.
When: With one Pro Controller connected over USB, CABLED is true; an independently paired second controller's advertisement is discarded, and an already connected Bluetooth pad is dropped. The advertised one-controller-per-link setup cannot work.
Do: Identify the physical controller on each link and suppress or disconnect only the Bluetooth link belonging to the cabled device.
@ -0,0 +244,4 @@w.Start()?;Ok(Self(w))}L2 (should fix): The advertisement callback sends into an unbounded channel even while the Bluetooth thread is occupied with a controller.
When: During a long Bluetooth play session, ble_main processes reports and does not drain rx until disconnect. Every matching manufacturer-data advertisement received in that time remains queued, so memory grows with session length and nearby advertising traffic.
Do: Use a bounded or coalescing advertisement queue and discard redundant advertisements while a controller is connected.
@fix
I didn't fix this pull request: the change I made would remove a switch this pull request adds (
let (tx, rx) = std::sync::mpsc::channel();inbuilder/crates/build-core/src/switch2.rs), which undoes it. So L2 and L3 are the author's now. Nothing was pushed.Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@fix it properly
a2906ec88c808955407cRecommendation: Request changes. A wired controller suppresses a separate Bluetooth controller, so two players cannot use those links at the same time. Discovery also does not recover when an LE adapter becomes available after startup.
What
@fixchangedI changed this pull request: the new head is
808955407c. I rebased it ontomain(bd4586c2e3).Not done
Nothing was built or run: the checks run again on the new head.
The change adds Windows Bluetooth support for the Switch 2 Pro Controller, including motion and rumble, using a separate virtual pad. The in-game test shows the feature working on one adapter, but the global cable flag prevents simultaneous use of distinct wired and wireless controllers.
Blocking (1): must change before merging.
builder/crates/build-core/src/switch2.rs:1308: The cable flag suppresses every Bluetooth controller, including a different physical controller. When: With one Pro Controller connected over USB, CABLED is true; an independently paired second controller's advertisement is discarded, and an already connected Bluetooth pad is dropped. The advertised one-controller-per-link setup cannot work. Do: Identify the physical controller on each link and suppress or disconnect only the Bluetooth link belonging to the cabled device.Should fix (2): not blocking, but worth doing before merging.
builder/crates/build-core/src/switch2/ble.rs:247: The advertisement callback sends into an unbounded channel even while the Bluetooth thread is occupied with a controller. When: During a long Bluetooth play session, ble_main processes reports and does not drain rx until disconnect. Every matching manufacturer-data advertisement received in that time remains queued, so memory grows with session length and nearby advertising traffic. Do: Use a bounded or coalescing advertisement queue and discard redundant advertisements while a controller is connected. (for the author:@fixcouldn't: Watch::start still sends every matching advertisement to an unbounded channel, while ble_main does not drain it during a connected session.)builder/crates/build-core/src/switch2.rs:1259: Bluetooth discovery exits permanently if no LE adapter is available at startup. When: A player starts the game before plugging in a Bluetooth dongle; adapter() returns None and the thread returns, so holding SYNC after the dongle is connected does nothing until the game is restarted. Do: Retry adapter discovery while the driver is running, including after a radio or adapter change. (for the author:@fixcouldn't: ble_main still returns permanently when adapter() returns None at startup, so a later adapter connection or enablement is not discovered.)Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1.Checks: they run again on this head; a failure shows on the pull request.
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested setup: the author reports working controls, motion and rumble at 104 Bluetooth reports per second on one Windows 11 PC. Adapter interoperability remains untested elsewhere.
Other systems: The new BLE path is Windows-only; its behavior on other Bluetooth adapters is unverified. USB and Bluetooth share cable arbitration, which currently affects separate controllers. The author reports no observed Bluetooth headset effect on the tested adapter.
Switches: HOS_SWITCH2 remains enabled by default and now controls both USB and Bluetooth support; HOS_SWITCH2=0 leaves both to a bridge. No new player switch is identified.
Reviewed:
808955407cagainstbd4586c2e3: Read the repository instructions and contribution rules, the pull request template, and the code paths for the four ledger items. Skimmed the remaining change and recorded runs; the full changed code was not read in this re-check. The historical base diff also contains intervening changes, so the rebased pull request was assessed againstbd4586c2e3.; nothing run (a code review).Checked and fine:
Testing: The author reports in-game testing on Windows 11 with one Bluetooth adapter and USB, plus Rust tests and broader checks. CI has not yet run on this head; no tests were run during this read-only review.
Overlaps and merge order: Longshot #3239 also changes the input reference paragraph and is reported to supply USB rumble-strength work used by this Bluetooth link; the second pull request to land needs a rebase.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
808955407c669f776190Rebased on
main@a2b7abf9(#3239's rumble paragraph merged into this one's), and the review's L1, L2 and L3 fixed in669f7761:no host given, as https://github.com/ndeadly/switch2_controller_research documents it), and only that controller's air
link is let go; another Switch 2 Pro Controller keeps its own. One that doesn't answer is taken to be any, as before.
In game the cable's answer was the air link's address (
4044f7ed86ccboth), and the handoff worked both ways twice.Two controllers at once is in Still to test: I have one.
board's adapter switched off and on in game; a dongle plugged in later is in Still to test.
ble.rs:45(a short manufacturer section from a controller paired elsewhere): not answered yet. Sucha section would read as host 0 and be taken as pairing; the research doesn't say whether one is sent, and finding out
needs a controller paired with a console. Left as it is.
Tested again in game (Testing has it), with #3239's
HOS_SWITCH2_HD=1run on the cable too.Testing names this PC's adapter (Intel Wireless Bluetooth on the board, USB 8087:0025), and Still to test asks for an adapter other than Intel's.
669f7761907436a610c9Rebased on
main@67dc8abe(head7436a610), before asking for review again. None of the six commits sincea2b7abf9changes this PR's code: #3301 (the Windows builder's DLL allowlist; this branch's builder passes it, its one extra importapi-ms-win-core-winrt-l1-1-0.dllbeing Windows' own), #3300, #3298, #3306, #3281, #3310. Two files changed on both sides and merged without conflicts:gpu/vk/switches.def(#3298'sRX_VK_PRESENT_GATErow) anddocs/user/graphics-and-controls.md(#3281's Skip Upscaler Wait row). Rebuilt here:dev.py rt(the builder compiled from this head) andrun_all.py --strict --changed origin/main: 70 passed, 3 failed (test_gfx_effects,test_lifter,test_rt_refl_lamps, which fail onmainon this PC too), 9 skipped. The in-game runs in Testing still hold: nothing they exercised changed.@review
Recommendation: Approve. The code is ready: only testing is left. The Bluetooth controller path works in the recorded Windows run, and the three code items are resolved. Adapter interoperability still needs a run on hardware other than the Intel adapter tested so far. Recommend approval; not approved on the forge.
Adds Windows Bluetooth LE support for the Switch 2 Pro Controller, including motion and rumble, while retaining USB support. Address-based handoff allows a different controller to remain connected over Bluetooth; the implementation adds a Windows-specific discovery and GATT path.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
Since the last review (on
808955407c)Resolved: L1 (The cable flag suppresses every Bluetooth controller, including a different physical contr…); L2 (The advertisement callback sends into an unbounded channel even while the Bluetooth thread…); L3 (Bluetooth discovery exits permanently if no LE adapter is available at startup.)
Still open: L4 (The new Windows Bluetooth path has only been exercised on one adapter.)
Checks: Still running: 11 checks.
Also noticed (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports successful pairing, reconnection, buttons, sticks, motion and rumble in game, with 104–109 reports per second on one Intel adapter. Interoperability on other adapters remains unproven.
Other systems: USB handoff was exercised with one controller; the two-controller case remains untested in game. Linux does not run the new Windows path. Bluetooth audio shares adapter airtime; the author observed no effect on a wireless headset.
Switches: HOS_SWITCH2 remains on by default and now covers Bluetooth as well as USB; HOS_SWITCH2_HD remains off by default and its experimental mode now also covers Bluetooth. The switch table and input documentation are updated.
Reviewed:
7436a610c9against67dc8abe81: Read AGENTS.md, CONTRIBUTING.md, the change and the relevant controller protocol and Windows link code; skimmed the lockfile, documentation changes, recorded runs and tests. The repository has no docs/review-checklist.md; the adjacent Tooling rules were unavailable.; nothing run (a code review).Checked and fine:
Testing: No commands or tests from the project were run. The author reports in-game Windows testing and passing controller unit tests; CI is still running.
Overlaps and merge order: None found in the supplied information; #3239 is already merged.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.