aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb/src
diff options
context:
space:
mode:
authorHaobo Gu <[email protected]>2024-08-15 10:58:10 +0800
committerHaobo Gu <[email protected]>2024-08-15 11:26:24 +0800
commita63d46507de7fbb44233ba5557630791f62a985a (patch)
treec38e1360a721ea3a08bc9c8dc051292656f18fd6 /embassy-usb/src
parent7a26e117ccd5f8669548cc8c2424be4691c1c402 (diff)
feat(usb): add device qualifier descriptor
Signed-off-by: Haobo Gu <[email protected]>
Diffstat (limited to 'embassy-usb/src')
-rw-r--r--embassy-usb/src/descriptor.rs21
-rw-r--r--embassy-usb/src/lib.rs4
2 files changed, 25 insertions, 0 deletions
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs
index eb3d1f53a..f1773fa8a 100644
--- a/embassy-usb/src/descriptor.rs
+++ b/embassy-usb/src/descriptor.rs
@@ -13,6 +13,8 @@ pub mod descriptor_type {
13 pub const STRING: u8 = 3; 13 pub const STRING: u8 = 3;
14 pub const INTERFACE: u8 = 4; 14 pub const INTERFACE: u8 = 4;
15 pub const ENDPOINT: u8 = 5; 15 pub const ENDPOINT: u8 = 5;
16 pub const DEVICE_QUALIFIER: u8 = 6;
17 pub const OTHER_SPEED_CONFIGURATION: u8 = 7;
16 pub const IAD: u8 = 11; 18 pub const IAD: u8 = 11;
17 pub const BOS: u8 = 15; 19 pub const BOS: u8 = 15;
18 pub const CAPABILITY: u8 = 16; 20 pub const CAPABILITY: u8 = 16;
@@ -272,6 +274,25 @@ pub(crate) fn device_descriptor(config: &Config) -> [u8; 18] {
272 ] 274 ]
273} 275}
274 276
277/// Create a new Device Qualifier Descriptor array.
278///
279/// All device qualifier descriptors are always 10 bytes, so there's no need for
280/// a variable-length buffer or DescriptorWriter.
281pub(crate) fn device_qualifier_descriptor(config: &Config) -> [u8; 10] {
282 [
283 10, // bLength
284 0x06, // bDescriptorType
285 0x10,
286 0x02, // bcdUSB 2.1
287 config.device_class, // bDeviceClass
288 config.device_sub_class, // bDeviceSubClass
289 config.device_protocol, // bDeviceProtocol
290 config.max_packet_size_0, // bMaxPacketSize0
291 1, // bNumConfigurations
292 0, // Reserved
293 ]
294}
295
275/// A writer for Binary Object Store descriptor. 296/// A writer for Binary Object Store descriptor.
276pub struct BosWriter<'a> { 297pub struct BosWriter<'a> {
277 pub(crate) writer: DescriptorWriter<'a>, 298 pub(crate) writer: DescriptorWriter<'a>,
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs
index d58950838..a5478ca0e 100644
--- a/embassy-usb/src/lib.rs
+++ b/embassy-usb/src/lib.rs
@@ -190,6 +190,7 @@ struct Inner<'d, D: Driver<'d>> {
190 190
191 config: Config<'d>, 191 config: Config<'d>,
192 device_descriptor: [u8; 18], 192 device_descriptor: [u8; 18],
193 device_qualifier_descriptor: [u8; 10],
193 config_descriptor: &'d [u8], 194 config_descriptor: &'d [u8],
194 bos_descriptor: &'d [u8], 195 bos_descriptor: &'d [u8],
195 msos_descriptor: crate::msos::MsOsDescriptorSet<'d>, 196 msos_descriptor: crate::msos::MsOsDescriptorSet<'d>,
@@ -225,6 +226,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
225 // This prevent further allocation by consuming the driver. 226 // This prevent further allocation by consuming the driver.
226 let (bus, control) = driver.start(config.max_packet_size_0 as u16); 227 let (bus, control) = driver.start(config.max_packet_size_0 as u16);
227 let device_descriptor = descriptor::device_descriptor(&config); 228 let device_descriptor = descriptor::device_descriptor(&config);
229 let device_qualifier_descriptor = descriptor::device_qualifier_descriptor(&config);
228 230
229 Self { 231 Self {
230 control_buf, 232 control_buf,
@@ -233,6 +235,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
233 bus, 235 bus,
234 config, 236 config,
235 device_descriptor, 237 device_descriptor,
238 device_qualifier_descriptor,
236 config_descriptor, 239 config_descriptor,
237 bos_descriptor, 240 bos_descriptor,
238 msos_descriptor, 241 msos_descriptor,
@@ -764,6 +767,7 @@ impl<'d, D: Driver<'d>> Inner<'d, D> {
764 } 767 }
765 } 768 }
766 } 769 }
770 descriptor_type::DEVICE_QUALIFIER => InResponse::Accepted(&self.device_qualifier_descriptor),
767 _ => InResponse::Rejected, 771 _ => InResponse::Rejected,
768 } 772 }
769 } 773 }