Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add asynchronous trait for CAN #520

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions embedded-can/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ repository = "https://github.com/rust-embedded/embedded-hal"

[dependencies]
nb = "1"

[features]
async = []
19 changes: 19 additions & 0 deletions embedded-can/src/asynchronous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Async CAN API

#![allow(async_fn_in_trait)]

/// 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. Waits until space is available in
/// the transmit buffer.
async fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>;

/// Waits until a frame was received or an error occurred.
async fn receive(&mut self) -> Result<Self::Frame, Self::Error>;
}
2 changes: 2 additions & 0 deletions embedded-can/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![warn(missing_docs)]
#![no_std]

#[cfg(feature = "async")]
pub mod asynchronous;
pub mod blocking;
pub mod nb;

Expand Down