Browse Source

Implement reading values from the BME280.

Mathias Gottschlag 5 years ago
parent
commit
8f05bab10e

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

44
 [[package]]
44
 [[package]]
45
 name = "bme280"
45
 name = "bme280"
46
 version = "0.2.1"
46
 version = "0.2.1"
47
-source = "registry+https://github.com/rust-lang/crates.io-index"
47
+source = "git+https://github.com/mgottschlag/bme280-rs?branch=destroy#e3c3f39a32261bd29b94431b97b214dff027e9bb"
48
 dependencies = [
48
 dependencies = [
49
  "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
49
  "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
50
 ]
50
 ]
91
 version = "0.1.8"
91
 version = "0.1.8"
92
 source = "registry+https://github.com/rust-lang/crates.io-index"
92
 source = "registry+https://github.com/rust-lang/crates.io-index"
93
 dependencies = [
93
 dependencies = [
94
- "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
94
+ "proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
95
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
95
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
96
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
96
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
97
 ]
97
 ]
113
 version = "0.5.0"
113
 version = "0.5.0"
114
 source = "registry+https://github.com/rust-lang/crates.io-index"
114
 source = "registry+https://github.com/rust-lang/crates.io-index"
115
 dependencies = [
115
 dependencies = [
116
- "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
116
+ "proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
117
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
117
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
118
  "rtfm-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
118
  "rtfm-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
119
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
119
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
131
 name = "display-firmware"
131
 name = "display-firmware"
132
 version = "0.0.1"
132
 version = "0.0.1"
133
 dependencies = [
133
 dependencies = [
134
- "bme280 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
134
+ "bme280 0.2.1 (git+https://github.com/mgottschlag/bme280-rs?branch=destroy)",
135
  "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
135
  "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
136
  "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
136
  "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
137
  "cortex-m-rtfm 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
137
  "cortex-m-rtfm 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
304
 
304
 
305
 [[package]]
305
 [[package]]
306
 name = "proc-macro2"
306
 name = "proc-macro2"
307
-version = "1.0.10"
307
+version = "1.0.12"
308
 source = "registry+https://github.com/rust-lang/crates.io-index"
308
 source = "registry+https://github.com/rust-lang/crates.io-index"
309
 dependencies = [
309
 dependencies = [
310
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
310
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
315
 version = "1.0.4"
315
 version = "1.0.4"
316
 source = "registry+https://github.com/rust-lang/crates.io-index"
316
 source = "registry+https://github.com/rust-lang/crates.io-index"
317
 dependencies = [
317
 dependencies = [
318
- "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
318
+ "proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
319
 ]
319
 ]
320
 
320
 
321
 [[package]]
321
 [[package]]
339
 source = "registry+https://github.com/rust-lang/crates.io-index"
339
 source = "registry+https://github.com/rust-lang/crates.io-index"
340
 dependencies = [
340
 dependencies = [
341
  "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
341
  "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
342
- "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
342
+ "proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
343
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
343
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
344
 ]
344
 ]
345
 
345
 
374
 version = "1.0.18"
374
 version = "1.0.18"
375
 source = "registry+https://github.com/rust-lang/crates.io-index"
375
 source = "registry+https://github.com/rust-lang/crates.io-index"
376
 dependencies = [
376
 dependencies = [
377
- "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
377
+ "proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
378
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
378
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
379
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
379
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
380
 ]
380
 ]
392
 version = "1.0.16"
392
 version = "1.0.16"
393
 source = "registry+https://github.com/rust-lang/crates.io-index"
393
 source = "registry+https://github.com/rust-lang/crates.io-index"
394
 dependencies = [
394
 dependencies = [
395
- "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
395
+ "proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
396
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
396
  "quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
397
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
397
  "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
398
 ]
398
 ]
447
 "checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
447
 "checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
448
 "checksum bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
448
 "checksum bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
449
 "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
449
 "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
450
-"checksum bme280 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bc93357f2a5603736e2c1f1ba8e18e9ec80efa7fdade5d6a37c11362b76363f4"
450
+"checksum bme280 0.2.1 (git+https://github.com/mgottschlag/bme280-rs?branch=destroy)" = "<none>"
451
 "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
451
 "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
452
 "checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
452
 "checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
453
 "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62"
453
 "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62"
475
 "checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
475
 "checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
476
 "checksum panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c"
476
 "checksum panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c"
477
 "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
477
 "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
478
-"checksum proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
478
+"checksum proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319"
479
 "checksum quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7"
479
 "checksum quote 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7"
480
 "checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
480
 "checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
481
 "checksum rgb 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "a85b83fd629b0ce765f45316774fa6aaa95947fd74c8e4bbf3c6d1e349701d95"
481
 "checksum rgb 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "a85b83fd629b0ce765f45316774fa6aaa95947fd74c8e4bbf3c6d1e349701d95"

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

20
 mkl25z4-hal = { git = "https://github.com/mgottschlag/mkl25z4-hal" }
20
 mkl25z4-hal = { git = "https://github.com/mgottschlag/mkl25z4-hal" }
21
 embedded-hal = "0.2.3"
21
 embedded-hal = "0.2.3"
22
 nb = "0.1.2"
22
 nb = "0.1.2"
23
-bme280 = "0.2.1"
23
+bme280 = { git = "https://github.com/mgottschlag/bme280-rs", branch = "destroy" }
24
 embedded-nrf24l01 = { git = "https://github.com/astro/embedded-nrf24l01" }
24
 embedded-nrf24l01 = { git = "https://github.com/astro/embedded-nrf24l01" }
25
 epd-waveshare = { git = "https://github.com/mgottschlag/epd-waveshare.git", branch = "streaming" }
25
 epd-waveshare = { git = "https://github.com/mgottschlag/epd-waveshare.git", branch = "streaming" }
26
 tinygfx = { git = "https://github.com/mgottschlag/tinygfx" }
26
 tinygfx = { git = "https://github.com/mgottschlag/tinygfx" }

+ 17
- 6
display/firmware/src/main.rs View File

4
 mod display;
4
 mod display;
5
 mod information;
5
 mod information;
6
 mod pins;
6
 mod pins;
7
+mod sensors;
7
 
8
 
8
 // TODO: Enable warnings again.
9
 // TODO: Enable warnings again.
9
 #[allow(unused)]
10
 #[allow(unused)]
17
 
18
 
18
 use display::{Display, DisplayState};
19
 use display::{Display, DisplayState};
19
 use information::{Information, TemperatureHumidity};
20
 use information::{Information, TemperatureHumidity};
20
-use pins::DisplayBmeSpi;
21
+use pins::{BME280Pins, DisplayBmeSpi};
21
 
22
 
22
 #[rtfm::app(device = mkl25z4_hal::mkl25z4, peripherals = true)]
23
 #[rtfm::app(device = mkl25z4_hal::mkl25z4, peripherals = true)]
23
 const APP: () = {
24
 const APP: () = {
26
         display_state: DisplayState,
27
         display_state: DisplayState,
27
         display: Display,
28
         display: Display,
28
         display_bme_spi: Option<DisplayBmeSpi>,
29
         display_bme_spi: Option<DisplayBmeSpi>,
30
+        bme_pins: Option<BME280Pins>,
29
         time: CopyableMonoTimer,
31
         time: CopyableMonoTimer,
30
     }
32
     }
31
 
33
 
73
             },
75
             },
74
             display,
76
             display,
75
             display_bme_spi: Some(pins.display_bme_spi),
77
             display_bme_spi: Some(pins.display_bme_spi),
78
+            bme_pins: Some(pins.bme),
76
             time,
79
             time,
77
         }
80
         }
78
     }
81
     }
