aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexmoon <[email protected]>2022-04-12 17:51:50 -0400
committeralexmoon <[email protected]>2022-04-13 14:55:02 -0400
commit2915e858baac442e71bac4b565746401deed22bd (patch)
treec4e91cc7de6be24000b9bb39096571d5f26f39df
parent7fde3abd5d7e04f6d79d325d4454d6eafabebc1f (diff)
Make Driver::disable async and fix comment
-rw-r--r--embassy-nrf/src/usb.rs9
-rw-r--r--embassy-usb/src/driver.rs7
-rw-r--r--embassy-usb/src/lib.rs2
3 files changed, 11 insertions, 7 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs
index 7f99b9a1c..b67201e67 100644
--- a/embassy-nrf/src/usb.rs
+++ b/embassy-nrf/src/usb.rs
@@ -208,6 +208,7 @@ pub struct Bus<'d, T: Instance> {
208 208
209impl<'d, T: Instance> driver::Bus for Bus<'d, T> { 209impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
210 type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; 210 type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
211 type DisableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
211 type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a; 212 type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a;
212 type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a; 213 type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a;
213 214
@@ -248,9 +249,11 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
248 } 249 }
249 } 250 }
250 251
251 fn disable(&mut self) { 252 fn disable(&mut self) -> Self::DisableFuture<'_> {
252 let regs = T::regs(); 253 async move {
253 regs.enable.write(|x| x.enable().disabled()); 254 let regs = T::regs();
255 regs.enable.write(|x| x.enable().disabled());
256 }
254 } 257 }
255 258
256 fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> { 259 fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> {
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs
index 99610deef..cedd349fb 100644
--- a/embassy-usb/src/driver.rs
+++ b/embassy-usb/src/driver.rs
@@ -59,6 +59,9 @@ pub trait Bus {
59 type EnableFuture<'a>: Future<Output = ()> + 'a 59 type EnableFuture<'a>: Future<Output = ()> + 'a
60 where 60 where
61 Self: 'a; 61 Self: 'a;
62 type DisableFuture<'a>: Future<Output = ()> + 'a
63 where
64 Self: 'a;
62 type PollFuture<'a>: Future<Output = Event> + 'a 65 type PollFuture<'a>: Future<Output = Event> + 'a
63 where 66 where
64 Self: 'a; 67 Self: 'a;
@@ -71,7 +74,7 @@ pub trait Bus {
71 fn enable(&mut self) -> Self::EnableFuture<'_>; 74 fn enable(&mut self) -> Self::EnableFuture<'_>;
72 75
73 /// Disables and powers down the USB peripheral. 76 /// Disables and powers down the USB peripheral.
74 fn disable(&mut self); 77 fn disable(&mut self) -> Self::DisableFuture<'_>;
75 78
76 fn poll<'a>(&'a mut self) -> Self::PollFuture<'a>; 79 fn poll<'a>(&'a mut self) -> Self::PollFuture<'a>;
77 80
@@ -103,8 +106,6 @@ pub trait Bus {
103 106
104 /// Initiates a remote wakeup of the host by the device. 107 /// Initiates a remote wakeup of the host by the device.
105 /// 108 ///
106 /// The default implementation just returns `Unsupported`.
107 ///
108 /// # Errors 109 /// # Errors
109 /// 110 ///
110 /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support 111 /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs
index 210908c2c..11561430b 100644
--- a/embassy-usb/src/lib.rs
+++ b/embassy-usb/src/lib.rs
@@ -198,7 +198,7 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
198 DeviceCommand::Enable => warn!("usb: Enable command received while enabled."), 198 DeviceCommand::Enable => warn!("usb: Enable command received while enabled."),
199 DeviceCommand::Disable => { 199 DeviceCommand::Disable => {
200 trace!("usb: disable"); 200 trace!("usb: disable");
201 self.bus.disable(); 201 self.bus.disable().await;
202 self.device_state = UsbDeviceState::Disabled; 202 self.device_state = UsbDeviceState::Disabled;
203 if let Some(h) = &self.handler { 203 if let Some(h) = &self.handler {
204 h.disabled(); 204 h.disabled();