Make Driver::disable async and fix comment

This commit is contained in:
alexmoon 2022-04-12 17:51:50 -04:00
parent 7fde3abd5d
commit 2915e858ba
3 changed files with 11 additions and 7 deletions

View file

@ -208,6 +208,7 @@ pub struct Bus<'d, T: Instance> {
impl<'d, T: Instance> driver::Bus for Bus<'d, T> { impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
type DisableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a; type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a;
type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a; type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a;
@ -248,9 +249,11 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
} }
} }
fn disable(&mut self) { fn disable(&mut self) -> Self::DisableFuture<'_> {
let regs = T::regs(); async move {
regs.enable.write(|x| x.enable().disabled()); let regs = T::regs();
regs.enable.write(|x| x.enable().disabled());
}
} }
fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> { fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> {

View file

@ -57,6 +57,9 @@ pub trait Driver<'a> {
pub trait Bus { pub trait Bus {
type EnableFuture<'a>: Future<Output = ()> + 'a type EnableFuture<'a>: Future<Output = ()> + 'a
where
Self: 'a;
type DisableFuture<'a>: Future<Output = ()> + 'a
where where
Self: 'a; Self: 'a;
type PollFuture<'a>: Future<Output = Event> + 'a type PollFuture<'a>: Future<Output = Event> + 'a
@ -71,7 +74,7 @@ pub trait Bus {
fn enable(&mut self) -> Self::EnableFuture<'_>; fn enable(&mut self) -> Self::EnableFuture<'_>;
/// Disables and powers down the USB peripheral. /// Disables and powers down the USB peripheral.
fn disable(&mut self); fn disable(&mut self) -> Self::DisableFuture<'_>;
fn poll<'a>(&'a mut self) -> Self::PollFuture<'a>; fn poll<'a>(&'a mut self) -> Self::PollFuture<'a>;
@ -103,8 +106,6 @@ pub trait Bus {
/// Initiates a remote wakeup of the host by the device. /// Initiates a remote wakeup of the host by the device.
/// ///
/// The default implementation just returns `Unsupported`.
///
/// # Errors /// # Errors
/// ///
/// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support

View file

@ -198,7 +198,7 @@ impl<'d, D: Driver<'d>, M: RawMutex> UsbDevice<'d, D, M> {
DeviceCommand::Enable => warn!("usb: Enable command received while enabled."), DeviceCommand::Enable => warn!("usb: Enable command received while enabled."),
DeviceCommand::Disable => { DeviceCommand::Disable => {
trace!("usb: disable"); trace!("usb: disable");
self.bus.disable(); self.bus.disable().await;
self.device_state = UsbDeviceState::Disabled; self.device_state = UsbDeviceState::Disabled;
if let Some(h) = &self.handler { if let Some(h) = &self.handler {
h.disabled(); h.disabled();