Skip to content

Commit bc1eaa0

Browse files
committed
Remove timer module, fugit & void deps
Removal lets us drop two direct dependencies. Nowadays, I think this module adds more complexity than it's worth, particularly when folks can write their own blocking delays against the drivers. I had no plans to add embedded-hal 1.0 support for these, so I figure removing them altogether would be more consistent than not supporting the newer traits.
1 parent a527abc commit bc1eaa0

9 files changed

Lines changed: 70 additions & 696 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ are still exposed when building with a chip feature.
5858
- `snvs`
5959
- `timer`
6060

61+
**BREAKING** Remove the `timer` module, including most embedded-hal 0.2 blocking
62+
delay implementations.
63+
6164
Introduce an `imxrt1180` feature to support the RT1180 series.
6265

6366
Add a `defmt` feature targeting version 0.3. When enabled, select imxrt-hal

Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ version = "1.0"
2424
[dependencies.bitflags]
2525
version = "1.3"
2626

27-
[dependencies.fugit]
28-
version = "0.3"
29-
30-
# For EH02 CountDown.
31-
[dependencies.void]
32-
version = "1"
33-
default-features = false
34-
3527
[dependencies.nb]
3628
version = "1"
3729

examples/hal_i2c_lcd1602.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,60 @@
1010
use board::lcd1602::*;
1111
use imxrt_hal as hal;
1212

13+
use hal::gpt::{Gpt, Mode, OutputCompareRegister};
14+
1315
const LCD_ADDRESS: u8 = 0x7c >> 1;
1416
const RGB_ADDRESS: u8 = 0xc4 >> 1;
1517

18+
/// A blocking delay adapter over a GPT timer.
19+
struct GptDelay {
20+
gpt: Gpt,
21+
ticks_per_ms: u32,
22+
}
23+
24+
impl GptDelay {
25+
fn new(mut gpt: Gpt, frequency_hz: u32) -> Self {
26+
gpt.disable();
27+
gpt.clear_rollover();
28+
gpt.set_rollover_interrupt_enable(false);
29+
gpt.set_mode(Mode::Restart);
30+
gpt.set_reset_on_enable(true);
31+
for ocr in [
32+
OutputCompareRegister::OCR1,
33+
OutputCompareRegister::OCR2,
34+
OutputCompareRegister::OCR3,
35+
] {
36+
gpt.clear_elapsed(ocr);
37+
gpt.set_output_interrupt_on_compare(ocr, false);
38+
}
39+
Self {
40+
gpt,
41+
ticks_per_ms: frequency_hz / 1_000,
42+
}
43+
}
44+
45+
fn block_ms(&mut self, ms: u32) {
46+
let ticks = self.ticks_per_ms.saturating_mul(ms);
47+
let ocr = OutputCompareRegister::OCR1;
48+
self.gpt.set_output_compare_count(ocr, ticks);
49+
self.gpt.enable();
50+
while !self.gpt.is_elapsed(ocr) {}
51+
self.gpt.clear_elapsed(ocr);
52+
self.gpt.disable();
53+
}
54+
}
55+
56+
impl eh02::blocking::delay::DelayMs<u16> for GptDelay {
57+
fn delay_ms(&mut self, ms: u16) {
58+
self.block_ms(ms as u32);
59+
}
60+
}
61+
1662
#[imxrt_rt::entry]
1763
fn main() -> ! {
1864
let (board::Common { gpt1, .. }, board::Specifics { i2c, .. }) = board::new();
1965

20-
let mut delay = hal::timer::Blocking::<_, { board::GPT1_FREQUENCY }>::from_gpt(gpt1);
66+
let mut delay = GptDelay::new(gpt1, board::GPT1_FREQUENCY);
2167
let mut lcd = Lcd::new(i2c, LCD_ADDRESS, RGB_ADDRESS, &mut delay).unwrap();
2268

2369
lcd.set_cursor(Cursor::On).unwrap();

examples/rtic_gpio_input.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
//!
33
//! It uses your board's button to react to falling edges.
44
//! The LED's state changes every time you press the button.
5-
//! A timer provides a little wait for debounce.
5+
//! A PIT channel provides a little wait for debounce.
66
77
#![no_std]
88
#![no_main]
99

1010
#[rtic::app(device = board, peripherals = false)]
1111
mod app {
12-
use hal::{gpio::Trigger, pit::Channel, timer::BlockingPit};
12+
use hal::gpio::Trigger;
13+
use hal::pit::{Channel, Pit};
1314
use imxrt_hal as hal;
1415

1516
#[shared]
@@ -19,7 +20,7 @@ mod app {
1920
struct Local {
2021
led: board::Led,
2122
button: board::Button,
22-
delay: BlockingPit<{ board::PIT_FREQUENCY }>,
23+
pit: Pit,
2324
}
2425

2526
#[init]
@@ -34,22 +35,29 @@ mod app {
3435
},
3536
) = board::new();
3637
led.set();
37-
let delay = BlockingPit::from_pit(pit, Channel::Chan2);
3838
let button_port = ports.button_mut();
3939
button_port
4040
.set_interrupt(&button, Some(Trigger::FallingEdge))
4141
.unwrap();
42-
(Shared {}, Local { led, button, delay })
42+
(Shared {}, Local { led, button, pit })
4343
}
4444

45-
#[task(binds = BOARD_BUTTON, local = [led, delay, button])]
45+
#[task(binds = BOARD_BUTTON, local = [led, pit, button])]
4646
fn button_press(cx: button_press::Context) {
47-
let delay = cx.local.delay;
47+
let pit = cx.local.pit;
4848
let led = cx.local.led;
4949
let button = cx.local.button;
5050

5151
led.toggle();
5252
button.clear_triggered();
53-
delay.block_us(1000);
53+
54+
// Simple blocking delay for debounce using PIT channel 2.
55+
let channel = Channel::Chan2;
56+
let ticks = board::PIT_FREQUENCY / 1_000; // 1 ms
57+
pit.set_load_timer_value(channel, ticks);
58+
pit.enable(channel);
59+
while !pit.is_elapsed(channel) {}
60+
pit.clear_elapsed(channel);
61+
pit.disable(channel);
5462
}
5563
}

0 commit comments

Comments
 (0)