diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs index 8cbb1a350..0c07bce64 100644 --- a/embassy-nrf/src/usb/mod.rs +++ b/embassy-nrf/src/usb/mod.rs @@ -473,6 +473,11 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir async fn wait_enabled(&mut self) { self.wait_enabled_state(true).await } + + fn is_enabled(&self) -> bool { + let ep_addr = self.info.addr.index(); + Dir::is_enabled(T::regs(), ep_addr) + } } #[allow(private_bounds)] diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 512271ae4..337d16671 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -538,6 +538,11 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> { .await; trace!("wait_enabled IN OK"); } + + fn is_enabled(&self) -> bool { + let index = self.info.addr.index(); + T::dpram().ep_in_control(index - 1).read().enable() + } } impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> { @@ -560,6 +565,11 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> { .await; trace!("wait_enabled OUT OK"); } + + fn is_enabled(&self) -> bool { + let index = self.info.addr.index(); + T::dpram().ep_in_control(index - 1).read().enable() + } } impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 81a2d2623..bfcfdf793 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -701,6 +701,11 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> { .await; trace!("wait_enabled IN OK"); } + + fn is_enabled(&self) -> bool { + let index = self.info.addr.index(); + T::regs().epr(index).read().stat_tx() != Stat::DISABLED + } } impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> { @@ -723,6 +728,11 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> { .await; trace!("wait_enabled OUT OK"); } + + fn is_enabled(&self) -> bool { + let index = self.info.addr.index(); + T::regs().epr(index).read().stat_rx() != Stat::DISABLED + } } impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { diff --git a/embassy-usb-driver/src/lib.rs b/embassy-usb-driver/src/lib.rs index 3b705c8c4..b0436f2e2 100644 --- a/embassy-usb-driver/src/lib.rs +++ b/embassy-usb-driver/src/lib.rs @@ -225,6 +225,9 @@ pub trait Endpoint { /// Wait for the endpoint to be enabled. async fn wait_enabled(&mut self); + + /// Check if the endpoint is enabled. + fn is_enabled(&self) -> bool; } /// OUT Endpoint trait. diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs index b90e059f6..9bf6a20c1 100644 --- a/embassy-usb-synopsys-otg/src/lib.rs +++ b/embassy-usb-synopsys-otg/src/lib.rs @@ -1008,6 +1008,11 @@ impl<'d> embassy_usb_driver::Endpoint for Endpoint<'d, In> { }) .await } + + fn is_enabled(&self) -> bool { + let ep_index = self.info.addr.index(); + self.regs.diepctl(ep_index).read().usbaep() + } } impl<'d> embassy_usb_driver::Endpoint for Endpoint<'d, Out> { @@ -1029,6 +1034,11 @@ impl<'d> embassy_usb_driver::Endpoint for Endpoint<'d, Out> { }) .await } + + fn is_enabled(&self) -> bool { + let ep_index = self.info.addr.index(); + self.regs.diepctl(ep_index).read().usbaep() + } } impl<'d> embassy_usb_driver::EndpointOut for Endpoint<'d, Out> {