Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ layer cake, and every setting lives in one menu.
- RetroPie hotkeys: **Select+Start** exit, **Select+R/L** save/load state, **Select+Left/Right** state slot, **Select+X** in-game menu, **Select+B** reset.
- **Select+R2** fast-forward, **Select+L2** screenshot, **Select+Y** game switcher (jump between your recent games, each resumed where you left it).
- Remaps per system and per game, including the RetroStone2's optional 6-button Mega Drive layout.
- **Keyboard** (menus): arrows move, **Enter** = A (open, confirm), **Esc** or **Backspace** = B (back), **Tab** = Select, **Space** = Start, X / Y, **Page Up / Page Down** = L / R, **Home / End** = L2 / R2. A keyboard is not a game controller (games need a pad or the built-in buttons), but in a game **Esc** opens the in-game menu (with Exit) and **Tab** is the hotkey button (**Tab+Space** exits).
- **Keyboard** (menus): arrows move, **Enter** = A (open, confirm), **Esc** or **Backspace** = B (back), **Tab** = Select, **Space** = Start, X / Y, **Page Up / Page Down** = L / R, **Home / End** = L2 / R2. A keyboard is not a game controller (games need a pad or the built-in buttons), but in a game **Esc** opens the in-game menu (with Exit) and **Tab** is the hotkey button (**Tab+Space** exits). A Bluetooth keyboard works the same once paired (Settings > Network > Bluetooth devices); mice are not used yet.

