Skip to content

Improve HID host error handling #3307

@harbaum

Description

@harbaum

Related area

HID host class driver

Hardware specification

RP2040/PIO_USB

Is your feature request related to a problem?

I am having some trouble with HID host unplug events on RP2040/PIO_USB as described in #3296

Part of the problem is that the HID host driver has quite limited error reporting. Especially, the result code is simply ignored:

(void) result;

As a result, the application cannot distinguish between errors and regular zero-length-packets which some HID devices like the Competition Pro USB Joystick actually sends.

Describe the solution you'd like

I think it'd be quite helpful to be able to distinguish between regular zero-byte-replies and errors to e.g. not flood the stack with further requests in an error state. This in turn contributes to the HUB communication problems in #3296

IMHO, a clean solution would be to return more information, but this would unfortunately break the existing API.

The length is returned through an unsigned value:

tuh_hid_report_received_cb(daddr, idx, epbuf->epin, (uint16_t) xferred_bytes);

As a result, it's not possible to e.g. report errors through negative values.

I'd therefore suggest returning a zero pointer in case of an error like so:

tuh_hid_report_received_cb(daddr, idx, (XFER_RESULT_SUCCESS == result)?epbuf->epin:NULL, (uint16_t) xferred_bytes);

This should not break any existing applications (unless they access the payload, even if they are told there isn't any).

I have checked existing issues, discussion and documentation

  • I confirm I have checked existing issues, discussion and documentation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions