Skip to content

Commit 987ceb1

Browse files
committed
add async API
1 parent 5e21d56 commit 987ceb1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

embedded-can/src/asynch.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! Async CAN API
2+
3+
/// An async CAN interface that is able to transmit and receive frames.
4+
pub trait Can {
5+
/// Associated frame type.
6+
type Frame: crate::Frame;
7+
8+
/// Associated error type.
9+
type Error: crate::Error;
10+
11+
/// Puts a frame in the transmit buffer.
12+
/// Awaits until space is available in the transmit buffer.
13+
async fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>;
14+
15+
/// Tries to put a frame in the transmit buffer.
16+
/// If no space is available in the transmit buffer `None` is returned.
17+
fn try_transmit(&mut self, frame: &Self::Frame) -> Option<Result<(), Self::Error>>;
18+
19+
/// Awaits until a frame was received or an error occurred.
20+
async fn receive(&mut self) -> Result<Self::Frame, Self::Error>;
21+
22+
/// Tries to receive a frame from the receive buffer.
23+
/// If no frame is available `None` is returned.
24+
fn try_receive(&mut self) -> Option<Result<Self::Frame, Self::Error>>;
25+
}

embedded-can/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
#![warn(missing_docs)]
44
#![no_std]
5+
#![allow(async_fn_in_trait)]
56

7+
pub mod asynch;
68
pub mod blocking;
79
pub mod nb;
810

0 commit comments

Comments
 (0)