Переглянути джерело

Base station firmware: Initial import.

Mathias Gottschlag 5 роки тому
джерело
коміт
2afad3b36e

+ 3
- 3
.gitignore Переглянути файл

@@ -1,6 +1,3 @@
1
-# For PCBs designed using KiCad: http://www.kicad-pcb.org/
2
-# Format documentation: http://kicad-pcb.org/help/file-formats/
3
-
4 1
 # Temporary files
5 2
 *.000
6 3
 *.bak
@@ -8,6 +5,7 @@
8 5
 *.kicad_pcb-bak
9 6
 *.sch-bak
10 7
 *~
8
+*.swp
11 9
 _autosave-*
12 10
 *.tmp
13 11
 *-save.pro
@@ -25,3 +23,5 @@ fp-info-cache*
25 23
 *.xml
26 24
 *.csv
27 25
 
26
+# Rust
27
+base-station/firmware/target

+ 6
- 0
README.md Переглянути файл

@@ -3,6 +3,12 @@
3 3
 
4 4
 This repository contains the description of a number of smart home devices as well as the source code for the corresponding firmware.
5 5
 
6
+# Compiling
7
+
8
+Compiling the base station firmware requires a rust toolchain for ARMv6m:
9
+
10
+    rustup target add thumbv6m-none-eabi
11
+
6 12
 # License
7 13
 
8 14
 The hardware contained in this repository is licensed under the [CERN Open Hardware Licence Version 2 - Weakly Reciprocal](cern_ohl_w_v2.txt), and the software is licensed under the [GNU General Public License v3](gpl-3.0.md).

+ 5
- 0
base-station/firmware/.cargo/config Переглянути файл

@@ -0,0 +1,5 @@
1
+[target.thumbv6m-none-eabi]
2
+rustflags = ["-C", "link-arg=-Tlink.x"]
3
+
4
+[build]
5
+target = "thumbv6m-none-eabi"

+ 18
- 0
base-station/firmware/.gdbinit Переглянути файл

@@ -0,0 +1,18 @@
1
+target extended-remote :3333
2
+
3
+monitor arm semihosting enable
4
+
5
+# # send captured ITM to the file itm.fifo
6
+# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
7
+# # 8000000 must match the core clock frequency
8
+# monitor tpiu config internal itm.fifo uart off 8000000
9
+
10
+# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
11
+# # 2000000 is the frequency of the SWO pin
12
+# monitor tpiu config external uart off 8000000 2000000
13
+
14
+# # enable ITM port 0
15
+# monitor itm port 0 on
16
+
17
+load
18
+step

+ 451
- 0
base-station/firmware/Cargo.lock Переглянути файл

