Skip to content

usb-device-hid: Fix boot protocol config in descriptor, default protocol mode, and protocol mode recover. #1036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy