diff options
| -rw-r--r-- | embassy-nrf/src/usb.rs | 20 | ||||
| -rw-r--r-- | embassy-usb/src/driver.rs | 10 | ||||
| -rw-r--r-- | embassy-usb/src/lib.rs | 6 |
3 files changed, 24 insertions, 12 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 9155eb37a..842abf162 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -616,6 +616,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 616 | type SetupFuture<'a> = impl Future<Output = [u8;8]> + 'a where Self: 'a; | 616 | type SetupFuture<'a> = impl Future<Output = [u8;8]> + 'a where Self: 'a; |
| 617 | type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; | 617 | type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; |
| 618 | type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; | 618 | type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; |
| 619 | type AcceptFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; | ||
| 620 | type RejectFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; | ||
| 619 | 621 | ||
| 620 | fn max_packet_size(&self) -> usize { | 622 | fn max_packet_size(&self) -> usize { |
| 621 | usize::from(self.max_packet_size) | 623 | usize::from(self.max_packet_size) |
| @@ -740,15 +742,19 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 740 | } | 742 | } |
| 741 | } | 743 | } |
| 742 | 744 | ||
| 743 | fn accept(&mut self) { | 745 | fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { |
| 744 | let regs = T::regs(); | 746 | async move { |
| 745 | regs.tasks_ep0status | 747 | let regs = T::regs(); |
| 746 | .write(|w| w.tasks_ep0status().bit(true)); | 748 | regs.tasks_ep0status |
| 749 | .write(|w| w.tasks_ep0status().bit(true)); | ||
| 750 | } | ||
| 747 | } | 751 | } |
| 748 | 752 | ||
| 749 | fn reject(&mut self) { | 753 | fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a> { |
| 750 | let regs = T::regs(); | 754 | async move { |
| 751 | regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(true)); | 755 | let regs = T::regs(); |
| 756 | regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(true)); | ||
| 757 | } | ||
| 752 | } | 758 | } |
| 753 | } | 759 | } |
| 754 | 760 | ||
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 9cd4afdab..0680df7a5 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs | |||
| @@ -144,6 +144,12 @@ pub trait ControlPipe { | |||
| 144 | type DataInFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a | 144 | type DataInFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a |
| 145 | where | 145 | where |
| 146 | Self: 'a; | 146 | Self: 'a; |
| 147 | type AcceptFuture<'a>: Future<Output = ()> + 'a | ||
| 148 | where | ||
| 149 | Self: 'a; | ||
| 150 | type RejectFuture<'a>: Future<Output = ()> + 'a | ||
| 151 | where | ||
| 152 | Self: 'a; | ||
| 147 | 153 | ||
| 148 | /// Maximum packet size for the control pipe | 154 | /// Maximum packet size for the control pipe |
| 149 | fn max_packet_size(&self) -> usize; | 155 | fn max_packet_size(&self) -> usize; |
| @@ -171,12 +177,12 @@ pub trait ControlPipe { | |||
| 171 | /// Accepts a control request. | 177 | /// Accepts a control request. |
| 172 | /// | 178 | /// |
| 173 | /// Causes the STATUS packet for the current request to be ACKed. | 179 | /// Causes the STATUS packet for the current request to be ACKed. |
| 174 | fn accept(&mut self); | 180 | fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a>; |
| 175 | 181 | ||
| 176 | /// Rejects a control request. | 182 | /// Rejects a control request. |
| 177 | /// | 183 | /// |
| 178 | /// Sets a STALL condition on the pipe to indicate an error. | 184 | /// Sets a STALL condition on the pipe to indicate an error. |
| 179 | fn reject(&mut self); | 185 | fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a>; |
| 180 | } | 186 | } |
| 181 | 187 | ||
| 182 | pub trait EndpointIn: Endpoint { | 188 | pub trait EndpointIn: Endpoint { |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 9101d81bd..b691bf11e 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -306,7 +306,7 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 306 | } | 306 | } |
| 307 | } | 307 | } |
| 308 | } | 308 | } |
| 309 | InResponse::Rejected => self.control.reject(), | 309 | InResponse::Rejected => self.control.reject().await, |
| 310 | } | 310 | } |
| 311 | } | 311 | } |
| 312 | 312 | ||
| @@ -337,8 +337,8 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 337 | trace!(" control out data: {:02x?}", data); | 337 | trace!(" control out data: {:02x?}", data); |
| 338 | 338 | ||
| 339 | match self.inner.handle_control_out(req, data) { | 339 | match self.inner.handle_control_out(req, data) { |
| 340 | OutResponse::Accepted => self.control.accept(), | 340 | OutResponse::Accepted => self.control.accept().await, |
| 341 | OutResponse::Rejected => self.control.reject(), | 341 | OutResponse::Rejected => self.control.reject().await, |
| 342 | } | 342 | } |
| 343 | } | 343 | } |
| 344 | } | 344 | } |