@@ -0,0 +1,451 @@
1
+# This file is automatically @generated by Cargo.
2
+# It is not intended for manual editing.
3
+[[package]]
4
+name = "aligned"
5
+version = "0.3.2"
6
+source = "registry+https://github.com/rust-lang/crates.io-index"
7
+dependencies = [
8
+ "as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
9
+]
10
+
11
+[[package]]
12
+name = "as-slice"
13
+version = "0.1.3"
14
+source = "registry+https://github.com/rust-lang/crates.io-index"
15
+dependencies = [
16
+ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
17
+ "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
18
+ "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
19
+]
20
+
21
+[[package]]
22
+name = "autocfg"
23
+version = "1.0.0"
24
+source = "registry+https://github.com/rust-lang/crates.io-index"
25
+
26
+[[package]]
27
+name = "bare-metal"
28
+version = "0.2.5"
29
+source = "registry+https://github.com/rust-lang/crates.io-index"
30
+dependencies = [
31
+ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
32
+]
33
+
34
+[[package]]
35
+name = "base-station-firmware"
36
+version = "0.0.1"
37
+dependencies = [
38
+ "bme280 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
39
+ "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
40
+ "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
41
+ "cortex-m-rtfm 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
42
+ "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
43
+ "embedded-epd 0.1.0 (git+https://github.com/mgottschlag/rust-embedded-epd)",
44
+ "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
45
+ "epd-assets 0.1.0 (git+https://github.com/mgottschlag/rust-epd-assets)",
46
+ "mkl25z4 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
47
+ "mkl25z4-hal 0.1.0 (git+https://github.com/mgottschlag/mkl25z4-hal)",
48
+ "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
49
+ "panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
50
+ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
51
+]
52
+
53
+[[package]]
54
+name = "bitflags"
55
+version = "1.2.1"
56
+source = "registry+https://github.com/rust-lang/crates.io-index"
57
+
58
+[[package]]
59
+name = "bme280"
60
+version = "0.2.1"
61
+source = "registry+https://github.com/rust-lang/crates.io-index"
62
+dependencies = [
63
+ "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
64
+]
65
+
66
+[[package]]
67
+name = "byteorder"
68
+version = "1.3.4"
69
+source = "registry+https://github.com/rust-lang/crates.io-index"
70
+
71
+[[package]]
72
+name = "cc"
73
+version = "1.0.50"
74
+source = "registry+https://github.com/rust-lang/crates.io-index"
75
+
76
+[[package]]
77
+name = "cortex-m"
78
+version = "0.6.2"
79
+source = "registry+https://github.com/rust-lang/crates.io-index"
80
+dependencies = [
81
+ "aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
82
+ "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
83
+ "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
84
+]
85
+
86
+[[package]]
87
+name = "cortex-m-rt"
88
+version = "0.6.12"
89
+source = "registry+https://github.com/rust-lang/crates.io-index"
90
+dependencies = [
91
+ "cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
92
+ "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
93
+]
94
+
95
+[[package]]
96
+name = "cortex-m-rt-macros"
97
+version = "0.1.8"
98
+source = "registry+https://github.com/rust-lang/crates.io-index"
99
+dependencies = [
100
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
101
+ "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
102
+ "syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
103
+]
104
+
105
+[[package]]
106
+name = "cortex-m-rtfm"
107
+version = "0.5.1"
108
+source = "registry+https://github.com/rust-lang/crates.io-index"
109
+dependencies = [
110
+ "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
111
+ "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
112
+ "cortex-m-rtfm-macros 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
113
+ "heapless 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
114
+ "rtfm-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
115
+]
116
+
117
+[[package]]
118
+name = "cortex-m-rtfm-macros"
119
+version = "0.5.0"
120
+source = "registry+https://github.com/rust-lang/crates.io-index"
121
+dependencies = [
122
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
123
+ "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
124
+ "rtfm-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
125
+ "syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
126
+]
127
+
128
+[[package]]
129
+name = "cortex-m-semihosting"
130
+version = "0.3.5"
131
+source = "registry+https://github.com/rust-lang/crates.io-index"
132
+dependencies = [
133
+ "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
134
+]
135
+
136
+[[package]]
137
+name = "embedded-epd"
138
+version = "0.1.0"
139
+source = "git+https://github.com/mgottschlag/rust-embedded-epd#5ce5a2fd7b84a86938680adab393132d68d01e77"
140
+dependencies = [
141
+ "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
142
+ "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
143
+]
144
+
145
+[[package]]
146
+name = "embedded-hal"
147
+version = "0.2.3"
148
+source = "registry+https://github.com/rust-lang/crates.io-index"
149
+dependencies = [
150
+ "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
151
+ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
152
+]
153
+
154
+[[package]]
155
+name = "epd-assets"
156
+version = "0.1.0"
157
+source = "git+https://github.com/mgottschlag/rust-epd-assets#3feee66fa2b6885525cb829045102f2dae1b8521"
158
+dependencies = [
159
+ "freetype-rs 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)",
160
+ "lodepng 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
161
+]
162
+
163
+[[package]]
164
+name = "freetype-rs"
165
+version = "0.19.1"
166
+source = "registry+https://github.com/rust-lang/crates.io-index"
167
+dependencies = [
168
+ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
169
+ "freetype-sys 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
170
+ "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
171
+]
172
+
173
+[[package]]
174
+name = "freetype-sys"
175
+version = "0.7.1"
176
+source = "registry+https://github.com/rust-lang/crates.io-index"
177
+dependencies = [
178
+ "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
179
+ "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
180
+ "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
181
+]
182
+
183
+[[package]]
184
+name = "generic-array"
185
+version = "0.12.3"
186
+source = "registry+https://github.com/rust-lang/crates.io-index"
187
+dependencies = [
188
+ "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
189
+]
190
+
191
+[[package]]
192
+name = "generic-array"
193
+version = "0.13.2"
194
+source = "registry+https://github.com/rust-lang/crates.io-index"
195
+dependencies = [
196
+ "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
197
+]
198
+
199
+[[package]]
200
+name = "hash32"
201
+version = "0.1.1"
202
+source = "registry+https://github.com/rust-lang/crates.io-index"
203
+dependencies = [
204
+ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
205
+]
206
+
207
+[[package]]
208
+name = "heapless"
209
+version = "0.5.3"
210
+source = "registry+https://github.com/rust-lang/crates.io-index"
211
+dependencies = [
212
+ "as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
213
+ "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
214
+ "hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
215
+]
216
+
217
+[[package]]
218
+name = "indexmap"
219
+version = "1.3.2"
220
+source = "registry+https://github.com/rust-lang/crates.io-index"
221
+dependencies = [
222
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
223
+]
224
+
225
+[[package]]
226
+name = "libc"
227
+version = "0.2.68"
228
+source = "registry+https://github.com/rust-lang/crates.io-index"
229
+
230
+[[package]]
231
+name = "libz-sys"
232
+version = "1.0.25"
233
+source = "registry+https://github.com/rust-lang/crates.io-index"
234
+dependencies = [
235
+ "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
236
+ "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
237
+ "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
238
+ "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
239
+]
240
+
241
+[[package]]
242
+name = "lodepng"
243
+version = "2.5.0"
244
+source = "registry+https://github.com/rust-lang/crates.io-index"
245
+dependencies = [
246
+ "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)",
247
+ "rgb 0.8.16 (registry+https://github.com/rust-lang/crates.io-index)",
248
+]
249
+
250
+[[package]]
251
+name = "mkl25z4"
252
+version = "0.0.3"
253
+source = "registry+https://github.com/rust-lang/crates.io-index"
254
+dependencies = [
255
+ "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
256
+ "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
257
+ "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
258
+ "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
259
+]
260
+
261
+[[package]]
262
+name = "mkl25z4-hal"
263
+version = "0.1.0"
264
+source = "git+https://github.com/mgottschlag/mkl25z4-hal#69f41e663e7e124adb0813793bf26d8232875ef1"
265
+dependencies = [
266
+ "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
267
+ "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
268
+ "mkl25z4 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
269
+ "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
270
+ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
271
+]
272
+
273
+[[package]]
274
+name = "nb"
275
+version = "0.1.2"
276
+source = "registry+https://github.com/rust-lang/crates.io-index"
277
+
278
+[[package]]
279
+name = "panic-semihosting"
280
+version = "0.5.3"
281
+source = "registry+https://github.com/rust-lang/crates.io-index"
282
+dependencies = [
283
+ "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
284
+ "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
285
+]
286
+
287
+[[package]]
288
+name = "pkg-config"
289
+version = "0.3.17"
290
+source = "registry+https://github.com/rust-lang/crates.io-index"
291
+
292
+[[package]]
293
+name = "proc-macro2"
294
+version = "1.0.9"
295
+source = "registry+https://github.com/rust-lang/crates.io-index"
296
+dependencies = [
297
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
298
+]
299
+
300
+[[package]]
301
+name = "quote"
302
+version = "1.0.3"
303
+source = "registry+https://github.com/rust-lang/crates.io-index"
304
+dependencies = [
305
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
306
+]
307
+
308
+[[package]]
309
+name = "r0"
310
+version = "0.2.2"
311
+source = "registry+https://github.com/rust-lang/crates.io-index"
312
+
313
+[[package]]
314
+name = "rgb"
315
+version = "0.8.16"
316
+source = "registry+https://github.com/rust-lang/crates.io-index"
317
+
318
+[[package]]
319
+name = "rtfm-core"
320
+version = "0.3.0"
321
+source = "registry+https://github.com/rust-lang/crates.io-index"
322
+
323
+[[package]]
324
+name = "rtfm-syntax"
325
+version = "0.4.0"
326
+source = "registry+https://github.com/rust-lang/crates.io-index"
327
+dependencies = [
328
+ "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
329
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
330
+ "syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
331
+]
332
+
333
+[[package]]
334
+name = "rustc_version"
335
+version = "0.2.3"
336
+source = "registry+https://github.com/rust-lang/crates.io-index"
337
+dependencies = [
338
+ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
339
+]
340
+
341
+[[package]]
342
+name = "semver"
343
+version = "0.9.0"
344
+source = "registry+https://github.com/rust-lang/crates.io-index"
345
+dependencies = [
346
+ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
347
+]
348
+
349
+[[package]]
350
+name = "semver-parser"
351
+version = "0.7.0"
352
+source = "registry+https://github.com/rust-lang/crates.io-index"
353
+
354
+[[package]]
355
+name = "stable_deref_trait"
356
+version = "1.1.1"
357
+source = "registry+https://github.com/rust-lang/crates.io-index"
358
+
359
+[[package]]
360
+name = "syn"
361
+version = "1.0.17"
362
+source = "registry+https://github.com/rust-lang/crates.io-index"
363
+dependencies = [
364
+ "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
365
+ "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
366
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
367
+]
368
+
369
+[[package]]
370
+name = "typenum"
371
+version = "1.11.2"
372
+source = "registry+https://github.com/rust-lang/crates.io-index"
373
+
374
+[[package]]
375
+name = "unicode-xid"
376
+version = "0.2.0"
377
+source = "registry+https://github.com/rust-lang/crates.io-index"
378
+
379
+[[package]]
380
+name = "vcell"
381
+version = "0.1.2"
382
+source = "registry+https://github.com/rust-lang/crates.io-index"
383
+
384
+[[package]]
385
+name = "vcpkg"
386
+version = "0.2.8"
387
+source = "registry+https://github.com/rust-lang/crates.io-index"
388
+
389
+[[package]]
390
+name = "void"
391
+version = "1.0.2"
392
+source = "registry+https://github.com/rust-lang/crates.io-index"
393
+
394
+[[package]]
395
+name = "volatile-register"
396
+version = "0.2.0"
397
+source = "registry+https://github.com/rust-lang/crates.io-index"
398
+dependencies = [
399
+ "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
400
+]
401
+
402
+[metadata]
403
+"checksum aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94"
404
+"checksum as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70"
405
+"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
406
+"checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
407
+"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
408
+"checksum bme280 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bc93357f2a5603736e2c1f1ba8e18e9ec80efa7fdade5d6a37c11362b76363f4"
409
+"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
410
+"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
411
+"checksum cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763"
412
+"checksum cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "00d518da72bba39496024b62607c1d8e37bcece44b2536664f1132a73a499a28"
413
+"checksum cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647"
414
+"checksum cortex-m-rtfm 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf0b9fd3f042cb3793d15daf3cea201b2f25c99b0b5b936a551bb6909c3ae5b"
415
+"checksum cortex-m-rtfm-macros 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c62092f6ff344e9b0adb748f0302ed69889ba2fae1fce446e3788d4726ea73bb"
416
+"checksum cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "113ef0ecffee2b62b58f9380f4469099b30e9f9cbee2804771b4203ba1762cfa"
417
+"checksum embedded-epd 0.1.0 (git+https://github.com/mgottschlag/rust-embedded-epd)" = "<none>"
418
+"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
419
+"checksum epd-assets 0.1.0 (git+https://github.com/mgottschlag/rust-epd-assets)" = "<none>"
420
+"checksum freetype-rs 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28cc92a7040ee7b631e4279e263f9a83aedc1eb6085c68d8ca4d072b5644e705"
421
+"checksum freetype-sys 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9c8666cce7cf6e51a290623647febfbab92480b4c3e0f495cb9d4d312b5d38"
422
+"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
423
+"checksum generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd"
424
+"checksum hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc"
425
+"checksum heapless 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10b591a0032f114b7a77d4fbfab452660c553055515b7d7ece355db080d19087"
426
+"checksum indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292"
427
+"checksum libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)" = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0"
428
+"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe"
429
+"checksum lodepng 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40ed9859b15e009b494528f32ad054c5baf67afabf3c05d27973ea151563d430"
430
+"checksum mkl25z4 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "91f9b185f1346b1fdc8337481e2fdf5f282d0e884e2c59e4ddea5328105017d7"
431
+"checksum mkl25z4-hal 0.1.0 (git+https://github.com/mgottschlag/mkl25z4-hal)" = "<none>"
432
+"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
433
+"checksum panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c"
434
+"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
435
+"checksum proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
436
+"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
437
+"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
438
+"checksum rgb 0.8.16 (registry+https://github.com/rust-lang/crates.io-index)" = "5ec4ab2cf0b27e111e266e161cf7f9efd20125a161190da1c0945c4a4408fef3"
439
+"checksum rtfm-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec893edb2aa5b70320b94896ffea22a7ebb1cf3f942bb67cd5b60a865a63493"
440
+"checksum rtfm-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4455e23c34df3d66454e7e218a4d76a7f83321d04a806be614463341cec4116e"
441
+"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
442
+"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
443
+"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
444
+"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
445
+"checksum syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
446
+"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
447
+"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
448
+"checksum vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c"
449
+"checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168"
450
+"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
451
+"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"

