Skip to content

Commit 5d6d0eb

Browse files
authored
Replace Date and Time types with time crate. (#310)
1 parent 8ef2415 commit 5d6d0eb

File tree

7 files changed

+70
-208
lines changed

7 files changed

+70
-208
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ version = "0.2.4"
5757
features = ["cortex-m", "fs"]
5858
optional = true
5959

60+
[dependencies.time]
61+
version = "0.3"
62+
default-features = false
63+
6064
[package.metadata.docs.rs]
6165
features = ["rt", "stm32l432", "stm32-usbd"]
6266

examples/rtc.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ extern crate panic_semihosting;
1111
extern crate stm32l4xx_hal as hal;
1212
// #[macro_use(block)]
1313
// extern crate nb;
14+
use time::{Date, Time};
1415

15-
use crate::hal::datetime::{Date, Time};
1616
use crate::hal::delay::Delay;
1717
use crate::hal::prelude::*;
1818
use crate::hal::rcc::{ClockSecuritySystem, CrystalBypass};
1919
use crate::hal::rtc::{Rtc, RtcClockSource, RtcConfig};
2020
use crate::rt::ExceptionFrame;
2121

2222
use crate::sh::hio;
23+
use core::convert::TryInto;
2324
use core::fmt::Write;
2425

2526
#[entry]
@@ -51,19 +52,19 @@ fn main() -> ! {
5152
RtcConfig::default().clock_config(RtcClockSource::LSE),
5253
);
5354

54-
let time = Time::new(21.hours(), 57.minutes(), 32.secs(), 0.micros(), false);
55-
let date = Date::new(1.day(), 24.date(), 4.month(), 2018.year());
55+
let time = Time::from_hms(21, 57, 32).unwrap();
56+
let date = Date::from_calendar_date(2018, 4.try_into().unwrap(), 24).unwrap();
5657

57-
rtc.set_date_time(date, time);
58+
rtc.set_datetime(&date.with_time(time));
5859

5960
timer.delay_ms(1000_u32);
6061
timer.delay_ms(1000_u32);
6162
timer.delay_ms(1000_u32);
6263

63-
let (rtc_date, rtc_time) = rtc.get_date_time();
64+
let rtc_datetime = rtc.get_datetime();
6465

65-
writeln!(hstdout, "Time: {:?}", rtc_time).unwrap();
66-
writeln!(hstdout, "Date: {:?}", rtc_date).unwrap();
66+
writeln!(hstdout, "Time: {:?}", rtc_datetime.time()).unwrap();
67+
writeln!(hstdout, "Date: {:?}", rtc_datetime.date()).unwrap();
6768
writeln!(hstdout, "Good bye!").unwrap();
6869
loop {
6970
continue;

examples/rtc_alarm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ extern crate cortex_m_semihosting as sh;
1010
extern crate panic_semihosting;
1111
extern crate stm32l4xx_hal as hal;
1212

13-
use crate::hal::datetime::{Date, Time};
1413
use crate::hal::prelude::*;
1514
use crate::hal::rcc::{ClockSecuritySystem, CrystalBypass};
1615
use crate::hal::rtc::{Event, Rtc, RtcClockSource, RtcConfig};
1716
use crate::rt::ExceptionFrame;
1817
use cortex_m::interrupt::{free, Mutex};
18+
use time::{Date, Time};
1919

2020
use crate::sh::hio;
21-
use core::{cell::RefCell, fmt::Write, ops::DerefMut};
21+
use core::{cell::RefCell, convert::TryInto, fmt::Write, ops::DerefMut};
2222
use hal::interrupt;
2323
use hal::pac;
2424
use pac::NVIC;
@@ -51,10 +51,10 @@ fn main() -> ! {
5151
RtcConfig::default().clock_config(RtcClockSource::LSE),
5252
);
5353

54-
let time = Time::new(21.hours(), 57.minutes(), 32.secs(), 0.micros(), false);
55-
let date = Date::new(1.day(), 24.date(), 4.month(), 2018.year());
54+
let time = Time::from_hms(21, 57, 32).unwrap();
55+
let date = Date::from_calendar_date(2018, 4.try_into().unwrap(), 24).unwrap();
5656

57-
rtc.set_date_time(date, time);
57+
rtc.set_datetime(&date.with_time(time));
5858

5959
// Set alarm A for 1 minute
6060
// let alarm_time = Time::new(21.hours(), 57.minutes(), 37.secs(), 0.micros(), false);

src/datetime.rs

Lines changed: 0 additions & 146 deletions
This file was deleted.

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This crate requires one of the following features enabled:
4444
stm32l431, stm32l451, stm32l471
4545
stm32l412, stm32l422, stm32l432, stm32l442, stm32l452, stm32l462
4646
stm32l433, stm32l443
47-
stm32l475,
47+
stm32l475,
4848
stm32l476, stm32l486, stm32l496, stm32l4a6
4949
stm32l4r9, stm32l4s9
5050
"
@@ -127,7 +127,6 @@ pub mod adc;
127127
#[cfg(not(any(feature = "stm32l412",)))]
128128
pub mod can;
129129
pub mod crc;
130-
pub mod datetime;
131130
pub mod delay;
132131
pub mod dma;
133132
pub mod dmamux;

src/prelude.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub use crate::hal::digital::v2::*;
44
pub use crate::hal::prelude::*; // embedded hal traits // for some reason v2 is not exported in the ehal prelude
55

66
pub use crate::crc::CrcExt as _stm32l4_hal_CrcExt;
7-
pub use crate::datetime::U32Ext as _stm32l4_hal_datetime_U32Ext;
87
pub use crate::dma::DmaExt as _stm32l4_hal_DmaExt;
98
pub use crate::flash::FlashExt as _stm32l4_hal_FlashExt;
109
pub use crate::gpio::ExtiPin as _stm32l4_hal_ExtiPin;

0 commit comments

Comments
 (0)