diff --git a/embedded-can/CHANGELOG.md b/embedded-can/CHANGELOG.md index 302c85a09..40417d228 100644 --- a/embedded-can/CHANGELOG.md +++ b/embedded-can/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -... +- Add async API. ## [v0.4.1] - 2022-09-28 diff --git a/embedded-can/src/asynch.rs b/embedded-can/src/asynch.rs new file mode 100644 index 000000000..cec274796 --- /dev/null +++ b/embedded-can/src/asynch.rs @@ -0,0 +1,17 @@ +//! Async CAN API + +/// An async CAN interface that is able to transmit and receive frames. +pub trait Can { + /// Associated frame type. + type Frame: crate::Frame; + + /// Associated error type. + type Error: crate::Error; + + /// Puts a frame in the transmit buffer. + /// Awaits until space is available in the transmit buffer. + async fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>; + + /// Awaits until a frame was received or an error occurred. + async fn receive(&mut self) -> Result; +} diff --git a/embedded-can/src/lib.rs b/embedded-can/src/lib.rs index 2de2b6ebc..1cfb59548 100644 --- a/embedded-can/src/lib.rs +++ b/embedded-can/src/lib.rs @@ -2,7 +2,9 @@ #![warn(missing_docs)] #![no_std] +#![allow(async_fn_in_trait)] +pub mod asynch; pub mod blocking; pub mod nb;