+ 48
- 0
base-station/firmware/Cargo.toml Переглянути файл

@@ -0,0 +1,48 @@
1
+[package]
2
+authors = ["Mathias Gottschlag <mgottschlag@gmail.com>"]
3
+categories = ["embedded", "no-std"]
4
+description = "smarthome base station firmware"
5
+keywords = ["arm", "cortex-m"]
6
+license = "MIT"
7
+name = "base-station-firmware"
8
+version = "0.0.1"
9
+build = "build.rs"
10
+edition = "2018"
11
+
12
+[dependencies]
13
+cortex-m = "0.6.2"
14
+cortex-m-rt = { version = "0.6.12", features = ["device"] }
15
+cortex-m-rtfm = "0.5.1"
16
+mkl25z4 = { version = "0.0.3", features = ["rt"] }
17
+#panic-halt = "0.2.0"
18
+panic-semihosting = "0.5.3"
19
+cortex-m-semihosting = "0.3.5"
20
+mkl25z4-hal = { git = "https://github.com/mgottschlag/mkl25z4-hal" }
21
+embedded-hal = "0.2.3"
22
+nb = "0.1.2"
23
+embedded-epd = { git = "https://github.com/mgottschlag/rust-embedded-epd" }
24
+bme280 = "0.2.1"
25
+
26
+[dependencies.void]
27
+default-features = false
28
+version = "1.0.2"
29
+
30
+[build-dependencies]
31
+epd-assets = { git = "https://github.com/mgottschlag/rust-epd-assets" }
32
+
33
+#[patch."https://github.com/mgottschlag/mkl25z4-hal"]
34
+#mkl25z4-hal = { path = "/home/mathias/Projects/microcontroller/mkl25z4-hal" }
35
+
36
+#[patch."https://github.com/mgottschlag/mkl25z4"]
37
+#mkl25z4 = { path = "/home/mathias/Projects/microcontroller/mkl25z4" }
38
+
39
+#[patch."https://github.com/mgottschlag/rust-embedded-epd"]
40
+#embedded-epd = { path = "/home/mathias/Projects/microcontroller/rust-embedded-epd" }
41
+
42
+#[patch."https://github.com/mgottschlag/rust-epd-assets"]
43
+#epd-assets = { path = "/home/mathias/Projects/microcontroller/rust-epd-assets" }
44
+
45
+[profile]
46
+[profile.release]
47
+debug = true
48
+lto = true

