1#![allow(missing_docs)]
3
4use e310x::Rtc as RTC;
5
6pub trait RtcExt {
7 fn constrain(self) -> Rtc;
8}
9
10impl RtcExt for RTC {
11 fn constrain(self) -> Rtc {
12 Rtc { _0: () }
13 }
14}
15
16pub struct Rtc {
17 _0: (),
18}
19
20impl Rtc {
21 #[inline]
22 pub fn is_pending(&self) -> bool {
23 unsafe { RTC::steal() }.rtccfg().read().cmpip().bit()
24 }
25
26 #[inline]
27 pub fn set_scale(&mut self, scale: u8) {
28 unsafe { RTC::steal().rtccfg().modify(|_, w| w.scale().bits(scale)) };
29 }
30
31 #[inline]
32 pub fn enable(&mut self) {
33 unsafe { RTC::steal() }
34 .rtccfg()
35 .modify(|_, w| w.enalways().bit(true));
36 }
37
38 #[inline]
39 pub fn disable(&mut self) {
40 unsafe { RTC::steal() }
41 .rtccfg()
42 .modify(|_, w| w.enalways().bit(false));
43 }
44
45 #[inline]
46 pub fn is_enabled(&self) -> bool {
47 unsafe { RTC::steal() }.rtccfg().read().enalways().bit()
48 }
49
50 #[inline]
51 pub fn rtc_lo(&self) -> u32 {
52 unsafe { RTC::steal() }.rtclo().read().bits()
53 }
54
55 #[inline]
56 pub fn rtc_hi(&self) -> u32 {
57 unsafe { RTC::steal() }.rtchi().read().bits()
58 }
59
60 pub fn rtc(&self) -> u64 {
61 loop {
62 let hi = self.rtc_hi();
63 let lo = self.rtc_lo();
64 if hi == self.rtc_hi() {
65 return ((hi as u64) << 32) | lo as u64;
66 }
67 }
68 }
69
70 #[inline]
71 pub fn set_rtc_lo(&mut self, value: u32) {
72 unsafe { RTC::steal().rtclo().write(|w| w.bits(value)) };
73 }
74
75 #[inline]
76 pub fn set_rtc_hi(&mut self, value: u16) {
77 unsafe { RTC::steal().rtchi().write(|w| w.value().bits(value)) };
78 }
79
80 pub fn set_rtc(&mut self, value: u64) {
81 self.set_rtc_hi((value >> 32) as u16);
82 self.set_rtc_lo(value as u32);
83 }
84
85 #[inline]
86 pub fn rtccmp(&self) -> u32 {
87 unsafe { RTC::steal() }.rtccmp().read().bits()
88 }
89
90 #[inline]
91 pub fn set_rtccmp(&mut self, value: u32) {
92 unsafe { RTC::steal().rtccmp().write(|w| w.bits(value)) };
93 }
94}