**Finding games**
- **Letter jump** and **search** (in one list or across all games).
Expand Down Expand Up @@ -150,6 +150,7 @@ program also builds and tests on a PC: `cd frontend && make check`. Details: [do
| [rom-transfer.md](docs/rom-transfer.md) | USB, web page and Windows share |
| [updates.md](docs/updates.md) | Signed system updates (`.rsu` packages, keys) |
| [power.md](docs/power.md) | Battery, charging, shutdown |
| [bluetooth-audio.md](docs/bluetooth-audio.md) | Bluetooth headphones (A2DP): routing, pairing, what to measure |
| [pro-storage.md](docs/pro-storage.md) | RetroStone2 Pro: eMMC and M.2 storage, starter card; game covers, multi-disc games, memory speed |
| [translating.md](docs/translating.md) | Adding or fixing a translation |
| [homebrew.md](docs/homebrew.md) | The bundled games and their licences |
Expand Down
58 changes: 55 additions & 3 deletions buildroot-external/board/common/rootfs-overlay/usr/bin/rsos-bt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
# rsos-bt list FILE write the devices BlueZ knows to FILE (replaced
# atomically), one per line: "MAC<TAB>state<TAB>name",
# state = connected, paired or found (seen by the
# scan, with a name: nameless ones are left out)
# scan, with a name: nameless ones are left out).
# An optional 4th field holds extras, a comma-separated
# list of key=value (readers ignore unknown keys):
# battery=85 (BlueZ "Battery Percentage", for a
# connected device that reports one) and
# audio=headphones (an A2DP sink: headphones, speaker), e.g.
# "MAC<TAB>connected<TAB>name<TAB>battery=85,audio=headphones"
# rsos-bt sink exit 0 if an A2DP sink is connected (the "bluealsa"
# ALSA PCM then plays to it), 1 if not; for scripts
# rsos-bt scan on|off start discovery in the background (it stops by
# itself after RSOS_BT_SCAN_S seconds, default 300) /
# stop it
Expand All @@ -29,8 +37,10 @@ SCAN_S=${RSOS_BT_SCAN_S:-300}
DAEMON_PID=${RSOS_BT_DAEMON_PID:-/run/rsos-net/bluetoothd.pid}
PATH=${RSOS_BT_PATH:-/usr/bin:/usr/sbin:/bin:/sbin}
export PATH
KINDS=$RUN_DIR/kinds # MAC<TAB>audio|other cache (bluetoothctl info is slow)

ESC=$(printf '\033')
TAB=$(printf '\t')

die() {
echo "rsos-bt: $*"
Expand All @@ -51,11 +61,34 @@ has() {
btctl info "$1" | grep -q "^[[:space:]]*$2: yes"
}

# battery MAC: the battery percentage BlueZ reports ("Battery Percentage:
# 0x55 (85)"), nothing if the device does not report one
battery() {
btctl info "$1" | sed -n 's/^[[:space:]]*Battery Percentage:.*(\([0-9]\{1,3\}\)).*$/\1/p' | head -n 1
}

# "Device MAC name" lines -> "MAC name"
devices() {
btctl devices "$@" | sed -n 's/^Device \([0-9A-Fa-f:]\{17\}\) *\(.*\)$/\1 \2/p'
}

# kind MAC: "audio" for an A2DP sink (headphones, speaker), "other" for the
# rest, empty while BlueZ does not know yet (no UUIDs or icon, e.g. a device
# the scan has just seen). Known answers are cached: the list runs every 1.5 s.
kind() {
k=$(grep "^$1$TAB" "$KINDS" 2> /dev/null | cut -f2)
if [ -z "$k" ]; then
info=$(btctl info "$1")
if echo "$info" | grep -qi 'UUID:.*\(Audio Sink\|0000110b-\)\|Icon: audio-'; then
k=audio
elif echo "$info" | grep -q 'UUID:\|Icon:'; then
k=other
fi
[ -n "$k" ] && mkdir -p "$RUN_DIR" 2> /dev/null && printf '%s\t%s\n' "$1" "$k" >> "$KINDS"
fi
echo "$k"
}

# bluetoothd, started by rsos-net bt on
bt_running() {
[ -f "$DAEMON_PID" ] && kill -0 "$(cat "$DAEMON_PID")" 2> /dev/null
Expand All @@ -72,6 +105,8 @@ list() {
name=$(echo "$name" | tr -d '\t')
if echo "$conn" | grep -qix "$mac"; then
st=connected
bat=$(battery "$mac")
extra=${bat:+battery=$bat}
elif echo "$paired" | grep -qix "$mac"; then
st=paired
else
Expand All @@ -82,7 +117,10 @@ list() {
"$(echo "$mac" | tr 'a-f' 'A-F')" ] && continue
st=found
fi
printf '%s%s%s%s%s\n' "$mac" "$tab" "$st" "$tab" "$name"
# audio=headphones: an A2DP sink (headphones, speaker)
[ "$(kind "$mac")" = audio ] && extra=${extra:+$extra,}audio=headphones
printf '%s%s%s%s%s%s\n' "$mac" "$tab" "$st" "$tab" "$name" "${extra:+$tab$extra}"
extra=
done > "$out.tmp"
else
: > "$out.tmp"
Expand All @@ -91,6 +129,15 @@ list() {
bt_running || die "Bluetooth is off"
}

# sink: an A2DP sink is connected
sink() {
bt_running || return 1
for mac in $(devices Connected | cut -d' ' -f1); do
[ "$(kind "$mac")" = audio ] && return 0
done
return 1
}

scan_off() {
if [ -f "$RUN_DIR/scan.pid" ]; then
kill "$(cat "$RUN_DIR/scan.pid")" 2> /dev/null
Expand Down Expand Up @@ -142,6 +189,7 @@ pair() {
cmd=$1
case "$cmd" in
list) list "$2"; exit $? ;;
sink) sink; exit $? ;;
scan)
case "$2" in
on) scan_on ;;
Expand All @@ -152,7 +200,7 @@ scan)
;;
pair | connect | disconnect | forget) ;;
*)
echo "usage: rsos-bt {list FILE|scan on|off|pair|connect|disconnect|forget MAC}" >&2
echo "usage: rsos-bt {list FILE|sink|scan on|off|pair|connect|disconnect|forget MAC}" >&2
exit 2
;;
esac
Expand All @@ -173,6 +221,10 @@ disconnect)
;;
forget)
btctl remove "$mac" > /dev/null
if [ -f "$KINDS" ]; then
grep -v "^$mac$TAB" "$KINDS" > "$KINDS.tmp"
mv -f "$KINDS.tmp" "$KINDS"
fi
devices Paired | grep -qi "^$mac " && die "cannot remove $mac"
exit 0
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# (nvmem "sunxi-sid"; the AP6210 nvram carries the
# Broadcom default MAC, for which brcmfmac picks a random
# one at every load); unset: the driver's MAC
[ -r /usr/libexec/rsos/board.sh ] && . /usr/libexec/rsos/board.sh

Check notice on line 50 in buildroot-external/board/common/rootfs-overlay/usr/bin/rsos-net

