-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.py
33 lines (30 loc) · 1.16 KB
/
boot.py
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
import usb_hid
# This is only one example of a gamepad descriptor, and may not suit your needs.
# https://marcelmg.github.io/usb_snes_gamepad/
GAMEPAD_REPORT_DESCRIPTOR = bytes((
0x05, 0x01, # USAGE_PAGE(Generic Desktop)
0x09, 0x05, # USAGE(Game Pad)
0xa1, 0x01, # COLLECTION(Application)
0xa1, 0x00, # COLLECTION(Physical)
0x05, 0x09, # USAGE_PAGE(Button)
0x19, 0x01, # USAGE_MINIMUM(Button 1)
0x29, 0x1c, # USAGE_MAXIMUM(Button 12) (Needs to be much higher)
0x15, 0x00, # LOGICAL_MINIMUM(0)
0x25, 0x01, # LOGICAL_MAXIMUM(1)
0x75, 0x01, # REPORT_SIZE(1)
0x95, 0x1c, # REPORT_COUNT(16) (Also higher than it should be)
0x81, 0x02, # INPUT(Data, Var, Abs)
0xc0, # END_COLLECTION
0xc0 # END_COLLECTION
))
gamepad = usb_hid.Device(
report_descriptor=GAMEPAD_REPORT_DESCRIPTOR,
usage_page=0x01, # Generic Desktop Control
usage=0x05, # Gamepad
report_ids=(1,), # Descriptor uses report ID 0.
in_report_lengths=(2,), # This gamepad sends 2 bytes in its report.
out_report_lengths=(0,), # It does not receive any reports.
)
usb_hid.enable(
(gamepad,)
)