Skip to content

Conversation

matteo-meluzzi
Copy link

@matteo-meluzzi matteo-meluzzi commented Sep 21, 2025

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.

  • Added the following methods to RequestHandler:
trait RequestHandler {
...
   fn set_protocol(&mut self, protocol: HidProtocolMode) -> OutResponse
...
   fn get_protocol(&self) -> HidProtocolMode 
...
}

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.

@matteo-meluzzi matteo-meluzzi force-pushed the 17-add-support-for-boot-protocol branch from f28184e to 5f5f71e Compare September 21, 2025 15:52
@matteo-meluzzi matteo-meluzzi force-pushed the 17-add-support-for-boot-protocol branch from 6ffe08f to 2cf7cc4 Compare September 21, 2025 16:00
@matteo-meluzzi matteo-meluzzi changed the title Add support for changing hid protocol mode Add support for changing hid protocol mode in embassy_usb Sep 21, 2025
@matteo-meluzzi matteo-meluzzi changed the title Add support for changing hid protocol mode in embassy_usb Add support for changing hid protocol mode in embassy-usb Sep 21, 2025
@matteo-meluzzi matteo-meluzzi force-pushed the 17-add-support-for-boot-protocol branch from 7e932a6 to 8eebece Compare September 23, 2025 18:52
@matteo-meluzzi
Copy link
Author

matteo-meluzzi commented Sep 23, 2025

Mouse example running in the BIOS

IMG_0019.MOV


/// 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"))]
Copy link
Contributor

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.

Copy link
Author

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

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);
Copy link
Contributor

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?

Copy link
Author

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.

@matteo-meluzzi matteo-meluzzi force-pushed the 17-add-support-for-boot-protocol branch from 32353e7 to 5c8218b Compare September 30, 2025 16:39
#[repr(u8)]
pub enum HidSubclass {
/// Only report mode is supported.
ReportOnly = 0,
Copy link
Contributor

@HaoboGu HaoboGu Sep 30, 2025

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

Copy link
Author

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.

@matteo-meluzzi matteo-meluzzi force-pushed the 17-add-support-for-boot-protocol branch from b434060 to d79d433 Compare October 1, 2025 16:30
@HaoboGu
Copy link
Contributor

HaoboGu commented Oct 1, 2025

lgtm!

@matteo-meluzzi
Copy link
Author

lgtm!

@HaoboGu i synced with main, we should be good to go

@matteo-meluzzi matteo-meluzzi requested a review from HaoboGu October 5, 2025 10:35
Copy link
Contributor

@HaoboGu HaoboGu left a 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.

@matteo-meluzzi
Copy link
Author

matteo-meluzzi commented Oct 6, 2025

Ah I see. @Dirbaio would you mind having a look as well?

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.

2 participants