View workflow job for this annotation

GitHub Actions / lint

Not following: /usr/libexec/rsos/board.sh: openBinaryFile: does not exist (No such file or directory) [SC1091]
WIFI_IF=wlan0
WIFI_MODULE=${RSOS_BOARD_WIFI_MODULE:-brcmfmac}
WIFI_MMC=$RSOS_BOARD_WIFI_SDIO_HOST
Expand All @@ -57,6 +57,7 @@
BT_MODULE=${RSOS_BOARD_BT_MODULE:-hci_uart}
BT_HCI=hci0
BLUETOOTHD=/usr/libexec/bluetooth/bluetoothd
BLUEALSA_BIN=/usr/bin/bluealsa
BT_STORE=/data/rsos/bluetooth.img
BT_STORE_MNT=/var/lib/bluetooth

Expand Down Expand Up @@ -278,6 +279,12 @@
"$BLUETOOTHD" -n > /dev/null 2>&1 9>&- &
echo $! > "$RUN_DIR/bluetoothd.pid"
fi
# Bluetooth headphones: the bluealsa daemon serves the "bluealsa" ALSA PCM (A2DP
# source only: no headset / hands-free). It waits for bluetoothd itself.
if [ -x "$BLUEALSA_BIN" ] && [ ! -f "$RUN_DIR/bluealsa.pid" ]; then
"$BLUEALSA_BIN" -p a2dp-source > /dev/null 2>&1 9>&- &
echo $! > "$RUN_DIR/bluealsa.pid"
fi
}

# BlueZ keeps its pairings in /var/lib/bluetooth/<adapter>/<device>/, with
Expand Down Expand Up @@ -324,6 +331,7 @@
}

bt_off() {
kill_pidfile "$RUN_DIR/bluealsa.pid"
kill_pidfile "$RUN_DIR/bluetoothd.pid"
# Let bluetoothd write its state and exit before the store goes away.
i=0
Expand Down
32 changes: 26 additions & 6 deletions buildroot-external/board/common/tests/bt-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# bluetoothctl that keeps its devices in a file: the list format (connected,
# paired, found; nameless devices left out; colour codes stripped), pair =
# pair + trust + connect with the Just Works agent, a pad that does not pair,
# connect / disconnect / forget, the scan started in the background and
# the battery of a connected pad (the battery= extra of the optional 4th field), connect / disconnect / forget, the scan started in the background and
# stopped, a bad address, Bluetooth off. The real bluetoothctl and pads need
# the device.
set -u
Expand Down Expand Up @@ -31,6 +31,7 @@ E4:17:D8:00:00:01 1 1 1 8BitDo SN30 Pro
F0:13:C3:00:00:02 0 0 0 Stadia5RHM-1a2b
A0:5A:5D:00:00:03 0 0 0 Wireless Controller
11:22:33:44:55:66 0 0 0 11-22-33-44-55-66
00:1B:66:00:00:07 0 0 0 WH-Headphones
EOF
cat > "$W/bin/bluetoothctl" << EOF
#!/bin/sh
Expand All @@ -53,7 +54,12 @@ devices)
info)
awk -v m="\$2" '\$1 == m {
print "Device " m " (public)"; print "\tPaired: " (\$2 ? "yes" : "no")
print "\tTrusted: " (\$3 ? "yes" : "no"); print "\tConnected: " (\$4 ? "yes" : "no") }' \$D
print "\tTrusted: " (\$3 ? "yes" : "no"); print "\tConnected: " (\$4 ? "yes" : "no")
if (\$4 && m == "E4:17:D8:00:00:01") print "\tBattery Percentage: 0x55 (85)"
if (\$4 && \$5 ~ /Headphones/) print "\tBattery Percentage: 0x37 (55)"
if (\$5 ~ /Headphones/) { print "\tIcon: audio-headphones"
print "\tUUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)" }
else if (\$5 !~ /^[0-9]/) print "\tIcon: input-gaming" }' \$D
;;
pair)
[ "\$2" = A0:5A:5D:00:00:03 ] && { echo "Failed to pair: org.bluez.Error.AuthenticationFailed"; exit 1; }
Expand All @@ -74,10 +80,12 @@ bt() { $SH "$BT" "$@"; }