BIN
base-station/firmware/assets/Roboto-Regular.ttf Переглянути файл


BIN
base-station/firmware/assets/RobotoMono-Regular.ttf Переглянути файл


BIN
base-station/firmware/assets/ic_alarm_black_24dp.png Переглянути файл


BIN
base-station/firmware/assets/ic_alarm_black_36dp.png Переглянути файл


+ 35
- 0
base-station/firmware/build.rs Переглянути файл

@@ -0,0 +1,35 @@
1
+extern crate epd_assets as assets;
2
+
3
+use std::env;
4
+use std::fs::File;
5
+use std::io::Write;
6
+use std::path::Path;
7
+
8
+fn main() {
9
+    let out_dir = env::var("OUT_DIR").unwrap();
10
+    let dest_path = Path::new(&out_dir).join("assets.rs");
11
+    let mut f = File::create(&dest_path).unwrap();
12
+
13
+    let mut font = assets::Font::load("assets/Roboto-Regular.ttf").unwrap();
14
+
15
+    let epd_font = font.generate("ROBOTO_100", 100, " 0123456789:", "crate::epd");
16
+    f.write_all(epd_font.as_bytes()).unwrap();
17
+
18
+    let epd_font = font.generate(
19
+        "ROBOTO_30",
20
+        30,
21
+        " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.",
22
+        "crate::epd",
23
+    );
24
+
25
+    f.write_all(epd_font.as_bytes()).unwrap();
26
+
27
+    let clock_image = assets::Image::load("assets/ic_alarm_black_36dp.png").unwrap();
28
+
29
+    f.write_all(
30
+        clock_image
31
+            .generate_bitmap("ALARM_CLOCK_36", "crate::epd")
32
+            .as_bytes(),
33
+    )
34
+    .unwrap();
35
+}

+ 2
- 0
base-station/firmware/gdb.sh Переглянути файл

@@ -0,0 +1,2 @@
1
+#!/bin/sh
2
+arm-none-eabi-gdb target/thumbv6m-none-eabi/release/smartclock-firmware

+ 13
- 0
base-station/firmware/memory.x Переглянути файл

@@ -0,0 +1,13 @@
1
+/* Parts taken from https://github.com/therealprof/mkw41z-hal/blob/master/memory.x */
2
+
3
+MEMORY
4
+{
5
+  FLASH : ORIGIN = 0x00000000, LENGTH = 128K
6
+  RAM : ORIGIN = 0x1ffff000, LENGTH = 16K
7
+  /* This chip has funny security bits at 0x400 ... */
8
+  FCF : ORIGIN = 0x00000400, LENGTH = 16
9
+}
10
+
11
+/* Skip the whole sector with the security bits and let program code start
12
+ * after to prevent nasty mishaps */
13
+_stext = 0x00000800;

+ 4
- 0
base-station/firmware/openocd-disable-watchdog.cfg Переглянути файл

