-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy path16_buttons_joystick_usb
51 lines (37 loc) · 1.41 KB
/
16_buttons_joystick_usb
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
# Created by https://github.com/milador/RaspberryPi-Joystick
#!/bin/bash
sleep 10
# Create 16 button 16_buttons_rpi_joystick gadget
cd /sys/kernel/config/usb_gadget/
mkdir -p 16_buttons_rpi_joystick
cd 16_buttons_rpi_joystick
# Define USB specification
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Joystick Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
echo 0x00 > bDeviceClass
echo 0x00 > bDeviceSubClass
echo 0x00 > bDeviceProtocol
# Perform localization
mkdir -p strings/0x409
echo "0123456789" > strings/0x409/serialnumber
echo "Raspberry Pi" > strings/0x409/manufacturer
echo "RaspberryPi Joystick" > strings/0x409/product
# Define the functions of the device
mkdir functions/hid.usb0
echo 0 > functions/hid.usb0/protocol
echo 0 > functions/hid.usb0/subclass
echo 4 > functions/hid.usb0/report_length
# Write report descriptor ( X and Y analog joysticks plus 16 buttons )
echo "05010904A1011581257F0901A10009300931750895028102C0A10005091901291015002501750195108102C0C0" | xxd -r -ps > functions/hid.usb0/report_desc
# Create configuration file
mkdir -p configs/c.1/strings/0x409
echo 0x80 > configs/c.1/bmAttributes
echo 100 > configs/c.1/MaxPower # 100 mA
echo "RaspberryPi Joystick Configuration" > configs/c.1/strings/0x409/configuration
# Link the configuration file
ln -s functions/hid.usb0 configs/c.1
# Activate device
ls /sys/class/udc > UDC
sleep 10