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

Offen Anfängerfreundlich
#1,176 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@Duhan07 arbeitet bereits daran.

Seit 19.11.2026.

  • #1177 von @Duhan07 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
embedded-iot

Rechercherichtung

Lies die Implementierung von usb-device-hid für HIDInterface, insbesondere desc_cfg(), und verfolge, wie Device.config() die Methode für beide Deskriptor-Durchläufe aufruft. Die Reproduktion im Issue zeigt das abweichende Byte des Interface-Deskriptors; bestätige die Korrektur, indem du das bereitgestellte Snippet erneut ausführst und prüfst, dass das Protokollbyte 02 ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

MouseInterface is enumerated as a boot keyboard, its interface descriptor has bInterfaceSubClass 1 and bInterfaceProtocol 1, but it should be protocol 2 (mouse).

Cause

HIDInterface.protocol stores both the descriptor protocol and the runtime protocol mode. desc_cfg() ends with self.protocol = 1 (report mode), and Device.config() calls desc_cfg() twice (once to measure the length, once to write). So the second call writes 1 for every boot interface.

Reproduction
  • MicroPython v1.29.0, ESP32_GENERIC_S3 (ESP32-S3, 2 MB PSRAM)
  • usb-device-hid 0.2.0, usb-device-mouse, installed with mip
from usb.device.core import Descriptor
from usb.device.mouse import MouseInterface

m = MouseInterface()
d = Descriptor(None)        # pass 1, as in Device.config()
m.desc_cfg(d, 0, 0, [])
buf = bytearray(d.o)
d = Descriptor(buf)          # pass 2
m.desc_cfg(d, 3, 1, [])
print(" ".join("%02x" % b for b in buf[:9]))

Output: 09 04 03 00 01 03 01 01 00 (last-but-one byte should be 02). macOS ioreg shows the same for interface "MicroPython Mouse".

Suggested fix

Store the descriptor value in a separate attribute (e.g. interface_protocol) and keep protocol for the runtime mode. I have tested this on the board.

Vorherrschende Sprache
Python
Sterne
2.9k
Forks
1.1k
Ø Merge
3 T. 21 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus micropython/micropython-lib

Alle Issues in micropython/micropython-lib

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.