echo "rsos-bt ($SH)"
check "list" bt list "$W/list"
check "list: connected, found, found; the nameless one and colour codes left out" \
[ "$(cat "$W/list")" = "E4:17:D8:00:00:01${T}connected${T}8BitDo SN30 Pro
check "list: connected (with its battery), found, found; the nameless one and colour codes left out" \
[ "$(cat "$W/list")" = "E4:17:D8:00:00:01${T}connected${T}8BitDo SN30 Pro${T}battery=85
F0:13:C3:00:00:02${T}found${T}Stadia5RHM-1a2b
A0:5A:5D:00:00:03${T}found${T}Wireless Controller" ]
A0:5A:5D:00:00:03${T}found${T}Wireless Controller
00:1B:66:00:00:07${T}found${T}WH-Headphones${T}audio=headphones" ]
check "sink: none connected" sh -c "! $SH '$BT' sink"
check "scan on starts a background bluetoothctl" bt scan on
pid=$(cat "$W/run/scan.pid" 2> /dev/null)
check " ... which runs" kill -0 "$pid"
Expand All @@ -90,13 +98,25 @@ check " ... Just Works agent, then trust and connect" \
grep -q 'bluetoothctl trust F0:13:C3:00:00:02' $LOG && grep -q 'connect F0:13:C3:00:00:02' $LOG"
bt list "$W/list"
check " ... now connected" grep -q "^F0:13:C3:00:00:02${T}connected${T}" "$W/list"
check " ... no extras field for a pad that does not report one" \
grep -qx "F0:13:C3:00:00:02${T}connected${T}Stadia5RHM-1a2b" "$W/list"
out=$(bt pair A0:5A:5D:00:00:03)
rc=$?
check "a pad that does not pair: exit 1, the reason" \
[ "$rc:$out" = "1:rsos-bt: pairing failed: Failed to pair: org.bluez.Error.AuthenticationFailed" ]
check "pair headphones: ok" bt pair 00:1B:66:00:00:07
bt list "$W/list"
check " ... connected, marked audio=headphones, with its battery first" grep -q "^00:1B:66:00:00:07${T}connected${T}WH-Headphones${T}battery=55,audio=headphones$" "$W/list"
check " ... a pad stays a plain three-field line" grep -q "^F0:13:C3:00:00:02${T}connected${T}Stadia5RHM-1a2b$" "$W/list"
check "sink: the headphones are connected" bt sink
bt disconnect 00:1B:66:00:00:07
check "sink: not after a disconnect" sh -c "! $SH '$BT' sink"
bt connect 00:1B:66:00:00:07
bt forget 00:1B:66:00:00:07
check " ... forgotten: its kind is not kept" sh -c "! grep -q 00:1B:66:00:00:07 '$W/run/kinds'"
check "disconnect" bt disconnect E4:17:D8:00:00:01
bt list "$W/list"
check " ... paired, not connected" grep -q "^E4:17:D8:00:00:01${T}paired${T}8BitDo SN30 Pro$" "$W/list"
check " ... paired, not connected, no battery" grep -q "^E4:17:D8:00:00:01${T}paired${T}8BitDo SN30 Pro$" "$W/list"
check "connect" bt connect E4:17:D8:00:00:01
check "forget" bt forget E4:17:D8:00:00:01
bt list "$W/list"
Expand Down
2 changes: 2 additions & 0 deletions buildroot-external/configs/retrostone2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ BR2_PACKAGE_WPA_SUPPLICANT=y
BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
BR2_PACKAGE_BLUEZ5_UTILS=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_AUDIO=y
BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_HID=y
BR2_PACKAGE_BLUEZ_ALSA=y

# Root filesystem (one A/B slot): ext4, mounted read-only, kernel + dtb +
# boot.scr in /boot. 384 MiB = the slot size in genimage.cfg.
Expand Down
2 changes: 2 additions & 0 deletions buildroot-external/configs/retrostone2_release_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ BR2_PACKAGE_WPA_SUPPLICANT=y
BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
BR2_PACKAGE_BLUEZ5_UTILS=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_AUDIO=y
BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_HID=y
BR2_PACKAGE_BLUEZ_ALSA=y

# Root filesystem (one A/B slot): ext4, mounted read-only, kernel + dtb +
# boot.scr in /boot. 384 MiB = the slot size in genimage.cfg.
Expand Down
Loading
Loading