Skip to content

support to get HID OUT report #3302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2020
Merged

support to get HID OUT report #3302

merged 4 commits into from
Sep 11, 2020

Conversation

xiongyihui
Copy link

This is a draft implementation to get USB HID OUT report, which added a report property for usb_hid.Device to get HID OUT report.
With the feature. we are able to get the keyboard leds info (capslock, numlock).

Usage:

indicators = usb_hid.devices[0].report[0]

Besides, Have added a report property to BLE HID ReportOut too.

@tannewt
Copy link
Member

tannewt commented Aug 19, 2020

@deshipu may want to review as well.

@dhalbert
Copy link
Collaborator

@xiongyihui This looks good as it stands. Do you still consider it a draft, or have you finished your testing?

@xiongyihui
Copy link
Author

I have tested it. It works well. I would use it in the M60 keyboard. Do you have any other ideas?

@dhalbert
Copy link
Collaborator

I'm wondering if we should call this out_report or received_report to distinguish it from the regular IN report. What do you think the best terminology is?

@xiongyihui
Copy link
Author

If we do not consider to add a out_report property to usb_hid.Device, I would prefer to use report. Otherwise, would use out_report and in_report.

@dhalbert
Copy link
Collaborator

@xiongyihui We have send_report(), which sends the IN report (obviously). Since there is no receive_report(), I was thinking the .report property should be .out_report(), to distinguish it from the IN report, since the OUT data in .report is not the same as the IN data send by send_report().

@xiongyihui
Copy link
Author

Use it as a function or a property? Maybe like DigitalInOut.value

@tannewt
Copy link
Member

tannewt commented Aug 31, 2020

I think a property would be best. It would return the latest report received.

@dhalbert
Copy link
Collaborator

dhalbert commented Sep 4, 2020

I do like send_report() since it is sending a stream of reports, not setting a value over and over. I don't think .report = next report is the right thing to do.

Then .report is a read-only property. But to distinguish the incoming (OUT) report from the outgoing (IN) report, I am suggesting calling it received_report. (The "OUT" vs "IN" designations are very confusing to the layperson, since they reflect the host's view.)

@deshipu
Copy link

deshipu commented Sep 4, 2020

If you use a property, people will be encouraged to use it in multiple conditions, and will be surprised when its value changes in between them. A function call encourages you to assign the returned value to a variable and work with that variable.

I tend to agree with this, even though we have DigitalInOut.value, _bleio.Characteristic.value, etc. However, would receive_report() hang until there was a received OUT report?

@tannewt
Copy link
Member

tannewt commented Sep 8, 2020

I think send_report() is fine as-is. I think @dhalbert's proposal is a property received_report that is the most recently received report (not a function as you suggest @deshipu.)

My one concern is if folks use HID as a serial-like transport and need every HID out report buffered. I think it's an abuse of the protocol but may still be done.

@dhalbert
Copy link
Collaborator

dhalbert commented Sep 8, 2020

I was proposing an actual function; I didn't really think about the hanging part. It could return None if no report was available.

We have a long-term interest in using HID RAW reports for communication with a host, because all hosts already support HID RAW natively and don't need drivers. That would require real FIFO support, so I would lean toward a function. It does not have to buffer for now; we can add that later.

@dglaude
Copy link

dglaude commented Sep 8, 2020

I am all for a function and adding FIFO in the future.
Report can be used to exfiltrate data from a computer (back to what pretend to be a USB keyboard).
To have a good bandwidth, you need to make sure no data is lost in those "LED" report.

@xiongyihui
Copy link
Author

xiongyihui commented Sep 9, 2020

For USB keyboard, losing some LED reports is not a big deal. We just need to show the latest LED status.
For HID RAW report, It would be different, as it would probably not use report IDs.

@dhalbert
Copy link
Collaborator

Let's try to finish this off. @xiongyihui I think you are right about the report ID's: they cannot be used for raw mode. Are you saying you still prefer a property, or that the received_report() function is not applicable for raw mode? I don't know if there are non-raw examples of OUT reports that should be FIFO'd.

@xiongyihui
Copy link
Author

The implementation of USB_HID depends on report IDs. It would be very difficult to add a raw mode to USB_HID.
Maybe add a new module USB_RAW_HID and an USB interface to support HID RAW, or use WebUSB instead of HID RAW.
I don't think we should consider raw mode or FIFO here, so I still prefer a property.

@dhalbert
Copy link
Collaborator

That is clear thinking, thanks. OK, how about calling it .last_received_report? That makes it clear it's not related to outgoing reports, and is not FIFO'd.

@xiongyihui
Copy link
Author

I'm OK with .last_received_report.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed changes to make it .last_received_report. @tannewt, if this is OK by you, we can merge.

Thank you @xiongyihui for your patience.

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

Successfully merging this pull request may close these issues.

5 participants