Skip to content

Commit 4c8a20b

Browse files
careyk007hannobraun
authored andcommitted
updating for backwards compatibility
1 parent 1b94b42 commit 4c8a20b

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

nrf52-hal-common/src/timer.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::target::{TIMER3, TIMER4};
1919

2020
use core::marker::PhantomData;
2121

22-
pub struct OneShotTimer;
23-
pub struct PeriodicTimer;
22+
pub struct OneShot;
23+
pub struct Periodic;
2424

2525

2626
/// Interface to a TIMER instance
@@ -30,13 +30,17 @@ pub struct PeriodicTimer;
3030
///
3131
/// CC[0] is used for the current/most-recent delay period and CC[1] is used
3232
/// to grab the current value of the counter at a given instant.
33-
pub struct Timer<T, U>(T, PhantomData<U>);
33+
pub struct BaseTimer<T, U>(T, PhantomData<U>);
3434

35-
impl<T> Timer<T, OneShotTimer>
35+
pub type Timer<T> = BaseTimer<T, OneShot>;
36+
pub type PeriodicTimer<T> = BaseTimer<T, Periodic>;
37+
pub type OneShotTimer<T> = BaseTimer<T, OneShot>;
38+
39+
impl<T> OneShotTimer<T>
3640
where
3741
T: Instance,
3842
{
39-
pub fn new(timer: T) -> Timer<T, OneShotTimer> {
43+
pub fn new(timer: T) -> OneShotTimer<T> {
4044
timer
4145
.shorts
4246
.write(|w| w.compare0_clear().enabled().compare0_stop().enabled());
@@ -45,22 +49,23 @@ where
4549
);
4650
timer.bitmode.write(|w| w.bitmode()._32bit());
4751

48-
Timer::<T, OneShotTimer>(timer, PhantomData)
52+
BaseTimer::<T, OneShot>(timer, PhantomData)
4953
}
5054

51-
pub fn into_periodic(self) -> Timer<T, PeriodicTimer> {
55+
pub fn into_periodic(self) -> PeriodicTimer<T> {
5256
self.0
5357
.shorts
5458
.write(|w| w.compare0_clear().enabled().compare0_stop().disabled());
55-
Timer::<T, PeriodicTimer>(self.free(), PhantomData)
59+
60+
BaseTimer::<T, Periodic>(self.free(), PhantomData)
5661
}
5762
}
5863

59-
impl<T> Timer<T, PeriodicTimer>
64+
impl<T> PeriodicTimer<T>
6065
where
6166
T: Instance,
6267
{
63-
pub fn new_periodic(timer: T) -> Timer<T, PeriodicTimer> {
68+
pub fn new_periodic(timer: T) -> PeriodicTimer<T> {
6469
timer
6570
.shorts
6671
.write(|w| w.compare0_clear().enabled().compare0_stop().disabled());
@@ -69,18 +74,19 @@ where
6974
);
7075
timer.bitmode.write(|w| w.bitmode()._32bit());
7176

72-
Timer::<T, PeriodicTimer>(timer, PhantomData)
77+
BaseTimer::<T, Periodic>(timer, PhantomData)
7378
}
7479

75-
pub fn into_oneshot(self) -> Timer<T, OneShotTimer> {
80+
pub fn into_oneshot(self) -> OneShotTimer<T> {
7681
self.0
7782
.shorts
7883
.write(|w| w.compare0_clear().enabled().compare0_stop().enabled());
79-
Timer::<T, OneShotTimer>(self.free(), PhantomData)
84+
85+
BaseTimer::<T, OneShot>(self.free(), PhantomData)
8086
}
8187
}
8288

83-
impl<T, U> Timer<T, U>
89+
impl<T, U> BaseTimer<T, U>
8490
where
8591
T: Instance,
8692
{
@@ -144,7 +150,7 @@ where
144150
}
145151
}
146152

147-
impl<T, U> timer::CountDown for Timer<T, U>
153+
impl<T, U> timer::CountDown for BaseTimer<T, U>
148154
where
149155
T: Instance,
150156
{
@@ -205,7 +211,7 @@ where
205211
}
206212
}
207213

208-
impl<T, U> timer::Cancel for Timer<T, U>
214+
impl<T, U> timer::Cancel for BaseTimer<T, U>
209215
where
210216
T: Instance,
211217
{
@@ -219,7 +225,7 @@ where
219225
}
220226
}
221227

222-
impl<T> timer::Periodic for Timer<T, PeriodicTimer>
228+
impl<T> timer::Periodic for PeriodicTimer<T>
223229
where
224230
T: Instance,
225231
{}

nrf52-hal-common/src/uarte.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::gpio::{
3333
Input,
3434
Floating,
3535
};
36-
use crate::timer::{self, Timer, OneShotTimer};
36+
use crate::timer::{self, Timer};
3737

3838
// Re-export SVD variants to allow user to directly set values
3939
pub use uarte0::{
@@ -236,7 +236,7 @@ impl<T> Uarte<T> where T: Instance {
236236
pub fn read_timeout<I>(
237237
&mut self,
238238
rx_buffer: &mut [u8],
239-
timer: &mut Timer<I, OneShotTimer>,
239+
timer: &mut Timer<I>,
240240
cycles: u32
241241
) -> Result<(), Error> where I: timer::Instance
242242
{

0 commit comments

Comments
 (0)