Skip to content

Commit

Permalink
RTC alarm & calibration output (#129)
Browse files Browse the repository at this point in the history
* rtc alarm & calibration output

* update RTC Alarm api

* clippy fixes

* add mask operations for RTC Alarm

* rtc alarms cleanup
  • Loading branch information
dotcypress authored Dec 1, 2022
1 parent 83dd084 commit afce1be
Show file tree
Hide file tree
Showing 2 changed files with 301 additions and 51 deletions.
45 changes: 19 additions & 26 deletions src/rcc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ impl Rcc {

pub(crate) fn enable_lse(&self, bypass: bool) {
self.bdcr
.modify(|_, w| w.lseon().set_bit().lsebyp().bit(bypass));
while self.bdcr.read().lserdy().bit_is_clear() {}
.modify(|_, w| w.lseon().bit(!bypass).lsebyp().bit(bypass));
while !bypass && self.bdcr.read().lserdy().bit_is_clear() {}
}

pub(crate) fn enable_lsi(&self) {
Expand All @@ -305,34 +305,18 @@ impl Rcc {
}

pub(crate) fn enable_rtc(&self, src: RTCSrc) {
let rtc_sel = match src {
RTCSrc::LSE => {
self.enable_lse(false);
0b01
}
RTCSrc::LSE_BYPASS => {
self.enable_lse(true);
0b01
}
RTCSrc::LSI => {
self.enable_lsi();
0b10
}
RTCSrc::HSE => {
self.enable_hse(false);
0b11
}
RTCSrc::HSE_BYPASS => {
self.enable_hse(true);
0b11
}
};

self.unlock_rtc();
self.apbenr1
.modify(|_, w| w.rtcapben().set_bit().pwren().set_bit());
self.apbsmenr1.modify(|_, w| w.rtcapbsmen().set_bit());
self.unlock_rtc();
self.bdcr.modify(|_, w| w.bdrst().set_bit());

let rtc_sel = match src {
RTCSrc::LSE | RTCSrc::LSE_BYPASS => 0b01,
RTCSrc::LSI => 0b10,
RTCSrc::HSE | RTCSrc::HSE_BYPASS => 0b11,
};

self.bdcr.modify(|_, w| unsafe {
w.rtcsel()
.bits(rtc_sel)
Expand All @@ -341,6 +325,15 @@ impl Rcc {
.bdrst()
.clear_bit()
});

self.unlock_rtc();
match src {
RTCSrc::LSE => self.enable_lse(false),
RTCSrc::LSE_BYPASS => self.enable_lse(true),
RTCSrc::LSI => self.enable_lsi(),
RTCSrc::HSE => self.enable_hse(false),
RTCSrc::HSE_BYPASS => self.enable_hse(true),
};
}
}

Expand Down
Loading

0 comments on commit afce1be

Please sign in to comment.