|
1 | 1 | //! Utilities for writing USB descriptors. |
2 | 2 |
|
| 3 | +use embassy_usb_driver::EndpointType; |
| 4 | + |
3 | 5 | use crate::builder::Config; |
4 | 6 | use crate::driver::EndpointInfo; |
5 | 7 | use crate::types::{InterfaceNumber, StringIndex}; |
@@ -44,6 +46,53 @@ pub(crate) struct DescriptorWriter<'a> { |
44 | 46 | num_endpoints_mark: Option<usize>, |
45 | 47 | } |
46 | 48 |
|
| 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 | + |
47 | 96 | impl<'a> DescriptorWriter<'a> { |
48 | 97 | pub(crate) fn new(buf: &'a mut [u8]) -> Self { |
49 | 98 | DescriptorWriter { |
@@ -87,7 +136,7 @@ impl<'a> DescriptorWriter<'a> { |
87 | 136 | descriptor_type::DEVICE, |
88 | 137 | &[ |
89 | 138 | 0x10, |
90 | | - 0x02, // bcdUSB 2.1 |
| 139 | + 0x01, // bcdUSB 2.1 |
91 | 140 | config.device_class, // bDeviceClass |
92 | 141 | config.device_sub_class, // bDeviceSubClass |
93 | 142 | config.device_protocol, // bDeviceProtocol |
@@ -232,16 +281,30 @@ impl<'a> DescriptorWriter<'a> { |
232 | 281 | None => panic!("you can only call `endpoint` after `interface/interface_alt`."), |
233 | 282 | }; |
234 | 283 |
|
| 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 | + |
235 | 296 | self.write( |
236 | 297 | descriptor_type::ENDPOINT, |
237 | 298 | &[ |
238 | | - endpoint.addr.into(), // bEndpointAddress |
239 | | - endpoint.ep_type as u8, // bmAttributes |
| 299 | + endpoint.addr.into(), // bEndpointAddress |
| 300 | + ep, // bmAttributes |
240 | 301 | endpoint.max_packet_size as u8, |
241 | 302 | (endpoint.max_packet_size >> 8) as u8, // wMaxPacketSize |
242 | 303 | endpoint.interval_ms, // bInterval |
| 304 | + refresh, // bRefresh |
| 305 | + addr, // bSynchAddress |
243 | 306 | ], |
244 | | - ); |
| 307 | + ) |
245 | 308 | } |
246 | 309 |
|
247 | 310 | /// Writes a string descriptor. |
|
0 commit comments