diff options
author | Brian Cully <bjc@kublai.com> | 2019-08-04 14:19:25 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2019-08-04 14:19:25 -0400 |
commit | e405c474f5e0e94288191223de7ae0f31ae0b15f (patch) | |
tree | 4ca89a92f0c868eb8feae272513c1e924b834adc /app/src/rtc.rs | |
parent | abd478d9425dd2d4acd5b58202b1a95b73ff217b (diff) | |
download | samd21-demo-e405c474f5e0e94288191223de7ae0f31ae0b15f.tar.gz samd21-demo-e405c474f5e0e94288191223de7ae0f31ae0b15f.zip |
Migrate everything over to separate libraries.
* `usb-host` is the crate containing the HAL traits.
* `bootkbd` is a crate for a bare-bones boot protocol keyboard
driver.
* `samd21-host` is a crate with an implementation of `usb-host` for
a SAMD21 platform, with an example for the trinket-m0 which uses
the `bootkbd` driver to print keyboard reports.
Diffstat (limited to 'app/src/rtc.rs')
-rw-r--r-- | app/src/rtc.rs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/app/src/rtc.rs b/app/src/rtc.rs deleted file mode 100644 index 79e450a..0000000 --- a/app/src/rtc.rs +++ /dev/null @@ -1,74 +0,0 @@ -use core::sync::atomic::{AtomicUsize, Ordering}; -use log; -use trinket_m0::{clock::GenericClockController, RTC}; - -struct Clock(AtomicUsize); -impl Clock { - const fn new() -> Self { - Self(AtomicUsize::new(0)) - } - - fn set(&self, millis: usize) { - self.0.store(millis, Ordering::SeqCst) - } - - // Slightly less than 1ms, due to using a 32,768Hz clock, we can't - // hit exactly 1ms, so we shoot for a bit under. - fn millis(&self) -> usize { - self.0.load(Ordering::SeqCst) - } -} - -static CLOCK: Clock = Clock::new(); - -// Set to run every ~500µs. -static COUNTER: u32 = 16; // 32 ticks requires 1024 cycles at 32,768Hz for 1 second. - -pub fn setup(mut rtc: RTC, clocks: &mut GenericClockController) -> impl FnMut() { - let rtc_clock = &clocks.gclk1(); - clocks.rtc(&rtc_clock); - - rtc.mode0().ctrl.write(|w| w.swrst().set_bit()); - while rtc.mode0().status.read().syncbusy().bit_is_set() {} - - rtc.mode0().ctrl.write(|w| { - w.mode().count32(); - - // Neither the prescaler nor matchlr values seem to work. Not - // sure why. - //w.prescaler().div1024(); - w.matchclr().set_bit() // Reset on match for periodic - }); - - rtc.mode0().comp[0].write(|w| unsafe { w.bits(COUNTER) }); - rtc.mode0().intflag.write(|w| w.cmp0().set_bit()); - rtc.mode0().intenset.write(|w| w.cmp0().set_bit()); - - // Enable the RTC and wait for sync. - rtc.mode0().ctrl.write(|w| w.enable().set_bit()); - while rtc.mode0().status.read().syncbusy().bit_is_set() {} - - move || handler(&mut rtc) -} - -pub fn millis() -> usize { - CLOCK.millis() -} - -fn handler(rtc: &mut RTC) { - // FIXME: matchclr doesn't seem to work to reset the counter? - rtc.mode0().count.write(|w| unsafe { w.bits(0) }); - rtc.mode0().intflag.write(|w| w.cmp0().set_bit()); - - static mut TICKS: usize = 0; - static mut ADD: bool = false; - unsafe { - if ADD { - TICKS += 1; - CLOCK.set(TICKS); - } - ADD = !ADD; - - log::logger().flush(); - } -} |