Commit f028adfd authored by Astro's avatar Astro
Browse files

l0dable: refactor utime into rtc::Time

parent c0b01859
......@@ -79,8 +79,8 @@ mod light_sensor;
pub use light_sensor::LightSensor;
pub mod vibra;
pub mod trng;
mod utime;
pub use utime::time;
mod rtc;
pub use rtc::{Seconds, MilliSeconds, Time};
mod fmt_buffer;
pub use fmt_buffer::{FmtBuffer, str_to_cstr};
mod bme680;
......
use core::ops::Sub;
use super::bindings::*;
pub trait Time {
fn time() -> Self;
fn set_time(&self);
}
pub struct Seconds(pub u32);
impl From<MilliSeconds> for Seconds {
fn from(ms: MilliSeconds) -> Seconds {
Seconds((ms.0 / 1000) as u32)
}
}
impl Time for Seconds {
fn time() -> Self {
let s = unsafe { epic_rtc_get_seconds() };
Seconds(s)
}
fn set_time(&self) {
// TODO
}
}
impl Sub for Seconds {
type Output = Seconds;
fn sub(self, rhs: Seconds) -> Self::Output {
Seconds(self.0 - rhs.0)
}
}
pub struct MilliSeconds(pub u64);
impl From<Seconds> for MilliSeconds {
fn from(s: Seconds) -> MilliSeconds {
MilliSeconds(s.0 as u64 * 1000)
}
}
impl Time for MilliSeconds {
fn time() -> Self {
let ms = unsafe { epic_rtc_get_milliseconds() };
MilliSeconds(ms)
}
fn set_time(&self) {
// TODO
}
}
impl Sub for MilliSeconds {
type Output = MilliSeconds;
fn sub(self, rhs: MilliSeconds) -> Self::Output {
MilliSeconds(self.0 - rhs.0)
}
}
use super::bindings::*;
pub fn time() -> u32 {
unsafe { epic_rtc_get_seconds() }
}
......@@ -163,7 +163,7 @@ enum GameResult {
}
fn game(level: u16, mut score: u32) -> GameResult {
let start_time = time();
let start_time = Seconds::time();
let display = Display::open();
let mut paddle = Display::W / 2;
......@@ -188,7 +188,7 @@ fn game(level: u16, mut score: u32) -> GameResult {
exit(0);
}
let mut check_finish = false;
let speed_steps = 2 + (time() - start_time) / 15;
let speed_steps = 2 + (Seconds::time() - start_time) / 15;
let speed_steps = (speed_steps >> 1) +
(speed_steps & tick & 1);
for _ in 0..speed_steps {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment