From ad2894e71bd0477e2a4144b6f8daaa2a98355fed Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 22 Jan 2022 22:22:36 +0100 Subject: [PATCH] MCU: use a rp_pico::hal::Timer instead of the RealTimeClock It has millisecond accurency, which is what we want --- .../rendering_backends/mcu/pico_st7789.rs | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs b/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs index ba255452a..98a496bd6 100644 --- a/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs +++ b/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs @@ -8,9 +8,9 @@ pub use cortex_m_rt::entry; use embedded_hal::blocking::spi::Transfer; use embedded_hal::digital::v2::{InputPin, OutputPin}; use embedded_time::rate::*; -use rp_pico::hal; use rp_pico::hal::pac; use rp_pico::hal::prelude::*; +use rp_pico::hal::{self, Timer}; use defmt_rtt as _; // global logger @@ -22,7 +22,6 @@ fn oom(layout: core::alloc::Layout) -> ! { panic!("Out of memory {:?}", layout); } use alloc_cortex_m::CortexMHeap; -use rp_pico::hal::rtc::{DateTime, RealTimeClock}; use crate::Devices; @@ -99,30 +98,16 @@ pub fn init_board() { ) .unwrap(); - let clock = RealTimeClock::new( - pac.RTC, - clocks.rtc_clock, - &mut pac.RESETS, - DateTime { - year: 1970, - month: 1, - day: 1, - day_of_week: hal::rtc::DayOfWeek::Thursday, - hour: 0, - minute: 0, - second: 0, - }, - ) - .unwrap(); + let timer = Timer::new(pac.TIMER, &mut pac.RESETS); - crate::init_with_display(PicoDevices { display, touch, last_touch: Default::default(), clock }); + crate::init_with_display(PicoDevices { display, touch, last_touch: Default::default(), timer }); } struct PicoDevices { display: Display, touch: Touch, last_touch: Option, - clock: RealTimeClock, + timer: Timer, } impl, SPI: Transfer> Devices @@ -167,12 +152,7 @@ impl, SPI: Tr } fn time(&mut self) -> core::time::Duration { - let time = self.clock.now(); - match time { - // FIXME! milisecond - Ok(t) => core::time::Duration::from_secs(t.second as u64 + t.minute as u64 * 60), - Err(_) => core::time::Duration::ZERO, - } + core::time::Duration::from_micros(self.timer.get_counter()) } }