This commit is contained in:
Brad Stein 2025-06-06 20:55:01 -05:00
parent 2941508920
commit b39d53e392

View File

@ -10,7 +10,7 @@ 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) # 2) Load kernel modules (idempotent)
modprobe dwc2 || { echo "dwc2 missing; 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; }
# 3) Mount configfs once # 3) Mount configfs once
@ -19,9 +19,12 @@ G=/sys/kernel/config/usb_gadget/navka
# 4) Tear down any previous half-built gadget # 4) Tear down any previous half-built gadget
if [[ -d $G ]]; then if [[ -d $G ]]; then
echo "" > "$G/UDC" || true echo "" >"$G/UDC" 2>/dev/null || true
find "$G/configs" -type l -delete || true find "$G/configs" -type l -delete 2>/dev/null || true
rm -rf "$G/functions/"*; rmdir "$G" || true for fn in "$G"/functions/*; do
[[ -d $fn ]] && rmdir "$fn" || true
done
rmdir "$G" 2>/dev/null || true
fi fi
# 5) Create gadget (boot-keyboard + UAC2 mic/spkr, 500 mA max) # 5) Create gadget (boot-keyboard + UAC2 mic/spkr, 500 mA max)
@ -46,18 +49,20 @@ echo -ne '\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25'\
'\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0' \ '\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0' \
>"$G/functions/hid.usb0/report_desc" >"$G/functions/hid.usb0/report_desc"
# -- Simple Audio # # -- UAC2 Audio
mkdir -p $G/functions/uac2.usb0 # mkdir -p $G/functions/uac2.usb0
echo 48000 > $G/functions/uac2.usb0/c_srate # echo 48000 > $G/functions/uac2.usb0/c_srate
echo 2 > $G/functions/uac2.usb0/c_ssize # echo 2 > $G/functions/uac2.usb0/c_ssize
echo 2 > $G/functions/uac2.usb0/p_chmask # echo 2 > $G/functions/uac2.usb0/p_chmask
# -- Config and Binds # -- Config
mkdir -p $G/configs/c.1/strings/0x409 mkdir -p $G/configs/c.1/strings/0x409
echo "Config 1" > $G/configs/c.1/strings/0x409/configuration echo "Config 1" > $G/configs/c.1/strings/0x409/configuration
echo 500 > $G/configs/c.1/MaxPower echo 500 > $G/configs/c.1/MaxPower
# -- Bindings
ln -s $G/functions/hid.usb0 $G/configs/c.1/ ln -s $G/functions/hid.usb0 $G/configs/c.1/
ln -s $G/functions/uac2.usb0 $G/configs/c.1/ # ln -s $G/functions/uac2.usb0 $G/configs/c.1/
# 6) Finally bind to first available UDC # 6) Finally bind to first available UDC
echo $(ls /sys/class/udc | head -n1) > $G/UDC echo $(ls /sys/class/udc | head -n1) > $G/UDC