Repository navigation
Conversation
HIDInterface.protocol held both the bInterfaceProtocol descriptor value and the runtime boot/report protocol mode. desc_cfg() resets it to 1 at the end, and Device.config() calls desc_cfg() twice (once to measure the length, once to write), so every boot interface was described as a keyboard. MouseInterface was announced as protocol 1 instead of 2. Store the descriptor value in a separate interface_protocol attribute. Fixes issue micropython#1176. Signed-off-by: Duhan Günsel <gnsl.duhan.07@gmail.com>
|
Tested on real firmware, with a test build that logs every HID request:
|
Zosili
left a comment
There was a problem hiding this comment.
Tested the patch against the descriptor path with a stub Descriptor that records the bytes
desc_cfg() writes, and it fixes the reported enumeration problem. Driving desc_cfg() twice like
Device.config() does, on master every interface ends up with bInterfaceProtocol = 1 (the reset
at the end of desc_cfg() overwrites the constructor value):
HIDInterface (no protocol) 09 04 03 01 03 01 01 00 00 subclass=1 protocol=1
HIDInterface(protocol=1) 09 04 03 01 03 01 01 00 00 subclass=1 protocol=1
HIDInterface(protocol=2) 09 04 03 01 03 01 01 00 00 subclass=1 protocol=1 <- mouse reports keyboard
With this branch:
HIDInterface (no protocol) 09 04 03 01 03 00 00 00 00 subclass=0 protocol=0
HIDInterface(protocol=1) 09 04 03 01 03 01 01 00 00 subclass=1 protocol=1
HIDInterface(protocol=2) 09 04 03 01 03 01 02 00 00 subclass=1 protocol=2
So MouseInterface now enumerates as a mouse, and self.protocol stays in report mode (1) as HID
1.11 F.5 wants. A side effect worth mentioning: GET_PROTOCOL before desc_cfg() has run now answers
1 (report) instead of the descriptor value, which is the correct answer for a device that has not
switched to boot mode.
One question about the version: metadata(version="0.2.1") is a patch bump, but the meaning of the
public protocol attribute changes — it used to be the descriptor value and is now the runtime mode,
so anything reading interface.protocol to find out what kind of HID device this is will get a
different answer. Would 0.3.0 be the more accurate bump?
Summary
MouseInterfacewas enumerated with bInterfaceProtocol 1 (keyboard) instead of 2 (mouse), becauseHIDInterface.protocolheld both the descriptor value and the runtime protocol mode, andDevice.config()builds the descriptor in two passes. This stores the descriptor value in a separateinterface_protocolattribute. The constructor argument is unchanged.Fixes #1176.
Testing
ESP32-S3 (ESP32_GENERIC_S3, 2 MB PSRAM), MicroPython v1.29.0, macOS host:
ioregand by building the descriptor on the board.Generative AI
I used generative AI tools when creating this PR, but I checked the code and I am responsible for the code and the description above.