Skip to content

Commit

Permalink
Impliment Wait from embedded-hal-async
Browse files Browse the repository at this point in the history
  • Loading branch information
leighleighleigh committed Jan 28, 2025
1 parent 89aba1c commit 653e88f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ features = [ "unproven" ]
package = "embedded-hal"
version = "1.0.0"

[dependencies.eh1_0_async]
package = "embedded-hal-async"
version = "1.0.0"

[package.metadata.docs.rs]
# To build locally:
Expand Down
98 changes: 98 additions & 0 deletions src/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@ mod digital {
}
}

impl<T, E> eh1_0_async::digital::Wait for Forward<T, ForwardInputPin>
where
T: eh0_2::digital::v2::InputPin<Error = E> + eh1_0_async::digital::Wait<Error = E>,
E: core::fmt::Debug,
{
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_high().await.map_err(ForwardError)
}

async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_low().await.map_err(ForwardError)
}

async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
self.inner
.wait_for_rising_edge()
.await
.map_err(ForwardError)
}

async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
self.inner
.wait_for_falling_edge()
.await
.map_err(ForwardError)
}

async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_any_edge().await.map_err(ForwardError)
}
}

impl<T, E> eh1_0::digital::ErrorType for Forward<T, ForwardOutputPin>
where
T: eh0_2::digital::v2::OutputPin<Error = E>,
Expand All @@ -122,6 +154,38 @@ mod digital {
}
}

impl<T, E> eh1_0_async::digital::Wait for Forward<T, ForwardOutputPin>
where
T: eh0_2::digital::v2::OutputPin<Error = E> + eh1_0_async::digital::Wait<Error = E>,
E: core::fmt::Debug,
{
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_high().await.map_err(ForwardError)
}

async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_low().await.map_err(ForwardError)
}

async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
self.inner
.wait_for_rising_edge()
.await
.map_err(ForwardError)
}

async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
self.inner
.wait_for_falling_edge()
.await
.map_err(ForwardError)
}

async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_any_edge().await.map_err(ForwardError)
}
}

impl<T, E> eh1_0::digital::ErrorType for Forward<T, ForwardIoPin>
where
T: eh0_2::digital::v2::OutputPin<Error = E> + eh0_2::digital::v2::InputPin<Error = E>,
Expand Down Expand Up @@ -161,6 +225,40 @@ mod digital {
self.inner.set_low().map_err(ForwardError)
}
}

impl<T, E> eh1_0_async::digital::Wait for Forward<T, ForwardIoPin>
where
T: eh0_2::digital::v2::InputPin<Error = E>
+ eh0_2::digital::v2::OutputPin<Error = E>
+ eh1_0_async::digital::Wait<Error = E>,
E: core::fmt::Debug,
{
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_high().await.map_err(ForwardError)
}

async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_low().await.map_err(ForwardError)
}

async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
self.inner
.wait_for_rising_edge()
.await
.map_err(ForwardError)
}

async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
self.inner
.wait_for_falling_edge()
.await
.map_err(ForwardError)
}

async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
self.inner.wait_for_any_edge().await.map_err(ForwardError)
}
}
}

/// Delays (blocking)
Expand Down

0 comments on commit 653e88f

Please sign in to comment.