@@ -0,0 +1,4 @@
1
+kl25.cpu configure -event reset-init {
2
+    echo "Disabling watchdog..."
3
+    mww 0x40048100 0x0
4
+}

+ 2
- 0
base-station/firmware/openocd.sh Переглянути файл

@@ -0,0 +1,2 @@
1
+#!/bin/sh
2
+openocd -f interface/cmsis-dap.cfg -f target/kl25.cfg

+ 2
- 0
base-station/firmware/program.sh Переглянути файл

@@ -0,0 +1,2 @@
1
+#!/bin/sh
2
+openocd -f interface/cmsis-dap.cfg -f target/kl25.cfg -c "program target/thumbv6m-none-eabi/release/smartclock-firmware reset exit"

+ 1
- 0
base-station/firmware/rust-toolchain Переглянути файл

@@ -0,0 +1 @@
1
+nightly-2020-03-27

+ 88
- 0
base-station/firmware/src/board/led.rs Переглянути файл

@@ -0,0 +1,88 @@
1
+//! User LEDs
2
+
3
+use mkl25z4_hal::gpio;
4
+use embedded_hal::digital::v2::OutputPin;
5
+
6
+pub struct Led {
7
+    pub red: gpio::gpiob::PB18<gpio::Output<gpio::PushPull>>,
8
+    pub green: gpio::gpiob::PB19<gpio::Output<gpio::PushPull>>,
9
+    pub blue: gpio::gpiod::PD1<gpio::Output<gpio::PushPull>>,
10
+}
11
+
12
+impl Led {
13
+    /// Sets the LED's color
14
+    pub fn set_color(&mut self, red: bool, green: bool, blue: bool) {
15
+        if red {
16
+            self.red.set_low().ok();
17
+        } else {
18
+            self.red.set_high().ok();
19
+        }
20
+        if green {
21
+            self.green.set_low().ok();
22
+        } else {
23
+            self.green.set_high().ok();
24
+        }
25
+        if blue {
26
+            self.blue.set_low().ok();
27
+        } else {
28
+            self.blue.set_high().ok();
29
+        }
30
+        // NOTE(safe) atomic write
31
+        /*unsafe {
32
+            if red {
33
+                (*GPIOB::ptr()).pcor.write(|w| w.ptco().bits(1 << 18));
34
+            } else {
35
+                (*GPIOB::ptr()).psor.write(|w| w.ptso().bits(1 << 18));
36
+            }
37
+            if green {
38
+                (*GPIOB::ptr()).pcor.write(|w| w.ptco().bits(1 << 19));
39
+            } else {
40
+                (*GPIOB::ptr()).psor.write(|w| w.ptso().bits(1 << 19));
41
+            }
42
+            if blue {
43
+                (*GPIOD::ptr()).pcor.write(|w| w.ptco().bits(1 << 1));
44
+            } else {
45
+                (*GPIOD::ptr()).psor.write(|w| w.ptso().bits(1 << 1));
46
+            }
47
+        }*/    }
48
+}
49
+
50
+//impl Led {
51
+//    /// Turns off the LED
52
+//    pub fn off(&self) {
53
+//        // NOTE(safe) atomic write
54
+//        unsafe { (*GPIOG.get()).bsrr.write(|w| w.bits(1 << (self.i + 16))) }
55
+//    }
56
+//
57
+//    /// Turns on the LED
58
+//    pub fn on(&self) {
59
+//        // NOTE(safe) atomic write
60
+//        unsafe { (*GPIOG.get()).bsrr.write(|w| w.bits(1 << self.i)) }
61
+//    }
62
+//}
63
+
64
+/*/// Initializes all the user LEDs
65
+pub fn init(portb: &PORTB, gpiob: &GPIOB, portd: &PORTD, gpiod: &GPIOD, sim: &SIM) {
66
+    // Power up peripherals
67
+    //rcc.ahb1enr.modify(|_, w| w.gpiogen().set_bit());
68
+    sim.scgc5.modify(|_, w| w.portb().set_bit().portd().set_bit());
69
+
70
+    // Configure pins as outputs
71
+    portb.pcr[18].modify(|_, w| w.mux().bits(1));
72
+    portb.pcr[19].modify(|_, w| w.mux().bits(1));
73
+    portd.pcr[1].modify(|_, w| w.mux().bits(1));
74
+    gpiod.pcor.write(|w| unsafe { w.ptco().bits(1 << 1) });
75
+    gpiob.pcor.write(|w| unsafe { w.ptco().bits((1 << 18) | (1 << 19)) });
76
+    gpiod.pddr.write(|w| unsafe { w.pdd().bits(1 << 1) });
77
+    gpiob.pddr.write(|w| unsafe { w.pdd().bits((1 << 18) | (1 << 19)) });
78
+    /*gpiog
79
+        .moder
80
+        .modify(
81
+            |_, w| {
82
+                w.moder13()
83
+                    .bits(1)
84
+                    .moder14()
85
+                    .bits(1)
86
+            },
87
+        );*/
88
+}*/

+ 1
- 0
base-station/firmware/src/board/mod.rs Переглянути файл

@@ -0,0 +1 @@
1
+pub mod led;

+ 411
- 0
base-station/firmware/src/main.rs Переглянути файл

