From 987ceb19254f69f8f12ae6e2d6522b3e6372bd5a Mon Sep 17 00:00:00 2001 From: Liam Kinne Date: Tue, 2 Apr 2024 23:40:06 +1000 Subject: [PATCH 1/5] add async API --- embedded-can/src/asynch.rs | 25 +++++++++++++++++++++++++ embedded-can/src/lib.rs | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 embedded-can/src/asynch.rs diff --git a/embedded-can/src/asynch.rs b/embedded-can/src/asynch.rs new file mode 100644 index 000000000..2285bed63 --- /dev/null +++ b/embedded-can/src/asynch.rs @@ -0,0 +1,25 @@ +//! 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>; + + /// Tries to put a frame in the transmit buffer. + /// If no space is available in the transmit buffer `None` is returned. + fn try_transmit(&mut self, frame: &Self::Frame) -> Option>; + + /// Awaits until a frame was received or an error occurred. + async fn receive(&mut self) -> Result; + + /// Tries to receive a frame from the receive buffer. + /// If no frame is available `None` is returned. + fn try_receive(&mut self) -> Option>; +} diff --git a/embedded-can/src/lib.rs b/embedded-can/src/lib.rs index 2de2b6ebc..1cfb59548 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; From 75580aaf0807057b9ea5d8ee0bb5c45ee541ec14 Mon Sep 17 00:00:00 2001 From: Liam Kinne Date: Tue, 2 Apr 2024 23:42:04 +1000 Subject: [PATCH 2/5] add changelog entry --- embedded-can/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded-can/CHANGELOG.md b/embedded-can/CHANGELOG.md index 302c85a09..40417d228 100644 --- a/embedded-can/CHANGELOG.md +++ b/embedded-can/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -... +- Add async API. ## [v0.4.1] - 2022-09-28 From 81bc3673ab828d580569f0c7fc2dae39e1182ae0 Mon Sep 17 00:00:00 2001 From: Liam Kinne Date: Wed, 3 Apr 2024 00:20:02 +1000 Subject: [PATCH 3/5] fix ci warning --- embedded-can/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/embedded-can/src/lib.rs b/embedded-can/src/lib.rs index 1cfb59548..929634148 100644 --- a/embedded-can/src/lib.rs +++ b/embedded-can/src/lib.rs @@ -2,6 +2,12 @@ #![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))] #![allow(async_fn_in_trait)] pub mod asynch; From a6c77cca0c833b66591e7200f1a7e9f4f5d53b3c Mon Sep 17 00:00:00 2001 From: Liam Kinne Date: Fri, 28 Jun 2024 08:30:29 +1000 Subject: [PATCH 4/5] remove try_ methods --- embedded-can/src/asynch.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/embedded-can/src/asynch.rs b/embedded-can/src/asynch.rs index 2285bed63..cec274796 100644 --- a/embedded-can/src/asynch.rs +++ b/embedded-can/src/asynch.rs @@ -12,14 +12,6 @@ pub trait Can { /// Awaits until space is available in the transmit buffer. async fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>; - /// Tries to put a frame in the transmit buffer. - /// If no space is available in the transmit buffer `None` is returned. - fn try_transmit(&mut self, frame: &Self::Frame) -> Option>; - /// Awaits until a frame was received or an error occurred. async fn receive(&mut self) -> Result; - - /// Tries to receive a frame from the receive buffer. - /// If no frame is available `None` is returned. - fn try_receive(&mut self) -> Option>; } From 37f4be69871a5cbf28607ea89968de3fb243fd4b Mon Sep 17 00:00:00 2001 From: Liam Kinne Date: Thu, 4 Jul 2024 20:15:50 +1000 Subject: [PATCH 5/5] Revert "fix ci warning" This reverts commit 81bc3673ab828d580569f0c7fc2dae39e1182ae0. --- embedded-can/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/embedded-can/src/lib.rs b/embedded-can/src/lib.rs index 929634148..1cfb59548 100644 --- a/embedded-can/src/lib.rs +++ b/embedded-can/src/lib.rs @@ -2,12 +2,6 @@ #![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))] #![allow(async_fn_in_trait)] pub mod asynch;