aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb/src
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-usb/src')
-rw-r--r--embassy-usb/src/builder.rs47
-rw-r--r--embassy-usb/src/class/cdc_acm.rs8
-rw-r--r--embassy-usb/src/class/cdc_ncm/mod.rs6
-rw-r--r--embassy-usb/src/class/cmsis_dap_v2.rs6
-rw-r--r--embassy-usb/src/class/hid.rs4
-rw-r--r--embassy-usb/src/class/midi.rs4
-rw-r--r--embassy-usb/src/class/uac1/speaker.rs3
-rw-r--r--embassy-usb/src/class/web_usb.rs2
8 files changed, 54 insertions, 26 deletions
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs
index 6c4b3f9a4..8d7abe46c 100644
--- a/embassy-usb/src/builder.rs
+++ b/embassy-usb/src/builder.rs
@@ -2,7 +2,7 @@ use heapless::Vec;
2 2
3use crate::config::MAX_HANDLER_COUNT; 3use crate::config::MAX_HANDLER_COUNT;
4use crate::descriptor::{BosWriter, DescriptorWriter, SynchronizationType, UsageType}; 4use crate::descriptor::{BosWriter, DescriptorWriter, SynchronizationType, UsageType};
5use crate::driver::{Driver, Endpoint, EndpointInfo, EndpointType}; 5use crate::driver::{Driver, Endpoint, EndpointAddress, EndpointInfo, EndpointType};
6use crate::msos::{DeviceLevelDescriptor, FunctionLevelDescriptor, MsOsDescriptorWriter}; 6use crate::msos::{DeviceLevelDescriptor, FunctionLevelDescriptor, MsOsDescriptorWriter};
7use crate::types::{InterfaceNumber, StringIndex}; 7use crate::types::{InterfaceNumber, StringIndex};
8use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START}; 8use crate::{Handler, Interface, UsbDevice, MAX_INTERFACE_COUNT, STRING_INDEX_CUSTOM_START};
@@ -465,11 +465,17 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
465 /// Allocate an IN endpoint, without writing its descriptor. 465 /// Allocate an IN endpoint, without writing its descriptor.
466 /// 466 ///
467 /// Used for granular control over the order of endpoint and descriptor creation. 467 /// Used for granular control over the order of endpoint and descriptor creation.
468 pub fn alloc_endpoint_in(&mut self, ep_type: EndpointType, max_packet_size: u16, interval_ms: u8) -> D::EndpointIn { 468 pub fn alloc_endpoint_in(
469 &mut self,
470 ep_type: EndpointType,
471 ep_addr: Option<EndpointAddress>,
472 max_packet_size: u16,
473 interval_ms: u8,
474 ) -> D::EndpointIn {
469 let ep = self 475 let ep = self
470 .builder 476 .builder
471 .driver 477 .driver
472 .alloc_endpoint_in(ep_type, max_packet_size, interval_ms) 478 .alloc_endpoint_in(ep_type, ep_addr, max_packet_size, interval_ms)
473 .expect("alloc_endpoint_in failed"); 479 .expect("alloc_endpoint_in failed");
474 480
475 ep 481 ep
@@ -478,13 +484,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
478 fn endpoint_in( 484 fn endpoint_in(
479 &mut self, 485 &mut self,
480 ep_type: EndpointType, 486 ep_type: EndpointType,
487 ep_addr: Option<EndpointAddress>,
481 max_packet_size: u16, 488 max_packet_size: u16,
482 interval_ms: u8, 489 interval_ms: u8,
483 synchronization_type: SynchronizationType, 490 synchronization_type: SynchronizationType,
484 usage_type: UsageType, 491 usage_type: UsageType,
485 extra_fields: &[u8], 492 extra_fields: &[u8],
486 ) -> D::EndpointIn { 493 ) -> D::EndpointIn {
487 let ep = self.alloc_endpoint_in(ep_type, max_packet_size, interval_ms); 494 let ep = self.alloc_endpoint_in(ep_type, ep_addr, max_packet_size, interval_ms);
488 self.endpoint_descriptor(ep.info(), synchronization_type, usage_type, extra_fields); 495 self.endpoint_descriptor(ep.info(), synchronization_type, usage_type, extra_fields);
489 496
490 ep 497 ep
@@ -496,13 +503,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
496 pub fn alloc_endpoint_out( 503 pub fn alloc_endpoint_out(
497 &mut self, 504 &mut self,
498 ep_type: EndpointType, 505 ep_type: EndpointType,
506 ep_addr: Option<EndpointAddress>,
499 max_packet_size: u16, 507 max_packet_size: u16,
500 interval_ms: u8, 508 interval_ms: u8,
501 ) -> D::EndpointOut { 509 ) -> D::EndpointOut {
502 let ep = self 510 let ep = self
503 .builder 511 .builder
504 .driver 512 .driver
505 .alloc_endpoint_out(ep_type, max_packet_size, interval_ms) 513 .alloc_endpoint_out(ep_type, ep_addr, max_packet_size, interval_ms)
506 .expect("alloc_endpoint_out failed"); 514 .expect("alloc_endpoint_out failed");
507 515
508 ep 516 ep
@@ -511,13 +519,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
511 fn endpoint_out( 519 fn endpoint_out(
512 &mut self, 520 &mut self,
513 ep_type: EndpointType, 521 ep_type: EndpointType,
522 ep_addr: Option<EndpointAddress>,
514 max_packet_size: u16, 523 max_packet_size: u16,
515 interval_ms: u8, 524 interval_ms: u8,
516 synchronization_type: SynchronizationType, 525 synchronization_type: SynchronizationType,
517 usage_type: UsageType, 526 usage_type: UsageType,
518 extra_fields: &[u8], 527 extra_fields: &[u8],
519 ) -> D::EndpointOut { 528 ) -> D::EndpointOut {
520 let ep = self.alloc_endpoint_out(ep_type, max_packet_size, interval_ms); 529 let ep = self.alloc_endpoint_out(ep_type, ep_addr, max_packet_size, interval_ms);
521 self.endpoint_descriptor(ep.info(), synchronization_type, usage_type, extra_fields); 530 self.endpoint_descriptor(ep.info(), synchronization_type, usage_type, extra_fields);
522 531
523 ep 532 ep
@@ -527,9 +536,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
527 /// 536 ///
528 /// Descriptors are written in the order builder functions are called. Note that some 537 /// Descriptors are written in the order builder functions are called. Note that some
529 /// classes care about the order. 538 /// classes care about the order.
530 pub fn endpoint_bulk_in(&mut self, max_packet_size: u16) -> D::EndpointIn { 539 pub fn endpoint_bulk_in(&mut self, ep_addr: Option<EndpointAddress>, max_packet_size: u16) -> D::EndpointIn {
531 self.endpoint_in( 540 self.endpoint_in(
532 EndpointType::Bulk, 541 EndpointType::Bulk,
542 ep_addr,
533 max_packet_size, 543 max_packet_size,
534 0, 544 0,
535 SynchronizationType::NoSynchronization, 545 SynchronizationType::NoSynchronization,
@@ -542,9 +552,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
542 /// 552 ///
543 /// Descriptors are written in the order builder functions are called. Note that some 553 /// Descriptors are written in the order builder functions are called. Note that some
544 /// classes care about the order. 554 /// classes care about the order.
545 pub fn endpoint_bulk_out(&mut self, max_packet_size: u16) -> D::EndpointOut { 555 pub fn endpoint_bulk_out(&mut self, ep_addr: Option<EndpointAddress>, max_packet_size: u16) -> D::EndpointOut {
546 self.endpoint_out( 556 self.endpoint_out(
547 EndpointType::Bulk, 557 EndpointType::Bulk,
558 ep_addr,
548 max_packet_size, 559 max_packet_size,
549 0, 560 0,
550 SynchronizationType::NoSynchronization, 561 SynchronizationType::NoSynchronization,
@@ -557,9 +568,15 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
557 /// 568 ///
558 /// Descriptors are written in the order builder functions are called. Note that some 569 /// Descriptors are written in the order builder functions are called. Note that some
559 /// classes care about the order. 570 /// classes care about the order.
560 pub fn endpoint_interrupt_in(&mut self, max_packet_size: u16, interval_ms: u8) -> D::EndpointIn { 571 pub fn endpoint_interrupt_in(
572 &mut self,
573 ep_addr: Option<EndpointAddress>,
574 max_packet_size: u16,
575 interval_ms: u8,
576 ) -> D::EndpointIn {
561 self.endpoint_in( 577 self.endpoint_in(
562 EndpointType::Interrupt, 578 EndpointType::Interrupt,
579 ep_addr,
563 max_packet_size, 580 max_packet_size,
564 interval_ms, 581 interval_ms,
565 SynchronizationType::NoSynchronization, 582 SynchronizationType::NoSynchronization,
@@ -569,9 +586,15 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
569 } 586 }
570 587
571 /// Allocate a INTERRUPT OUT endpoint and write its descriptor. 588 /// Allocate a INTERRUPT OUT endpoint and write its descriptor.
572 pub fn endpoint_interrupt_out(&mut self, max_packet_size: u16, interval_ms: u8) -> D::EndpointOut { 589 pub fn endpoint_interrupt_out(
590 &mut self,
591 ep_addr: Option<EndpointAddress>,
592 max_packet_size: u16,
593 interval_ms: u8,
594 ) -> D::EndpointOut {
573 self.endpoint_out( 595 self.endpoint_out(
574 EndpointType::Interrupt, 596 EndpointType::Interrupt,
597 ep_addr,
575 max_packet_size, 598 max_packet_size,
576 interval_ms, 599 interval_ms,
577 SynchronizationType::NoSynchronization, 600 SynchronizationType::NoSynchronization,
@@ -586,6 +609,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
586 /// classes care about the order. 609 /// classes care about the order.
587 pub fn endpoint_isochronous_in( 610 pub fn endpoint_isochronous_in(
588 &mut self, 611 &mut self,
612 ep_addr: Option<EndpointAddress>,
589 max_packet_size: u16, 613 max_packet_size: u16,
590 interval_ms: u8, 614 interval_ms: u8,
591 synchronization_type: SynchronizationType, 615 synchronization_type: SynchronizationType,
@@ -594,6 +618,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
594 ) -> D::EndpointIn { 618 ) -> D::EndpointIn {
595 self.endpoint_in( 619 self.endpoint_in(
596 EndpointType::Isochronous, 620 EndpointType::Isochronous,
621 ep_addr,
597 max_packet_size, 622 max_packet_size,
598 interval_ms, 623 interval_ms,
599 synchronization_type, 624 synchronization_type,
@@ -605,6 +630,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
605 /// Allocate a ISOCHRONOUS OUT endpoint and write its descriptor. 630 /// Allocate a ISOCHRONOUS OUT endpoint and write its descriptor.
606 pub fn endpoint_isochronous_out( 631 pub fn endpoint_isochronous_out(
607 &mut self, 632 &mut self,
633 ep_addr: Option<EndpointAddress>,
608 max_packet_size: u16, 634 max_packet_size: u16,
609 interval_ms: u8, 635 interval_ms: u8,
610 synchronization_type: SynchronizationType, 636 synchronization_type: SynchronizationType,
@@ -613,6 +639,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
613 ) -> D::EndpointOut { 639 ) -> D::EndpointOut {
614 self.endpoint_out( 640 self.endpoint_out(
615 EndpointType::Isochronous, 641 EndpointType::Isochronous,
642 ep_addr,
616 max_packet_size, 643 max_packet_size,
617 interval_ms, 644 interval_ms,
618 synchronization_type, 645 synchronization_type,
diff --git a/embassy-usb/src/class/cdc_acm.rs b/embassy-usb/src/class/cdc_acm.rs
index 732a433f8..0a1a5e64f 100644
--- a/embassy-usb/src/class/cdc_acm.rs
+++ b/embassy-usb/src/class/cdc_acm.rs
@@ -254,14 +254,14 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> {
254 ], 254 ],
255 ); 255 );
256 256
257 let comm_ep = alt.endpoint_interrupt_in(8, 255); 257 let comm_ep = alt.endpoint_interrupt_in(None, 8, 255);
258 258
259 // Data interface 259 // Data interface
260 let mut iface = func.interface(); 260 let mut iface = func.interface();
261 let data_if = iface.interface_number(); 261 let data_if = iface.interface_number();
262 let mut alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NONE, None); 262 let mut alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NONE, None);
263 let read_ep = alt.endpoint_bulk_out(max_packet_size); 263 let read_ep = alt.endpoint_bulk_out(None, max_packet_size);
264 let write_ep = alt.endpoint_bulk_in(max_packet_size); 264 let write_ep = alt.endpoint_bulk_in(None, max_packet_size);
265 265
266 drop(func); 266 drop(func);
267 267
@@ -501,7 +501,7 @@ impl<'d, D: Driver<'d>> BufferedReceiver<'d, D> {
501 fn read_from_buffer(&mut self, buf: &mut [u8]) -> usize { 501 fn read_from_buffer(&mut self, buf: &mut [u8]) -> usize {
502 let available = &self.buffer[self.start..self.end]; 502 let available = &self.buffer[self.start..self.end];
503 let len = core::cmp::min(available.len(), buf.len()); 503 let len = core::cmp::min(available.len(), buf.len());
504 buf[..len].copy_from_slice(&self.buffer[..len]); 504 buf[..len].copy_from_slice(&available[..len]);
505 self.start += len; 505 self.start += len;
506 len 506 len
507 } 507 }
diff --git a/embassy-usb/src/class/cdc_ncm/mod.rs b/embassy-usb/src/class/cdc_ncm/mod.rs
index 09d923d2a..3af853091 100644
--- a/embassy-usb/src/class/cdc_ncm/mod.rs
+++ b/embassy-usb/src/class/cdc_ncm/mod.rs
@@ -313,15 +313,15 @@ impl<'d, D: Driver<'d>> CdcNcmClass<'d, D> {
313 ], 313 ],
314 ); 314 );
315 315
316 let comm_ep = alt.endpoint_interrupt_in(8, 255); 316 let comm_ep = alt.endpoint_interrupt_in(None, 8, 255);
317 317
318 // Data interface 318 // Data interface
319 let mut iface = func.interface(); 319 let mut iface = func.interface();
320 let data_if = iface.interface_number(); 320 let data_if = iface.interface_number();
321 let _alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NTB, None); 321 let _alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NTB, None);
322 let mut alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NTB, None); 322 let mut alt = iface.alt_setting(USB_CLASS_CDC_DATA, 0x00, CDC_PROTOCOL_NTB, None);
323 let read_ep = alt.endpoint_bulk_out(max_packet_size); 323 let read_ep = alt.endpoint_bulk_out(None, max_packet_size);
324 let write_ep = alt.endpoint_bulk_in(max_packet_size); 324 let write_ep = alt.endpoint_bulk_in(None, max_packet_size);
325 325
326 drop(func); 326 drop(func);
327 327
diff --git a/embassy-usb/src/class/cmsis_dap_v2.rs b/embassy-usb/src/class/cmsis_dap_v2.rs
index a94e3ddb7..a9fd9cdf0 100644
--- a/embassy-usb/src/class/cmsis_dap_v2.rs
+++ b/embassy-usb/src/class/cmsis_dap_v2.rs
@@ -61,10 +61,10 @@ impl<'d, D: Driver<'d>> CmsisDapV2Class<'d, D> {
61 )); 61 ));
62 let mut interface = function.interface(); 62 let mut interface = function.interface();
63 let mut alt = interface.alt_setting(0xFF, 0, 0, Some(iface_string)); 63 let mut alt = interface.alt_setting(0xFF, 0, 0, Some(iface_string));
64 let read_ep = alt.endpoint_bulk_out(max_packet_size); 64 let read_ep = alt.endpoint_bulk_out(None, max_packet_size);
65 let write_ep = alt.endpoint_bulk_in(max_packet_size); 65 let write_ep = alt.endpoint_bulk_in(None, max_packet_size);
66 let trace_ep = if trace { 66 let trace_ep = if trace {
67 Some(alt.endpoint_bulk_in(max_packet_size)) 67 Some(alt.endpoint_bulk_in(None, max_packet_size))
68 } else { 68 } else {
69 None 69 None
70 }; 70 };
diff --git a/embassy-usb/src/class/hid.rs b/embassy-usb/src/class/hid.rs
index 6d9e0aced..182e1f83f 100644
--- a/embassy-usb/src/class/hid.rs
+++ b/embassy-usb/src/class/hid.rs
@@ -133,9 +133,9 @@ fn build<'d, D: Driver<'d>>(
133 ], 133 ],
134 ); 134 );
135 135
136 let ep_in = alt.endpoint_interrupt_in(config.max_packet_size, config.poll_ms); 136 let ep_in = alt.endpoint_interrupt_in(None, config.max_packet_size, config.poll_ms);
137 let ep_out = if with_out_endpoint { 137 let ep_out = if with_out_endpoint {
138 Some(alt.endpoint_interrupt_out(config.max_packet_size, config.poll_ms)) 138 Some(alt.endpoint_interrupt_out(None, config.max_packet_size, config.poll_ms))
139 } else { 139 } else {
140 None 140 None
141 }; 141 };
diff --git a/embassy-usb/src/class/midi.rs b/embassy-usb/src/class/midi.rs
index 52a96f278..1d152ca44 100644
--- a/embassy-usb/src/class/midi.rs
+++ b/embassy-usb/src/class/midi.rs
@@ -129,14 +129,14 @@ impl<'d, D: Driver<'d>> MidiClass<'d, D> {
129 for i in 0..n_out_jacks { 129 for i in 0..n_out_jacks {
130 endpoint_data[2 + i as usize] = in_jack_id_emb(i); 130 endpoint_data[2 + i as usize] = in_jack_id_emb(i);
131 } 131 }
132 let read_ep = alt.endpoint_bulk_out(max_packet_size); 132 let read_ep = alt.endpoint_bulk_out(None, max_packet_size);
133 alt.descriptor(CS_ENDPOINT, &endpoint_data[0..2 + n_out_jacks as usize]); 133 alt.descriptor(CS_ENDPOINT, &endpoint_data[0..2 + n_out_jacks as usize]);
134 134
135 endpoint_data[1] = n_in_jacks; 135 endpoint_data[1] = n_in_jacks;
136 for i in 0..n_in_jacks { 136 for i in 0..n_in_jacks {
137 endpoint_data[2 + i as usize] = out_jack_id_emb(i); 137 endpoint_data[2 + i as usize] = out_jack_id_emb(i);
138 } 138 }
139 let write_ep = alt.endpoint_bulk_in(max_packet_size); 139 let write_ep = alt.endpoint_bulk_in(None, max_packet_size);
140 alt.descriptor(CS_ENDPOINT, &endpoint_data[0..2 + n_in_jacks as usize]); 140 alt.descriptor(CS_ENDPOINT, &endpoint_data[0..2 + n_in_jacks as usize]);
141 141
142 MidiClass { read_ep, write_ep } 142 MidiClass { read_ep, write_ep }
diff --git a/embassy-usb/src/class/uac1/speaker.rs b/embassy-usb/src/class/uac1/speaker.rs
index 1ff29088c..9565e2a25 100644
--- a/embassy-usb/src/class/uac1/speaker.rs
+++ b/embassy-usb/src/class/uac1/speaker.rs
@@ -268,9 +268,10 @@ impl<'d, D: Driver<'d>> Speaker<'d, D> {
268 268
269 alt.descriptor(CS_INTERFACE, &format_descriptor); 269 alt.descriptor(CS_INTERFACE, &format_descriptor);
270 270
271 let streaming_endpoint = alt.alloc_endpoint_out(EndpointType::Isochronous, max_packet_size, 1); 271 let streaming_endpoint = alt.alloc_endpoint_out(EndpointType::Isochronous, None, max_packet_size, 1);
272 let feedback_endpoint = alt.alloc_endpoint_in( 272 let feedback_endpoint = alt.alloc_endpoint_in(
273 EndpointType::Isochronous, 273 EndpointType::Isochronous,
274 None,
274 4, // Feedback packets are 24 bit (10.14 format). 275 4, // Feedback packets are 24 bit (10.14 format).
275 1, 276 1,
276 ); 277 );
diff --git a/embassy-usb/src/class/web_usb.rs b/embassy-usb/src/class/web_usb.rs
index 405944f14..154b219ca 100644
--- a/embassy-usb/src/class/web_usb.rs
+++ b/embassy-usb/src/class/web_usb.rs
@@ -84,7 +84,7 @@ impl<'d> Control<'d> {
84} 84}
85 85
86impl<'d> Handler for Control<'d> { 86impl<'d> Handler for Control<'d> {
87 fn control_in(&mut self, req: Request, _data: &mut [u8]) -> Option<InResponse> { 87 fn control_in(&mut self, req: Request, _data: &mut [u8]) -> Option<InResponse<'_>> {
88 let landing_value = if self.landing_url.is_some() { 1 } else { 0 }; 88 let landing_value = if self.landing_url.is_some() { 1 } else { 0 };
89 if req.request_type == RequestType::Vendor 89 if req.request_type == RequestType::Vendor
90 && req.recipient == Recipient::Device 90 && req.recipient == Recipient::Device