Skip to content

usb-device-mouse: Give send_report() a timeout. - #1182

Open
Zosili wants to merge 1 commit into
micropython:masterfrom
Zosili:usb-mouse-send-report-timeout
Open

Zosili wants to merge 1 commit into
micropython:masterfrom
Zosili:usb-mouse-send-report-timeout

Conversation

@Zosili

@Zosili Zosili commented Nov 25, 2026

Copy link
Copy Markdown

Closes #1178.

MouseInterface.send_report() waits for the previous report with
while self.busy(): machine.idle() and no timeout, so a host that never reads
the interrupt endpoint leaves the first report pending and every later call,
including the ones from click_*() and move_by(), blocks the whole program.
HIDInterface.send_report() has a 100 ms timeout for exactly this, it was just
never reached because the wait happens before calling it.

The loop now uses the same deadline and returns False without touching _buf
in that case, and timeout_ms is exposed as an argument, defaulting to 100 like
the base class. The manifest version is bumped for the new argument.

usb-device packages are not covered by tools/ci.sh, so the check was a local
stub harness that drives machine.idle() and the endpoint state:

  • host that never reads: send_report() returns False after the deadline and
    leaves the report buffer untouched (the unpatched code spins forever);
  • host that reads after a few polls: the report is queued unchanged;
  • interface not open: returns False as before.

A host that never reads the interrupt endpoint leaves the first report
pending, so the wait loop in MouseInterface.send_report() never
finishes and every later call, including the ones from click_*() and
move_by(), blocks the whole program. HIDInterface.send_report() has
this timeout already, it was just never reached.

The loop now gives up after timeout_ms and returns False without
touching the report buffer, and the manifest version is bumped for the
new argument.

Signed-off-by: Zosili <zhx1005427725@outlook.com>
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-mouse: send_report() blocks forever if the host never reads the mouse

1 participant