Skip to content

Commit 2d83032

Browse files
hannobraunYatekii
authored andcommitted
Remove RtcExt
1 parent 863a3c1 commit 2d83032

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

nrf52-hal-common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub mod prelude {
2929

3030
pub use crate::clocks::ClocksExt;
3131
pub use crate::gpio::GpioExt;
32-
pub use crate::rtc::RtcExt;
3332
pub use crate::saadc::SaadcExt;
3433
pub use crate::spim::SpimExt;
3534
pub use crate::time::U32Ext;

nrf52-hal-common/src/rtc.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,18 @@ pub struct Rtc<T, M> {
2020
_mode: M,
2121
}
2222

23-
/// An extension trait for constructing the high level interface
24-
pub trait RtcExt: Deref<Target = rtc0::RegisterBlock> + Sized {
25-
// The interrupt that belongs to this RTC instance.
26-
const INTERRUPT: Interrupt;
27-
28-
fn constrain(self) -> Rtc<Self, Stopped>;
29-
}
30-
31-
macro_rules! impl_rtc_ext {
32-
($($rtc:ident,)*) => {
33-
$(
34-
impl RtcExt for $rtc {
35-
const INTERRUPT: Interrupt = Interrupt::$rtc;
36-
37-
fn constrain(self) -> Rtc<$rtc, Stopped> {
38-
Rtc {
39-
periph: self,
40-
_mode: Stopped,
41-
}
42-
}
43-
}
44-
)+
23+
impl<T> Rtc<T, Stopped>
24+
where
25+
T: Instance,
26+
{
27+
pub fn new(rtc: T) -> Self {
28+
Rtc {
29+
periph: rtc,
30+
_mode: Stopped,
31+
}
4532
}
4633
}
4734

48-
impl_rtc_ext!(RTC0, RTC1,);
49-
50-
#[cfg(not(feature = "52810"))]
51-
impl_rtc_ext!(RTC2,);
52-
5335
/// Interrupts/Events that can be generated by the RTCn peripheral
5436
pub enum RtcInterrupt {
5537
Tick,
@@ -70,7 +52,7 @@ pub enum RtcCompareReg {
7052

7153
impl<T, M> Rtc<T, M>
7254
where
73-
T: RtcExt,
55+
T: Instance,
7456
{
7557
/// Enable/start the Real Time Counter
7658
pub fn enable_counter(self) -> Rtc<T, Started> {
@@ -221,7 +203,7 @@ pub enum Error {
221203

222204
impl<T> Rtc<T, Stopped>
223205
where
224-
T: RtcExt,
206+
T: Instance,
225207
{
226208
/// Set the prescaler for the RTC peripheral. 12 bits of range.
227209
/// fRTC = 32_768 / (`prescaler` + 1 )
@@ -235,3 +217,25 @@ where
235217
Ok(())
236218
}
237219
}
220+
221+
222+
/// Implemented by all RTC instances
223+
pub trait Instance: Deref<Target = rtc0::RegisterBlock> {
224+
/// This interrupt associated with this RTC instance
225+
const INTERRUPT: Interrupt;
226+
}
227+
228+
macro_rules! impl_instance {
229+
($($name:ident,)*) => {
230+
$(
231+
impl Instance for $name {
232+
const INTERRUPT: Interrupt = Interrupt::$name;
233+
}
234+
)*
235+
}
236+
}
237+
238+
impl_instance!(RTC0, RTC1,);
239+
240+
#[cfg(not(feature = "52810"))]
241+
impl_instance!(RTC2,);

0 commit comments

Comments
 (0)