diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-05-09 02:07:48 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-05-09 02:07:48 +0200 |
| commit | 2e104170de36295243608fbbebebdc6f52e8f8d0 (patch) | |
| tree | dd9c72b14006ee682eef35000f6f1744d8b897dc /embassy-nrf | |
| parent | e9ab960ebf1ab5da2e062663079b77aebf51c40f (diff) | |
usb: remove address arg from endpoint allocation.
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/usb.rs | 59 |
1 files changed, 21 insertions, 38 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 | ||
