Skip to content

Commit 72c73d8

Browse files
committed
debugging why 2mS pulling usb
1 parent dac0be5 commit 72c73d8

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

embassy-usb/src/builder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ impl<'d, D: Driver<'d>> Builder<'d, D> {
200200

201201
// Log the number of allocator bytes actually used in descriptor buffers
202202
info!("USB: device_descriptor used: {}", self.device_descriptor.position());
203-
info!("USB: config_descriptor used: {}", self.config_descriptor.position());
203+
info!(
204+
"USB: config_descriptor used: {} {:02x}",
205+
self.config_descriptor.position(),
206+
self.config_descriptor.buf[..self.config_descriptor.position()],
207+
);
204208
info!("USB: bos_descriptor used: {}", self.bos_descriptor.writer.position());
205209
info!("USB: msos_descriptor used: {}", msos_descriptor.len());
206210
info!("USB: control_buf size: {}", self.control_buf.len());

embassy-usb/src/descriptor.rs

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Utilities for writing USB descriptors.
22
3+
use embassy_usb_driver::EndpointType;
4+
35
use crate::builder::Config;
46
use crate::driver::EndpointInfo;
57
use crate::types::{InterfaceNumber, StringIndex};
@@ -44,6 +46,53 @@ pub(crate) struct DescriptorWriter<'a> {
4446
num_endpoints_mark: Option<usize>,
4547
}
4648

49+
// [09] 009: [02, 6a, 00, 02, 01, 00, 80, 32]
50+
// [08] 008: [0b, 00, 02, 01, 01, 00, 00]
51+
// [09] 009: [04, 00, 00, 00, 01, 01, 00, 00]
52+
// [09] 009: [24, 01, 00, 01, 2b, 00, 01, 01]
53+
// [0c] 012: [24, 02, 01, 01, 01, 03, 02, 03, 00, 00, 00]
54+
// [09] 009: [24, 03, 03, 02, 03, 01, 01, 00]
55+
// [09] 009: [04, 01, 00, 00, 01, 02, 00, 00]
56+
// [09] 009: [04, 01, 01, 01, 01, 02, 00, 00]
57+
// [07] 007: [24, 01, 01, 01, 01, 00]
58+
// [0b] 011: [24, 02, 01, 02, 02, 10, 01, 80, bb, 00]
59+
// [07] 007: [05, 01, 01, c8, 00, 01]
60+
// [07] 007: [25, 01, 01, 00, 00, 00]
61+
62+
// C.3.2 Configuration Descriptor
63+
// 9: [02, 77, 00, 02, 01, 00, 80, 32] (Ok)
64+
65+
// ??????
66+
// 8: [0b, 00, 02, 01, 01, 00, 00]
67+
68+
// Standard AC Interface Descriptor
69+
// 9: [04, 00, 00, 00, 01, 01, 00, 00] (Ok)
70+
71+
// Class-specific Interface Descriptor
72+
// 9: [24, 01, 00, 01, 2b, 00, 01, 01] (Nok)
73+
74+
// Input Terminal Descriptor (ID1) USB
75+
// 12: [24, 02, 01, 01, 01, 03, 02, 03, 00, 00, 00] (Ok)
76+
77+
// 13: [24, 06, 02, 01, 02, 03, 00, 00, 00, 00, 00, 00]
78+
79+
// Output Terminal Descriptor (ID4)
80+
// 9: [24, 03, 03, 02, 03, 01, 02, 00] (Ok)
81+
82+
// Zero-bandwidth Alternate Setting 0
83+
// 9: [04, 01, 00, 00, 01, 02, 00, 00] (Ok)
84+
// Operational Alternate Setting 1
85+
// 9: [04, 01, 01, 01, 01, 02, 00, 00] (Ok)
86+
87+
// Table C-16: USB Telephone Class-specific AS Interface Descriptor
88+
// 7: [24, 01, 01, 01, 01, 00] (Ok)
89+
// Type I Format Type Descriptor
90+
// 11: [24, 02, 01, 02, 02, 10, 01, 80, bb, 00] (Ok)
91+
// Table C-18: USB Telephone Standard Endpoint Descriptor
92+
// 7: [05, 01, 01, c8, 00, 01] (Ok)
93+
// Class-specific Isochronous Audio Data Endpoint Descriptor
94+
// 7: [25, 01, 01, 00, 00, 00] (Ok)
95+
4796
impl<'a> DescriptorWriter<'a> {
4897
pub(crate) fn new(buf: &'a mut [u8]) -> Self {
4998
DescriptorWriter {
@@ -87,7 +136,7 @@ impl<'a> DescriptorWriter<'a> {
87136
descriptor_type::DEVICE,
88137
&[
89138
0x10,
90-
0x02, // bcdUSB 2.1
139+
0x01, // bcdUSB 2.1
91140
config.device_class, // bDeviceClass
92141
config.device_sub_class, // bDeviceSubClass
93142
config.device_protocol, // bDeviceProtocol
@@ -232,16 +281,30 @@ impl<'a> DescriptorWriter<'a> {
232281
None => panic!("you can only call `endpoint` after `interface/interface_alt`."),
233282
};
234283

284+
let refresh = if matches!(endpoint.ep_type, EndpointType::Interrupt) {
285+
7
286+
} else {
287+
0
288+
};
289+
290+
let (ep, addr) = if matches!(endpoint.ep_type, EndpointType::Isochronous) {
291+
(0x09, 0x00)
292+
} else {
293+
(endpoint.ep_type as u8, 0x00)
294+
};
295+
235296
self.write(
236297
descriptor_type::ENDPOINT,
237298
&[
238-
endpoint.addr.into(), // bEndpointAddress
239-
endpoint.ep_type as u8, // bmAttributes
299+
endpoint.addr.into(), // bEndpointAddress
300+
ep, // bmAttributes
240301
endpoint.max_packet_size as u8,
241302
(endpoint.max_packet_size >> 8) as u8, // wMaxPacketSize
242303
endpoint.interval_ms, // bInterval
304+
refresh, // bRefresh
305+
addr, // bSynchAddress
243306
],
244-
);
307+
)
245308
}
246309

247310
/// Writes a string descriptor.

0 commit comments

Comments
 (0)