Convert MS OS descriptor builder to a writer API
This brings it inline with the other embassy-usb descriptor APIs and allows it to integrate well with the Builder to allow class constructors to add MS OS descriptors. Also adds a `usb_serial_winusb` example to demonstrate how to use the API.
This commit is contained in:
@ -136,8 +136,8 @@ struct Inner<'d, D: Driver<'d>> {
|
||||
set_address_pending: bool,
|
||||
|
||||
interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>,
|
||||
|
||||
msos_descriptor: Option<crate::msos::MsOsDescriptorSet<'d>>,
|
||||
#[cfg(feature = "msos-descriptor")]
|
||||
msos_descriptor: crate::msos::MsOsDescriptorSet<'d>,
|
||||
}
|
||||
|
||||
impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
|
||||
@ -150,7 +150,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
|
||||
bos_descriptor: &'d [u8],
|
||||
interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>,
|
||||
control_buf: &'d mut [u8],
|
||||
msos_descriptor: Option<crate::msos::MsOsDescriptorSet<'d>>,
|
||||
#[cfg(feature = "msos-descriptor")] msos_descriptor: crate::msos::MsOsDescriptorSet<'d>,
|
||||
) -> UsbDevice<'d, D> {
|
||||
// Start the USB bus.
|
||||
// This prevent further allocation by consuming the driver.
|
||||
@ -174,6 +174,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
|
||||
address: 0,
|
||||
set_address_pending: false,
|
||||
interfaces,
|
||||
#[cfg(feature = "msos-descriptor")]
|
||||
msos_descriptor,
|
||||
},
|
||||
}
|
||||
@ -608,11 +609,12 @@ impl<'d, D: Driver<'d>> Inner<'d, D> {
|
||||
None => InResponse::Rejected,
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "msos-descriptor")]
|
||||
(RequestType::Vendor, Recipient::Device) => {
|
||||
if let Some(msos) = &self.msos_descriptor {
|
||||
if req.request == msos.vendor_code() && req.index == 7 {
|
||||
if !self.msos_descriptor.is_empty() {
|
||||
if req.request == self.msos_descriptor.vendor_code() && req.index == 7 {
|
||||
// Index 7 retrieves the MS OS Descriptor Set
|
||||
InResponse::Accepted(msos.descriptor())
|
||||
InResponse::Accepted(self.msos_descriptor.descriptor())
|
||||
} else {
|
||||
InResponse::Rejected
|
||||
}
|
||||
|
Reference in New Issue
Block a user