I'm setting up my pi0 as HID Keyboard. I've followed this link Pi0 libcomposite gadget.
Every thing works fine, the pi is well recognized as USB Keyboard
$ dmesg
[ +16,318525] usb 1-1.3: new high-speed USB device number 8 using ehci-pci
[ +0,093215] usb 1-1.3: New USB device found, idVendor=1d6b, idProduct=0104
[ +0,000003] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ +0,000001] usb 1-1.3: Product: hid3myPi
[ +0,000001] usb 1-1.3: Manufacturer: sk4mi
[ +0,000001] usb 1-1.3: SerialNumber: 1049799107101100
[ +0,001447] input: sk4mi hid3myPi as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.0/0003:1D6B:0104.0004/input/input15
[ +0,053447] hid-generic 0003:1D6B:0104.0004: input,hidraw2: USB HID v1.01 Keyboard [sk4mi hid3myPi] on usb-0000:00:1a.0-1.3/input0
with lsusb:
$ lsusb
Bus 001 Device 008: ID 1d6b:0104 Linux Foundation Multifunction Composite Gadget
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x1d6b Linux Foundation
idProduct 0x0104 Multifunction Composite Gadget
bcdDevice 1.00
iManufacturer 1 sk4mi
iProduct 2 hid3myPi
iSerial 3 1049799107101100
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 4 Config 1 : test
bmAttributes 0x80
(Bus Powered)
MaxPower 250mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 1 Boot Interface Subclass
bInterfaceProtocol 1 Keyboard
iInterface 5 HID Interface
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.01
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 63
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 4
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 4
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0000
(Bus Powered)
But now there is a little problem: when i send keystrokes to the host, the layout keyboard of HID device is wrong.
Per example, when i want to send the a char, i send:
echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0 #press a
echo -ne "\0\0\x0\0\0\0\0\0" > /dev/hidg0 #release key
But it's a q on the screen. So the device is configured as qwerty keyboard, but i want to send in azerty mode.
my script to initiate pi0 as HID device:
# load libcomposite module
modprobe libcomposite
# create gadget
cd /sys/kernel/config/usb_gadget/
mkdir -p hidzero
cd hidzero
echo 0x1d6b > idVendor
echo 0x0104 > idProduct
echo 0x0100 > bcdDevice
echo 0x0200 > bcdUSB
echo 8 > bCountryCode
mkdir -p strings/0x409
echo "1049799107101100" > strings/0x409/serialnumber
echo "sk4mi" > strings/0x409/manufacturer
echo "hid3myPi" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1 : test" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
#-------------------
#functions here:
# ------------------
#hid conf
mkdir -p functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
bash -c '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'
ln -s functions/hid.usb0 configs/c.1/
#end functions
ls /sys/class/udc > UDC
I try to change the value of bCountryCode, but it don't take effect as we can see on lsusb result...
Anyone knows how to change that ?
Thanks!
Sk4mi