diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 8d589aed..23401c83 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs @@ -101,37 +101,6 @@ impl<'d, T: Instance> Driver<'d, T> { } } } - - fn set_stalled(ep_addr: EndpointAddress, stalled: bool) { - let regs = T::regs(); - - unsafe { - if ep_addr.index() == 0 { - regs.tasks_ep0stall - .write(|w| w.tasks_ep0stall().bit(stalled)); - } else { - regs.epstall.write(|w| { - w.ep().bits(ep_addr.index() as u8 & 0b111); - w.io().bit(ep_addr.is_in()); - w.stall().bit(stalled) - }); - } - } - - //if stalled { - // self.busy_in_endpoints &= !(1 << ep_addr.index()); - //} - } - - fn is_stalled(ep_addr: EndpointAddress) -> bool { - let regs = T::regs(); - - let i = ep_addr.index(); - match ep_addr.direction() { - UsbDirection::Out => regs.halted.epout[i].read().getstatus().is_halted(), - UsbDirection::In => regs.halted.epin[i].read().getstatus().is_halted(), - } - } } 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> { } fn endpoint_set_stalled(&mut self, ep_addr: EndpointAddress, stalled: bool) { - Driver::::set_stalled(ep_addr, stalled) + let regs = T::regs(); + unsafe { + if ep_addr.index() == 0 { + regs.tasks_ep0stall + .write(|w| w.tasks_ep0stall().bit(stalled)); + } else { + regs.epstall.write(|w| { + w.ep().bits(ep_addr.index() as u8 & 0b111); + w.io().bit(ep_addr.is_in()); + w.stall().bit(stalled) + }); + } + } } fn endpoint_is_stalled(&mut self, ep_addr: EndpointAddress) -> bool { - Driver::::is_stalled(ep_addr) + let regs = T::regs(); + let i = ep_addr.index(); + match ep_addr.direction() { + UsbDirection::Out => regs.halted.epout[i].read().getstatus().is_halted(), + UsbDirection::In => regs.halted.epin[i].read().getstatus().is_halted(), + } } 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 &self.info } - fn set_stalled(&self, stalled: bool) { - Driver::::set_stalled(self.info.addr, stalled) - } - - fn is_stalled(&self) -> bool { - Driver::::is_stalled(self.info.addr) - } - type WaitEnabledFuture<'a> = impl Future + 'a where Self: 'a; fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> { diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 8454b041..acd2e298 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs @@ -118,17 +118,8 @@ pub trait Endpoint { /// Get the endpoint address fn info(&self) -> &EndpointInfo; - /// Sets or clears the STALL condition for an endpoint. If the endpoint is an OUT endpoint, it - /// should be prepared to receive data again. - fn set_stalled(&self, stalled: bool); - - /// Gets whether the STALL condition is set for an endpoint. - fn is_stalled(&self) -> bool; - /// Waits for the endpoint to be enabled. fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_>; - - // TODO enable/disable? } pub trait EndpointOut: Endpoint {