Updates -
Composite Gadget I was able to get USB composite gadgets (libcomposite) working on my 5 Moons. This allows the 5 Moons to behave as several types of USB gadget at the same time, e.g. Audio, Ethernet, ACM (which is serial I think…). I’m copying the setup/teardown script I came up with below, for reference.
MIDI - I was able to get the 5 Moons to appear on my mac as a USB Midi device, however it seems that ALSA’s ‘seq’ module was not included in the kernel build, and Pd seems to depend on that to be able to communicate with MIDI. I was able to send and receive MIDI over ALSA’s rawmidi device, but just not to Pd. This seems to apply to regular MIDI devices plugged into the 5 Moons’ USB-A port too. (I noticed in /proc/config.gz
that CONFIG_SND_SEQUENCER
is not set.)
Audio - I mentioned previously that the Pd schedular blocks with the following conditions:
- USB Gadget is enabled
- Pd is configured to use one of the USB audio gadgets for audio input and/or output
- An application on my Mac or iOS is not actively running and sending/receiving audio over USB to the 5 Moons
I haven’t found a workaround for this, and I suspect it won’t be possible to get Pd to not block when audio data isn’t being actively sent over USB under these conditions. It’s not a dealbreaker for exploring USB audio but it is something to keep in mind. The fix if Pd glitches out is to restart the Pd process.
usb_audio_ether_acm.sh
#!/bin/bash
# Script to setup and enable a composite Audio, Ethernet and Serial USB gadget
set -x
whoami
modprobe libcomposite
mount -t configfs none /sys/kernel/config
if [ ! -d "/sys/kernel/config" ]; then
echo "/sys/kernel/config does not exist."
exit 1
fi
cd /sys/kernel/config/usb_gadget/
GADGET_DIR="g1"
mkdir -p $GADGET_DIR
cd $GADGET_DIR
# Set basic USB device settings
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0101 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "420" > strings/0x409/serialnumber
echo "Critter" > strings/0x409/manufacturer
echo "5Moons" > strings/0x409/product
# Create a configuration
mkdir -p configs/c.1
mkdir -p configs/c.1/strings/0x409
echo "Configuration 1" > configs/c.1/strings/0x409/configuration
echo 100 > configs/c.1/MaxPower
# Add USB functions. Note: Required driver for each function is loaded automatically.
# Add USB Audio 2 device
UAC2_DIR="functions/uac2.usb0"
mkdir -p $UAC2_DIR
# Playback settings: Stereo, 48000 Hz, 16-bit
echo 0x3 > $UAC2_DIR/p_chmask # 1 for mono, 3 for stereo (10 channels aka 0x3ff seems to be the max allowed)
echo 48000 > $UAC2_DIR/p_srate
# Capture settings: Stereo, 48000 Hz, 16-bit
echo 0x3 > $UAC2_DIR/c_chmask # 1 for mono, 3 for stereo
echo 48000 > $UAC2_DIR/c_srate
ln -s $UAC2_DIR configs/c.1/
# Add USB Ethernet Device
ECM_DIR="functions/ecm.usb0"
mkdir -p $ECM_DIR
ln -s $ECM_DIR configs/c.1/
echo "USB ECM ETHERNET GADGET CONFIGURED"
# Add USB Serial Device
ACM_DIR="functions/acm.usb0"
mkdir -p $ACM_DIR
ln -s $ACM_DIR configs/c.1/
echo "USB ACM GADGET CONFIGURED"
# Bind USB Device Configuration to USB Device (from /sys/class/udc)
echo "ci_hdrc.0" > UDC
echo "USB AUDIO GADGET CONFIGURED"
# Configure ethernet
ifconfig usb0 192.168.0.100 netmask 255.255.255.0
echo "ETHERNET CONFIGURED"
usb_audio_ether_acm_down.sh
#!/bin/bash
# Script to disable and take down a composite Audio, Ethernet and Serial USB gadget
set -x
if [ ! -d "/sys/kernel/config" ]; then
echo "/sys/kernel/config does not exist."
exit 1
fi
cd /sys/kernel/config/usb_gadget/g1
echo "" > UDC
rm configs/c.1/uac2.usb0
rm configs/c.1/ecm.usb0
rm configs/c.1/acm.usb0
rmdir configs/c.1/strings/0x409
rmdir configs/c.1
rmdir functions/uac2.usb0
rmdir functions/ecm.usb0
rmdir functions/acm.usb0
rmdir strings/0x409
cd ..
rmdir g1
# After a gadget is disabled and torn down, the modules remain loaded.
rmmod usb_f_uac2
rmmod usb_f_ecm
rmmod usb_f_acm
echo "USB GADGET DEACTIVATED"