aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-synopsys-otg
diff options
context:
space:
mode:
authorkorbin <[email protected]>2025-07-13 20:30:26 -0600
committerkorbin <[email protected]>2025-07-13 20:40:54 -0600
commitb666a88ab175043d711c97b67b5b4d3bf409f102 (patch)
tree02436ff11d08664b4a12aa9b5f2c915f012ba13d /embassy-usb-synopsys-otg
parent9651cfca51a273ba46d34ce8197fc0e63389b09e (diff)
make usb endpoint allocator methods accept an optional EndpointAddress
Diffstat (limited to 'embassy-usb-synopsys-otg')
-rw-r--r--embassy-usb-synopsys-otg/src/lib.rs43
1 files changed, 31 insertions, 12 deletions
diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs
index fc4428b54..7fc142a4e 100644
--- a/embassy-usb-synopsys-otg/src/lib.rs
+++ b/embassy-usb-synopsys-otg/src/lib.rs
@@ -345,6 +345,7 @@ impl<'d, const MAX_EP_COUNT: usize> Driver<'d, MAX_EP_COUNT> {
345 fn alloc_endpoint<D: Dir>( 345 fn alloc_endpoint<D: Dir>(
346 &mut self, 346 &mut self,
347 ep_type: EndpointType, 347 ep_type: EndpointType,
348 ep_addr: Option<EndpointAddress>,
348 max_packet_size: u16, 349 max_packet_size: u16,
349 interval_ms: u8, 350 interval_ms: u8,
350 ) -> Result<Endpoint<'d, D>, EndpointAllocError> { 351 ) -> Result<Endpoint<'d, D>, EndpointAllocError> {
@@ -379,15 +380,31 @@ impl<'d, const MAX_EP_COUNT: usize> Driver<'d, MAX_EP_COUNT> {
379 Direction::In => &mut self.ep_in[..self.instance.endpoint_count], 380 Direction::In => &mut self.ep_in[..self.instance.endpoint_count],
380 }; 381 };
381 382
382 // Find free endpoint slot 383 // Find endpoint slot
383 let slot = eps.iter_mut().enumerate().find(|(i, ep)| { 384 let slot = if let Some(addr) = ep_addr {
384 if *i == 0 && ep_type != EndpointType::Control { 385 // Use the specified endpoint address
385 // reserved for control pipe 386 let requested_index = addr.index();
386 false 387 if requested_index >= self.instance.endpoint_count {
387 } else { 388 return Err(EndpointAllocError);
388 ep.is_none()
389 } 389 }
390 }); 390 if requested_index == 0 && ep_type != EndpointType::Control {
391 return Err(EndpointAllocError); // EP0 is reserved for control
392 }
393 if eps[requested_index].is_some() {
394 return Err(EndpointAllocError); // Already allocated
395 }
396 Some((requested_index, &mut eps[requested_index]))
397 } else {
398 // Find any free endpoint slot
399 eps.iter_mut().enumerate().find(|(i, ep)| {
400 if *i == 0 && ep_type != EndpointType::Control {
401 // reserved for control pipe
402 false
403 } else {
404 ep.is_none()
405 }
406 })
407 };
391 408
392 let index = match slot { 409 let index = match slot {
393 Some((index, ep)) => { 410 Some((index, ep)) => {
@@ -438,27 +455,29 @@ impl<'d, const MAX_EP_COUNT: usize> embassy_usb_driver::Driver<'d> for Driver<'d
438 fn alloc_endpoint_in( 455 fn alloc_endpoint_in(
439 &mut self, 456 &mut self,
440 ep_type: EndpointType, 457 ep_type: EndpointType,
458 ep_addr: Option<EndpointAddress>,
441 max_packet_size: u16, 459 max_packet_size: u16,
442 interval_ms: u8, 460 interval_ms: u8,
443 ) -> Result<Self::EndpointIn, EndpointAllocError> { 461 ) -> Result<Self::EndpointIn, EndpointAllocError> {
444 self.alloc_endpoint(ep_type, max_packet_size, interval_ms) 462 self.alloc_endpoint(ep_type, ep_addr, max_packet_size, interval_ms)
445 } 463 }
446 464
447 fn alloc_endpoint_out( 465 fn alloc_endpoint_out(
448 &mut self, 466 &mut self,
449 ep_type: EndpointType, 467 ep_type: EndpointType,
468 ep_addr: Option<EndpointAddress>,
450 max_packet_size: u16, 469 max_packet_size: u16,
451 interval_ms: u8, 470 interval_ms: u8,
452 ) -> Result<Self::EndpointOut, EndpointAllocError> { 471 ) -> Result<Self::EndpointOut, EndpointAllocError> {
453 self.alloc_endpoint(ep_type, max_packet_size, interval_ms) 472 self.alloc_endpoint(ep_type, ep_addr, max_packet_size, interval_ms)
454 } 473 }
455 474
456 fn start(mut self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { 475 fn start(mut self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) {
457 let ep_out = self 476 let ep_out = self
458 .alloc_endpoint(EndpointType::Control, control_max_packet_size, 0) 477 .alloc_endpoint(EndpointType::Control, None, control_max_packet_size, 0)
459 .unwrap(); 478 .unwrap();
460 let ep_in = self 479 let ep_in = self
461 .alloc_endpoint(EndpointType::Control, control_max_packet_size, 0) 480 .alloc_endpoint(EndpointType::Control, None, control_max_packet_size, 0)
462 .unwrap(); 481 .unwrap();
463 assert_eq!(ep_out.info.addr.index(), 0); 482 assert_eq!(ep_out.info.addr.index(), 0);
464 assert_eq!(ep_in.info.addr.index(), 0); 483 assert_eq!(ep_in.info.addr.index(), 0);