Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions micropython/usb/usb-device-hid/usb/device/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
_INTERFACE_SUBCLASS_NONE = const(0x00)
_INTERFACE_SUBCLASS_BOOT = const(0x01)

# These values will only make sense when interface subclass
# is 0x01, which indicates boot protocol support.
_INTERFACE_PROTOCOL_NONE = const(0x00)
_INTERFACE_PROTOCOL_KEYBOARD = const(0x01)
_INTERFACE_PROTOCOL_MOUSE = const(0x02)
Expand Down Expand Up @@ -130,7 +132,9 @@ def desc_cfg(self, desc, itf_num, ep_num, strs):
itf_num,
1,
_INTERFACE_CLASS,
_INTERFACE_SUBCLASS_NONE,
_INTERFACE_SUBCLASS_NONE
if self.protocol == _INTERFACE_PROTOCOL_NONE
else _INTERFACE_SUBCLASS_BOOT,
self.protocol,
len(strs) if self.interface_str else 0,
)
Expand All @@ -148,7 +152,12 @@ def desc_cfg(self, desc, itf_num, ep_num, strs):
desc.endpoint(self._int_ep, "interrupt", 8, 8)

self.idle_rate = 0
self.protocol = 0

# This variable is reused to track boot protocol status.
# 0 for boot protocol, 1 for report protocol
# According to Device Class Definition for Human Interface Devices (HID) v1.11
# Appendix F.5, the device comes up in non-boot mode by default.
self.protocol = 1

def num_eps(self):
return 1
Expand Down Expand Up @@ -197,6 +206,8 @@ def on_interface_control_xfer(self, stage, request):
if desc_type == _DESC_HID_TYPE:
return self.get_hid_descriptor()
if desc_type == _DESC_REPORT_TYPE:
# Reset to report protocol when report descriptor is requested
self.protocol = 1
return self.report_descriptor
elif req_type == _REQ_TYPE_CLASS:
# HID Spec p50: 7.2 Class-Specific Requests
Expand Down
Loading