@@ -0,0 +1,411 @@
1
+#![no_main]
2
+#![no_std]
3
+
4
+mod board;
5
+mod assets {
6
+    include!(concat!(env!("OUT_DIR"), "/assets.rs"));
7
+}
8
+
9
+
10
+use cortex_m_semihosting::{debug, hprintln};
11
+use mkl25z4_hal as hal;
12
+use panic_semihosting as _;
13
+use mkl25z4_hal::gpio::GpioExt;
14
+use mkl25z4_hal::spi::{Phase, Polarity, Spi};
15
+use mkl25z4_hal::time::{NonCopyableMonoTimer, U32Ext};
16
+use mkl25z4_hal::timer::{Timer, TimerInterrupt};
17
+use embedded_hal::digital::v2::OutputPin;
18
+use embedded_epd::{gui, Display};
19
+use embedded_epd as epd;
20
+use nb::block;
21
+use embedded_hal::timer::CountDown;
22
+
23
+use board::led;
24
+
25
+struct EPDTimer<Timer> {
26
+    timer: Timer,
27
+}
28
+
29
+impl<Timer> CountDown for EPDTimer<Timer>
30
+where
31
+    Timer: CountDown<Time = hal::time::Hertz>,
32
+{
33
+    type Time = epd::Hertz;
34
+
35
+    fn start<T>(&mut self, timeout: T)
36
+    where
37
+        T: Into<epd::Hertz>,
38
+    {
39
+        self.timer.start(hal::time::Hertz(timeout.into().0))
40
+    }
41
+
42
+    fn wait(&mut self) -> nb::Result<(), void::Void> {
43
+        self.timer.wait()
44
+    }
45
+}
46
+
47
+#[rtfm::app(device = mkl25z4_hal::mkl25z4, peripherals = true)]
48
+const APP: () = {
49
+    struct Resources {
50
+    }
51
+
52
+    #[init]
53
+    fn init(ctx: init::Context) {
54
+        let mut sim = ctx.device.SIM;
55
+        mkl25z4_hal::watchdog::disable(&mut sim);
56
+        let clocks = mkl25z4_hal::clocks::init();
57
+
58
+        let mut gpiob = ctx.device.GPIOB.split(&mut sim);
59
+        let mut gpioc = ctx.device.GPIOC.split(&mut sim);
60
+        let mut gpiod = ctx.device.GPIOD.split(&mut sim);
61
+
62
+        let mut led = led::Led {
63
+            red: gpiob.pb18.into_push_pull_output(&mut gpiob.pddr),
64
+            green: gpiob.pb19.into_push_pull_output(&mut gpiob.pddr),
65
+            blue: gpiod.pd1.into_push_pull_output(&mut gpiod.pddr),
66
+        };
67
+        //led::init(&p.device.PORTB, &p.device.GPIOB, &p.device.PORTD, &p.device.GPIOD, &p.device.SIM);
68
+        led.set_color(true, true, true);
69
+
70
+        /*for _ in 0..2 {
71
+            time.delay_ms(1000);
72
+            led.set_color(false, false, true);
73
+            time.delay_ms(1000);
74
+            led.set_color(false, true, false);
75
+        }*/
76
+
77
+        let mosi = gpioc.pc6.into_alternate(&mut gpioc.pddr);
78
+        let miso = gpioc.pc7.into_alternate(&mut gpioc.pddr);
79
+        let sck = gpioc.pc5.into_alternate(&mut gpioc.pddr);
80
+        let mode = hal::spi::Mode {
81
+            polarity: Polarity::IdleLow,
82
+            phase: Phase::CaptureOnFirstTransition,
83
+        };
84
+        let spi0 = Spi::spi0(ctx.device.SPI0, mosi, miso, sck, mode, &mut sim);
85
+
86
+        // Initialize the display.
87
+        let busy = gpioc.pc3.into_floating_input(&mut gpioc.pddr);
88
+        let mut reset = gpioc.pc2.into_push_pull_output(&mut gpioc.pddr);
89
+        reset.set_high().unwrap();
90
+        let mut data_cmd = gpioc.pc1.into_push_pull_output(&mut gpioc.pddr);
91
+        data_cmd.set_high().unwrap();
92
+        let mut cs = gpioc.pc0.into_push_pull_output(&mut gpioc.pddr);
93
+        cs.set_high().unwrap();
94
+
95
+        let t = EPDTimer {
96
+            timer: Timer::pit(ctx.device.PIT, hal::time::Hertz(1), clocks, &mut sim),
97
+        };
98
+
99
+        let mut display = epd::gdew042z15::GDEW042Z15::new(spi0, busy, reset, data_cmd, cs, t);
100
+        block!(display.init()).ok();
101
+        block!(display.start_frame()).ok();
102
+        led.set_color(false, false, false);
103
+        let layout = gui::Layout::new(
104
+            400,
105
+            300,
106
+            gui::VerticalSplit::expand_bottom(
107
+                24,
108
+                gui::Fill::new(epd::Color::White),
109
+                gui::VerticalSplit::expand_bottom(
110
+                    1,
111
+                    gui::Fill::new(epd::Color::Black),
112
+                    gui::HorizontalSplit::expand_right(
113
+                        48,
114
+                        gui::Fill::new(epd::Color::White),
115
+                        //gui::Image::new(&assets::ALARM_CLOCK_36),
116
+                        gui::HorizontalSplit::expand_right(
117
+                            1,
118
+                            gui::Fill::new(epd::Color::Black),
119
+                            gui::HorizontalSplit::expand_left(
120
+                                49,
121
+                                gui::VerticalSplit::expand_bottom(
122
+                                    132,
123
+                                    gui::Align::new(
124
+                                        gui::HorizontalAlign::Center,
125
+                                        gui::VerticalAlign::Top,
126
+                                        gui::Text::new("12:34", &assets::ROBOTO_100),
127
+                                    ),
128
+                                    gui::Align::new(
129
+                                        gui::HorizontalAlign::Center,
130
+                                        gui::VerticalAlign::Top,
131
+                                        gui::HorizontalSplit::expand_right(
132
+                                            36,
133
+                                            gui::Image::new(&assets::ALARM_CLOCK_36),
134
+                                            gui::Text::new("Do. 8:00", &assets::ROBOTO_30),
135
+                                        ),
136
+                                    ),
137
+                                ),
138
+                                gui::Fill::new(epd::Color::White),
139
+                            ),
140
+                        ),
141
+                    ),
142
+                ),
143
+            ),
144
+        );
145
+        let mut row_buffer = [0u8; 400 / 8];
146
+        layout.render(&mut display, &mut row_buffer);
147
+        display.end_frame();
148
+        led.set_color(true, true, false);
149
+
150
+        let (_, _, _, _, _, mut t) = display.destroy();
151
+
152
+        /*let pit_ = display.time.deactivate(&mut p.device.SIM);*/
153
+        t.start(epd::Hertz(1));
154
+        t.timer.enable_interrupt();
155
+        let mut nvic = ctx.core.NVIC;
156
+        nvic.enable(mkl25z4::Interrupt::PIT);
157
+
158
+        led.set_color(true, true, true);
159
+    }
160
+
161
+    #[idle]
162
+    fn idle(_cx: idle::Context) -> ! {
163
+        // Sleep
164
+        loop {
165
+            // wfi needs to be disabled for GDB
166
+            /*// add some side effect to prevent this from turning into a UDF instruction
167
+            // see rust-lang/rust#28728 for details
168
+            atomic::compiler_fence(Ordering::SeqCst);*/
169
+            cortex_m::asm::wfi();
170
+        }
171
+    }
172
+};
173
+
174
+/*#![no_main]
175
+#![no_std]
176
+
177
+extern crate cortex_m;
178
+extern crate cortex_m_rt as rt;
179
+//extern crate cortex_m_rtfm as rtfm;
180
+extern crate embedded_epd as epd;
181
+extern crate embedded_hal;
182
+extern crate mkl25z4;
183
+extern crate mkl25z4_hal as hal;
184
+//extern crate panic_halt;
185
+extern crate panic_semihosting;
186
+extern crate void;
187
+#[macro_use(block)]
188
+extern crate nb;
189
+extern crate bme280;
190
+
191
+mod board;
192
+mod assets {
193
+    include!(concat!(env!("OUT_DIR"), "/assets.rs"));
194
+}
195
+
196
+use bme280::BME280;
197
+use board::led;
198
+use embedded_hal::prelude::*;
199
+use embedded_hal::timer::CountDown;
200
+use epd::{gui, Display};
201
+use hal::gpio::GpioExt;
202
+use hal::i2c::BlockingI2c;
203
+use hal::spi::{Phase, Polarity, Spi};
204
+use hal::time::{NonCopyableMonoTimer, U32Ext};
205
+use hal::timer::{Timer, TimerInterrupt};
206
+use rt::pre_init;
207
+use rtfm::{app, Threshold};
208
+
209
+/*use core::sync::atomic;
210
+use core::sync::atomic::Ordering;*/
211
+
212
+struct EPDTimer<Timer> {
213
+    timer: Timer,
214
+}
215
+
216
+impl<Timer> CountDown for EPDTimer<Timer>
217
+where
218
+    Timer: CountDown<Time = hal::time::Hertz>,
219
+{
220
+    type Time = epd::Hertz;
221
+
222
+    fn start<T>(&mut self, timeout: T)
223
+    where
224
+        T: Into<epd::Hertz>,
225
+    {
226
+        self.timer.start(hal::time::Hertz(timeout.into().0))
227
+    }
228
+
229
+    fn wait(&mut self) -> nb::Result<(), void::Void> {
230
+        self.timer.wait()
231
+    }
232
+}
233
+
234
+#[pre_init]
235
+unsafe fn disable_watchdog() {
236
+    use mkl25z4::SIM;
237
+    (*SIM::ptr()).copc.write(|w| w.bits(0));
238
+}
239
+
240
+app! {
241
+    device: mkl25z4,
242
+
243
+    resources: {
244
+        static ON: bool = false;
245
+        static pit: hal::timer::Timer<mkl25z4::PIT>;
246
+        static rgb_led: led::Led;
247
+    },
248
+
249
+    tasks: {
250
+        PIT: {
251
+            path: pit_handler,
252
+            resources: [pit, rgb_led, ON],
253
+        },
254
+    },
255
+}
256
+
257
+fn init(mut p: init::Peripherals, _r: init::Resources) -> init::LateResources {
258
+    mkl25z4_hal::watchdog::disable(&mut p.device.SIM);
259
+    let clocks = mkl25z4_hal::clocks::init();
260
+    //let time = hal::time::MonoTimer::new(p.device.PIT, clocks, &mut p.device.SIM);
261
+
262
+    let mut gpiob = p.device.GPIOB.split(&mut p.device.SIM);
263
+    let mut gpioc = p.device.GPIOC.split(&mut p.device.SIM);
264
+    let mut gpiod = p.device.GPIOD.split(&mut p.device.SIM);
265
+
266
+    let mut led = led::Led {
267
+        red: gpiob.pb18.into_push_pull_output(&mut gpiob.pddr),
268
+        green: gpiob.pb19.into_push_pull_output(&mut gpiob.pddr),
269
+        blue: gpiod.pd1.into_push_pull_output(&mut gpiod.pddr),
270
+    };
271
+    //led::init(&p.device.PORTB, &p.device.GPIOB, &p.device.PORTD, &p.device.GPIOD, &p.device.SIM);
272
+    led.set_color(true, true, true);
273
+
274
+    let timer = NonCopyableMonoTimer::new(p.device.PIT, clocks, &mut p.device.SIM);
275
+    let scl = gpiob.pb2.into_alternate(&mut gpiob.pddr);
276
+    let sda = gpiob.pb3.into_alternate(&mut gpiob.pddr);
277
+    let i2c0 = BlockingI2c::i2c0(
278
+        p.device.I2C0,
279
+        sda,
280
+        scl,
281
+        100000u32.hz(),
282
+        timer,
283
+        clocks,
284
+        &mut p.device.SIM,
285
+        1000000,
286
+        10,
287
+        1000000,
288
+        1000000,
289
+    );
290
+    let mut bme280 = BME280::new_primary(i2c0);
291
+    let (_, _, _, timer) = i2c0.free(&mut p.device.SIM);
292
+    let pit_ = timer.free(&mut p.device.SIM);
293
+
294
+    /*for _ in 0..2 {
295
+        time.delay_ms(1000);
296
+        led.set_color(false, false, true);
297
+        time.delay_ms(1000);
298
+        led.set_color(false, true, false);
299
+    }*/
300
+
301
+    let mosi = gpioc.pc6.into_alternate(&mut gpioc.pddr);
302
+    let miso = gpioc.pc7.into_alternate(&mut gpioc.pddr);
303
+    let sck = gpioc.pc5.into_alternate(&mut gpioc.pddr);
304
+    let mode = hal::spi::Mode {
305
+        polarity: Polarity::IdleLow,
306
+        phase: Phase::CaptureOnFirstTransition,
307
+    };
308
+    let spi0 = Spi::spi0(p.device.SPI0, mosi, miso, sck, mode, &mut p.device.SIM);
309
+
310
+    // Initialize the display.
311
+    let busy = gpioc.pc3.into_floating_input(&mut gpioc.pddr);
312
+    let mut reset = gpioc.pc2.into_push_pull_output(&mut gpioc.pddr);
313
+    reset.set_high();
314
+    let mut data_cmd = gpioc.pc1.into_push_pull_output(&mut gpioc.pddr);
315
+    data_cmd.set_high();
316
+    let mut cs = gpioc.pc0.into_push_pull_output(&mut gpioc.pddr);
317
+    cs.set_high();
318
+
319
+    let t = EPDTimer {
320
+        timer: Timer::pit(pit_, hal::time::Hertz(1), clocks, &mut p.device.SIM),
321
+    };
322
+
323
+    let mut display = epd::gdew042z15::GDEW042Z15::new(spi0, busy, reset, data_cmd, cs, t);
324
+    block!(display.init()).ok();
325
+    block!(display.start_frame()).ok();
326
+    led.set_color(false, false, false);
327
+    let layout = gui::Layout::new(
328
+        400,
329
+        300,
330
+        gui::VerticalSplit::expand_bottom(
331
+            24,
332
+            gui::Fill::new(epd::Color::White),
333
+            gui::VerticalSplit::expand_bottom(
334
+                1,
335
+                gui::Fill::new(epd::Color::Black),
336
+                gui::HorizontalSplit::expand_right(
337
+                    48,
338
+                    gui::Fill::new(epd::Color::White),
339
+                    //gui::Image::new(&assets::ALARM_CLOCK_36),
340
+                    gui::HorizontalSplit::expand_right(
341
+                        1,
342
+                        gui::Fill::new(epd::Color::Black),
343
+                        gui::HorizontalSplit::expand_left(
344
+                            49,
345
+                            gui::VerticalSplit::expand_bottom(
346
+                                132,
347
+                                gui::Align::new(
348
+                                    gui::HorizontalAlign::Center,
349
+                                    gui::VerticalAlign::Top,
350
+                                    gui::Text::new("12:34", &assets::ROBOTO_100),
351
+                                ),
352
+                                gui::Align::new(
353
+                                    gui::HorizontalAlign::Center,
354
+                                    gui::VerticalAlign::Top,
355
+                                    gui::HorizontalSplit::expand_right(
356
+                                        36,
357
+                                        gui::Image::new(&assets::ALARM_CLOCK_36),
358
+                                        gui::Text::new("Do. 8:00", &assets::ROBOTO_30),
359
+                                    ),
360
+                                ),
361
+                            ),
362
+                            gui::Fill::new(epd::Color::White),
363
+                        ),
364
+                    ),
365
+                ),
366
+            ),
367
+        ),
368
+    );
369
+    let mut row_buffer = [0u8; 400 / 8];
370
+    layout.render(&mut display, &mut row_buffer);
371
+    display.end_frame();
372
+    led.set_color(true, true, false);
373
+
374
+    let (_, _, _, _, _, mut t) = display.destroy();
375
+
376
+    /*let pit_ = display.time.deactivate(&mut p.device.SIM);*/
377
+    t.start(epd::Hertz(1));
378
+    t.timer.enable_interrupt();
379
+    p.core.NVIC.enable(mkl25z4::Interrupt::PIT);
380
+
381
+    led.set_color(true, true, true);
382
+
383
+    init::LateResources {
384
+        pit: t.timer,
385
+        rgb_led: led,
386
+    }
387
+}
388
+
389
+fn idle() -> ! {
390
+    // Sleep
391
+    loop {
392
+        // wfi needs to be disabled for GDB
393
+        /*// add some side effect to prevent this from turning into a UDF instruction
394
+        // see rust-lang/rust#28728 for details
395
+        atomic::compiler_fence(Ordering::SeqCst);*/
396
+        rtfm::wfi();
397
+    }
398
+}
399
+
400
+// TASKS
401
+
402
+// Toggle the state of the LED
403
+fn pit_handler(_t: &mut Threshold, mut r: PIT::Resources) {
404
+    if *r.ON {
405
+        r.rgb_led.set_color(false, false, true);
406
+    } else {
407
+        r.rgb_led.set_color(true, false, false);
408
+    }
409
+    r.pit.wait().ok();
410
+    *r.ON = !*r.ON;
411
+}*/

Завантаження…
Відмінити
Зберегти