1

I am trying to make a composite USB device using ConfigFS on my Raspberry Pi Zero. I followed this guide to create a USB device: http://isticktoit.net/?p=1383

I have set up a standard USB device using this script at boot (via /etc/rc.local):

#!/bin/bash

cd /sys/kernel/config/usb_gadget/
mkdir -p isticktoit
cd isticktoit

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 "fedcba9876543210" > strings/0x409/serialnumber
echo "JW" > strings/0x409/manufacturer
echo "DoItForTheWenHua" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower

# Add functions here
mkdir -p functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 3 > functions/hid.usb0/report_length
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x03\\x15\\x00\\x25\\x01\\x95\\x03\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x05\\x81\\x03\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x02\\x81\\x06\\xc0\\xc0 > functions/hid.usb0/report_desc
ln -s functions/hid.usb0 configs/c.1/

mkdir -p functions/hid.usb1
echo 1 > functions/hid.usb1/protocol
echo 1 > functions/hid.usb1/subclass
echo 8 > functions/hid.usb1/report_length
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb1/report_desc
ln -s functions/hid.usb1 /configs/c.1/

# End functions
ls /sys/class/udc > UDC

The first function, hid.usb0, has a report descriptor for moving mouse (3 bytes), and the second function, hid.usb1, has a report descriptor for typing on the keyboard (8 bytes).

I can write 3 bytes to the usb device at /dev/hidg0, and move the mouse using the first function, hid.usb0. I tried to write 3 bytes for the first function, and 8 bytes for the second function together as 11 bytes, and while the mouse moved, there was no keyboard input (even though the report I passed should have made a keypress).

How do I specify that I want to switch to the second function, hid.usb1?

  • Any particular reason you want to use two different functions for that? A single HID devices on a single function can produce both keyboard and mouse events, you just have to use different report types (which are specified in the HID descriptor). – dirkt Jul 9 '18 at 5:58
  • I figured that I could make one big report descriptor. The main reason is me being curious about how multiple functions work (and the fact that each tutorial keeps saying it's possible, but not telling how). But I also wanted to create a data stream and a HID device together, which would require two functions. – James Meas Jul 9 '18 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.