diff --git a/Cargo.toml b/Cargo.toml index a8c7e82ac..d2961061c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,9 @@ travis-ci = { repository = "lpc-rs/lpc8xx-hal" } [dependencies] -cortex-m = "0.6.3" -nb = "1.0.0" +cortex-m = "0.6.3" +embedded-time = "0.10.0" +nb = "1.0.0" # This should be in [dev-dependencies], but those can't be optional. # Issue: https://github.com/rust-lang/cargo/issues/1596 @@ -158,6 +159,10 @@ required-features = ["rt-selected", "82x"] name = "i2c_eeprom" required-features = ["rt-selected"] +[[example]] +name = "mrt_clock" +required-features = ["rt-selected", "845"] + [[example]] name = "pinint" required-features = ["rt-selected", "845"] diff --git a/examples/mrt_clock.rs b/examples/mrt_clock.rs new file mode 100644 index 000000000..75f7a8ad0 --- /dev/null +++ b/examples/mrt_clock.rs @@ -0,0 +1,32 @@ +#![no_main] +#![no_std] + +extern crate panic_rtt_target; + +use embedded_time::{duration::Extensions as _, Clock as _}; +use lpc8xx_hal::{cortex_m_rt::entry, gpio::Level, mrt, Peripherals}; + +#[entry] +fn main() -> ! { + rtt_target::rtt_init_print!(); + + let p = Peripherals::take().unwrap(); + + let mut syscon = p.SYSCON.split(); + let gpio = p.GPIO.enable(&mut syscon.handle); + let mut mrt = p.MRT0.split(&mut syscon.handle).mrt0; + + let mut led = p + .pins + .pio1_1 + .into_output_pin(gpio.tokens.pio1_1, Level::Low); + + loop { + mrt.start(mrt::MAX_VALUE); + + let timer = mrt.new_timer(1u32.seconds()); + timer.start().unwrap().wait().unwrap(); + + led.toggle(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 12e6e29a0..f52e7fe34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,7 @@ pub extern crate cortex_m; pub extern crate cortex_m_rt; pub extern crate embedded_hal; pub extern crate embedded_hal_alpha; +pub extern crate embedded_time; pub extern crate nb; pub extern crate void; diff --git a/src/mrt.rs b/src/mrt.rs index d9d5c5b6a..0051c2435 100644 --- a/src/mrt.rs +++ b/src/mrt.rs @@ -13,7 +13,10 @@ use crate::{ }; use embedded_hal::timer::{CountDown, Periodic}; -use nb::{Error, Result}; +use embedded_hal_alpha::timer::{ + CountDown as CountDownAlpha, Periodic as PeriodicAlpha, +}; +use embedded_time::{clock, fraction::Fraction, Instant}; use void::Void; /// Represents the MRT instance @@ -74,32 +77,13 @@ where Self(RegProxy::new()) } - /// Returns the current timer value - pub fn value(&self) -> u32 { - self.0.timer.read().value().bits() - } -} - -impl CountDown for Channel -where - T: Trait, -{ - /// The timer operates in clock ticks from the system clock, that means it - /// runs at 12_000_000 ticks per second if you haven't changed it. - /// - /// It can also only use values smaller than 0x7FFFFFFF. - type Time = u32; - - /// Start counting down from the given count + /// Start the timer /// /// The `reload` argument must be smaller than or equal to [`MAX_VALUE`]. /// /// [`MAX_VALUE`]: constant.MAX_VALUE.html - fn start