diff options
| -rw-r--r-- | embassy-nrf/src/usb.rs | 59 | ||||
| -rw-r--r-- | embassy-usb/src/builder.rs | 14 | ||||
| -rw-r--r-- | embassy-usb/src/driver.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_hid_keyboard.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_hid_mouse.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_serial.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_serial_multitask.rs | 4 |
7 files changed, 32 insertions, 53 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index c032b2cc5..70393532f 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -143,38 +143,32 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { | |||
| 143 | 143 | ||
| 144 | fn alloc_endpoint_in( | 144 | fn alloc_endpoint_in( |
| 145 | &mut self, | 145 | &mut self, |
| 146 | ep_addr: Option<EndpointAddress>, | ||
| 147 | ep_type: EndpointType, | 146 | ep_type: EndpointType, |
| 148 | max_packet_size: u16, | 147 | packet_size: u16, |
| 149 | interval: u8, | 148 | interval: u8, |
| 150 | ) -> Result<Self::EndpointIn, driver::EndpointAllocError> { | 149 | ) -> Result<Self::EndpointIn, driver::EndpointAllocError> { |
| 151 | let index = self | 150 | let index = self.alloc_in.allocate(ep_type, packet_size, interval)?; |
| 152 | .alloc_in | ||
| 153 | .allocate(ep_addr, ep_type, max_packet_size, interval)?; | ||
| 154 | let ep_addr = EndpointAddress::from_parts(index, UsbDirection::In); | 151 | let ep_addr = EndpointAddress::from_parts(index, UsbDirection::In); |
| 155 | Ok(Endpoint::new(EndpointInfo { | 152 | Ok(Endpoint::new(EndpointInfo { |
| 156 | addr: ep_addr, | 153 | addr: ep_addr, |
| 157 | ep_type, | 154 | ep_type, |
| 158 | max_packet_size, | 155 | max_packet_size: packet_size, |
| 159 | interval, | 156 | interval, |
| 160 | })) | 157 | })) |
| 161 | } | 158 | } |
| 162 | 159 | ||
| 163 | fn alloc_endpoint_out( | 160 | fn alloc_endpoint_out( |
| 164 | &mut self, | 161 | &mut self, |
| 165 | ep_addr: Option<EndpointAddress>, | ||
| 166 | ep_type: EndpointType, | 162 | ep_type: EndpointType, |
| 167 | max_packet_size: u16, | 163 | packet_size: u16, |
| 168 | interval: u8, | 164 | interval: u8, |
| 169 | ) -> Result<Self::EndpointOut, driver::EndpointAllocError> { | 165 | ) -> Result<Self::EndpointOut, driver::EndpointAllocError> { |
| 170 | let index = self | 166 | let index = self.alloc_out.allocate(ep_type, packet_size, interval)?; |
| 171 | .alloc_out | ||
| 172 | .allocate(ep_addr, ep_type, max_packet_size, interval)?; | ||
| 173 | let ep_addr = EndpointAddress::from_parts(index, UsbDirection::Out); | 167 | let ep_addr = EndpointAddress::from_parts(index, UsbDirection::Out); |
| 174 | Ok(Endpoint::new(EndpointInfo { | 168 | Ok(Endpoint::new(EndpointInfo { |
| 175 | addr: ep_addr, | 169 | addr: ep_addr, |
| 176 | ep_type, | 170 | ep_type, |
| 177 | max_packet_size, | 171 | max_packet_size: packet_size, |
| 178 | interval, | 172 | interval, |
| 179 | })) | 173 | })) |
| 180 | } | 174 | } |
| @@ -183,8 +177,10 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { | |||
| 183 | &mut self, | 177 | &mut self, |
| 184 | max_packet_size: u16, | 178 | max_packet_size: u16, |
| 185 | ) -> Result<Self::ControlPipe, driver::EndpointAllocError> { | 179 | ) -> Result<Self::ControlPipe, driver::EndpointAllocError> { |
| 186 | self.alloc_endpoint_out(Some(0x00.into()), EndpointType::Control, max_packet_size, 0)?; | 180 | self.alloc_in.used |= 0x01; |
| 187 | self.alloc_endpoint_in(Some(0x80.into()), EndpointType::Control, max_packet_size, 0)?; | 181 | self.alloc_in.lens[0] = max_packet_size as u8; |
| 182 | self.alloc_out.used |= 0x01; | ||
| 183 | self.alloc_out.lens[0] = max_packet_size as u8; | ||
| 188 | Ok(ControlPipe { | 184 | Ok(ControlPipe { |
| 189 | _phantom: PhantomData, | 185 | _phantom: PhantomData, |
| 190 | max_packet_size, | 186 | max_packet_size, |
| @@ -681,8 +677,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 681 | .await; | 677 | .await; |
| 682 | 678 | ||
| 683 | // Reset shorts | 679 | // Reset shorts |
| 684 | regs.shorts | 680 | regs.shorts.write(|w| w); |
| 685 | .modify(|_, w| w.ep0datadone_ep0status().clear_bit()); | ||
| 686 | regs.events_ep0setup.reset(); | 681 | regs.events_ep0setup.reset(); |
| 687 | 682 | ||
| 688 | let mut buf = [0; 8]; | 683 | let mut buf = [0; 8]; |
| @@ -746,7 +741,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 746 | } | 741 | } |
| 747 | 742 | ||
| 748 | regs.shorts | 743 | regs.shorts |
| 749 | .modify(|_, w| w.ep0datadone_ep0status().bit(last_packet)); | 744 | .write(|w| w.ep0datadone_ep0status().bit(last_packet)); |
| 750 | 745 | ||
| 751 | regs.intenset.write(|w| { | 746 | regs.intenset.write(|w| { |
| 752 | w.usbreset().set(); | 747 | w.usbreset().set(); |
| @@ -810,7 +805,6 @@ impl Allocator { | |||
| 810 | 805 | ||
| 811 | fn allocate( | 806 | fn allocate( |
| 812 | &mut self, | 807 | &mut self, |
| 813 | ep_addr: Option<EndpointAddress>, | ||
| 814 | ep_type: EndpointType, | 808 | ep_type: EndpointType, |
| 815 | max_packet_size: u16, | 809 | max_packet_size: u16, |
| 816 | _interval: u8, | 810 | _interval: u8, |
| @@ -828,27 +822,16 @@ impl Allocator { | |||
| 828 | 822 | ||
| 829 | // Endpoint directions are allocated individually. | 823 | // Endpoint directions are allocated individually. |
| 830 | 824 | ||
| 831 | let alloc_index = if let Some(ep_addr) = ep_addr { | 825 | let alloc_index = match ep_type { |
| 832 | match (ep_addr.index(), ep_type) { | 826 | EndpointType::Isochronous => 8, |
| 833 | (0, EndpointType::Control) => {} | 827 | EndpointType::Control => return Err(driver::EndpointAllocError), |
| 834 | (8, EndpointType::Isochronous) => {} | 828 | EndpointType::Interrupt | EndpointType::Bulk => { |
| 835 | (n, EndpointType::Bulk) | (n, EndpointType::Interrupt) if n >= 1 && n <= 7 => {} | 829 | // Find rightmost zero bit in 1..=7 |
| 836 | _ => return Err(driver::EndpointAllocError), | 830 | let ones = (self.used >> 1).trailing_ones() as usize; |
| 837 | } | 831 | if ones >= 7 { |
| 838 | 832 | return Err(driver::EndpointAllocError); | |
| 839 | ep_addr.index() | ||
| 840 | } else { | ||
| 841 | match ep_type { | ||
| 842 | EndpointType::Isochronous => 8, | ||
| 843 | EndpointType::Control => 0, | ||
| 844 | EndpointType::Interrupt | EndpointType::Bulk => { | ||
| 845 | // Find rightmost zero bit in 1..=7 | ||
| 846 | let ones = (self.used >> 1).trailing_ones() as usize; | ||
| 847 | if ones >= 7 { | ||
| 848 | return Err(driver::EndpointAllocError); | ||
| 849 | } | ||
| 850 | ones + 1 | ||
| 851 | } | 833 | } |
| 834 | ones + 1 | ||
| 852 | } | 835 | } |
| 853 | }; | 836 | }; |
| 854 | 837 | ||
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 8cf9c82a9..698a5f765 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -372,7 +372,6 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 372 | 372 | ||
| 373 | fn endpoint_in( | 373 | fn endpoint_in( |
| 374 | &mut self, | 374 | &mut self, |
| 375 | ep_addr: Option<EndpointAddress>, | ||
| 376 | ep_type: EndpointType, | 375 | ep_type: EndpointType, |
| 377 | max_packet_size: u16, | 376 | max_packet_size: u16, |
| 378 | interval: u8, | 377 | interval: u8, |
| @@ -380,7 +379,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 380 | let ep = self | 379 | let ep = self |
| 381 | .builder | 380 | .builder |
| 382 | .driver | 381 | .driver |
| 383 | .alloc_endpoint_in(ep_addr, ep_type, max_packet_size, interval) | 382 | .alloc_endpoint_in(ep_type, max_packet_size, interval) |
| 384 | .expect("alloc_endpoint_in failed"); | 383 | .expect("alloc_endpoint_in failed"); |
| 385 | 384 | ||
| 386 | self.builder.config_descriptor.endpoint(ep.info()); | 385 | self.builder.config_descriptor.endpoint(ep.info()); |
| @@ -390,7 +389,6 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 390 | 389 | ||
| 391 | fn endpoint_out( | 390 | fn endpoint_out( |
| 392 | &mut self, | 391 | &mut self, |
| 393 | ep_addr: Option<EndpointAddress>, | ||
| 394 | ep_type: EndpointType, | 392 | ep_type: EndpointType, |
| 395 | max_packet_size: u16, | 393 | max_packet_size: u16, |
| 396 | interval: u8, | 394 | interval: u8, |
| @@ -398,7 +396,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 398 | let ep = self | 396 | let ep = self |
| 399 | .builder | 397 | .builder |
| 400 | .driver | 398 | .driver |
| 401 | .alloc_endpoint_out(ep_addr, ep_type, max_packet_size, interval) | 399 | .alloc_endpoint_out(ep_type, max_packet_size, interval) |
| 402 | .expect("alloc_endpoint_out failed"); | 400 | .expect("alloc_endpoint_out failed"); |
| 403 | 401 | ||
| 404 | self.builder.config_descriptor.endpoint(ep.info()); | 402 | self.builder.config_descriptor.endpoint(ep.info()); |
| @@ -411,7 +409,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 411 | /// Descriptors are written in the order builder functions are called. Note that some | 409 | /// Descriptors are written in the order builder functions are called. Note that some |
| 412 | /// classes care about the order. | 410 | /// classes care about the order. |
| 413 | pub fn endpoint_bulk_in(&mut self, max_packet_size: u16) -> D::EndpointIn { | 411 | pub fn endpoint_bulk_in(&mut self, max_packet_size: u16) -> D::EndpointIn { |
| 414 | self.endpoint_in(None, EndpointType::Bulk, max_packet_size, 0) | 412 | self.endpoint_in(EndpointType::Bulk, max_packet_size, 0) |
| 415 | } | 413 | } |
| 416 | 414 | ||
| 417 | /// Allocate a BULK OUT endpoint and write its descriptor. | 415 | /// Allocate a BULK OUT endpoint and write its descriptor. |
| @@ -419,7 +417,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 419 | /// Descriptors are written in the order builder functions are called. Note that some | 417 | /// Descriptors are written in the order builder functions are called. Note that some |
| 420 | /// classes care about the order. | 418 | /// classes care about the order. |
| 421 | pub fn endpoint_bulk_out(&mut self, max_packet_size: u16) -> D::EndpointOut { | 419 | pub fn endpoint_bulk_out(&mut self, max_packet_size: u16) -> D::EndpointOut { |
| 422 | self.endpoint_out(None, EndpointType::Bulk, max_packet_size, 0) | 420 | self.endpoint_out(EndpointType::Bulk, max_packet_size, 0) |
| 423 | } | 421 | } |
| 424 | 422 | ||
| 425 | /// Allocate a INTERRUPT IN endpoint and write its descriptor. | 423 | /// Allocate a INTERRUPT IN endpoint and write its descriptor. |
| @@ -427,11 +425,11 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { | |||
| 427 | /// Descriptors are written in the order builder functions are called. Note that some | 425 | /// Descriptors are written in the order builder functions are called. Note that some |
| 428 | /// classes care about the order. | 426 | /// classes care about the order. |
| 429 | pub fn endpoint_interrupt_in(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointIn { | 427 | pub fn endpoint_interrupt_in(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointIn { |
| 430 | self.endpoint_in(None, EndpointType::Interrupt, max_packet_size, interval) | 428 | self.endpoint_in(EndpointType::Interrupt, max_packet_size, interval) |
| 431 | } | 429 | } |
| 432 | 430 | ||
| 433 | /// Allocate a INTERRUPT OUT endpoint and write its descriptor. | 431 | /// Allocate a INTERRUPT OUT endpoint and write its descriptor. |
| 434 | pub fn endpoint_interrupt_out(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointOut { | 432 | pub fn endpoint_interrupt_out(&mut self, max_packet_size: u16, interval: u8) -> D::EndpointOut { |
| 435 | self.endpoint_out(None, EndpointType::Interrupt, max_packet_size, interval) | 433 | self.endpoint_out(EndpointType::Interrupt, max_packet_size, interval) |
| 436 | } | 434 | } |
| 437 | } | 435 | } |
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index e552dc7b6..a782b377c 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs | |||
| @@ -25,7 +25,6 @@ pub trait Driver<'a> { | |||
| 25 | /// * `interval` - Polling interval parameter for interrupt endpoints. | 25 | /// * `interval` - Polling interval parameter for interrupt endpoints. |
| 26 | fn alloc_endpoint_out( | 26 | fn alloc_endpoint_out( |
| 27 | &mut self, | 27 | &mut self, |
| 28 | ep_addr: Option<EndpointAddress>, | ||
| 29 | ep_type: EndpointType, | 28 | ep_type: EndpointType, |
| 30 | max_packet_size: u16, | 29 | max_packet_size: u16, |
| 31 | interval: u8, | 30 | interval: u8, |
| @@ -33,7 +32,6 @@ pub trait Driver<'a> { | |||
| 33 | 32 | ||
| 34 | fn alloc_endpoint_in( | 33 | fn alloc_endpoint_in( |
| 35 | &mut self, | 34 | &mut self, |
| 36 | ep_addr: Option<EndpointAddress>, | ||
| 37 | ep_type: EndpointType, | 35 | ep_type: EndpointType, |
| 38 | max_packet_size: u16, | 36 | max_packet_size: u16, |
| 39 | interval: u8, | 37 | interval: u8, |
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index 3852dd8da..d855a3a57 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs | |||
| @@ -71,7 +71,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 71 | let mut device_descriptor = [0; 256]; | 71 | let mut device_descriptor = [0; 256]; |
| 72 | let mut config_descriptor = [0; 256]; | 72 | let mut config_descriptor = [0; 256]; |
| 73 | let mut bos_descriptor = [0; 256]; | 73 | let mut bos_descriptor = [0; 256]; |
| 74 | let mut control_buf = [0; 16]; | 74 | let mut control_buf = [0; 64]; |
| 75 | let request_handler = MyRequestHandler {}; | 75 | let request_handler = MyRequestHandler {}; |
| 76 | let device_state_handler = MyDeviceStateHandler::new(); | 76 | let device_state_handler = MyDeviceStateHandler::new(); |
| 77 | 77 | ||
diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs index e70dc51a5..c526c1c6f 100644 --- a/examples/nrf/src/bin/usb_hid_mouse.rs +++ b/examples/nrf/src/bin/usb_hid_mouse.rs | |||
| @@ -50,7 +50,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 50 | let mut device_descriptor = [0; 256]; | 50 | let mut device_descriptor = [0; 256]; |
| 51 | let mut config_descriptor = [0; 256]; | 51 | let mut config_descriptor = [0; 256]; |
| 52 | let mut bos_descriptor = [0; 256]; | 52 | let mut bos_descriptor = [0; 256]; |
| 53 | let mut control_buf = [0; 16]; | 53 | let mut control_buf = [0; 64]; |
| 54 | let request_handler = MyRequestHandler {}; | 54 | let request_handler = MyRequestHandler {}; |
| 55 | 55 | ||
| 56 | let mut state = State::new(); | 56 | let mut state = State::new(); |
diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs index bc41c2acf..11651f82c 100644 --- a/examples/nrf/src/bin/usb_serial.rs +++ b/examples/nrf/src/bin/usb_serial.rs | |||
| @@ -48,7 +48,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 48 | let mut device_descriptor = [0; 256]; | 48 | let mut device_descriptor = [0; 256]; |
| 49 | let mut config_descriptor = [0; 256]; | 49 | let mut config_descriptor = [0; 256]; |
| 50 | let mut bos_descriptor = [0; 256]; | 50 | let mut bos_descriptor = [0; 256]; |
| 51 | let mut control_buf = [0; 7]; | 51 | let mut control_buf = [0; 64]; |
| 52 | 52 | ||
| 53 | let mut state = State::new(); | 53 | let mut state = State::new(); |
| 54 | 54 | ||
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 31e0af483..d8fac7a24 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs | |||
| @@ -64,7 +64,7 @@ async fn main(spawner: Spawner, p: Peripherals) { | |||
| 64 | device_descriptor: [u8; 256], | 64 | device_descriptor: [u8; 256], |
| 65 | config_descriptor: [u8; 256], | 65 | config_descriptor: [u8; 256], |
| 66 | bos_descriptor: [u8; 256], | 66 | bos_descriptor: [u8; 256], |
| 67 | control_buf: [u8; 7], | 67 | control_buf: [u8; 64], |
| 68 | serial_state: State<'static>, | 68 | serial_state: State<'static>, |
| 69 | } | 69 | } |
| 70 | static RESOURCES: Forever<Resources> = Forever::new(); | 70 | static RESOURCES: Forever<Resources> = Forever::new(); |
| @@ -72,7 +72,7 @@ async fn main(spawner: Spawner, p: Peripherals) { | |||
| 72 | device_descriptor: [0; 256], | 72 | device_descriptor: [0; 256], |
| 73 | config_descriptor: [0; 256], | 73 | config_descriptor: [0; 256], |
| 74 | bos_descriptor: [0; 256], | 74 | bos_descriptor: [0; 256], |
| 75 | control_buf: [0; 7], | 75 | control_buf: [0; 64], |
| 76 | serial_state: State::new(), | 76 | serial_state: State::new(), |
| 77 | }); | 77 | }); |
| 78 | 78 | ||
