diff options
| -rw-r--r-- | embassy-nrf/src/usb.rs | 60 | ||||
| -rw-r--r-- | embassy-usb/src/driver.rs | 9 |
2 files changed, 19 insertions, 50 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 8d589aeda..23401c837 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -101,37 +101,6 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | |||
| 105 | fn set_stalled(ep_addr: EndpointAddress, stalled: bool) { | ||
| 106 | let regs = T::regs(); | ||
| 107 | |||
| 108 | unsafe { | ||
| 109 | if ep_addr.index() == 0 { | ||
| 110 | regs.tasks_ep0stall | ||
| 111 | .write(|w| w.tasks_ep0stall().bit(stalled)); | ||
| 112 | } else { | ||
| 113 | regs.epstall.write(|w| { | ||
| 114 | w.ep().bits(ep_addr.index() as u8 & 0b111); | ||
| 115 | w.io().bit(ep_addr.is_in()); | ||
| 116 | w.stall().bit(stalled) | ||
| 117 | }); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | //if stalled { | ||
| 122 | // self.busy_in_endpoints &= !(1 << ep_addr.index()); | ||
| 123 | //} | ||
| 124 | } | ||
| 125 | |||
| 126 | fn is_stalled(ep_addr: EndpointAddress) -> bool { | ||
| 127 | let regs = T::regs(); | ||
| 128 | |||
| 129 | let i = ep_addr.index(); | ||
| 130 | match ep_addr.direction() { | ||
| 131 | UsbDirection::Out => regs.halted.epout[i].read().getstatus().is_halted(), | ||
| 132 | UsbDirection::In => regs.halted.epin[i].read().getstatus().is_halted(), | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | 104 | } |
| 136 | 105 | ||
| 137 | impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { | 106 | impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { |
| @@ -294,11 +263,28 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 294 | } | 263 | } |
| 295 | 264 | ||
| 296 | fn endpoint_set_stalled(&mut self, ep_addr: EndpointAddress, stalled: bool) { | 265 | fn endpoint_set_stalled(&mut self, ep_addr: EndpointAddress, stalled: bool) { |
| 297 | Driver::<T>::set_stalled(ep_addr, stalled) | 266 | let regs = T::regs(); |
| 267 | unsafe { | ||
| 268 | if ep_addr.index() == 0 { | ||
| 269 | regs.tasks_ep0stall | ||
| 270 | .write(|w| w.tasks_ep0stall().bit(stalled)); | ||
| 271 | } else { | ||
| 272 | regs.epstall.write(|w| { | ||
| 273 | w.ep().bits(ep_addr.index() as u8 & 0b111); | ||
| 274 | w.io().bit(ep_addr.is_in()); | ||
| 275 | w.stall().bit(stalled) | ||
| 276 | }); | ||
| 277 | } | ||
| 278 | } | ||
| 298 | } | 279 | } |
| 299 | 280 | ||
| 300 | fn endpoint_is_stalled(&mut self, ep_addr: EndpointAddress) -> bool { | 281 | fn endpoint_is_stalled(&mut self, ep_addr: EndpointAddress) -> bool { |
| 301 | Driver::<T>::is_stalled(ep_addr) | 282 | let regs = T::regs(); |
| 283 | let i = ep_addr.index(); | ||
| 284 | match ep_addr.direction() { | ||
| 285 | UsbDirection::Out => regs.halted.epout[i].read().getstatus().is_halted(), | ||
| 286 | UsbDirection::In => regs.halted.epin[i].read().getstatus().is_halted(), | ||
| 287 | } | ||
| 302 | } | 288 | } |
| 303 | 289 | ||
| 304 | fn endpoint_set_enabled(&mut self, ep_addr: EndpointAddress, enabled: bool) { | 290 | fn endpoint_set_enabled(&mut self, ep_addr: EndpointAddress, enabled: bool) { |
| @@ -464,14 +450,6 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir | |||
| 464 | &self.info | 450 | &self.info |
| 465 | } | 451 | } |
| 466 | 452 | ||
| 467 | fn set_stalled(&self, stalled: bool) { | ||
| 468 | Driver::<T>::set_stalled(self.info.addr, stalled) | ||
| 469 | } | ||
| 470 | |||
| 471 | fn is_stalled(&self) -> bool { | ||
| 472 | Driver::<T>::is_stalled(self.info.addr) | ||
| 473 | } | ||
| 474 | |||
| 475 | type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; | 453 | type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; |
| 476 | 454 | ||
| 477 | fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> { | 455 | fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> { |
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 8454b041f..acd2e298d 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs | |||
| @@ -118,17 +118,8 @@ pub trait Endpoint { | |||
| 118 | /// Get the endpoint address | 118 | /// Get the endpoint address |
| 119 | fn info(&self) -> &EndpointInfo; | 119 | fn info(&self) -> &EndpointInfo; |
| 120 | 120 | ||
| 121 | /// Sets or clears the STALL condition for an endpoint. If the endpoint is an OUT endpoint, it | ||
| 122 | /// should be prepared to receive data again. | ||
| 123 | fn set_stalled(&self, stalled: bool); | ||
| 124 | |||
| 125 | /// Gets whether the STALL condition is set for an endpoint. | ||
| 126 | fn is_stalled(&self) -> bool; | ||
| 127 | |||
| 128 | /// Waits for the endpoint to be enabled. | 121 | /// Waits for the endpoint to be enabled. |
| 129 | fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_>; | 122 | fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_>; |
| 130 | |||
| 131 | // TODO enable/disable? | ||
| 132 | } | 123 | } |
| 133 | 124 | ||
| 134 | pub trait EndpointOut: Endpoint { | 125 | pub trait EndpointOut: Endpoint { |
