Skip to content

Commit

Permalink
Revert PR #42 and following fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
almindor committed Jun 25, 2022
1 parent c7e37ab commit 0b5c869
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .github/bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ delete_merged_branches = true
required_approvals = 1
status = [
"ci-linux (stable)",
"ci-linux (1.59.0)",
"ci-linux (1.42.0)",
"build-other (macOS-latest)",
"build-other (windows-latest)",
"Rustfmt"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
continue-on-error: ${{ matrix.experimental || false }}
strategy:
matrix:
# All generated code should be running on stable now, MRSV is 1.59.0
rust: [nightly, stable, 1.59.0]
# All generated code should be running on stable now, MRSV is 1.42.0
rust: [nightly, stable, 1.42.0]

include:
# Nightly is only for reference and allowed to fail
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "e310x-hal"
version = "0.10.0-alpha.1"
version = "0.9.3"
authors = ["David Craven <[email protected]>"]
repository = "https://github.com/riscv-rust/e310x-hal"
categories = ["embedded", "hardware-support", "no-std"]
Expand All @@ -10,9 +10,9 @@ license = "ISC"
edition = "2018"

[dependencies]
embedded-hal = "=1.0.0-alpha.7"
embedded-hal = { version = "0.2.6", features = ["unproven"] }
nb = "1.0.0"
riscv = "0.8.0"
riscv = "0.7.0"
e310x = { version = "0.9.0", features = ["rt"] }

[features]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This project is developed and maintained by the [RISC-V team][team].

## Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might*
This crate is guaranteed to compile on stable Rust 1.42.0 and up. It *might*
compile with older versions but that may change in any new patch release.

## License
Expand Down
93 changes: 80 additions & 13 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use crate::clock::Clocks;
use crate::core::clint::{MTIME, MTIMECMP};
use core::convert::Infallible;
use embedded_hal::delay::blocking::DelayUs;
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
use riscv::register::{mie, mip};

/// Machine timer (mtime) as a busyloop delay provider
Expand All @@ -18,16 +17,65 @@ impl Delay {
}
}

impl DelayUs for Delay {
type Error = Infallible;

fn delay_us(&mut self, us: u32) -> Result<(), Infallible> {
impl DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
let ticks = (us as u64) * TICKS_PER_SECOND / 1_000_000;

let mtime = MTIME;
let t = mtime.mtime() + ticks;
while mtime.mtime() < t {}
Ok(())
}
}

// This is a workaround to allow `delay_us(42)` construction without specifying a type.
impl DelayUs<i32> for Delay {
#[inline(always)]
fn delay_us(&mut self, us: i32) {
assert!(us >= 0);
self.delay_us(us as u32);
}
}

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

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

impl DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
self.delay_us(ms * 1000);
}
}

// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
impl DelayMs<i32> for Delay {
#[inline(always)]
fn delay_ms(&mut self, ms: i32) {
assert!(ms >= 0);
self.delay_ms(ms as u32);
}
}

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

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

Expand All @@ -47,11 +95,9 @@ impl Sleep {
}
}

impl DelayUs for Sleep {
type Error = Infallible;

fn delay_us(&mut self, us: u32) -> Result<(), Infallible> {
let ticks = (us as u64) * (self.clock_freq as u64) / 1_000_000;
impl DelayMs<u32> for Sleep {
fn delay_ms(&mut self, ms: u32) {
let ticks = (ms as u64) * (self.clock_freq as u64) / 1000;
let t = MTIME.mtime() + ticks;

self.mtimecmp.set_mtimecmp(t);
Expand Down Expand Up @@ -80,7 +126,28 @@ impl DelayUs for Sleep {
unsafe {
mie::clear_mtimer();
}
}
}

// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
impl DelayMs<i32> for Sleep {
#[inline(always)]
fn delay_ms(&mut self, ms: i32) {
assert!(ms >= 0);
self.delay_ms(ms as u32);
}
}

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

Ok(())
impl DelayMs<u8> for Sleep {
#[inline(always)]
fn delay_ms(&mut self, ms: u8) {
self.delay_ms(u32::from(ms));
}
}
13 changes: 5 additions & 8 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ macro_rules! gpio {
use core::marker::PhantomData;
use core::convert::Infallible;

use embedded_hal::digital::ErrorType;
use embedded_hal::digital::blocking::{InputPin, OutputPin, StatefulOutputPin,
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin,
ToggleableOutputPin};
use e310x::$GPIOX;
use super::{Unknown, IOF0, IOF1, Drive, Floating, GpioExt, Input, Invert,
Expand Down Expand Up @@ -276,11 +275,9 @@ macro_rules! gpio {
}
}

impl<MODE> ErrorType for $PXi<Input<MODE>> {
impl<MODE> InputPin for $PXi<Input<MODE>> {
type Error = Infallible;
}

impl<MODE> InputPin for $PXi<Input<MODE>> {
fn is_high(&self) -> Result<bool, Infallible> {
Ok($GPIOX::input_value(Self::INDEX))

Expand All @@ -301,11 +298,9 @@ macro_rules! gpio {
}
}

impl<MODE> ErrorType for $PXi<Output<MODE>> {
impl<MODE> OutputPin for $PXi<Output<MODE>> {
type Error = Infallible;
}

impl<MODE> OutputPin for $PXi<Output<MODE>> {
fn set_high(&mut self) -> Result<(), Infallible> {
$GPIOX::set_output_value(Self::INDEX, true);
Ok(())
Expand All @@ -318,6 +313,8 @@ macro_rules! gpio {
}

impl<MODE> ToggleableOutputPin for $PXi<Output<MODE>> {
type Error = Infallible;

/// Toggles the pin state.
fn toggle(&mut self) -> Result<(), Infallible> {
$GPIOX::toggle_pin(Self::INDEX);
Expand Down
Loading

0 comments on commit 0b5c869

Please sign in to comment.