diff options
| author | Matt Ickstadt <[email protected]> | 2023-01-12 14:59:25 -0600 |
|---|---|---|
| committer | alexmoon <[email protected]> | 2023-02-07 14:24:35 -0500 |
| commit | f5ff3c4ac31c79cedf077f559dbd5685886399cc (patch) | |
| tree | 6f8b76bd443453fde4e01a8f366e45cfb9edb9da /embassy-usb/src/lib.rs | |
| parent | a7fa7d0de2fa7b8fab889879b6003df8427c6841 (diff) | |
usb: add support for MS OS Descriptors
Diffstat (limited to 'embassy-usb/src/lib.rs')
| -rw-r--r-- | embassy-usb/src/lib.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 2656af29d..948b8d523 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -13,6 +13,7 @@ pub mod class; | |||
| 13 | pub mod control; | 13 | pub mod control; |
| 14 | pub mod descriptor; | 14 | pub mod descriptor; |
| 15 | mod descriptor_reader; | 15 | mod descriptor_reader; |
| 16 | pub mod msos; | ||
| 16 | pub mod types; | 17 | pub mod types; |
| 17 | 18 | ||
| 18 | use embassy_futures::select::{select, Either}; | 19 | use embassy_futures::select::{select, Either}; |
| @@ -135,6 +136,8 @@ struct Inner<'d, D: Driver<'d>> { | |||
| 135 | set_address_pending: bool, | 136 | set_address_pending: bool, |
| 136 | 137 | ||
| 137 | interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>, | 138 | interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>, |
| 139 | |||
| 140 | msos_descriptor: Option<crate::msos::MsOsDescriptorSet<'d>>, | ||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | 143 | impl<'d, D: Driver<'d>> UsbDevice<'d, D> { |
| @@ -147,6 +150,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 147 | bos_descriptor: &'d [u8], | 150 | bos_descriptor: &'d [u8], |
| 148 | interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>, | 151 | interfaces: Vec<Interface<'d>, MAX_INTERFACE_COUNT>, |
| 149 | control_buf: &'d mut [u8], | 152 | control_buf: &'d mut [u8], |
| 153 | msos_descriptor: Option<crate::msos::MsOsDescriptorSet<'d>>, | ||
| 150 | ) -> UsbDevice<'d, D> { | 154 | ) -> UsbDevice<'d, D> { |
| 151 | // Start the USB bus. | 155 | // Start the USB bus. |
| 152 | // This prevent further allocation by consuming the driver. | 156 | // This prevent further allocation by consuming the driver. |
| @@ -170,6 +174,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 170 | address: 0, | 174 | address: 0, |
| 171 | set_address_pending: false, | 175 | set_address_pending: false, |
| 172 | interfaces, | 176 | interfaces, |
| 177 | msos_descriptor, | ||
| 173 | }, | 178 | }, |
| 174 | } | 179 | } |
| 175 | } | 180 | } |
| @@ -603,6 +608,18 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { | |||
| 603 | None => InResponse::Rejected, | 608 | None => InResponse::Rejected, |
| 604 | } | 609 | } |
| 605 | } | 610 | } |
| 611 | (RequestType::Vendor, Recipient::Device) => { | ||
| 612 | if let Some(msos) = &self.msos_descriptor { | ||
| 613 | if req.request == msos.vendor_code() && req.index == 7 { | ||
| 614 | // Index 7 retrieves the MS OS Descriptor Set | ||
| 615 | InResponse::Accepted(msos.descriptor()) | ||
| 616 | } else { | ||
| 617 | InResponse::Rejected | ||
| 618 | } | ||
| 619 | } else { | ||
| 620 | InResponse::Rejected | ||
| 621 | } | ||
| 622 | } | ||
| 606 | _ => InResponse::Rejected, | 623 | _ => InResponse::Rejected, |
| 607 | } | 624 | } |
| 608 | } | 625 | } |
