Skip to content

Commit 5370838

Browse files
authored
Merge pull request #3259 from HaoboGu/feat/usb_device_qualifier_desc
embassy-usb: add USB device qualifier descriptor
2 parents 7a26e11 + a63d465 commit 5370838

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

embassy-usb/src/descriptor.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub mod descriptor_type {
1313
pub const STRING: u8 = 3;
1414
pub const INTERFACE: u8 = 4;
1515
pub const ENDPOINT: u8 = 5;
16+
pub const DEVICE_QUALIFIER: u8 = 6;
17+
pub const OTHER_SPEED_CONFIGURATION: u8 = 7;
1618
pub const IAD: u8 = 11;
1719
pub const BOS: u8 = 15;
1820
pub const CAPABILITY: u8 = 16;
@@ -272,6 +274,25 @@ pub(crate) fn device_descriptor(config: &Config) -> [u8; 18] {
272274
]
273275
}
274276

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.
281+
pub(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+
275296
/// A writer for Binary Object Store descriptor.
276297
pub struct BosWriter<'a> {
277298
pub(crate) writer: DescriptorWriter<'a>,

embassy-usb/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ struct Inner<'d, D: Driver<'d>> {
190190

191191
config: Config<'d>,
192192
device_descriptor: [u8; 18],
193+
device_qualifier_descriptor: [u8; 10],
193194
config_descriptor: &'d [u8],
194195
bos_descriptor: &'d [u8],
195196
msos_descriptor: crate::msos::MsOsDescriptorSet<'d>,
@@ -225,6 +226,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
225226
// This prevent further allocation by consuming the driver.
226227
let (bus, control) = driver.start(config.max_packet_size_0 as u16);
227228
let device_descriptor = descriptor::device_descriptor(&config);
229+
let device_qualifier_descriptor = descriptor::device_qualifier_descriptor(&config);
228230

229231
Self {
230232
control_buf,
@@ -233,6 +235,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
233235
bus,
234236
config,
235237
device_descriptor,
238+
device_qualifier_descriptor,
236239
config_descriptor,
237240
bos_descriptor,
238241
msos_descriptor,
@@ -764,6 +767,7 @@ impl<'d, D: Driver<'d>> Inner<'d, D> {
764767
}
765768
}
766769
}
770+
descriptor_type::DEVICE_QUALIFIER => InResponse::Accepted(&self.device_qualifier_descriptor),
767771
_ => InResponse::Rejected,
768772
}
769773
}

0 commit comments

Comments
 (0)