diff --git a/embedded-can/CHANGELOG.md b/embedded-can/CHANGELOG.md index 6ef70c03..96ecbcdb 100644 --- a/embedded-can/CHANGELOG.md +++ b/embedded-can/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - `as_raw_unchecked` getter function for `Id` +- 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..2f3b5a0b --- /dev/null +++ b/embedded-can/src/asynch.rs @@ -0,0 +1,36 @@ +//! Async CAN API + +use core::future::Future; + +/// 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. + /// + /// If the transmit buffer is full, this function will try to replace a + /// pending lower priority frame and return the frame that was replaced. If + /// no lower-priority frames can be replaced, this call should wait for a + /// frame to be transmitted and then try again. + fn transmit( + &mut self, + frame: &Self::Frame, + ) -> impl Future, 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. + fn receive(&mut self) -> impl Future>; +} diff --git a/embedded-can/src/lib.rs b/embedded-can/src/lib.rs index 86248f3c..d515202c 100644 --- a/embedded-can/src/lib.rs +++ b/embedded-can/src/lib.rs @@ -3,6 +3,7 @@ #![warn(missing_docs)] #![no_std] +pub mod asynch; pub mod blocking; pub mod nb;