Chip: USB hid on libcomposite

Da raspibo.
Versione del 14 feb 2016 alle 17:35 di Renzo (discussione | contributi)
(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

I succeedeed to configure Chip as a USD-hid device using the libcomposite support. It is just a proof-of-concept.

(This example works on my linux kernel see: Compile the Linux kernel for Chip: my personal HOWTO)

First of all, remove all the g_* modules. e.g.:

sudo rmmod g_serial

Here is the script to start the service. (more than a script, it is a voodoo ritual).

#!/bin/bash
cd /sys/kernel/config/usb_gadget
mkdir g1
cd g1
echo "0x1d6b" > idVendor
echo "0x0104" > idProduct
mkdir strings/0x409
echo "My␣serial" > strings/0x409/serialnumber
echo "My␣Vendor" > strings/0x409/manufacturer
echo "My␣Product" > strings/0x409/product
mkdir functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
/bin/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.usb0/report_desc
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo Conf 1 > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower
ln -s functions/hid.usb0 configs/c.1
echo musb-hdrc.1.auto > UDC

This script must run as root (e.g. launch it with sudo).

At the completion of the script there is on chip /dev/hidg0 and the host "sees" a new USB keyboard.

The test program presented in the kernel docs works like a charm.

If it is hard to set up the hid service, it is not trivial to stop it, too.

Here is a second script to turn off the hid service.

 
#!/bin/bash
cd /sys/kernel/config/usb_gadget/g1
echo "" > UDC
rm configs/c.1/hid.usb0
rmdir configs/c.1/strings/0x409
rmdir configs/c.1
rmdir strings/0x409
rmdir functions/hid.usb0
cd ..
rmdir g1