diff --git a/embedded-can/CHANGELOG.md b/embedded-can/CHANGELOG.md index f8719d63..3699d355 100644 --- a/embedded-can/CHANGELOG.md +++ b/embedded-can/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `core::error::Error` implementations for every custom `impl Error` - Increased MSRV to 1.81 due to `core::error::Error` +- 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 00000000..3a1939c7 --- /dev/null +++ b/embedded-can/src/asynch.rs @@ -0,0 +1,26 @@ +//! Async CAN API + +/// An async CAN interface that is able to transmit frames. +pub trait CanTx { + /// Associated frame type. + type Frame: crate::Frame; + + /// Associated error type. + type Error: crate::Error; + + /// Puts a frame in the transmit buffer or awaits until space is available + /// in the transmit buffer. + async fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>; +} + +/// An async CAN interface that is able to receive frames. +pub trait CanRx { + /// Associated frame type. + type Frame: crate::Frame; + + /// Associated error type. + type Error: crate::Error; + + /// Awaits until a frame was received or an error occurs. + async fn receive(&mut self) -> Result; +} diff --git a/embedded-can/src/lib.rs b/embedded-can/src/lib.rs index bb010b96..9f349000 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;