Audio Overhaul
This commit is contained in:
parent
0a44f36f5d
commit
d5a29147cc
@ -1,16 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# scripts/daemon/lesavka-core.sh - background stealth daemon to present gadget as usb hub of genuine devices
|
# lesavka‑core.sh – one‑shot USB‑gadget bring‑up (Pi‑5 / Arch‑ARM)
|
||||||
# Proven Pi-5 configfs gadget: HID keyboard+mouse
|
# Presents: • Boot‑protocol keyboard (hidg0)
|
||||||
# Still need Web Cam Support + stereo UAC2
|
# • Boot‑protocol mouse (hidg1)
|
||||||
|
# • Stereo UAC2 speaker + microphone
|
||||||
# lesavka-core - one-shot gadget bring-up for Pi-5 / Arch-ARM
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# 1) Ensure the dwc2 peripheral overlay is active exactly once
|
#──────────────────────────────────────────────────
|
||||||
|
# 1. Ensure overlay + kernel modules
|
||||||
|
#──────────────────────────────────────────────────
|
||||||
CFG=/boot/config.txt
|
CFG=/boot/config.txt
|
||||||
grep -q 'dtoverlay=dwc2,dr_mode=peripheral' "$CFG" || echo 'dtoverlay=dwc2,dr_mode=peripheral' >> "$CFG"
|
grep -q 'dtoverlay=dwc2,dr_mode=peripheral' "$CFG" || echo 'dtoverlay=dwc2,dr_mode=peripheral' >> "$CFG"
|
||||||
|
|
||||||
# 2) Load kernel modules (idempotent)
|
|
||||||
modprobe dwc2 || { echo "dwc2 not in kernel; abort" >&2; exit 1; }
|
modprobe dwc2 || { echo "dwc2 not in kernel; abort" >&2; exit 1; }
|
||||||
modprobe libcomposite || { echo "libcomposite not in kernel; abort" >&2; exit 1; }
|
modprobe libcomposite || { echo "libcomposite not in kernel; abort" >&2; exit 1; }
|
||||||
|
|
||||||
@ -21,6 +21,9 @@ udevadm control --reload
|
|||||||
udevadm trigger --subsystem-match=video4linux
|
udevadm trigger --subsystem-match=video4linux
|
||||||
udevadm settle
|
udevadm settle
|
||||||
|
|
||||||
|
#──────────────────────────────────────────────────
|
||||||
|
# 2. Wait for UDC device to appear (max 10 s)
|
||||||
|
#──────────────────────────────────────────────────
|
||||||
echo "[lesavka-core] ⏳ waiting for UDC to register ..."
|
echo "[lesavka-core] ⏳ waiting for UDC to register ..."
|
||||||
UDC=""
|
UDC=""
|
||||||
for _ in {1..100}; do # 100 × 100ms = 10s
|
for _ in {1..100}; do # 100 × 100ms = 10s
|
||||||
@ -48,11 +51,12 @@ fi
|
|||||||
[[ -n $UDC ]] || { echo "❌ UDC not present after manual bind"; exit 1; }
|
[[ -n $UDC ]] || { echo "❌ UDC not present after manual bind"; exit 1; }
|
||||||
echo "[lesavka-core] ✅ UDC detected: $UDC"
|
echo "[lesavka-core] ✅ UDC detected: $UDC"
|
||||||
|
|
||||||
# 3) Mount configfs once
|
#──────────────────────────────────────────────────
|
||||||
|
# 3. (Re‑)create gadget
|
||||||
|
#──────────────────────────────────────────────────
|
||||||
mountpoint -q /sys/kernel/config || mount -t configfs none /sys/kernel/config
|
mountpoint -q /sys/kernel/config || mount -t configfs none /sys/kernel/config
|
||||||
G=/sys/kernel/config/usb_gadget/lesavka
|
G=/sys/kernel/config/usb_gadget/lesavka
|
||||||
|
|
||||||
# 4) Tear down any previous half-built gadget
|
|
||||||
if [[ -d $G ]]; then
|
if [[ -d $G ]]; then
|
||||||
echo '' >"$G/UDC" 2>/dev/null || true
|
echo '' >"$G/UDC" 2>/dev/null || true
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
@ -60,7 +64,6 @@ if [[ -d $G ]]; then
|
|||||||
rm -rf "$G" 2>/dev/null || true
|
rm -rf "$G" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 5) Create gadget (boot-keyboard + UAC2 mic/spkr, 500 mA max)
|
|
||||||
mkdir -p "$G"
|
mkdir -p "$G"
|
||||||
echo 0x1d6b >"$G/idVendor" # Linux Foundation
|
echo 0x1d6b >"$G/idVendor" # Linux Foundation
|
||||||
echo 0x0104 >"$G/idProduct" # Multifunction Composite Gadget
|
echo 0x0104 >"$G/idProduct" # Multifunction Composite Gadget
|
||||||
@ -95,28 +98,32 @@ printf '\x05\x01\x09\x02\xa1\x01\x09\x01\xa1\x00'\
|
|||||||
|
|
||||||
# ---------- UAC2 function – speaker + mic, 2×48 kHz stereo ---------
|
# ---------- UAC2 function – speaker + mic, 2×48 kHz stereo ---------
|
||||||
mkdir -p "$G/functions/uac2.usb0"
|
mkdir -p "$G/functions/uac2.usb0"
|
||||||
cfg="$G/functions/uac2.usb0"
|
U="$G/functions/uac2.usb0"
|
||||||
echo 48000 >"$cfg/s_spk/freq"
|
# Playback (speaker)
|
||||||
echo 2 >"$cfg/s_spk/chs" # L+R
|
echo 0x3 >"$U/p_chmask" # L+R
|
||||||
echo 16 >"$cfg/s_spk/strm_maxpacket"
|
echo 48000 >"$U/p_srate"
|
||||||
echo 48000 >"$cfg/c_mic/freq"
|
echo 2 >"$U/p_ssize" # 16 bit
|
||||||
echo 2 >"$cfg/c_mic/chs"
|
# Capture (microphone)
|
||||||
echo 16 >"$cfg/c_mic/strm_maxpacket"
|
echo 0x3 >"$U/c_chmask"
|
||||||
|
echo 48000 >"$U/c_srate"
|
||||||
|
echo 2 >"$U/c_ssize"
|
||||||
|
# Optional: allocate a few extra request buffers
|
||||||
|
echo 32 >"$U/req_number" 2>/dev/null || true
|
||||||
|
|
||||||
# ----------------------- configuration -----------------------------
|
# ----------------------- configuration -----------------------------
|
||||||
mkdir -p "$G/configs/c.1/strings/0x409"
|
mkdir -p "$G/configs/c.1/strings/0x409"
|
||||||
echo 500 > "$G/configs/c.1/MaxPower"
|
echo 500 > "$G/configs/c.1/MaxPower"
|
||||||
echo "Config 1" > "$G/configs/c.1/strings/0x409/configuration"
|
# echo "Config 1" > "$G/configs/c.1/strings/0x409/configuration"
|
||||||
|
echo "Config 1: HID + UAC2" >"$G/configs/c.1/strings/0x409/configuration"
|
||||||
|
|
||||||
# 6) Finally bind to first available UDC
|
|
||||||
ln -s $G/functions/hid.usb0 $G/configs/c.1/
|
ln -s $G/functions/hid.usb0 $G/configs/c.1/
|
||||||
ln -s $G/functions/hid.usb1 $G/configs/c.1/
|
ln -s $G/functions/hid.usb1 $G/configs/c.1/
|
||||||
ln -sf "$cfg" "$G/configs/c.1/"
|
ln -sf "$cfg" "$G/configs/c.1/"
|
||||||
|
|
||||||
# 7) Finally bind to first available UDC
|
#──────────────────────────────────────────────────
|
||||||
|
# 4. Bind gadget
|
||||||
|
#──────────────────────────────────────────────────
|
||||||
echo "$UDC" >"$G/UDC"
|
echo "$UDC" >"$G/UDC"
|
||||||
echo "[lesavka-core] 🎉 gadget ready"
|
log "🎉 gadget bound on $UDC (hidg0, hidg1, UAC2 L+R)"
|
||||||
echo "⌨️ hidg0 gadget ready on controller $UDC"
|
|
||||||
echo "🖱️ hidg1 gadget ready on controller $UDC"
|
exit 0
|
||||||
echo "🎧 UAC2 gadget ready on controller $UDC"
|
|
||||||
echo "🎤 UAC2 gadget ready on controller $UDC"
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user