Skip to content

Commit 9d3da52

Browse files
committed
usb mouse: Use bytes literal for report descriptor.
(More RAM and bytecode efficient.) Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent cc864f4 commit 9d3da52

File tree

1 file changed

+30
-54
lines changed
  • micropython/usb/usb-device-mouse/usb/device

1 file changed

+30
-54
lines changed

micropython/usb/usb-device-mouse/usb/device/mouse.py

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -61,58 +61,34 @@ def move_by(self, dx, dy):
6161

6262

6363
# Basic 3-button mouse HID Report Descriptor.
64-
# This is cribbed from Appendix E.10 of the HID v1.11 document.
65-
_MOUSE_REPORT_DESC = bytes(
66-
[
67-
0x05,
68-
0x01, # Usage Page (Generic Desktop)
69-
0x09,
70-
0x02, # Usage (Mouse)
71-
0xA1,
72-
0x01, # Collection (Application)
73-
0x09,
74-
0x01, # Usage (Pointer)
75-
0xA1,
76-
0x00, # Collection (Physical)
77-
0x05,
78-
0x09, # Usage Page (Buttons)
79-
0x19,
80-
0x01, # Usage Minimum (01),
81-
0x29,
82-
0x03, # Usage Maximun (03),
83-
0x15,
84-
0x00, # Logical Minimum (0),
85-
0x25,
86-
0x01, # Logical Maximum (1),
87-
0x95,
88-
0x03, # Report Count (3),
89-
0x75,
90-
0x01, # Report Size (1),
91-
0x81,
92-
0x02, # Input (Data, Variable, Absolute), ;3 button bits
93-
0x95,
94-
0x01, # Report Count (1),
95-
0x75,
96-
0x05, # Report Size (5),
97-
0x81,
98-
0x01, # Input (Constant), ;5 bit padding
99-
0x05,
100-
0x01, # Usage Page (Generic Desktop),
101-
0x09,
102-
0x30, # Usage (X),
103-
0x09,
104-
0x31, # Usage (Y),
105-
0x15,
106-
0x81, # Logical Minimum (-127),
107-
0x25,
108-
0x7F, # Logical Maximum (127),
109-
0x75,
110-
0x08, # Report Size (8),
111-
0x95,
112-
0x02, # Report Count (2),
113-
0x81,
114-
0x06, # Input (Data, Variable, Relative), ;2 position bytes (X & Y)
115-
0xC0, # End Collection,
116-
0xC0, # End Collection
117-
]
64+
# This is based on Appendix E.10 of the HID v1.11 document.
65+
# fmt: off
66+
_MOUSE_REPORT_DESC = (
67+
b'\x05\x01' # Usage Page (Generic Desktop)
68+
b'\x09\x02' # Usage (Mouse)
69+
b'\xA1\x01' # Collection (Application)
70+
b'\x09\x01' # Usage (Pointer)
71+
b'\xA1\x00' # Collection (Physical)
72+
b'\x05\x09' # Usage Page (Buttons)
73+
b'\x19\x01' # Usage Minimum (01),
74+
b'\x29\x03' # Usage Maximun (03),
75+
b'\x15\x00' # Logical Minimum (0),
76+
b'\x25\x01' # Logical Maximum (1),
77+
b'\x95\x03' # Report Count (3),
78+
b'\x75\x01' # Report Size (1),
79+
b'\x81\x02' # Input (Data, Variable, Absolute), ;3 button bits
80+
b'\x95\x01' # Report Count (1),
81+
b'\x75\x05' # Report Size (5),
82+
b'\x81\x01' # Input (Constant), ;5 bit padding
83+
b'\x05\x01' # Usage Page (Generic Desktop),
84+
b'\x09\x30' # Usage (X),
85+
b'\x09\x31' # Usage (Y),
86+
b'\x15\x81' # Logical Minimum (-127),
87+
b'\x25\x7F' # Logical Maximum (127),
88+
b'\x75\x08' # Report Size (8),
89+
b'\x95\x02' # Report Count (2),
90+
b'\x81\x06' # Input (Data, Variable, Relative), ;2 position bytes (X & Y)
91+
b'\xC0' # End Collection
92+
b'\xC0' # End Collection
11893
)
94+
# fmt: on

0 commit comments

Comments
 (0)