Skip to content

Commit f2bf323

Browse files
hannobraunYatekii
authored andcommitted
Remove TimerExt
1 parent bf89b5e commit f2bf323

File tree

10 files changed

+40
-46
lines changed

10 files changed

+40
-46
lines changed

boards/adafruit-nrf52-bluefruit-le/examples/blinky.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use adafruit_nrf52_bluefruit_le::{prelude::*, Board};
99
use core::fmt::Write;
1010
use cortex_m_rt::{entry, exception, ExceptionFrame};
1111
use nb::block;
12-
use nrf52832_hal::Timer;
12+
use nrf52832_hal::timer::{self, Timer};
1313

1414

1515
#[entry]
1616
fn main() -> ! {
1717
let mut b = Board::take().unwrap();
1818

19-
let mut timer = b.TIMER4.constrain();
19+
let mut timer = Timer::new(b.TIMER4);
2020

2121
b.leds.red.disable();
2222
b.leds.blue.disable();
@@ -65,7 +65,7 @@ fn main() -> ! {
6565

6666
fn delay<T>(timer: &mut Timer<T>, cycles: u32)
6767
where
68-
T: TimerExt,
68+
T: timer::Instance,
6969
{
7070
timer.start(cycles);
7171
block!(timer.wait()).unwrap();

boards/adafruit_nrf52pro/examples/blinky.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use panic_semihosting;
1010
use adafruit_nrf52pro_bsc::hal::{
1111
prelude::*,
1212
gpio::Level,
13-
timer::Timer,
13+
timer::{self, Timer},
1414
};
1515
use adafruit_nrf52pro_bsc::nrf52832_pac::{Peripherals};
1616
use adafruit_nrf52pro_bsc::Pins;
@@ -24,7 +24,7 @@ fn main() -> ! {
2424
let mut led1 = pins.led1.into_push_pull_output(Level::Low);
2525
let mut led2 = pins.led2.into_push_pull_output(Level::Low);
2626

27-
let mut timer = p.TIMER0.constrain();
27+
let mut timer = Timer::new(p.TIMER0);
2828

2929
// Alternately flash the red and blue leds
3030
loop {
@@ -39,7 +39,7 @@ fn main() -> ! {
3939

4040
fn delay<T>(timer: &mut Timer<T>, cycles: u32)
4141
where
42-
T: TimerExt,
42+
T: timer::Instance,
4343
{
4444
timer.start(cycles);
4545
block!(timer.wait());

boards/nRF52-DK/examples/blinky.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ extern crate panic_semihosting;
66
extern crate nrf52_dk_bsp as dk;
77
extern crate nb;
88

9-
use dk::{ Board, prelude::* };
9+
use dk::{ Board, prelude::*, nrf52832_hal::Timer };
1010
use rt::entry;
1111
use nb::block;
1212

1313
#[entry]
1414
fn main() -> ! {
1515
let mut board = Board::take().unwrap();
1616

17-
let mut timer = board.TIMER0.constrain();
17+
let mut timer = Timer::new(board.TIMER0);
1818

1919
let mut led_is_on = false;
2020
loop {

boards/nRF52-DK/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extern crate cortex_m;
77

88
extern crate cortex_m_rt;
9-
extern crate nrf52832_hal;
9+
pub extern crate nrf52832_hal;
1010

1111
/// Exports traits that are usually needed when using this crate
1212
pub mod prelude {

boards/nRF52840-DK/examples/blinky.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use panic_semihosting;
1010
use nrf52840_dk_bsp::{
1111
hal::{
1212
prelude::*,
13-
timer::Timer,
13+
timer::{self, Timer},
1414
},
1515
Board,
1616
};
@@ -20,7 +20,7 @@ use nrf52840_dk_bsp::{
2020
fn main() -> ! {
2121
let mut nrf52 = Board::take().unwrap();
2222

23-
let mut timer = nrf52.TIMER0.constrain();
23+
let mut timer = Timer::new(nrf52.TIMER0);
2424

2525
// Alternately flash the red and blue leds
2626
loop {
@@ -33,7 +33,7 @@ fn main() -> ! {
3333

3434
fn delay<T>(timer: &mut Timer<T>, cycles: u32)
3535
where
36-
T: TimerExt,
36+
T: timer::Instance,
3737
{
3838
timer.start(cycles);
3939
let _ = block!(timer.wait());

nrf52-hal-common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub mod prelude {
3030
pub use crate::clocks::ClocksExt;
3131
pub use crate::gpio::GpioExt;
3232
pub use crate::time::U32Ext;
33-
pub use crate::timer::TimerExt;
3433
pub use crate::twim::TwimExt;
3534
pub use crate::uarte::UarteExt;
3635
}

nrf52-hal-common/src/timer.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,6 @@ use void::{unreachable, Void};
1212
#[cfg(any(feature = "52832", feature = "52840"))]
1313
use crate::target::{TIMER3, TIMER4};
1414

15-
pub trait TimerExt: Deref<Target = timer0::RegisterBlock> + Sized {
16-
// The interrupt that belongs to this timer instance
17-
const INTERRUPT: Interrupt;
18-
19-
fn constrain(self) -> Timer<Self>;
20-
}
21-
22-
macro_rules! impl_timer_ext {
23-
($($timer:tt,)*) => {
24-
$(
25-
impl TimerExt for $timer {
26-
const INTERRUPT: Interrupt = Interrupt::$timer;
27-
28-
fn constrain(self) -> Timer<Self> {
29-
Timer::new(self)
30-
}
31-
}
32-
)*
33-
}
34-
}
35-
36-
impl_timer_ext!(TIMER0, TIMER1, TIMER2,);
37-
38-
#[cfg(any(feature = "52832", feature = "52840"))]
39-
impl_timer_ext!(TIMER3, TIMER4,);
4015

4116
/// Interface to a TIMER instance
4217
///
@@ -46,9 +21,9 @@ pub struct Timer<T>(T);
4621

4722
impl<T> Timer<T>
4823
where
49-
T: TimerExt,
24+
T: Instance,
5025
{
51-
fn new(timer: T) -> Self {
26+
pub fn new(timer: T) -> Self {
5227
timer
5328
.shorts
5429
.write(|w| w.compare0_clear().enabled().compare0_stop().enabled());
@@ -102,7 +77,7 @@ where
10277

10378
impl<T> timer::CountDown for Timer<T>
10479
where
105-
T: TimerExt,
80+
T: Instance,
10681
{
10782
type Time = u32;
10883

@@ -151,7 +126,7 @@ where
151126

152127
impl<T> timer::Cancel for Timer<T>
153128
where
154-
T: TimerExt,
129+
T: Instance,
155130
{
156131
type Error = ();
157132

@@ -162,3 +137,25 @@ where
162137
Ok(())
163138
}
164139
}
140+
141+
142+
/// Implemented by all `TIMER` instances
143+
pub trait Instance: Deref<Target = timer0::RegisterBlock> {
144+
/// This interrupt associated with this RTC instance
145+
const INTERRUPT: Interrupt;
146+
}
147+
148+
macro_rules! impl_instance {
149+
($($name:ident,)*) => {
150+
$(
151+
impl Instance for $name {
152+
const INTERRUPT: Interrupt = Interrupt::$name;
153+
}
154+
)*
155+
}
156+
}
157+
158+
impl_instance!(TIMER0, TIMER1, TIMER2,);
159+
160+
#[cfg(any(feature = "52832", feature = "52840"))]
161+
impl_instance!(TIMER3, TIMER4,);

nrf52-hal-common/src/uarte.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::gpio::{
2222
Input,
2323
Floating,
2424
};
25-
use crate::timer::Timer;
25+
use crate::timer::{self, Timer};
2626

2727
// Re-export SVD variants to allow user to directly set values
2828
pub use crate::target::uarte0::{
@@ -216,7 +216,7 @@ impl<T> Uarte<T> where T: UarteExt {
216216
rx_buffer: &mut [u8],
217217
timer: &mut Timer<I>,
218218
cycles: u32
219-
) -> Result<(), Error> where I: TimerExt
219+
) -> Result<(), Error> where I: timer::Instance
220220
{
221221
// Start the read
222222
self.start_read(rx_buffer)?;

nrf52810-hal/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod prelude {
1111
pub use crate::clocks::ClocksExt;
1212
pub use crate::gpio::GpioExt;
1313
pub use crate::time::U32Ext;
14-
pub use crate::timer::TimerExt;
1514
pub use crate::uarte::UarteExt;
1615
}
1716

nrf52840-hal/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod prelude {
1111
pub use crate::clocks::ClocksExt;
1212
pub use crate::gpio::GpioExt;
1313
pub use crate::time::U32Ext;
14-
pub use crate::timer::TimerExt;
1514
pub use crate::uarte::UarteExt;
1615
}
1716

0 commit comments

Comments
 (0)