91
         // TODO
94
         // TODO
92
     }
95
     }
93
 
96
 
94
-    #[task(priority = 1, spawn = [update_display], resources = [info])]
97
+    #[task(priority = 1, spawn = [update_display], resources = [info, bme_pins, display_bme_spi, &time])]
95
     fn fetch_update(mut ctx: fetch_update::Context) {
98
     fn fetch_update(mut ctx: fetch_update::Context) {
96
         // Fetch local updates.
99
         // Fetch local updates.
97
-        // TODO
100
+        let time = ctx.resources.time.clone();
101
+        let pins = ctx.resources.bme_pins.take().unwrap();
102
+        let (pins, values) = ctx.resources.display_bme_spi.lock(|display_bme_spi| {
103
+            let spi = display_bme_spi.take().unwrap();
104
+            let (pins, spi, values) = sensors::bme280(pins, spi, time);
105
+            *display_bme_spi = Some(spi);
106
+            (pins, values)
107
+        });
108
+        *ctx.resources.bme_pins = Some(pins);
98
 
109
 
99
         // Send local measurements to the base station. This needs to be done before fetching data
110
         // Send local measurements to the base station. This needs to be done before fetching data
100
         // from the base station as the base station might return the data to us.
111
         // from the base station as the base station might return the data to us.
104
         // TODO
115
         // TODO
105
         ctx.resources.info.lock(|info| {
116
         ctx.resources.info.lock(|info| {
106
             info.inside = Some(TemperatureHumidity {
117
             info.inside = Some(TemperatureHumidity {
107
-                temperature: -212,
108
-                humidity: 345,
118
+                temperature: values.temperature,
119
+                humidity: values.humidity,
109
             });
120
             });
110
-            info.pressure = Some(100000);
121
+            info.pressure = Some(values.pressure);
111
         });
122
         });
112
 
123
 
113
         // If the update failed, simply increment the time and place a hint that
124
         // If the update failed, simply increment the time and place a hint that

+ 41
- 0
display/firmware/src/sensors.rs View File

1
+use bme280::spi::BME280;
2
+use embedded_hal::digital::v2::OutputPin;
3
+use mkl25z4_hal::time::CopyableMonoTimer;
4
+
5
+use super::pins::{BME280Pins, DisplayBmeSpi};
6
+
7
+pub fn bme280(
8
+    mut pins: BME280Pins,
9
+    spi: DisplayBmeSpi,
10
+    delay: CopyableMonoTimer,
11
+) -> (BME280Pins, DisplayBmeSpi, BME280Data) {
12
+    // Enable power.
13
+    pins.pwr.set_low().ok();
14
+
15
+    // Read the sensor.
16
+    let mut bme = BME280::new(spi, pins.cs, delay).unwrap();
17
+    bme.init().unwrap();
18
+    let values = bme.measure().unwrap();
19
+    let (spi, cs, _) = bme.destroy();
20
+
21
+    // Disable power again.
22
+    pins.pwr.set_high().ok();
23
+    (
24
+        BME280Pins {
25
+            pwr: pins.pwr,
26
+            cs: cs,
27
+        },
28
+        spi,
29
+        BME280Data {
30
+            temperature: (values.temperature * 10.0) as i32,
31
+            humidity: (values.humidity * 10.0) as u32,
32
+            pressure: values.pressure as u32,
33
+        },
34
+    )
35
+}
36
+
37
+pub struct BME280Data {
38
+    pub temperature: i32,
39
+    pub humidity: u32,
40
+    pub pressure: u32,
41
+}

Loading…
Cancel
Save