Skip to content

Commit 9031aa3

Browse files
hyx0329dpgeorge
authored andcommitted
usb-device-hid: Fix descriptor protocol config and set correct default.
Subclass in HID interface descriptor is a flag of boot protocol support. Set it according to the interface protocol settings. HID devices should come up in non-boot mode according to Device Class Definition for Human Interface Devices (HID) v1.11 Appendix F.5. Set the initial state of interface protocol to report protocol. Signed-off-by: Hyx <hyx0329@outlook.com>
1 parent 852f2cc commit 9031aa3

File tree

1 file changed

+11
-2
lines changed
  • micropython/usb/usb-device-hid/usb/device

1 file changed

+11
-2
lines changed

micropython/usb/usb-device-hid/usb/device/hid.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
_INTERFACE_SUBCLASS_NONE = const(0x00)
3535
_INTERFACE_SUBCLASS_BOOT = const(0x01)
3636

37+
# These values will only make sense when interface subclass
38+
# is 0x01, which indicates boot protocol support.
3739
_INTERFACE_PROTOCOL_NONE = const(0x00)
3840
_INTERFACE_PROTOCOL_KEYBOARD = const(0x01)
3941
_INTERFACE_PROTOCOL_MOUSE = const(0x02)
@@ -131,7 +133,9 @@ def desc_cfg(self, desc, itf_num, ep_num, strs):
131133
itf_num,
132134
1,
133135
_INTERFACE_CLASS,
134-
_INTERFACE_SUBCLASS_NONE,
136+
_INTERFACE_SUBCLASS_NONE
137+
if self.protocol == _INTERFACE_PROTOCOL_NONE
138+
else _INTERFACE_SUBCLASS_BOOT,
135139
self.protocol,
136140
len(strs) if self.interface_str else 0,
137141
)
@@ -149,7 +153,12 @@ def desc_cfg(self, desc, itf_num, ep_num, strs):
149153
desc.endpoint(self._int_ep, "interrupt", 8, 8)
150154

151155
self.idle_rate = 0
152-
self.protocol = 0
156+
157+
# This variable is reused to track boot protocol status.
158+
# 0 for boot protocol, 1 for report protocol
159+
# According to Device Class Definition for Human Interface Devices (HID) v1.11
160+
# Appendix F.5, the device comes up in non-boot mode by default.
161+
self.protocol = 1
153162

154163
def num_eps(self):
155164
return 1

0 commit comments

Comments
 (0)