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 async API for CAN #585

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion embedded-can/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

...
- Add async API.

## [v0.4.1] - 2022-09-28

Expand Down
17 changes: 17 additions & 0 deletions embedded-can/src/asynch.rs
Original file line number Diff line number Diff line change
@@ -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<Self::Frame, Self::Error>;
}
10 changes: 9 additions & 1 deletion embedded-can/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

#![warn(missing_docs)]
#![no_std]

// disable warning for already-stabilized features.
// Needed to pass CI, because we deny warnings.
// We don't immediately remove them to not immediately break older nightlies.
// When all features are stable, we'll remove them.
#![cfg_attr(nightly, allow(stable_features, unknown_lints))]
#![cfg_attr(nightly, feature(async_fn_in_trait, impl_trait_projections))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these cfg_attrs do nothing without this in build.rs.

These were for compat with older nightlies before AFIT was stable. Now that AFIT has been stable for a few rust versions since 1.75, i'd just not put them, and support stable 1.75+ only.

#![allow(async_fn_in_trait)]

pub mod asynch;
pub mod blocking;
pub mod nb;

Expand Down
Loading