usb: add the Endpoint::is_enabled function

This commit is contained in:
Matt Ickstadt 2024-05-28 11:15:09 -05:00
parent 000b022ae2
commit beab53b4ea
5 changed files with 38 additions and 0 deletions

View File

@ -473,6 +473,11 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
async fn wait_enabled(&mut self) { async fn wait_enabled(&mut self) {
self.wait_enabled_state(true).await 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)] #[allow(private_bounds)]

View File

@ -538,6 +538,11 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> {
.await; .await;
trace!("wait_enabled IN OK"); 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> { 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; .await;
trace!("wait_enabled OUT OK"); 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> { impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {

View File

@ -701,6 +701,11 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> {
.await; .await;
trace!("wait_enabled IN OK"); 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> { 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; .await;
trace!("wait_enabled OUT OK"); 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> { impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {

View File

@ -225,6 +225,9 @@ pub trait Endpoint {
/// Wait for the endpoint to be enabled. /// Wait for the endpoint to be enabled.
async fn wait_enabled(&mut self); async fn wait_enabled(&mut self);
/// Check if the endpoint is enabled.
fn is_enabled(&self) -> bool;
} }
/// OUT Endpoint trait. /// OUT Endpoint trait.

View File

@ -1008,6 +1008,11 @@ impl<'d> embassy_usb_driver::Endpoint for Endpoint<'d, In> {
}) })
.await .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> { 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 .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> { impl<'d> embassy_usb_driver::EndpointOut for Endpoint<'d, Out> {