Skip to content

Commit

Permalink
Update embedded-hal dependency to 1.0.0-alpha.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedcharles committed Feb 24, 2022
1 parent cd31989 commit 72165e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "riscv"
version = "0.7.0"
version = "0.8.0-alpha.7"
repository = "https://github.com/rust-embedded/riscv"
authors = ["The RISC-V Team <[email protected]>"]
categories = ["embedded", "hardware-support", "no-std"]
Expand All @@ -17,8 +17,8 @@ targets = [

[dependencies]
bare-metal = "1.0.0"
bit_field = "0.10.0"
embedded-hal = "0.2.6"
bit_field = "0.10.1"
embedded-hal = "=1.0.0-alpha.7"

[build-dependencies]
riscv-target = "0.1.2"
Expand Down
72 changes: 8 additions & 64 deletions src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::register::mcycle;
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
use core::convert::Infallible;
use embedded_hal::delay::blocking::DelayUs;

/// Machine mode cycle counter (`mcycle`) as a delay provider
#[derive(Copy, Clone)]
Expand All @@ -15,71 +16,14 @@ impl McycleDelay {
}
}

impl DelayUs<u64> 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 clock = ((us as u64) * (self.ticks_second as u64)) / 1_000_000;
while mcycle::read64().wrapping_sub(t0) <= clock {}
}
}

impl DelayUs<u32> 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<i32> for McycleDelay {
#[inline(always)]
fn delay_us(&mut self, us: i32) {
assert!(us >= 0);
self.delay_us(us as u32);
}
}

impl DelayUs<u16> for McycleDelay {
#[inline(always)]
fn delay_us(&mut self, us: u16) {
self.delay_us(us as u32)
}
}

impl DelayUs<u8> for McycleDelay {
#[inline(always)]
fn delay_us(&mut self, us: u8) {
self.delay_us(us as u32)
}
}

impl DelayMs<u32> 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<i32> for McycleDelay {
#[inline(always)]
fn delay_ms(&mut self, ms: i32) {
assert!(ms >= 0);
self.delay_ms(ms as u32);
}
}

impl DelayMs<u16> for McycleDelay {
#[inline(always)]
fn delay_ms(&mut self, ms: u16) {
self.delay_ms(ms as u32)
}
}

impl DelayMs<u8> for McycleDelay {
#[inline(always)]
fn delay_ms(&mut self, ms: u8) {
self.delay_ms(ms as u32)
Ok(())
}
}

0 comments on commit 72165e0

Please sign in to comment.