Skip to content

usb-device-hid: Keep interface protocol separate from protocol mode. - #1177

Open
Duhan07 wants to merge 1 commit into
micropython:masterfrom
Duhan07:usb-device-hid-interface-protocol
Open

Duhan07 wants to merge 1 commit into
micropython:masterfrom
Duhan07:usb-device-hid-interface-protocol

Conversation

@Duhan07

@Duhan07 Duhan07 commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary

MouseInterface was enumerated with bInterfaceProtocol 1 (keyboard) instead of 2 (mouse), because HIDInterface.protocol held both the descriptor value and the runtime protocol mode, and Device.config() builds the descriptor in two passes. This stores the descriptor value in a separate interface_protocol attribute. The constructor argument is unchanged.

Fixes #1176.

Testing

ESP32-S3 (ESP32_GENERIC_S3, 2 MB PSRAM), MicroPython v1.29.0, macOS host:

  • Before: interface "MicroPython Mouse" = class 3 / subclass 1 / protocol 1.
  • After: class 3 / subclass 1 / protocol 2. Keyboard still 3 / 1 / 1.
  • Checked with ioreg and by building the descriptor on the board.
  • Keyboard + mouse composite demo still types and moves the pointer.
  • Not tested: a real BIOS in boot protocol mode, other ports.

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.

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>
@Duhan07

Duhan07 commented Nov 19, 2026

Copy link
Copy Markdown
Author

Tested on real firmware, with a test build that logs every HID request:

  • Gigabyte B550M K (AMI-based UEFI, BIOS F-B): never sends SET_PROTOCOL, reads the report descriptors and stays in report mode. Keyboard and mouse work in setup with or without this fix.
  • EDK2/OVMF (QEMU 11.1.3, edk2-stable202408, device passed through):
    • without this fix, EDK2's keyboard driver also binds to the mouse interface: it sends SET_PROTOCOL(boot) and keyboard LED reports to it, then drops its 3-byte reports;
    • with this fix, only the keyboard gets SET_PROTOCOL(boot), and the mouse interface is left alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usb-device-hid: MouseInterface reports bInterfaceProtocol 1 (keyboard) instead of 2

1 participant