Skip to content

Commit f37c741

Browse files
committed
Update embedded-hal to 1.0
1 parent 27f78b5 commit f37c741

File tree

5 files changed

+14
-70
lines changed

5 files changed

+14
-70
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
# All generated code should be running on stable now, MRSV is 1.59.0
15-
toolchain: [ stable, nightly, 1.59.0 ]
15+
toolchain: [ stable, nightly, 1.60.0 ]
1616
target:
1717
- riscv32i-unknown-none-elf
1818
- riscv32imc-unknown-none-elf

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2020

2121
### Changed
2222

23+
- Update `embedded-hal` dependency to v1.0 (bumps MSRV to 1.60)
2324
- `misa::MXL` renamed to `misa::XLEN`
2425
- Removed `bit_field` dependency
2526
- CI actions updated. They now use `checkout@v3` and `dtolnay/rust-toolchain`.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ targets = [
2222
critical-section-single-hart = ["critical-section/restore-state-bool"]
2323

2424
[dependencies]
25-
critical-section = "1.1.0"
26-
embedded-hal = "0.2.6"
25+
critical-section = "1.1.2"
26+
embedded-hal = "1.0.0-rc.1"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This project is developed and maintained by the [RISC-V team][team].
1212

1313
## Minimum Supported Rust Version (MSRV)
1414

15-
This crate is guaranteed to compile on stable Rust 1.59 and up. It *might*
15+
This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
1616
compile with older versions but that may change in any new patch release.
1717

1818
## License

src/delay.rs

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,30 @@
11
//! Delay devices and providers
22
use crate::register::mcycle;
3-
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
3+
use embedded_hal::delay::DelayUs;
44

55
/// Machine mode cycle counter (`mcycle`) as a delay provider
66
#[derive(Copy, Clone)]
7+
#[repr(transparent)]
78
pub struct McycleDelay {
9+
/// The clock speed of the core, in Hertz
810
ticks_second: u32,
911
}
1012

1113
impl McycleDelay {
1214
/// Constructs the delay provider.
1315
/// `ticks_second` should be the clock speed of the core, in Hertz
14-
#[inline(always)]
15-
pub fn new(ticks_second: u32) -> Self {
16+
#[inline]
17+
pub const fn new(ticks_second: u32) -> Self {
1618
Self { ticks_second }
1719
}
1820
}
1921

20-
impl DelayUs<u64> for McycleDelay {
22+
impl DelayUs for McycleDelay {
2123
#[inline]
22-
fn delay_us(&mut self, us: u64) {
24+
fn delay_us(&mut self, us: u32) {
2325
let t0 = mcycle::read64();
24-
let clock = (us * (self.ticks_second as u64)) / 1_000_000;
26+
let us_64: u64 = us.into();
27+
let clock = (us_64 * (self.ticks_second as u64)) / 1_000_000u64;
2528
while mcycle::read64().wrapping_sub(t0) <= clock {}
2629
}
2730
}
28-
29-
impl DelayUs<u32> for McycleDelay {
30-
#[inline(always)]
31-
fn delay_us(&mut self, us: u32) {
32-
self.delay_us(us as u64)
33-
}
34-
}
35-
36-
// Implemented for constructions like `delay.delay_us(50_000);`
37-
impl DelayUs<i32> for McycleDelay {
38-
#[inline(always)]
39-
fn delay_us(&mut self, us: i32) {
40-
assert!(us >= 0);
41-
self.delay_us(us as u32);
42-
}
43-
}
44-
45-
impl DelayUs<u16> for McycleDelay {
46-
#[inline(always)]
47-
fn delay_us(&mut self, us: u16) {
48-
self.delay_us(us as u32)
49-
}
50-
}
51-
52-
impl DelayUs<u8> for McycleDelay {
53-
#[inline(always)]
54-
fn delay_us(&mut self, us: u8) {
55-
self.delay_us(us as u32)
56-
}
57-
}
58-
59-
impl DelayMs<u32> for McycleDelay {
60-
#[inline]
61-
fn delay_ms(&mut self, ms: u32) {
62-
self.delay_us((ms as u64) * 1000)
63-
}
64-
}
65-
66-
// Implemented for constructions like `delay.delay_ms(50_000);`
67-
impl DelayMs<i32> for McycleDelay {
68-
#[inline(always)]
69-
fn delay_ms(&mut self, ms: i32) {
70-
assert!(ms >= 0);
71-
self.delay_ms(ms as u32);
72-
}
73-
}
74-
75-
impl DelayMs<u16> for McycleDelay {
76-
#[inline(always)]
77-
fn delay_ms(&mut self, ms: u16) {
78-
self.delay_ms(ms as u32)
79-
}
80-
}
81-
82-
impl DelayMs<u8> for McycleDelay {
83-
#[inline(always)]
84-
fn delay_ms(&mut self, ms: u8) {
85-
self.delay_ms(ms as u32)
86-
}
87-
}

0 commit comments

Comments
 (0)