Skip to content

Bluetooth: pad battery and PIN message, keyboards and mice, headphones (A2DP) prototype - #19

Open
KurdtNervanna wants to merge 3 commits into
PaddleStroke:mainfrom
KurdtNervanna:bt-pad-battery
Open

KurdtNervanna wants to merge 3 commits into
PaddleStroke:mainfrom
KurdtNervanna:bt-pad-battery

Conversation

@KurdtNervanna

@KurdtNervanna KurdtNervanna commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Follows the Bluetooth devices screen (Settings > Network > Bluetooth devices, issue #13). This PR replaces #19 and #20 and adds a third part, Bluetooth headphones. It is three commits, one per part, so each part can be reviewed or dropped separately:

  1. Bluetooth devices: pad battery level, clearer message when a pad needs a PIN or cable (was Bluetooth: pad battery and PIN message, keyboards and mice, headphones (A2DP) prototype #19)
  2. input: a pointer is no gamepad; document Bluetooth keyboards and mice (was input: a pointer is no gamepad; document Bluetooth keyboards and mice #20)
  3. Bluetooth headphones (A2DP) prototype: bluez-alsa, routing, pairing screen (new, prototype)

The shared rsos-bt list format

Parts 1 and 3 both add information to the device list, so they share one optional 4th field. It holds a comma-separated list of key=value extras. The frontend ignores keys it does not know, so more can be added later. A device with no extras still has three fields, as before:

MAC<TAB>connected|paired|found<TAB>name[<TAB>key=value[,key=value...]]
00:1B:66:00:00:01<TAB>connected<TAB>Wireless Controller<TAB>battery=85
00:1B:66:00:00:07<TAB>connected<TAB>WH-1000XM3<TAB>battery=55,audio=headphones
  • battery=N: the BlueZ "Battery Percentage" (bluetoothctl info) of a connected device that reports one.
  • audio=headphones: the device is an A2DP sink, meaning its UUID is 110b or its icon is audio-*. The answer is cached in /run/rsos-bt/kinds because the list is rebuilt every 1.5 s.

1. Pad battery level and the PIN/cable message

  • rsos-bt list adds battery=85 for a connected device that reports its battery. The screen then shows "connected, 85%".
  • A pairing that fails with AuthenticationFailed, or that asks for a PIN or passkey, now gets a message saying the controller needs a PIN or a USB cable first, instead of the generic "put it in pairing mode". A PlayStation 3 pad is an example.
  • Tests: bt-test.sh (the battery field from the stub bluetoothctl) and make check-ui (a fake helper with FAKE_BT_FAIL=pin shows the new dialog). Docs: docs/build.md. Two new messages are in rsos.pot.

2. Keyboards and mice: a pointer is not a gamepad

  • classify_dev() in frontend/src/input/input.c now holds the node classification: pad, keyboard or nothing.
  • A trackpad, a tablet or a pad's touchpad node (absolute X, 4 or more buttons, no KEY_A) used to be taken for an unconfigured gamepad and got a player port. Pointers are now excluded from the generic heuristic. A node with explicit pad bits (BTN_GAMEPAD, BTN_JOYSTICK, BTN_TRIGGER_HAPPY) is still a pad.
  • 8 new cases in frontend/tests/test_input.c (make check-input, classify).
  • docs/input-design.md has a new "Keyboards and mice" section on what works today with USB and Bluetooth keyboards and mice: a keyboard works in the menus and for the in-game hotkeys, and a mouse is ignored. It also lists what is not built yet: keyboard and mouse forwarding to cores, a menu cursor, and a device-type label in the list. The README has one extra sentence about it.

3. Bluetooth headphones (A2DP): prototype

This part is a prototype. It has not been run on a RetroStone2, and it has not been tried with real headphones. It builds, and the host tests pass. Everything below about behaviour on the device is design, not measurement. If you would rather take parts 1 and 2 now and keep this one for later, the commit can be dropped on its own.

  • Image: BR2_PACKAGE_BLUEZ_ALSA (bluez-alsa 4.3.1: the bluealsa daemon, the ALSA plugin, SBC) and BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_AUDIO are added to retrostone2_defconfig and retrostone2_release_defconfig. The option names were checked against the Buildroot 2026.02.3 sources. The other boards have no Bluetooth, so their configs are unchanged. AAC, aptX and LDAC are not built, only SBC.
  • Daemon: rsos-net bt on starts bluealsa -p a2dp-source next to bluetoothd, and bt off stops it. In 4.3.1 the daemon is called bluealsa; bluealsad is the name in later releases. Headset and hands-free profiles are not enabled.
  • Routing: audio_open() first tries plug:bluealsa, which fails to open when no sink is connected, and uses a buffer of at least 120 ms there. If that fails it falls back to the existing card choice (HDMI or the codec), unchanged. If the sink disappears during a game (-ENODEV), the host reopens on the card. The settings key audio_bluetooth = false keeps the sound on the card.
  • Screen and helper: a connected audio device is shown as "headphones" (or "headphones, 55%"), and the failure messages say headphones. rsos-bt sink exits 0 when an A2DP sink is connected, for scripts and for a future native-game launcher (AUDIODEV=plug:bluealsa).
  • Docs: docs/bluetooth-audio.md covers the design, the routing rule, volume, and the list of things to measure. There is a README docs-table row for it.
  • Tests: bt-test.sh has a stub headphone device (the audio=headphones extra, sink, and forget clears the kind cache). make check-ui pairs headphones successfully and also shows the headphones failure message.

Hardware risks that have to be measured before this is a feature:

  • A2DP latency: SBC usually adds 100–250 ms. Video stays smooth because pacing follows the audio fill, but the sound arrives late. That is fine for an RPG and bad for rhythm games. The 120 ms latency_bt_ms is a guess that needs tuning.
  • WiFi/Bluetooth coexistence: the AP6210 has one 2.4 GHz radio for both WiFi (SDIO) and Bluetooth (UART), and 5 GHz is not an option. A2DP during a ROM transfer, scraping or SMB may stutter, or it may slow the transfer.
  • Volume: the volume wheel drives the analog codec, not Bluetooth. Nothing sets the A2DP (AVRCP) volume yet, so the headphones start at whatever level they remember, which may be very loud or very quiet.
  • SBC CPU cost on the A20: the bluealsa daemon has to encode while a heavy core runs (N64, PSX). This needs CPU and underrun counts.
  • Native-game sleep/quit: the frontend stops and kills native games with process-group SIGSTOP/SIGCONT/SIGKILL. To check: no click or latch on resume, a killed game does not leave the transport acquired, and the bluealsa daemon is never in the signalled group.
  • Also to check: whether the headphones' AVRCP buttons appear as an input device that takes a player slot, reconnect at boot and during a game, bt off/on cycles, idle power, and the D-Bus policy for org.bluealsa.

What was tested

Host only, on WSL Ubuntu:

  • buildroot-external/board/common/tests/bt-test.sh: 23 ok, 0 failed
  • buildroot-external/board/common/tests/release-defconfig-test.sh: ok (retrostone1 and retrostone2 release blocks)
  • buildroot-external/board/common/tests/board-sh-test.sh: 11 passed, 0 failed (sh)
  • frontend: make check-input, make check-ui, make check-i18n and the full make check all pass (exit 0, ending in check-frontend: OK)

po/rsos.pot contains only the new and changed messages. A full make pot also moves source references in files this PR does not touch (screens.c, storage.c, …), because those were already out of date on main. That churn is left out.

Not tried: no real Bluetooth pad, keyboard, mouse or headphones, and no RetroStone2. Pairing, the battery readout, the PIN message, keyboard and mouse classification, and all of the audio part have only been checked against stub bluetoothctl output and fake input devices. shellcheck was not run locally because it is not installed. The U-Boot host-tools part of the board script tests could not run either, because the download from ftp.denx.de fails.

CI note: the upstream CI board-script job currently fails on that same ftp.denx.de U-Boot download. The failure is in the job's setup, not in these changes.

🤖 Generated with Claude Code

…s a PIN or cable

rsos-bt list adds an optional 4th field (BlueZ Battery Percentage) for a
connected device; the screen shows "connected, 85%". A pairing that fails
with AuthenticationFailed or a PIN/passkey request now says the pad needs a
PIN or a USB cable first. Tests, docs and rsos.pot updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@KurdtNervanna

Copy link
Copy Markdown
Contributor Author

A note on CI: the board script tests job fails on this PR, but not in the tests themselves. Its first step (scripts/ci/uboot-host-tools.sh) downloads u-boot-2026.07.tar.bz2 from ftp.denx.de, and that download does not complete: the job stops about two minutes in, before any test runs. I checked from another machine and ftp.denx.de also times out there, so it looks like a problem with that server, not with the change. The other six checks (make check, ASan, both cross-compiles, defconfigs and lint) pass.

Once the server answers, a re-run of that job should be enough. I can't re-run it from the fork, so I'll leave it for you; tell me if you would rather I push a small commit to retrigger CI.

KurdtNervanna and others added 2 commits November 20, 2026 09:49
A trackpad, tablet or a pad's touchpad node (absolute X, 4+ buttons, no
KEY_A) was taken for an unconfigured gamepad and got a player port. Move the
node classification into classify_dev() and exclude pointers from the generic
heuristic (explicit pad bits still win). Test: make check-input (classify).

docs/input-design.md: what works for USB/Bluetooth keyboards and mice today
and what is not built (core keyboard/mouse forwarding, menu cursor).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…creen

- defconfigs (retrostone2 + release): BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_AUDIO,
  BR2_PACKAGE_BLUEZ_ALSA (names checked against Buildroot 2026.02.3)
- rsos-net: bluealsa -p a2dp-source (the daemon name in bluez-alsa 4.3.1) with bluetoothd
- rsos-bt: audio=headphones in the list extras field for A2DP sinks (cached), rsos-bt sink
- frontend audio: try plug:bluealsa first (120 ms buffer), fall back to the
  card when it does not open or the sink vanishes; settings audio_bluetooth
- devices screen: headphones shown/worded as such; stub tests, check-ui
- docs/bluetooth-audio.md: design and the risks to measure on hardware

Untested on hardware.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KurdtNervanna KurdtNervanna changed the title Bluetooth devices: pad battery level, clearer message when a pad needs a PIN or cable Bluetooth: pad battery and PIN message, keyboards and mice, headphones (A2DP) prototype Nov 20, 2026
KurdtNervanna added a commit to KurdtNervanna/RetroStoneOS that referenced this pull request Nov 21, 2026
…dphones prototype) into pro-storage

The three commits of upstream PR PaddleStroke#19. Conflicts: README docs table (both rows
kept), test_input.c (both test sets kept), rsos.pot (regenerated), and
input.c, where the fork's caps_are_pad() and the branch's classify_dev()
guard against the same thing: classify_dev() now calls caps_are_pad() for the
generic pad case, so touch pads, multitouch nodes, keys named A, mice, pens and
finger tools are all kept out of the player ports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant