Skip to content

Commit ee93f53

Browse files
committed
Don't go into init mode when reading the clock. Tested in release. removed assertion for delay_us, this is something that needs to come back but atm causing issues
1 parent 5abebff commit ee93f53

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

src/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl DelayUs<u32> for Delay {
4949
fn delay_us(&mut self, us: u32) {
5050
let rvr = us * (self.clocks.sysclk().0 / 1_000_000);
5151

52-
assert!(rvr < (1 << 24));
52+
// assert!(rvr < (1 << 24)); //TODO fix this assertion
5353

5454
self.syst.set_reload(rvr);
5555
self.syst.clear_current();

src/rtc.rs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use stm32l4::stm32l4x2::{RTC};
77

88
#[derive(Clone,Copy,Debug)]
99
pub struct Time {
10-
hours: u8,
11-
minutes: u8,
12-
seconds: u8,
13-
daylight_savings: bool
10+
pub hours: u8,
11+
pub minutes: u8,
12+
pub seconds: u8,
13+
pub daylight_savings: bool
1414
}
1515

1616
impl Time {
@@ -26,10 +26,10 @@ impl Time {
2626

2727
#[derive(Clone,Copy,Debug)]
2828
pub struct Date {
29-
day: u8,
30-
date: u8,
31-
month: u8,
32-
year: u16,
29+
pub day: u8,
30+
pub date: u8,
31+
pub month: u8,
32+
pub year: u16,
3333
}
3434

3535
impl Date {
@@ -152,19 +152,14 @@ impl Rtc {
152152

153153
pub fn get_time(&self) -> Time {
154154
let time;
155-
write_protection(&self.rtc, false);
156-
{
157-
init_mode(&self.rtc, true);
158-
{
159-
let timer = self.rtc.tr.read();
160-
let cr = self.rtc.cr.read();
161-
time = Time::new(bcd2_to_byte((timer.ht().bits(), timer.hu().bits())),
162-
bcd2_to_byte((timer.mnt().bits(), timer.mnu().bits())),
163-
bcd2_to_byte((timer.st().bits(), timer.su().bits())),
164-
cr.fmt().bit());
165-
}
166-
init_mode(&self.rtc, false);
167-
}
155+
156+
let timer = self.rtc.tr.read();
157+
let cr = self.rtc.cr.read();
158+
time = Time::new(bcd2_to_byte((timer.ht().bits(), timer.hu().bits())),
159+
bcd2_to_byte((timer.mnt().bits(), timer.mnu().bits())),
160+
bcd2_to_byte((timer.st().bits(), timer.su().bits())),
161+
cr.fmt().bit());
162+
168163
write_protection(&self.rtc, true);
169164

170165
time
@@ -198,22 +193,12 @@ impl Rtc {
198193

199194
pub fn get_date(&self) -> Date {
200195
let date;
201-
write_protection(&self.rtc, false);
202-
{
203-
init_mode(&self.rtc, true);
204-
{
205-
let dater = self.rtc.dr.read();
206-
let (yt, yu) = (dater.yt().bits(), dater.yu().bits());
207-
date = Date::new(dater.wdu().bits(),
208-
bcd2_to_byte((dater.dt().bits(), dater.du().bits())),
209-
bcd2_to_byte((dater.mt().bit() as u8, dater.mu().bits())),
210-
(bcd2_to_byte((dater.yt().bits(), dater.yu().bits())) as u16 + 1970_u16) as u16,
211-
);
212-
}
213-
init_mode(&self.rtc, false);
214-
}
215-
write_protection(&self.rtc, true);
216196

197+
let dater = self.rtc.dr.read();
198+
date = Date::new(dater.wdu().bits(),
199+
bcd2_to_byte((dater.dt().bits(), dater.du().bits())),
200+
bcd2_to_byte((dater.mt().bit() as u8, dater.mu().bits())),
201+
(bcd2_to_byte((dater.yt().bits(), dater.yu().bits())) as u16 + 1970_u16) as u16);
217202
date
218203
}
219204

0 commit comments

Comments
 (0)