forked from milador/RaspberryPi-Joystick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps_gamepad_usb
48 lines (36 loc) · 1.29 KB
/
ps_gamepad_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
#!/bin/bash
# This must run as root!
# This creates a generic gamepad with 2 sticks, 1 dpad, and 14 buttons.
sleep 30
# Create psgamepad gadget
cd /sys/kernel/config/usb_gadget/
mkdir -p psgamepad
cd psgamepad
# Define USB specification
echo 0x0f0d > idVendor # Linux Foundation
echo 0x00c1 > idProduct # Gamepad
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 "Raspberry Pi" > strings/0x409/manufacturer
echo "PSGamepad" > 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 8 > functions/hid.usb0/report_length
# Write report descriptor ( 2 analog sticks, 1 dpad, 14 buttons )
echo "05010905a10115002501350045017501950e05091901290e81029502810105012507463b017504950165140939814265009501810126ff0046ff000930093109320935750895048102750895018101c0" | 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 500 > configs/c.1/MaxPower # 500 mA
# Link the configuration file
ln -s functions/hid.usb0 configs/c.1
# Activate device
ls /sys/class/udc > UDC
sleep 10