Skip to content

Commit fca6043

Browse files
committed
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 <[email protected]>
1 parent f95568d commit fca6043

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)
@@ -130,7 +132,9 @@ def desc_cfg(self, desc, itf_num, ep_num, strs):
130132
itf_num,
131133
1,
132134
_INTERFACE_CLASS,
133-
_INTERFACE_SUBCLASS_NONE,
135+
_INTERFACE_SUBCLASS_NONE
136+
if self.protocol == _INTERFACE_PROTOCOL_NONE
137+
else _INTERFACE_SUBCLASS_BOOT,
134138
self.protocol,
135139
len(strs) if self.interface_str else 0,
136140
)
@@ -148,7 +152,12 @@ def desc_cfg(self, desc, itf_num, ep_num, strs):
148152
desc.endpoint(self._int_ep, "interrupt", 8, 8)
149153

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

153162
def num_eps(self):
154163
return 1

0 commit comments

Comments
 (0)