-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for changing hid protocol mode in embassy-usb #4691
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
base: main
Are you sure you want to change the base?
Add support for changing hid protocol mode in embassy-usb #4691
Conversation
f28184e
to
5f5f71e
Compare
6ffe08f
to
2cf7cc4
Compare
7e932a6
to
8eebece
Compare
Mouse example running in the BIOS IMG_0019.MOV |
embassy-usb/src/class/hid.rs
Outdated
|
||
/// Get/Set Protocol mapping | ||
/// See (7.2.5 and 7.2.6): <https://www.usb.org/sites/default/files/hid1_11.pdf> | ||
#[cfg(not(feature = "usbd-hid"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just defining HidProtocolMode
in embassy-usb
is fine, no need to import it from usbd-hid
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point, i removed the import
embassy-usb/src/class/hid.rs
Outdated
let len = config.report_descriptor.len(); | ||
|
||
let mut func = builder.function(USB_CLASS_HID, USB_SUBCLASS_NONE, USB_PROTOCOL_NONE); | ||
let mut func = builder.function(USB_CLASS_HID, usb_subclass, usb_protocol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason that config.device_sub_class
and config.device_protocol
are not used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HaoboGu, I believe that the config.device_sub_class
and config.device_protocol
you're referring to belong to the USB device config ( embassy_usb::Config
), while the build() function has a HID class config (embassy_usb::class::hid::Config
) as parameter.
Now that I read your comment, I realize that it would be better if the usb_subclass
and usb_protocol
were specified in embassy_usb::class::hid::Config
. I made the necessary enum definitions and updated embassy_usb::class::hid::Config
. The issue with this is that it's not backwards compatible. I hope that's fine.
32353e7
to
5c8218b
Compare
embassy-usb/src/class/hid.rs
Outdated
#[repr(u8)] | ||
pub enum HidSubclass { | ||
/// Only report mode is supported. | ||
ReportOnly = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use the name from hid spec, aka No
and Boot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HaoboGu , that's a nice idea. I updated the names as you suggested. I also updated all usb_hid_mouse
and usb_hid_keyboard
examples.
b434060
to
d79d433
Compare
lgtm! |
@HaoboGu i synced with main, we should be good to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks really good to me, but I'm not the person that has the power to merge PRs. Maybe Dirbaio wants to have a look too.
Ah I see. @Dirbaio would you mind having a look as well? |
Related issue: #2997
When a computer boots in the BIOS, it does not read full HID reports. Instead, it relies on a much simpler mode called "Boot" see https://wiki.osdev.org/USB_Human_Interface_Devices for more details. This MR adds support to switch to using that USB protocol instead of the normal reports.
RequestHandler
:The change does not affect old code, because the default implementation of the methods is to reject the switch to Boot protocol, as it was in the previous versions of the code.