From fca60439fe4fe0e9a50a6bf145811b2a7f6860b4 Mon Sep 17 00:00:00 2001 From: Hyx Date: Wed, 30 Jul 2025 21:15:54 +0800 Subject: [PATCH 1/2] 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 --- micropython/usb/usb-device-hid/usb/device/hid.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/micropython/usb/usb-device-hid/usb/device/hid.py b/micropython/usb/usb-device-hid/usb/device/hid.py index 9e4c70dde..3dc219ee9 100644 --- a/micropython/usb/usb-device-hid/usb/device/hid.py +++ b/micropython/usb/usb-device-hid/usb/device/hid.py @@ -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) @@ -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, ) @@ -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 From 7f8899d9fe4fd396523db1b22aac18db8289a0d7 Mon Sep 17 00:00:00 2001 From: Hyx Date: Wed, 30 Jul 2025 22:39:05 +0800 Subject: [PATCH 2/2] usb-device-hid: Use report protocol after report descriptor requested. So HID device will exit boot protocol mode when entering normal OS. Signed-off-by: Hyx --- micropython/usb/usb-device-hid/usb/device/hid.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/micropython/usb/usb-device-hid/usb/device/hid.py b/micropython/usb/usb-device-hid/usb/device/hid.py index 3dc219ee9..ce7dcc7bc 100644 --- a/micropython/usb/usb-device-hid/usb/device/hid.py +++ b/micropython/usb/usb-device-hid/usb/device/hid.py @@ -206,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 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