diff --git a/CHANGELOG.md b/CHANGELOG.md index c2082d1c..af22d73a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix `asm::delay()` to ensure count register is always reloaded +### Changed + + - Use new `DelayUs` trait from `embedded-hal` `v1.0.0-alpha.8` + - NOTE: this removes `DelayMs` and `DelayUs` with `u64` version ## [v0.8.0] - 2022-04-20 diff --git a/Cargo.toml b/Cargo.toml index 25a14779..99c94bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "riscv" -version = "0.8.0" +version = "0.9.0-alpha.1" rust-version = "1.59" repository = "https://github.com/rust-embedded/riscv" authors = ["The RISC-V Team "] @@ -19,4 +19,4 @@ targets = [ [dependencies] bare-metal = "1.0.0" bit_field = "0.10.0" -embedded-hal = "0.2.6" +embedded-hal = "1.0.0-alpha.8" diff --git a/src/delay.rs b/src/delay.rs index 041cb479..d52bd70f 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -1,6 +1,7 @@ -//! Delay devices and providers +use core::convert::Infallible; + use crate::register::mcycle; -use embedded_hal::blocking::delay::{DelayMs, DelayUs}; +use embedded_hal::delay::blocking::DelayUs; /// Machine mode cycle counter (`mcycle`) as a delay provider #[derive(Copy, Clone)] @@ -17,71 +18,16 @@ impl McycleDelay { } } -impl DelayUs for McycleDelay { +impl DelayUs for McycleDelay { + type Error = Infallible; + #[inline] - fn delay_us(&mut self, us: u64) { + fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { let t0 = mcycle::read64(); - let clock = (us * (self.ticks_second as u64)) / 1_000_000; + let us_64: u64 = us.into(); + let clock = (us_64 * (self.ticks_second as u64)) / 1_000_000u64; while mcycle::read64().wrapping_sub(t0) <= clock {} - } -} -impl DelayUs for McycleDelay { - #[inline(always)] - fn delay_us(&mut self, us: u32) { - self.delay_us(us as u64) - } -} - -// Implemented for constructions like `delay.delay_us(50_000);` -impl DelayUs for McycleDelay { - #[inline(always)] - fn delay_us(&mut self, us: i32) { - assert!(us >= 0); - self.delay_us(us as u32); - } -} - -impl DelayUs for McycleDelay { - #[inline(always)] - fn delay_us(&mut self, us: u16) { - self.delay_us(us as u32) - } -} - -impl DelayUs for McycleDelay { - #[inline(always)] - fn delay_us(&mut self, us: u8) { - self.delay_us(us as u32) - } -} - -impl DelayMs for McycleDelay { - #[inline] - fn delay_ms(&mut self, ms: u32) { - self.delay_us((ms as u64) * 1000) - } -} - -// Implemented for constructions like `delay.delay_ms(50_000);` -impl DelayMs for McycleDelay { - #[inline(always)] - fn delay_ms(&mut self, ms: i32) { - assert!(ms >= 0); - self.delay_ms(ms as u32); - } -} - -impl DelayMs for McycleDelay { - #[inline(always)] - fn delay_ms(&mut self, ms: u16) { - self.delay_ms(ms as u32) - } -} - -impl DelayMs for McycleDelay { - #[inline(always)] - fn delay_ms(&mut self, ms: u8) { - self.delay_ms(ms as u32) + Ok(()) } }