Browse Source

display: Add update timer.

Mathias Gottschlag 5 years ago
parent
commit
5a5f722287
2 changed files with 15 additions and 3 deletions
  1. 1
    1
      display/firmware/Cargo.lock
  2. 14
    2
      display/firmware/src/main.rs

+ 1
- 1
display/firmware/Cargo.lock View File

280
 [[package]]
280
 [[package]]
281
 name = "mkl25z4-hal"
281
 name = "mkl25z4-hal"
282
 version = "0.1.0"
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
 dependencies = [
284
 dependencies = [
285
  "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
285
  "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
286
  "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
286
  "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",

+ 14
- 2
display/firmware/src/main.rs View File

13
     include!(concat!(env!("OUT_DIR"), "/assets.rs"));
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
 use mkl25z4_hal::clocks::ClockConfiguration;
18
 use mkl25z4_hal::clocks::ClockConfiguration;
19
+use mkl25z4_hal::mkl25z4::{Interrupt, LPTMR0};
17
 use mkl25z4_hal::time::{CopyableMonoTimer, NonCopyableMonoTimer, U32Ext};
20
 use mkl25z4_hal::time::{CopyableMonoTimer, NonCopyableMonoTimer, U32Ext};
21
+use mkl25z4_hal::timer::Timer;
22
+use mkl25z4_hal::timer::TimerInterrupt;
18
 use panic_semihosting as _;
23
 use panic_semihosting as _;
19
 
24
 
20
 use display::{Display, DisplayState};
25
 use display::{Display, DisplayState};
32
         bme_pins: Option<BME280Pins>,
37
         bme_pins: Option<BME280Pins>,
33
         radio: Option<Radio>,
38
         radio: Option<Radio>,
34
         time: CopyableMonoTimer,
39
         time: CopyableMonoTimer,
40
+        update_timer: Timer<LPTMR0>,
35
     }
41
     }
36
 
42
 
37
     #[init(spawn = [fetch_update])]
43
     #[init(spawn = [fetch_update])]
63
 
69
 
64
         let radio = Radio::init(pins.nrf, time);
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
         // Fetch the first update.
76
         // Fetch the first update.
67
         ctx.spawn.fetch_update().ok();
77
         ctx.spawn.fetch_update().ok();
68
 
78
 
83
             bme_pins: Some(pins.bme),
93
             bme_pins: Some(pins.bme),
84
             radio: Some(radio),
94
             radio: Some(radio),
85
             time,
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
     fn lptmr0_interrupt(ctx: lptmr0_interrupt::Context) {
101
     fn lptmr0_interrupt(ctx: lptmr0_interrupt::Context) {
91
         // Restart the timer.
102
         // Restart the timer.
92
-        // TODO
103
+        ctx.resources.update_timer.start(10.s());
104
+        ctx.resources.update_timer.enable_interrupt();
93
 
105
 
94
         // Trigger an update of the displayed values.
106
         // Trigger an update of the displayed values.
95
         ctx.spawn.fetch_update().ok();
107
         ctx.spawn.fetch_update().ok();

Loading…
Cancel
Save