From 977bc2732a5871cb5c09bf6842de6a016cf1c9b6 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sun, 17 Apr 2022 22:39:31 +0100 Subject: [PATCH] Remove unmaintained implementation async i2c. --- rp2040-hal/CHANGELOG.md | 4 + rp2040-hal/Cargo.toml | 14 -- rp2040-hal/src/i2c/controller.rs | 3 - .../src/i2c/controller/embassy_support.rs | 219 ------------------ rp2040-hal/src/lib.rs | 2 - 5 files changed, 4 insertions(+), 238 deletions(-) delete mode 100644 rp2040-hal/src/i2c/controller/embassy_support.rs diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 2759d75..9bd6e45 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed + +- removed i2c embassy driver prototype + ## [0.4.0] - 2022-03-09 ### Added diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index ea0e1c3..6ea6523 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -30,17 +30,6 @@ critical-section = { version = "0.2.4", features = ["custom-impl"] } futures = { version = "0.3", default-features = false, optional = true } chrono = { version = "0.4", default-features = false, optional = true } -# namespaced features will let us use "dep:embassy-traits" in the features rather than using this -# trick of renaming the crate. -# -# This is commented out so that we can publish to crates.io -# -# [dependencies.embassy_traits] -# git = "https://github.com/embassy-rs/embassy" -# rev = "6d6e6f55b8a9ecd38b5a6d3bb11f74b2654afdeb" -# package = "embassy-traits" -# optional = true - [dev-dependencies] cortex-m-rt = "0.7" panic-halt = "0.2.0" @@ -51,9 +40,6 @@ dht-sensor = "0.2.1" [features] rt = ["rp2040-pac/rt"] -# This is commented out so that we can publish to crates.io -# -# embassy-traits = ["embassy_traits", "futures"] alloc = [] rom-func-cache = [] disable-intrinsics = [] diff --git a/rp2040-hal/src/i2c/controller.rs b/rp2040-hal/src/i2c/controller.rs index bd4ac7c..0098c9b 100644 --- a/rp2040-hal/src/i2c/controller.rs +++ b/rp2040-hal/src/i2c/controller.rs @@ -14,9 +14,6 @@ use eh1_0_alpha::i2c as eh1; use super::{i2c_reserved_addr, Controller, Error, SclPin, SdaPin, I2C}; -#[cfg(feature = "embassy-traits")] -mod embassy_support; - impl, Sda: PinId + BankPinId, Scl: PinId + BankPinId> I2C, Pin), Controller> { diff --git a/rp2040-hal/src/i2c/controller/embassy_support.rs b/rp2040-hal/src/i2c/controller/embassy_support.rs deleted file mode 100644 index 4bfb2f1..0000000 --- a/rp2040-hal/src/i2c/controller/embassy_support.rs +++ /dev/null @@ -1,219 +0,0 @@ -use core::{future::Future, iter::Peekable, ops::Deref, task::Poll}; - -use super::{Block, Controller, Error, I2C}; - -impl, PINS> I2C { - async fn non_blocking_read_internal<'a, U: Iterator + 'a>( - &mut self, - mut buffer: Peekable, - ) -> Result<(), Error> { - let mut first = true; - while let Some(byte) = buffer.next() { - let last = buffer.peek().is_none(); - - // wait until there is space in the FIFO to write the next byte - block_on(|| { - if self.tx_fifo_full() { - Poll::Pending - } else { - Poll::Ready(()) - } - }) - .await; - - self.i2c.ic_data_cmd.write(|w| { - if first { - w.restart().enable(); - first = false; - } else { - w.restart().disable(); - } - - if last { - w.stop().enable(); - } else { - w.stop().disable(); - } - - w.cmd().read() - }); - - block_on(|| { - if let Some(abort_reason) = self.read_and_clear_abort_reason() { - Poll::Ready(Err(Error::Abort(abort_reason))) - } else if self.i2c.ic_rxflr.read().bits() != 0 { - Poll::Ready(Ok(())) - } else { - Poll::Pending - } - }) - .await?; - - *byte = self.i2c.ic_data_cmd.read().dat().bits(); - } - - Ok(()) - } - - async fn non_blocking_write_internal( - &mut self, - bytes: impl IntoIterator, - do_stop: bool, - ) -> Result<(), Error> { - let mut bytes = bytes.into_iter().peekable(); - while let Some(byte) = bytes.next() { - let last = bytes.peek().is_none(); - - self.i2c.ic_data_cmd.write(|w| { - if do_stop && last { - w.stop().enable(); - } else { - w.stop().disable(); - } - unsafe { w.dat().bits(byte) } - }); - - // Wait until the transmission of the address/data from the internal - // shift register has completed. For this to function correctly, the - // TX_EMPTY_CTRL flag in IC_CON must be set. The TX_EMPTY_CTRL flag - // was set in i2c_init. - block_on(|| { - if self.i2c.ic_raw_intr_stat.read().tx_empty().is_inactive() { - Poll::Pending - } else { - Poll::Ready(()) - } - }) - .await; - - let abort_reason = self.read_and_clear_abort_reason(); - - if abort_reason.is_some() || (do_stop && last) { - // If the transaction was aborted or if it completed - // successfully wait until the STOP condition has occured. - - block_on(|| { - if self.i2c.ic_raw_intr_stat.read().stop_det().is_inactive() { - Poll::Pending - } else { - Poll::Ready(()) - } - }) - .await; - - self.i2c.ic_clr_stop_det.read().clr_stop_det(); - } - - // Note the hardware issues a STOP automatically on an abort condition. - // Note also the hardware clears RX FIFO as well as TX on abort, - // ecause we set hwparam IC_AVOID_RX_FIFO_FLUSH_ON_TX_ABRT to 0. - if let Some(abort_reason) = abort_reason { - return Err(Error::Abort(abort_reason)); - } - } - - Ok(()) - } -} -async fn block_on Poll, T>(mut f: F) -> T { - futures::future::poll_fn(|cx| { - // always ready to scan - cx.waker().wake_by_ref(); - - f() - }) - .await -} - -impl embassy_traits::i2c::I2c for I2C -where - T: Deref, - A: embassy_traits::i2c::AddressMode + 'static + Into, -{ - type Error = Error; - - #[rustfmt::skip] - type WriteFuture<'a> - where - Self: 'a = impl Future> + 'a; - - #[rustfmt::skip] - type ReadFuture<'a> - where - Self: 'a = impl Future> + 'a; - - #[rustfmt::skip] - type WriteReadFuture<'a> - where - Self: 'a = impl Future> + 'a; - - fn read<'a>(&'a mut self, address: A, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { - let mut buffer = buffer.iter_mut().peekable(); - let addr: u16 = address.into(); - - async move { - self.setup(addr); - - Self::validate(addr, None, Some(buffer.peek().is_none()))?; - - self.non_blocking_read_internal(buffer).await - } - } - - fn write<'a>(&'a mut self, address: A, bytes: &'a [u8]) -> Self::WriteFuture<'a> { - async move { - let addr: u16 = address.into(); - Self::validate(addr, Some(bytes.is_empty()), None)?; - self.setup(addr); - - self.non_blocking_write_internal(bytes.iter().cloned(), true) - .await - } - } - - fn write_read<'a>( - &'a mut self, - address: A, - bytes: &'a [u8], - buffer: &'a mut [u8], - ) -> Self::WriteReadFuture<'a> { - async move { - let addr: u16 = address.into(); - Self::validate(addr, Some(bytes.is_empty()), Some(buffer.is_empty()))?; - self.setup(addr); - - self.non_blocking_write_internal(bytes.iter().cloned(), false) - .await?; - self.non_blocking_read_internal(buffer.iter_mut().peekable()) - .await - } - } -} -impl embassy_traits::i2c::WriteIter for I2C -where - T: Deref, - A: embassy_traits::i2c::AddressMode + 'static + Into, -{ - type Error = Error; - - #[rustfmt::skip] - type WriteIterFuture<'a, U> - where - U: 'a + IntoIterator, - Self: 'a = impl Future> + 'a; - - fn write_iter<'a, U>(&'a mut self, address: A, bytes: U) -> Self::WriteIterFuture<'a, U> - where - U: IntoIterator + 'a, - { - let addr: u16 = address.into(); - async move { - let mut bytes = bytes.into_iter().peekable(); - Self::validate(addr, Some(bytes.peek().is_none()), None)?; - - self.setup(addr); - - self.non_blocking_write_internal(bytes, true).await - } - } -} diff --git a/rp2040-hal/src/lib.rs b/rp2040-hal/src/lib.rs index 3153868..6e2aa8f 100644 --- a/rp2040-hal/src/lib.rs +++ b/rp2040-hal/src/lib.rs @@ -5,8 +5,6 @@ #![warn(missing_docs)] #![no_std] -#![cfg_attr(feature = "embassy-traits", feature(generic_associated_types))] -#![cfg_attr(feature = "embassy-traits", feature(type_alias_impl_trait))] extern crate cortex_m; extern crate embedded_hal as hal;