From e3f1f0791851aa754264c6ee5a12a538a3b8db46 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Tue, 22 Aug 2023 17:09:25 -0400 Subject: [PATCH] Fix errors arising from converting to fugit --- hal/Cargo.toml | 2 +- hal/src/async_hal/timer.rs | 15 +++++++-------- hal/src/lib.rs | 2 -- hal/src/sercom/i2c/flags.rs | 2 ++ hal/src/sercom/spi.rs | 2 ++ hal/src/sercom/spi/async_api.rs | 13 ++++++++++--- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/hal/Cargo.toml b/hal/Cargo.toml index 2b21be88c84..7af11931ce7 100644 --- a/hal/Cargo.toml +++ b/hal/Cargo.toml @@ -56,7 +56,7 @@ void = {version = "1.0", default-features = false} cortex-m-interrupt = {version = "0.2.1-git", git = "https://github.com/datdenkikniet/cortex-m-interrupt.git", rev = "9baa936", optional = true} embassy-sync = {version = "0.2", optional = true} embedded-hal-alpha = {package = "embedded-hal", version = "1.0.0-alpha.10"} -embedded-hal-async = {version = "0.2.0-alpha.1", optional = true} +embedded-hal-async = {version = "=0.2.0-alpha.1", optional = true} embedded-sdmmc = {version = "0.3", optional = true} futures = {version = "0.3", default-features = false, features = ["async-await"], optional = true} jlink_rtt = {version = "0.2", optional = true} diff --git a/hal/src/async_hal/timer.rs b/hal/src/async_hal/timer.rs index b3e058ad19c..ab492ee005d 100644 --- a/hal/src/async_hal/timer.rs +++ b/hal/src/async_hal/timer.rs @@ -1,7 +1,4 @@ -use crate::{ - ehal::timer::CountDown, time::Nanoseconds, timer_traits::InterruptDrivenTimer, - typelevel::Sealed, -}; +use crate::{ehal::timer::CountDown, timer_traits::InterruptDrivenTimer, typelevel::Sealed}; use atomic_polyfill::AtomicBool; use core::{ future::poll_fn, @@ -11,6 +8,7 @@ use core::{ use cortex_m::interrupt::InterruptNumber; use cortex_m_interrupt::NvicInterruptRegistration; use embassy_sync::waitqueue::AtomicWaker; +use fugit::{MicrosDurationU32, MillisDurationU32, NanosDurationU32}; #[cfg(feature = "thumbv6")] use crate::thumbv6m::timer; @@ -139,7 +137,7 @@ where { /// Delay asynchronously #[inline] - pub async fn delay(&mut self, count: impl Into) { + pub async fn delay(&mut self, count: NanosDurationU32) { self.timer.start(count); self.timer.enable_interrupt(); @@ -169,7 +167,6 @@ where #[cfg(feature = "nightly")] mod impl_ehal { use super::*; - use crate::time::U32Ext; use embedded_hal_async::delay::DelayUs; impl DelayUs for TimerFuture @@ -178,11 +175,13 @@ mod impl_ehal { I: InterruptNumber, { async fn delay_ms(&mut self, ms: u32) { - self.delay(ms.ms()).await; + self.delay(MillisDurationU32::from_ticks(ms).convert()) + .await; } async fn delay_us(&mut self, us: u32) { - self.delay(us.us()).await; + self.delay(MicrosDurationU32::from_ticks(us).convert()) + .await; } } } diff --git a/hal/src/lib.rs b/hal/src/lib.rs index 35f29a86eda..0171e61aa5f 100644 --- a/hal/src/lib.rs +++ b/hal/src/lib.rs @@ -85,8 +85,6 @@ pub mod timer_traits; #[cfg(feature = "async")] pub mod async_hal; -#[cfg(feature = "async")] -pub use async_hal::*; #[cfg(feature = "async")] pub use cortex_m_interrupt::{self, take_exception, take_nvic_interrupt}; diff --git a/hal/src/sercom/i2c/flags.rs b/hal/src/sercom/i2c/flags.rs index eb98a216c6d..89bb8c60eac 100644 --- a/hal/src/sercom/i2c/flags.rs +++ b/hal/src/sercom/i2c/flags.rs @@ -87,6 +87,8 @@ pub enum Error { #[cfg(feature = "nightly")] impl embedded_hal_async::i2c::Error for Error { + // _ pattern reachable when "dma" feature enabled. + #[allow(unreachable_patterns)] fn kind(&self) -> embedded_hal_async::i2c::ErrorKind { use embedded_hal_async::i2c::{ErrorKind, NoAcknowledgeSource}; match self { diff --git a/hal/src/sercom/spi.rs b/hal/src/sercom/spi.rs index effffcf7f7a..db7810cd0fb 100644 --- a/hal/src/sercom/spi.rs +++ b/hal/src/sercom/spi.rs @@ -472,6 +472,8 @@ pub enum Error { #[cfg(all(feature = "async", feature = "nightly"))] impl embedded_hal_async::spi::Error for Error { + // _ pattern reachable when "dma" feature enabled. + #[allow(unreachable_patterns)] fn kind(&self) -> embedded_hal_async::spi::ErrorKind { use embedded_hal_async::spi::ErrorKind; diff --git a/hal/src/sercom/spi/async_api.rs b/hal/src/sercom/spi/async_api.rs index dfd4dcaae26..8ca17b2262f 100644 --- a/hal/src/sercom/spi/async_api.rs +++ b/hal/src/sercom/spi/async_api.rs @@ -287,7 +287,7 @@ where #[cfg(feature = "nightly")] mod impl_ehal { use super::*; - use crate::sercom::spi::{Error, Size}; + use crate::sercom::spi::Error; use embedded_hal_async::spi::{ErrorType, SpiBus, SpiBusFlush, SpiBusRead, SpiBusWrite}; impl ErrorType for SpiFuture @@ -391,12 +391,19 @@ mod impl_ehal { S: Sercom + 'static, Self: SpiBusWrite + SpiBusRead + ErrorType, { - async fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { + async fn transfer<'a>( + &'a mut self, + read: &'a mut [W], + write: &'a [W], + ) -> Result<(), Self::Error> { self.transfer_word_by_word(read, write).await?; Ok(()) } - async fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error> { + async fn transfer_in_place<'a>( + &'a mut self, + words: &'a mut [W], + ) -> Result<(), Self::Error> { // Can only ever do word-by-word to avoid DMA race conditions for word in words { let read = self.simultaneous_word(*word).await?;