aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb/src/builder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-usb/src/builder.rs')
-rw-r--r--embassy-usb/src/builder.rs47
1 files changed, 37 insertions, 10 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,