aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src
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-rp/src
parent9651cfca51a273ba46d34ce8197fc0e63389b09e (diff)
make usb endpoint allocator methods accept an optional EndpointAddress
Diffstat (limited to 'embassy-rp/src')
-rw-r--r--embassy-rp/src/usb.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs
index 96541ade6..671ecbd32 100644
--- a/embassy-rp/src/usb.rs
+++ b/embassy-rp/src/usb.rs
@@ -153,6 +153,7 @@ impl<'d, T: Instance> Driver<'d, T> {
153 fn alloc_endpoint<D: Dir>( 153 fn alloc_endpoint<D: Dir>(
154 &mut self, 154 &mut self,
155 ep_type: EndpointType, 155 ep_type: EndpointType,
156 ep_addr: Option<EndpointAddress>,
156 max_packet_size: u16, 157 max_packet_size: u16,
157 interval_ms: u8, 158 interval_ms: u8,
158 ) -> Result<Endpoint<'d, T, D>, driver::EndpointAllocError> { 159 ) -> Result<Endpoint<'d, T, D>, driver::EndpointAllocError> {
@@ -169,12 +170,25 @@ impl<'d, T: Instance> Driver<'d, T> {
169 Direction::In => &mut self.ep_in, 170 Direction::In => &mut self.ep_in,
170 }; 171 };
171 172
172 let index = alloc.iter_mut().enumerate().find(|(i, ep)| { 173 let index = if let Some(addr) = ep_addr {
173 if *i == 0 { 174 // Use the specified endpoint address
174 return false; // reserved for control pipe 175 let requested_index = addr.index();
176 if requested_index == 0 || requested_index >= EP_COUNT {
177 return Err(EndpointAllocError);
175 } 178 }
176 !ep.used 179 if alloc[requested_index].used {
177 }); 180 return Err(EndpointAllocError);
181 }
182 Some((requested_index, &mut alloc[requested_index]))
183 } else {
184 // Find any available endpoint
185 alloc.iter_mut().enumerate().find(|(i, ep)| {
186 if *i == 0 {
187 return false; // reserved for control pipe
188 }
189 !ep.used
190 })
191 };
178 192
179 let (index, ep) = index.ok_or(EndpointAllocError)?; 193 let (index, ep) = index.ok_or(EndpointAllocError)?;
180 assert!(!ep.used); 194 assert!(!ep.used);
@@ -299,19 +313,21 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
299 fn alloc_endpoint_in( 313 fn alloc_endpoint_in(
300 &mut self, 314 &mut self,
301 ep_type: EndpointType, 315 ep_type: EndpointType,
316 ep_addr: Option<EndpointAddress>,
302 max_packet_size: u16, 317 max_packet_size: u16,
303 interval_ms: u8, 318 interval_ms: u8,
304 ) -> Result<Self::EndpointIn, driver::EndpointAllocError> { 319 ) -> Result<Self::EndpointIn, driver::EndpointAllocError> {
305 self.alloc_endpoint(ep_type, max_packet_size, interval_ms) 320 self.alloc_endpoint(ep_type, ep_addr, max_packet_size, interval_ms)
306 } 321 }
307 322
308 fn alloc_endpoint_out( 323 fn alloc_endpoint_out(
309 &mut self, 324 &mut self,
310 ep_type: EndpointType, 325 ep_type: EndpointType,
326 ep_addr: Option<EndpointAddress>,
311 max_packet_size: u16, 327 max_packet_size: u16,
312 interval_ms: u8, 328 interval_ms: u8,
313 ) -> Result<Self::EndpointOut, driver::EndpointAllocError> { 329 ) -> Result<Self::EndpointOut, driver::EndpointAllocError> {
314 self.alloc_endpoint(ep_type, max_packet_size, interval_ms) 330 self.alloc_endpoint(ep_type, ep_addr, max_packet_size, interval_ms)
315 } 331 }
316 332
317 fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { 333 fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) {