Skip to content

Commit

Permalink
Fix errors arising from converting to fugit
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeaurivage committed Aug 22, 2023
1 parent 25ed7b4 commit 580dc89
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
15 changes: 7 additions & 8 deletions hal/src/async_hal/timer.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -139,7 +137,7 @@ where
{
/// Delay asynchronously
#[inline]
pub async fn delay(&mut self, count: impl Into<Nanoseconds>) {
pub async fn delay(&mut self, count: NanosDurationU32) {
self.timer.start(count);
self.timer.enable_interrupt();

Expand Down Expand Up @@ -169,7 +167,6 @@ where
#[cfg(feature = "nightly")]
mod impl_ehal {
use super::*;
use crate::time::U32Ext;
use embedded_hal_async::delay::DelayUs;

impl<T, I> DelayUs for TimerFuture<T, I>
Expand All @@ -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;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 2 additions & 0 deletions hal/src/sercom/i2c/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions hal/src/sercom/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 11 additions & 4 deletions hal/src/sercom/spi/async_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C, A, N, S, R, T> ErrorType for SpiFuture<C, A, N, R, T>
Expand Down Expand Up @@ -391,12 +391,19 @@ mod impl_ehal {
S: Sercom + 'static,
Self: SpiBusWrite<W> + SpiBusRead<W> + ErrorType<Error = Error>,
{
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?;
Expand All @@ -412,7 +419,7 @@ mod impl_ehal {
where
C: ValidConfig<Sercom = S, Word = W>,
C::Word: PrimInt + AsPrimitive<DataWidth> + crate::dmac::Beat + Copy,
C::Size: Size<Word = C::Word>,
C::Size: super::super::Size<Word = C::Word>,
DataWidth: AsPrimitive<C::Word>,
N: InterruptNumber,
R: crate::dmac::AnyChannel<Status = crate::dmac::ReadyFuture>,
Expand Down

0 comments on commit 580dc89

Please sign in to comment.