Procházet zdrojové kódy

display: Add update timer.

Mathias Gottschlag před 5 roky
rodič
revize
5a5f722287
2 změnil soubory, kde provedl 15 přidání a 3 odebrání
  1. 1
    1
      display/firmware/Cargo.lock
  2. 14
    2
      display/firmware/src/main.rs

+ 1
- 1
display/firmware/Cargo.lock Zobrazit soubor

@@ -280,7 +280,7 @@ dependencies = [
280 280
 [[package]]
281 281
 name = "mkl25z4-hal"
282 282
 version = "0.1.0"
283
-source = "git+https://github.com/mgottschlag/mkl25z4-hal#80bcfffaef6da16a8257cc8478dba026f618c5f0"
283
+source = "git+https://github.com/mgottschlag/mkl25z4-hal#743740c348d24bd9ba22724b1cce62ff3c93078b"
284 284
 dependencies = [
285 285
  "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
286 286
  "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",

+ 14
- 2
display/firmware/src/main.rs Zobrazit soubor

@@ -13,8 +13,13 @@ mod assets {
13 13
     include!(concat!(env!("OUT_DIR"), "/assets.rs"));
14 14
 }
15 15
 
16
+use cortex_m::peripheral::NVIC;
17
+use embedded_hal::timer::CountDown;
16 18
 use mkl25z4_hal::clocks::ClockConfiguration;
19
+use mkl25z4_hal::mkl25z4::{Interrupt, LPTMR0};
17 20
 use mkl25z4_hal::time::{CopyableMonoTimer, NonCopyableMonoTimer, U32Ext};
21
+use mkl25z4_hal::timer::Timer;
22
+use mkl25z4_hal::timer::TimerInterrupt;
18 23
 use panic_semihosting as _;
19 24
 
20 25
 use display::{Display, DisplayState};
@@ -32,6 +37,7 @@ const APP: () = {
32 37
         bme_pins: Option<BME280Pins>,
33 38
         radio: Option<Radio>,
34 39
         time: CopyableMonoTimer,
40
+        update_timer: Timer<LPTMR0>,
35 41
     }
36 42
 
37 43
     #[init(spawn = [fetch_update])]
@@ -63,6 +69,10 @@ const APP: () = {
63 69
 
64 70
         let radio = Radio::init(pins.nrf, time);
65 71
 
72
+        let update_timer = Timer::lptmr0(ctx.device.LPTMR0, 10.s(), clocks, &mut sim);
73
+        update_timer.enable_interrupt();
74
+        unsafe { NVIC::unmask(Interrupt::LPTMR0) };
75
+
66 76
         // Fetch the first update.
67 77
         ctx.spawn.fetch_update().ok();
68 78
 
@@ -83,13 +93,15 @@ const APP: () = {
83 93
             bme_pins: Some(pins.bme),
84 94
             radio: Some(radio),
85 95
             time,
96
+            update_timer,
86 97
         }
87 98
     }
88 99
 
89
-    #[task(binds = LPTMR0, priority = 3, spawn = [fetch_update])]
100
+    #[task(binds = LPTMR0, priority = 3, spawn = [fetch_update], resources = [update_timer])]
90 101
     fn lptmr0_interrupt(ctx: lptmr0_interrupt::Context) {
91 102
         // Restart the timer.
92
-        // TODO
103
+        ctx.resources.update_timer.start(10.s());
104
+        ctx.resources.update_timer.enable_interrupt();
93 105
 
94 106
         // Trigger an update of the displayed values.
95 107
         ctx.spawn.fetch_update().ok();

Loading…
Zrušit
Uložit