Skip to content

Commit 50491f5

Browse files
committed
Simplify waiter
1 parent c051a7a commit 50491f5

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
rtic-monotonic = { version = "1.0", optional = true }
6666
rtrb = { version = "0.3", default-features = false }
6767
stm32f1 = { version = "0.16", optional = true }
68-
waiter-trait = "0.5"
68+
waiter-trait = "0.6"
6969

7070
[profile.release]
7171
codegen-units = 1

examples/f103c8/src/main.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use stm32f1_hal::{
2121
time::MonoTimer,
2222
timer::*,
2323
uart::{self, UartPeriphExt},
24-
waiter_trait::{self, Counter, NonInterval, Waiter},
24+
waiter_trait::{self, Counter, prelude::*},
2525
};
2626

2727
mod led_task;
@@ -112,7 +112,7 @@ fn main() -> ! {
112112
let mut led = gpiob
113113
.pb0
114114
.into_open_drain_output_with_state(&mut gpiob.crl, PinState::High);
115-
let mut water = sys_timer.waiter_us(1.secs(), NonInterval::new());
115+
let mut water = sys_timer.waiter(1.secs());
116116
// let water = mono_timer.waiter(1.secs());
117117
let mut led_task = LedTask::new(led, water.start());
118118

@@ -173,11 +173,11 @@ fn uart_interrupt_init<U: UartPeriphExt + 'static>(
173173
mcu: &mut Mcu,
174174
timer: &SystemTimer,
175175
) -> UartPollTask<impl embedded_io::Write + 'static, impl embedded_io::Read + 'static> {
176-
let (rx, mut rx_it) = rx.into_interrupt(64, timer.waiter_us(100.micros(), NonInterval::new()));
176+
let (rx, mut rx_it) = rx.into_interrupt(64, timer.waiter(100.micros()));
177177
let (tx, mut tx_it) = tx.into_interrupt(
178178
32,
179-
timer.waiter_us(0.micros(), NonInterval::new()),
180-
timer.waiter_us(32 * 200.micros(), NonInterval::new()),
179+
timer.waiter(0.micros()),
180+
timer.waiter(32 * 200.micros()),
181181
);
182182
interrupt_callback.set(mcu, move || {
183183
rx_it.handler();
@@ -195,17 +195,13 @@ fn uart_dma_init<'r, U: UartPeriphExt + 'static>(
195195
mcu: &mut Mcu,
196196
timer: &SystemTimer,
197197
) -> UartPollTask<impl embedded_io::Write + 'static, impl embedded_io::Read + 'r> {
198-
let uart_rx = rx.into_dma_circle(
199-
dma_rx,
200-
64,
201-
timer.waiter_us(100.micros(), NonInterval::new()),
202-
);
198+
let uart_rx = rx.into_dma_circle(dma_rx, 64, timer.waiter(100.micros()));
203199
dma_tx.set_interrupt(DmaEvent::TransferComplete, true);
204200
let (uart_tx, mut tx_it) = tx.into_dma_ringbuf(
205201
dma_tx,
206202
32,
207-
timer.waiter_us(0.micros(), NonInterval::new()),
208-
timer.waiter_us(32 * 200.micros(), NonInterval::new()),
203+
timer.waiter(0.micros()),
204+
timer.waiter(32 * 200.micros()),
209205
);
210206
interrupt_callback.set(mcu, move || {
211207
tx_it.interrupt_reload();

src/time.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ use core::ops;
3333
use cortex_m::peripheral::{DCB, DWT};
3434

3535
use crate::rcc::Clocks;
36-
use waiter_trait::{Interval, TickInstant, TickWaiter};
36+
use waiter_trait::{NonInterval, TickInstant, TickWaiter};
3737

3838
/// Bits per second
3939
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Debug)]
4040
pub struct Bps(pub u32);
4141

4242
pub use fugit::{
4343
Duration, HertzU32 as Hertz, KilohertzU32 as KiloHertz, MegahertzU32 as MegaHertz,
44-
MicrosDurationU32 as MicroSeconds, MillisDurationU32 as MilliSeconds, NanosDurationU64,
44+
MicrosDurationU32 as MicroSeconds, MillisDurationU32 as MilliSeconds, NanosDurationU32,
45+
NanosDurationU64,
4546
};
4647

4748
/// Extension trait that adds convenience methods to the `u32` type
@@ -153,21 +154,16 @@ impl MonoTimer {
153154
}
154155
}
155156

156-
pub fn waiter_us<I: Interval>(
157-
&self,
158-
timeout: MicroSeconds,
159-
interval: I,
160-
) -> TickWaiter<DwtInstant, I, u32> {
161-
TickWaiter::us(timeout.ticks(), interval, self.frequency.raw())
157+
pub fn waiter(&self, timeout: NanosDurationU32) -> TickWaiter<DwtInstant, NonInterval, u32> {
158+
TickWaiter::new(timeout, NonInterval::new(), self.frequency.raw())
162159
}
163160

164-
/// It can wait longer with a nanosecond timeout.
165-
pub fn waiter_ns<I: Interval>(
161+
/// It can wait longer.
162+
pub fn waiter_u64(
166163
&self,
167164
timeout: NanosDurationU64,
168-
interval: I,
169-
) -> TickWaiter<DwtInstant, I, u64> {
170-
TickWaiter::ns(timeout.ticks(), interval, self.frequency.raw())
165+
) -> TickWaiter<DwtInstant, NonInterval, u64> {
166+
TickWaiter::new_u64(timeout, NonInterval::new(), self.frequency.raw())
171167
}
172168
}
173169

src/timer/syst.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use crate::Mcu;
55
use core::ops::{Deref, DerefMut};
66
use cortex_m::peripheral::{SYST, syst::SystClkSource};
77
use fugit::{
8-
HertzU32 as Hertz, MicrosDurationU32, NanosDurationU64, TimerDurationU32, TimerInstantU32,
8+
HertzU32 as Hertz, NanosDurationU32, NanosDurationU64, TimerDurationU32, TimerInstantU32,
99
};
10-
use waiter_trait::{Interval, TickInstant, TickWaiter};
10+
use waiter_trait::{NonInterval, TickInstant, TickWaiter};
1111

1212
pub trait SysTimerInit: Sized {
1313
/// Creates timer which takes [Hertz] as Duration
@@ -77,21 +77,19 @@ impl SystemTimer {
7777
self.syst.clear_current();
7878
}
7979

80-
pub fn waiter_us<I: Interval>(
80+
pub fn waiter(
8181
&self,
82-
timeout: MicrosDurationU32,
83-
interval: I,
84-
) -> TickWaiter<SysTickInstant, I, u32> {
85-
TickWaiter::us(timeout.ticks(), interval, self.clk.raw())
82+
timeout: NanosDurationU32,
83+
) -> TickWaiter<SysTickInstant, NonInterval, u32> {
84+
TickWaiter::new(timeout, NonInterval::new(), self.clk.raw())
8685
}
8786

88-
/// It can wait longer with a nanosecond timeout.
89-
pub fn waiter_ns<I: Interval>(
87+
/// It can wait longer.
88+
pub fn waiter_u64(
9089
&self,
9190
timeout: NanosDurationU64,
92-
interval: I,
93-
) -> TickWaiter<SysTickInstant, I, u64> {
94-
TickWaiter::ns(timeout.ticks(), interval, self.clk.raw())
91+
) -> TickWaiter<SysTickInstant, NonInterval, u64> {
92+
TickWaiter::new_u64(timeout, NonInterval::new(), self.clk.raw())
9593
}
9694
}
9795

0 commit comments

Comments
 (0)