-
Notifications
You must be signed in to change notification settings - Fork 2
/
create-usb-gadgets
executable file
·63 lines (51 loc) · 1.84 KB
/
create-usb-gadgets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
# Script to create USB Gadgets on a Pi
# Two USB Audio gadgets are created and a USB MIDI gadget
#
# USB Audio configuration:
# 8,16,24,27 channels at 4 kHz, 16 bit. 27 is max.
#AUDIO_CHANNEL_MASK=255
#AUDIO_CHANNEL_MASK=65535
#AUDIO_CHANNEL_MASK=16777215
AUDIO_CHANNEL_MASK=134217727 # 27
AUDIO_SAMPLE_RATES=4000
AUDIO_SAMPLE_SIZE=2
# USB MIDI configuration
MIDI_ID="Zoxnoxious-MIDI"
# Load libcomposite: use this to enable multiple gadgets
modprobe libcomposite
# Create a gadget called usb-gadgets
cd /sys/kernel/config/usb_gadget/
mkdir -p usb-gadgets
cd usb-gadgets
# Configure our gadget details
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "023456789abcdef1" > strings/0x409/serialnumber
echo "Zoxnoxious Engineering" > strings/0x409/manufacturer
echo "Zoxnoxious MIDI and Audio" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
# UAC2 (audio) gadget
# attributes from: https://www.kernel.org/doc/Documentation/ABI/testing/configfs-usb-gadget-uac2
for i in 0 1
do
mkdir -p functions/uac2.usb${i}
echo $AUDIO_CHANNEL_MASK > functions/uac2.usb${i}/c_chmask
echo $AUDIO_SAMPLE_RATES > functions/uac2.usb${i}/c_srate
echo $AUDIO_SAMPLE_SIZE > functions/uac2.usb${i}/c_ssize
echo $AUDIO_CHANNEL_MASK > functions/uac2.usb${i}/p_chmask
echo $AUDIO_SAMPLE_RATES > functions/uac2.usb${i}/p_srate
echo $AUDIO_SAMPLE_SIZE > functions/uac2.usb${i}/p_ssize
ln -s functions/uac2.usb${i} configs/c.1/
done
# MIDI gadget
# attributes from: https://www.kernel.org/doc/Documentation/ABI/testing/configfs-usb-gadget-midi
mkdir -p functions/midi.usb0
echo MIDI_ID > functions/midi.usb0/id
ln -s functions/midi.usb0 configs/c.1/
# End functions
udevadm settle -t 5
ls /sys/class/udc > UDC