Skip to content

Commit 478988f

Browse files
committed
Fix clippy warnings about old chrono API
Also prints which RTC it found.
1 parent aaedb42 commit 478988f

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ embedded-sdmmc = { version = "0.6", default-features = false, features = [
6262
] }
6363
# CODEC register control
6464
tlv320aic23 = "0.1.0"
65+
# Calendar/Date/Time functions and types
66+
chrono = { version = "0.4.38", default-features = false }
6567

6668
[build-dependencies]
6769
neotron-common-bios = "0.12.0"

src/main.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ use core::{
6868
};
6969

7070
// Third Party Stuff
71+
use chrono::DateTime;
7172
use defmt::info;
7273
use defmt_rtt as _;
73-
use ds1307::{Datelike, NaiveDateTime, Timelike};
74+
use ds1307::{Datelike, Timelike};
7475
use embedded_hal::{
7576
blocking::i2c::{
7677
Read as _I2cRead, WriteIter as _I2cWriteIter, WriteIterRead as _I2cWriteIterRead,
@@ -677,6 +678,19 @@ fn sign_on() {
677678
false,
678679
));
679680

681+
let _ = writeln!(&tc);
682+
683+
// Show the time.
684+
if let Some(hw) = HARDWARE.lock().as_mut() {
685+
if let Some(rtc_kind) = hw.rtc.get_kind() {
686+
let _ = writeln!(&tc, "RTC : Found {}", rtc_kind);
687+
} else {
688+
let _ = writeln!(&tc, "RTC : None");
689+
}
690+
}
691+
692+
// Do a delay.
693+
//
680694
// This is in 100ms units
681695
let mut countdown = 15;
682696
loop {
@@ -707,7 +721,7 @@ fn sign_on() {
707721
}
708722
}
709723

710-
write!(&tc, "Now starting OS (if present)...").unwrap();
724+
write!(&tc, "Looking for OS at 0x1002_0000....").unwrap();
711725
}
712726

713727
/// Paint the Core 0 and Core 1 stacks
@@ -897,8 +911,8 @@ impl Hardware {
897911
time.minute(),
898912
time.second()
899913
);
900-
let ticks_at_boot_us =
901-
time.timestamp_micros() - (SECONDS_BETWEEN_UNIX_AND_NEOTRON_EPOCH * 1_000_000);
914+
let ticks_at_boot_us = time.and_utc().timestamp_micros()
915+
- (SECONDS_BETWEEN_UNIX_AND_NEOTRON_EPOCH * 1_000_000);
902916
defmt::info!("Ticks at boot: {}", ticks_at_boot_us);
903917
ticks_at_boot_us
904918
}
@@ -1745,12 +1759,12 @@ pub extern "C" fn time_clock_set(time: common::Time) {
17451759
hw.bootup_at = ticks_at_boot;
17461760

17471761
// 5. Convert to calendar time
1748-
if let Some(new_time) = NaiveDateTime::from_timestamp_opt(
1762+
if let Some(new_time) = DateTime::from_timestamp(
17491763
i64::from(time.secs) + SECONDS_BETWEEN_UNIX_AND_NEOTRON_EPOCH,
17501764
time.nsecs,
17511765
) {
17521766
// 6. Update the hardware RTC as well
1753-
match hw.rtc.set_time(hw.i2c.acquire_i2c(), new_time) {
1767+
match hw.rtc.set_time(hw.i2c.acquire_i2c(), new_time.naive_utc()) {
17541768
Ok(_) => {
17551769
defmt::info!("Time set in RTC OK");
17561770
}

src/rtc.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@ impl Rtc {
240240
Self::None => Err(Error::NoRtcFound),
241241
}
242242
}
243+
244+
/// Get the name of the RTC we found
245+
///
246+
/// Returns `None` if no RTC was found
247+
pub fn get_kind(&self) -> Option<&'static str> {
248+
match self {
249+
Self::Ds1307 => Some("DS1307"),
250+
Self::Mcp7940n => Some("MCP7940N"),
251+
Self::None => None,
252+
}
253+
}
243254
}
244255

245256
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)