From 44f01ea73fceb1a0e1aaa717b5216762b6f3d1f8 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 21 Nov 2022 21:13:51 +0100 Subject: [PATCH 1/3] async: switch to async-fn-in-traits --- .github/workflows/clippy.yml | 2 +- embedded-hal-async/src/delay.rs | 28 +---- embedded-hal-async/src/digital.rs | 67 +++-------- embedded-hal-async/src/i2c.rs | 62 +++------- embedded-hal-async/src/lib.rs | 3 +- embedded-hal-async/src/spi.rs | 180 ++++++++---------------------- 6 files changed, 86 insertions(+), 256 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index facdb772c..19c7acbac 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -14,7 +14,7 @@ jobs: profile: minimal # embedded-hal-async needs nightly. # Use a pinned version to avoid spontaneous breakages (new clippy lints are added often) - toolchain: nightly-2022-09-25 + toolchain: nightly-2022-11-22 override: true components: clippy - run: cargo clippy -- --deny=warnings \ No newline at end of file diff --git a/embedded-hal-async/src/delay.rs b/embedded-hal-async/src/delay.rs index 5fd247c9a..9106dc4d7 100644 --- a/embedded-hal-async/src/delay.rs +++ b/embedded-hal-async/src/delay.rs @@ -1,29 +1,17 @@ //! Delays -use core::future::Future; - /// Microsecond delay pub trait DelayUs { /// Enumeration of errors type Error: core::fmt::Debug; - /// The future returned by the `delay_us` function. - type DelayUsFuture<'a>: Future> - where - Self: 'a; - /// Pauses execution for at minimum `us` microseconds. Pause can be longer /// if the implementation requires it due to precision/timing issues. - fn delay_us(&mut self, us: u32) -> Self::DelayUsFuture<'_>; - - /// The future returned by the `delay_ms` function. - type DelayMsFuture<'a>: Future> - where - Self: 'a; + async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error>; /// Pauses execution for at minimum `ms` milliseconds. Pause can be longer /// if the implementation requires it due to precision/timing issues. - fn delay_ms(&mut self, ms: u32) -> Self::DelayMsFuture<'_>; + async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error>; } impl DelayUs for &mut T @@ -32,15 +20,11 @@ where { type Error = T::Error; - type DelayUsFuture<'a> = T::DelayUsFuture<'a> where Self: 'a; - - fn delay_us(&mut self, us: u32) -> Self::DelayUsFuture<'_> { - T::delay_us(self, us) + async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { + T::delay_us(self, us).await } - type DelayMsFuture<'a> = T::DelayMsFuture<'a> where Self: 'a; - - fn delay_ms(&mut self, ms: u32) -> Self::DelayMsFuture<'_> { - T::delay_ms(self, ms) + async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { + T::delay_ms(self, ms).await } } diff --git a/embedded-hal-async/src/digital.rs b/embedded-hal-async/src/digital.rs index 46912e611..600876975 100644 --- a/embedded-hal-async/src/digital.rs +++ b/embedded-hal-async/src/digital.rs @@ -16,93 +16,56 @@ //! } //! ``` -use core::future::Future; - /// Asynchronously wait for GPIO pin state. pub trait Wait: embedded_hal::digital::ErrorType { - /// The future returned by the `wait_for_high` function. - type WaitForHighFuture<'a>: Future> - where - Self: 'a; - /// Wait until the pin is high. If it is already high, return immediately. /// /// # Note for implementers /// The pin may have switched back to low before the task was run after /// being woken. The future should still resolve in that case. - fn wait_for_high(&mut self) -> Self::WaitForHighFuture<'_>; - - /// The future returned by `wait_for_low`. - type WaitForLowFuture<'a>: Future> - where - Self: 'a; + async fn wait_for_high(&mut self) -> Result<(), Self::Error>; /// Wait until the pin is low. If it is already low, return immediately. /// /// # Note for implementers /// The pin may have switched back to high before the task was run after /// being woken. The future should still resolve in that case. - fn wait_for_low(&mut self) -> Self::WaitForLowFuture<'_>; - - /// The future returned from `wait_for_rising_edge`. - type WaitForRisingEdgeFuture<'a>: Future> - where - Self: 'a; + async fn wait_for_low(&mut self) -> Result<(), Self::Error>; /// Wait for the pin to undergo a transition from low to high. /// /// If the pin is already high, this does *not* return immediately, it'll wait for the /// pin to go low and then high again. - fn wait_for_rising_edge(&mut self) -> Self::WaitForRisingEdgeFuture<'_>; - - /// The future returned from `wait_for_falling_edge`. - type WaitForFallingEdgeFuture<'a>: Future> - where - Self: 'a; + async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error>; /// Wait for the pin to undergo a transition from high to low. /// /// If the pin is already low, this does *not* return immediately, it'll wait for the /// pin to go high and then low again. - fn wait_for_falling_edge(&mut self) -> Self::WaitForFallingEdgeFuture<'_>; - - /// The future returned from `wait_for_any_edge`. - type WaitForAnyEdgeFuture<'a>: Future> - where - Self: 'a; + async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error>; /// Wait for the pin to undergo any transition, i.e low to high OR high to low. - fn wait_for_any_edge(&mut self) -> Self::WaitForAnyEdgeFuture<'_>; + async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error>; } impl Wait for &mut T { - type WaitForHighFuture<'a> = T::WaitForHighFuture<'a> where Self: 'a; - - fn wait_for_high(&mut self) -> Self::WaitForHighFuture<'_> { - T::wait_for_high(self) + async fn wait_for_high(&mut self) -> Result<(), Self::Error> { + T::wait_for_high(self).await } - type WaitForLowFuture<'a> = T::WaitForLowFuture<'a> where Self: 'a; - - fn wait_for_low(&mut self) -> Self::WaitForLowFuture<'_> { - T::wait_for_low(self) + async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + T::wait_for_low(self).await } - type WaitForRisingEdgeFuture<'a> = T::WaitForRisingEdgeFuture<'a> where Self: 'a; - - fn wait_for_rising_edge(&mut self) -> Self::WaitForRisingEdgeFuture<'_> { - T::wait_for_rising_edge(self) + async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + T::wait_for_rising_edge(self).await } - type WaitForFallingEdgeFuture<'a> = T::WaitForFallingEdgeFuture<'a> where Self: 'a; - - fn wait_for_falling_edge(&mut self) -> Self::WaitForFallingEdgeFuture<'_> { - T::wait_for_falling_edge(self) + async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + T::wait_for_falling_edge(self).await } - type WaitForAnyEdgeFuture<'a> = T::WaitForAnyEdgeFuture<'a> where Self: 'a; - - fn wait_for_any_edge(&mut self) -> Self::WaitForAnyEdgeFuture<'_> { - T::wait_for_any_edge(self) + async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + T::wait_for_any_edge(self).await } } diff --git a/embedded-hal-async/src/i2c.rs b/embedded-hal-async/src/i2c.rs index 30133ce12..4f84beb0d 100644 --- a/embedded-hal-async/src/i2c.rs +++ b/embedded-hal-async/src/i2c.rs @@ -16,7 +16,6 @@ //! Since 7-bit addressing is the mode of the majority of I2C devices, //! `SevenBitAddress` has been set as default mode and thus can be omitted if desired. -use core::future::Future; pub use embedded_hal::i2c::Operation; pub use embedded_hal::i2c::{ AddressMode, Error, ErrorKind, ErrorType, NoAcknowledgeSource, SevenBitAddress, TenBitAddress, @@ -24,11 +23,6 @@ pub use embedded_hal::i2c::{ /// Async i2c pub trait I2c: ErrorType { - /// Future returned by the `read` method. - type ReadFuture<'a>: Future> - where - Self: 'a; - /// Reads enough bytes from slave with `address` to fill `buffer` /// /// # I2C Events (contract) @@ -47,12 +41,7 @@ pub trait I2c: ErrorType { /// - `MAK` = master acknowledge /// - `NMAK` = master no acknowledge /// - `SP` = stop condition - fn read<'a>(&'a mut self, address: A, read: &'a mut [u8]) -> Self::ReadFuture<'a>; - - /// Future returned by the `write` method. - type WriteFuture<'a>: Future> - where - Self: 'a; + async fn read<'a>(&'a mut self, address: A, read: &'a mut [u8]) -> Result<(), Self::Error>; /// Writes bytes to slave with address `address` /// @@ -70,12 +59,7 @@ pub trait I2c: ErrorType { /// - `SAK` = slave acknowledge /// - `Bi` = ith byte of data /// - `SP` = stop condition - fn write<'a>(&'a mut self, address: A, write: &'a [u8]) -> Self::WriteFuture<'a>; - - /// Future returned by the `write_read` method. - type WriteReadFuture<'a>: Future> - where - Self: 'a; + async fn write<'a>(&'a mut self, address: A, write: &'a [u8]) -> Result<(), Self::Error>; /// Writes bytes to slave with address `address` and then reads enough bytes to fill `read` *in a /// single transaction*. @@ -99,18 +83,12 @@ pub trait I2c: ErrorType { /// - `MAK` = master acknowledge /// - `NMAK` = master no acknowledge /// - `SP` = stop condition - fn write_read<'a>( + async fn write_read<'a>( &'a mut self, address: A, write: &'a [u8], read: &'a mut [u8], - ) -> Self::WriteReadFuture<'a>; - - /// Future returned by the `transaction` method. - type TransactionFuture<'a, 'b>: Future> - where - Self: 'a, - 'b: 'a; + ) -> Result<(), Self::Error>; /// Execute the provided operations on the I2C bus as a single transaction. /// @@ -125,44 +103,36 @@ pub trait I2c: ErrorType { /// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing /// - `SR` = repeated start condition /// - `SP` = stop condition - fn transaction<'a, 'b>( + async fn transaction<'a, 'b>( &'a mut self, address: A, operations: &'a mut [Operation<'b>], - ) -> Self::TransactionFuture<'a, 'b>; + ) -> Result<(), Self::Error>; } impl> I2c for &mut T { - type ReadFuture<'a> = T::ReadFuture<'a> where Self: 'a; - - fn read<'a>(&'a mut self, address: A, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { - T::read(self, address, buffer) + async fn read<'a>(&'a mut self, address: A, buffer: &'a mut [u8]) -> Result<(), Self::Error> { + T::read(self, address, buffer).await } - type WriteFuture<'a> = T::WriteFuture<'a> where Self: 'a; - - fn write<'a>(&'a mut self, address: A, bytes: &'a [u8]) -> Self::WriteFuture<'a> { - T::write(self, address, bytes) + async fn write<'a>(&'a mut self, address: A, bytes: &'a [u8]) -> Result<(), Self::Error> { + T::write(self, address, bytes).await } - type WriteReadFuture<'a> = T::WriteReadFuture<'a> where Self: 'a; - - fn write_read<'a>( + async fn write_read<'a>( &'a mut self, address: A, bytes: &'a [u8], buffer: &'a mut [u8], - ) -> Self::WriteReadFuture<'a> { - T::write_read(self, address, bytes, buffer) + ) -> Result<(), Self::Error> { + T::write_read(self, address, bytes, buffer).await } - type TransactionFuture<'a, 'b> = T::TransactionFuture<'a, 'b> where Self: 'a, 'b: 'a; - - fn transaction<'a, 'b>( + async fn transaction<'a, 'b>( &'a mut self, address: A, operations: &'a mut [Operation<'b>], - ) -> Self::TransactionFuture<'a, 'b> { - T::transaction(self, address, operations) + ) -> Result<(), Self::Error> { + T::transaction(self, address, operations).await } } diff --git a/embedded-hal-async/src/lib.rs b/embedded-hal-async/src/lib.rs index 07b3b966a..14748349c 100644 --- a/embedded-hal-async/src/lib.rs +++ b/embedded-hal-async/src/lib.rs @@ -9,7 +9,8 @@ #![warn(missing_docs)] #![no_std] -#![feature(type_alias_impl_trait)] +#![allow(incomplete_features)] +#![feature(async_fn_in_trait, impl_trait_projections)] pub mod delay; pub mod digital; diff --git a/embedded-hal-async/src/spi.rs b/embedded-hal-async/src/spi.rs index 6d1682ba3..2f563820c 100644 --- a/embedded-hal-async/src/spi.rs +++ b/embedded-hal-async/src/spi.rs @@ -8,34 +8,6 @@ pub use embedded_hal::spi::{ Error, ErrorKind, ErrorType, Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3, }; -type ReadFuture<'a, T, Word> -where - T: SpiDevice + ?Sized + 'a, - T::Bus: SpiBusRead, - Word: Copy + 'static, -= impl Future> + 'a; - -type WriteFuture<'a, T, Word> -where - T: SpiDevice + ?Sized + 'a, - T::Bus: SpiBusWrite, - Word: Copy + 'static, -= impl Future> + 'a; - -type TransferFuture<'a, T, Word> -where - T: SpiDevice + ?Sized + 'a, - T::Bus: SpiBus, - Word: Copy + 'static, -= impl Future> + 'a; - -type TransferInPlaceFuture<'a, T, Word> -where - T: SpiDevice + ?Sized + 'a, - T::Bus: SpiBus, - Word: Copy + 'static, -= impl Future> + 'a; - #[macro_export] /// Do an SPI transaction on a bus. /// This is a safe wrapper for [SpiDevice::transaction], which handles dereferencing the raw pointer for you. @@ -151,14 +123,6 @@ pub unsafe trait SpiDevice: ErrorType { /// SPI Bus type for this device. type Bus: ErrorType; - /// Future returned by the `transaction` method. - type TransactionFuture<'a, R, F, Fut>: Future> - where - Self: 'a, - R: 'a, - F: FnOnce(*mut Self::Bus) -> Fut + 'a, - Fut: Future::Error>> + 'a; - /// Perform a transaction against the device. /// /// **NOTE:** @@ -186,22 +150,22 @@ pub unsafe trait SpiDevice: ErrorType { /// /// Implementers of the `SpiDevice` trait must guarantee that the pointer is valid and dereferencable /// for the entire duration of the closure. - fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut> + async fn transaction(&mut self, f: F) -> Result where - F: FnOnce(*mut Self::Bus) -> Fut + 'a, - Fut: Future::Error>> + 'a; + F: FnOnce(*mut Self::Bus) -> Fut, + Fut: Future::Error>>; /// Do a read within a transaction. /// /// This is a convenience method equivalent to `device.transaction(|bus| bus.read(buf))`. /// /// See also: [`SpiDevice::transaction`], [`SpiBusRead::read`] - fn read<'a, Word>(&'a mut self, buf: &'a mut [Word]) -> ReadFuture<'a, Self, Word> + async fn read<'a, Word>(&'a mut self, buf: &'a mut [Word]) -> Result<(), Self::Error> where Self::Bus: SpiBusRead, Word: Copy + 'static, { - transaction!(self, move |bus| async move { bus.read(buf).await }) + transaction!(self, move |bus| async move { bus.read(buf).await }).await } /// Do a write within a transaction. @@ -209,12 +173,12 @@ pub unsafe trait SpiDevice: ErrorType { /// This is a convenience method equivalent to `device.transaction(|bus| bus.write(buf))`. /// /// See also: [`SpiDevice::transaction`], [`SpiBusWrite::write`] - fn write<'a, Word>(&'a mut self, buf: &'a [Word]) -> WriteFuture<'a, Self, Word> + async fn write<'a, Word>(&'a mut self, buf: &'a [Word]) -> Result<(), Self::Error> where Self::Bus: SpiBusWrite, Word: Copy + 'static, { - transaction!(self, move |bus| async move { bus.write(buf).await }) + transaction!(self, move |bus| async move { bus.write(buf).await }).await } /// Do a transfer within a transaction. @@ -222,11 +186,11 @@ pub unsafe trait SpiDevice: ErrorType { /// This is a convenience method equivalent to `device.transaction(|bus| bus.transfer(read, write))`. /// /// See also: [`SpiDevice::transaction`], [`SpiBus::transfer`] - fn transfer<'a, Word>( + async fn transfer<'a, Word>( &'a mut self, read: &'a mut [Word], write: &'a [Word], - ) -> TransferFuture<'a, Self, Word> + ) -> Result<(), Self::Error> where Self::Bus: SpiBus, Word: Copy + 'static, @@ -235,6 +199,7 @@ pub unsafe trait SpiDevice: ErrorType { self, move |bus| async move { bus.transfer(read, write).await } ) + .await } /// Do an in-place transfer within a transaction. @@ -242,10 +207,10 @@ pub unsafe trait SpiDevice: ErrorType { /// This is a convenience method equivalent to `device.transaction(|bus| bus.transfer_in_place(buf))`. /// /// See also: [`SpiDevice::transaction`], [`SpiBus::transfer_in_place`] - fn transfer_in_place<'a, Word>( + async fn transfer_in_place<'a, Word>( &'a mut self, buf: &'a mut [Word], - ) -> TransferInPlaceFuture<'a, Self, Word> + ) -> Result<(), Self::Error> where Self::Bus: SpiBus, Word: Copy + 'static, @@ -254,54 +219,38 @@ pub unsafe trait SpiDevice: ErrorType { self, move |bus| async move { bus.transfer_in_place(buf).await } ) + .await } } unsafe impl SpiDevice for &mut T { type Bus = T::Bus; - type TransactionFuture<'a, R, F, Fut> = T::TransactionFuture<'a, R, F, Fut> + async fn transaction(&mut self, f: F) -> Result where - Self: 'a, R: 'a, F: FnOnce(*mut Self::Bus) -> Fut + 'a, - Fut: Future::Error>> + 'a; - - fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut> - where - F: FnOnce(*mut Self::Bus) -> Fut + 'a, - Fut: Future::Error>> + 'a, + F: FnOnce(*mut Self::Bus) -> Fut, + Fut: Future::Error>>, { - T::transaction(self, f) + T::transaction(self, f).await } } /// Flush support for SPI bus pub trait SpiBusFlush: ErrorType { - /// Future returned by the `flush` method. - type FlushFuture<'a>: Future> - where - Self: 'a; - /// Wait until all operations have completed and the bus is idle. /// /// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for information on flushing. - fn flush(&mut self) -> Self::FlushFuture<'_>; + async fn flush(&mut self) -> Result<(), Self::Error>; } impl SpiBusFlush for &mut T { - type FlushFuture<'a> = T::FlushFuture<'a> where Self: 'a; - - fn flush(&mut self) -> Self::FlushFuture<'_> { - T::flush(self) + async fn flush(&mut self) -> Result<(), Self::Error> { + T::flush(self).await } } /// Read-only SPI bus pub trait SpiBusRead: SpiBusFlush { - /// Future returned by the `read` method. - type ReadFuture<'a>: Future> - where - Self: 'a; - /// Read `words` from the slave. /// /// The word value sent on MOSI during reading is implementation-defined, @@ -309,36 +258,27 @@ pub trait SpiBusRead: SpiBusFlush { /// /// Implementations are allowed to return before the operation is /// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing. - fn read<'a>(&'a mut self, words: &'a mut [Word]) -> Self::ReadFuture<'a>; + async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error>; } impl, Word: 'static + Copy> SpiBusRead for &mut T { - type ReadFuture<'a> = T::ReadFuture<'a> where Self: 'a; - - fn read<'a>(&'a mut self, words: &'a mut [Word]) -> Self::ReadFuture<'a> { - T::read(self, words) + async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error> { + T::read(self, words).await } } /// Write-only SPI pub trait SpiBusWrite: SpiBusFlush { - /// Future returned by the `write` method. - type WriteFuture<'a>: Future> - where - Self: 'a; - /// Write `words` to the slave, ignoring all the incoming words /// /// Implementations are allowed to return before the operation is /// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing. - fn write<'a>(&'a mut self, words: &'a [Word]) -> Self::WriteFuture<'a>; + async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error>; } impl, Word: 'static + Copy> SpiBusWrite for &mut T { - type WriteFuture<'a> = T::WriteFuture<'a> where Self: 'a; - - fn write<'a>(&'a mut self, words: &'a [Word]) -> Self::WriteFuture<'a> { - T::write(self, words) + async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error> { + T::write(self, words).await } } @@ -348,11 +288,6 @@ impl, Word: 'static + Copy> SpiBusWrite for &mut T { /// /// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for important information on SPI Bus vs Device traits. pub trait SpiBus: SpiBusRead + SpiBusWrite { - /// Future returned by the `transfer` method. - type TransferFuture<'a>: Future> - where - Self: 'a; - /// Write and read simultaneously. `write` is written to the slave on MOSI and /// words received on MISO are stored in `read`. /// @@ -364,16 +299,11 @@ pub trait SpiBus: SpiBusRead + SpiBusWrite( + async fn transfer<'a>( &'a mut self, read: &'a mut [Word], write: &'a [Word], - ) -> Self::TransferFuture<'a>; - - /// Future returned by the `transfer_in_place` method. - type TransferInPlaceFuture<'a>: Future> - where - Self: 'a; + ) -> Result<(), Self::Error>; /// Write and read simultaneously. The contents of `words` are /// written to the slave, and the received words are stored into the same @@ -381,30 +311,20 @@ pub trait SpiBus: SpiBusRead + SpiBusWrite( - &'a mut self, - words: &'a mut [Word], - ) -> Self::TransferInPlaceFuture<'a>; + async fn transfer_in_place<'a>(&'a mut self, words: &'a mut [Word]) -> Result<(), Self::Error>; } impl, Word: 'static + Copy> SpiBus for &mut T { - type TransferFuture<'a> = T::TransferFuture<'a> where Self: 'a; - - fn transfer<'a>( + async fn transfer<'a>( &'a mut self, read: &'a mut [Word], write: &'a [Word], - ) -> Self::TransferFuture<'a> { - T::transfer(self, read, write) + ) -> Result<(), Self::Error> { + T::transfer(self, read, write).await } - type TransferInPlaceFuture<'a> = T::TransferInPlaceFuture<'a> where Self: 'a; - - fn transfer_in_place<'a>( - &'a mut self, - words: &'a mut [Word], - ) -> Self::TransferInPlaceFuture<'a> { - T::transfer_in_place(self, words) + async fn transfer_in_place<'a>(&'a mut self, words: &'a mut [Word]) -> Result<(), Self::Error> { + T::transfer_in_place(self, words).await } } @@ -488,31 +408,23 @@ where { type Bus = BUS; - type TransactionFuture<'a, R, F, Fut> = impl Future> + 'a + async fn transaction(&mut self, f: F) -> Result where - Self: 'a, R: 'a, F: FnOnce(*mut Self::Bus) -> Fut + 'a, - Fut: Future::Error>> + 'a; - - fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut> - where - R: 'a, - F: FnOnce(*mut Self::Bus) -> Fut + 'a, - Fut: Future::Error>> + 'a, + F: FnOnce(*mut Self::Bus) -> Fut, + Fut: Future::Error>>, { - async move { - self.cs.set_low().map_err(ExclusiveDeviceError::Cs)?; + self.cs.set_low().map_err(ExclusiveDeviceError::Cs)?; - let f_res = f(&mut self.bus).await; + let f_res = f(&mut self.bus).await; - // On failure, it's important to still flush and deassert CS. - let flush_res = self.bus.flush().await; - let cs_res = self.cs.set_high(); + // On failure, it's important to still flush and deassert CS. + let flush_res = self.bus.flush().await; + let cs_res = self.cs.set_high(); - let f_res = f_res.map_err(ExclusiveDeviceError::Spi)?; - flush_res.map_err(ExclusiveDeviceError::Spi)?; - cs_res.map_err(ExclusiveDeviceError::Cs)?; + let f_res = f_res.map_err(ExclusiveDeviceError::Spi)?; + flush_res.map_err(ExclusiveDeviceError::Spi)?; + cs_res.map_err(ExclusiveDeviceError::Cs)?; - Ok(f_res) - } + Ok(f_res) } } From 2387a5c5f21212742b182136e36388d60ad0b62d Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 23 Nov 2022 17:12:01 +0100 Subject: [PATCH 2/3] Fix CI tests for MSRV --- embedded-hal-nb/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embedded-hal-nb/Cargo.toml b/embedded-hal-nb/Cargo.toml index 8ac731cb4..6e8f49c71 100644 --- a/embedded-hal-nb/Cargo.toml +++ b/embedded-hal-nb/Cargo.toml @@ -15,6 +15,6 @@ repository = "https://github.com/rust-embedded/embedded-hal" embedded-hal = { version = "=1.0.0-alpha.9", path = "../embedded-hal" } nb = "1" -[dev-dependencies.stm32f1] -version = "0.15" -features = ["stm32f103", "rt"] +[dev-dependencies] +cortex-m-rt = "=0.7.1" # 0.7.2 bumped its MSRV higher than embedded-hal's +stm32f1 = { version = "0.15", features = ["stm32f103", "rt"] } From ad0b9f2136df7327c0704d12ee19eb5406777c79 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 23 Nov 2022 17:17:04 +0100 Subject: [PATCH 3/3] Release embedded-hal-async v0.2.0-alpha.0 --- embedded-hal-async/CHANGELOG.md | 6 +++++- embedded-hal-async/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/embedded-hal-async/CHANGELOG.md b/embedded-hal-async/CHANGELOG.md index 9fa801586..dbed8a393 100644 --- a/embedded-hal-async/CHANGELOG.md +++ b/embedded-hal-async/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.2.0-alpha.0] - 2022-11-23 + +- Switch all traits to use [`async_fn_in_trait`](https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-in-trait-nightly.html) (AFIT). Requires `nightly-2022-11-22` or newer. ## [v0.1.0-alpha.3] - 2022-10-26 @@ -34,7 +37,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). First release to crates.io -[Unreleased]: https://github.com/rust-embedded/embedded-hal/compare/embedded-hal-async-v0.1.0-alpha.3...HEAD +[Unreleased]: https://github.com/rust-embedded/embedded-hal/compare/embedded-hal-async-v0.2.0-alpha.0...HEAD +[v0.2.0-alpha.0]: https://github.com/rust-embedded/embedded-hal/compare/embedded-hal-async-v0.1.0-alpha.3...embedded-hal-async-v0.2.0-alpha.0 [v0.1.0-alpha.3]: https://github.com/rust-embedded/embedded-hal/compare/embedded-hal-async-v0.1.0-alpha.2...embedded-hal-async-v0.1.0-alpha.3 [v0.1.0-alpha.2]: https://github.com/rust-embedded/embedded-hal/compare/embedded-hal-async-v0.1.0-alpha.1...embedded-hal-async-v0.1.0-alpha.2 [v0.1.0-alpha.1]: https://github.com/rust-embedded/embedded-hal/compare/embedded-hal-async-v0.1.0-alpha.0...embedded-hal-async-v0.1.0-alpha.1 diff --git a/embedded-hal-async/Cargo.toml b/embedded-hal-async/Cargo.toml index 05246f47e..7078beb6e 100644 --- a/embedded-hal-async/Cargo.toml +++ b/embedded-hal-async/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" name = "embedded-hal-async" readme = "README.md" repository = "https://github.com/rust-embedded/embedded-hal" -version = "0.1.0-alpha.3" +version = "0.2.0-alpha.0" [dependencies] embedded-hal = { version = "=1.0.0-alpha.9", path = "../embedded-hal" }