thingy_91_nrf9160_bsp/lib.rs
1//! Board support crate for the Nordic Thingy:91 nRF9160
2//! https://www.nordicsemi.com/Software-and-tools/Prototyping-platforms/Nordic-Thingy-91
3//!
4#![no_std]
5
6pub extern crate nrf9160_hal as hal;
7
8/// Exports traits that are usually needed when using this crate
9pub mod prelude {
10 pub use hal::prelude::*;
11}
12
13use hal::{
14 gpio::{p0, Disconnected, Input, Level, Output, Pin, PullUp, PushPull},
15 pac::{CorePeripherals, Peripherals, PWM0_NS},
16 pwm::{self, Pwm},
17 uarte::{self, Baudrate as UartBaudrate, Parity as UartParity, Uarte},
18};
19
20use hal::prelude::InputPin;
21
22pub use hal::pac;
23
24/// Provides access to all features of the Thingy:91 board
25#[allow(non_snake_case)]
26pub struct Board {
27 /// The nRF9160's pins which are not otherwise occupied on the Thingy:91
28 pub pins: Pins,
29
30 /// The Thingy:91 UART which is wired to the virtual USB CDC port
31 pub cdc_uart: Uarte<pac::UARTE0_NS>,
32
33 /// The LEDs on the Thingy:91 board
34 pub leds: Leds<PWM0_NS>,
35
36 /// The buttons on the Thingy:91 board
37 pub buttons: Buttons,
38
39 /// Cortex-M33 Core peripheral: Cache and branch predictor maintenance operations
40 pub CBP: pac::CBP,
41
42 /// Cortex-M33 Core peripheral: CPUID
43 pub CPUID: pac::CPUID,
44
45 /// Cortex-M33 Core peripheral: Debug Control Block
46 pub DCB: pac::DCB,
47
48 /// Cortex-M33 Core peripheral: Data Watchpoint and Trace unit
49 pub DWT: pac::DWT,
50
51 /// Cortex-M33 Core peripheral: Flash Patch and Breakpoint unit
52 pub FPB: pac::FPB,
53
54 /// Cortex-M33 Core peripheral: Floating Point Unit
55 pub FPU: pac::FPU,
56
57 /// Cortex-M33 Core peripheral: Instrumentation Trace Macrocell
58 pub ITM: pac::ITM,
59
60 /// Cortex-M33 Core peripheral: Memory Protection Unit
61 pub MPU: pac::MPU,
62
63 /// Cortex-M33 Core peripheral: Nested Vector Interrupt Controller
64 pub NVIC: pac::NVIC,
65
66 /// Cortex-M33 Core peripheral: System Control Block
67 pub SCB: pac::SCB,
68
69 /// Cortex-M33 Core peripheral: SysTick Timer
70 pub SYST: pac::SYST,
71
72 /// Cortex-M33 Core peripheral: Trace Port Interface Unit
73 pub TPIU: pac::TPIU,
74
75 /// nRF9160 Non-secure peripheral: Clock management 0
76 pub CLOCK_NS: pac::CLOCK_NS,
77
78 /// nRF9160 Non-secure peripheral: Distributed Programmable Peripheral Interconnect Controller 0
79 pub DPPIC_NS: pac::DPPIC_NS,
80
81 /// nRF9160 Non-secure peripheral: Event Generator Unit 0
82 pub EGU0_NS: pac::EGU0_NS,
83
84 /// nRF9160 Non-secure peripheral: Event Generator Unit 1
85 pub EGU1_NS: pac::EGU1_NS,
86
87 /// nRF9160 Non-secure peripheral: Event Generator Unit 2
88 pub EGU2_NS: pac::EGU2_NS,
89
90 /// nRF9160 Non-secure peripheral: Event Generator Unit 3
91 pub EGU3_NS: pac::EGU3_NS,
92
93 /// nRF9160 Non-secure peripheral: Event Generator Unit 3
94 pub EGU4_NS: pac::EGU4_NS,
95
96 /// nRF9160 Non-secure peripheral: Event Generator Unit 5
97 pub EGU5_NS: pac::EGU5_NS,
98
99 /// nRF9160 Non-secure peripheral: FPU 0
100 pub FPU_NS: pac::FPU_NS,
101
102 /// nRF9160 Non-secure peripheral: GPIO Tasks and Events 1
103 pub GPIOTE1_NS: pac::GPIOTE1_NS,
104
105 /// nRF9160 Non-secure peripheral: Inter-IC Sound 0
106 pub I2S_NS: pac::I2S_NS,
107
108 /// nRF9160 Non-secure peripheral: Inter Processor Communication 0
109 pub IPC_NS: pac::IPC_NS,
110
111 /// nRF9160 Non-secure peripheral: Key management unit 0
112 pub KMU_NS: pac::KMU_NS,
113
114 /// nRF9160 Non-secure peripheral: Non-volatile memory controller 0
115 pub NVMC_NS: pac::NVMC_NS,
116
117 /// nRF9160 Non-secure peripheral: Pulse Density Modulation (Digital Microphone) Interface 0
118 pub PDM_NS: pac::PDM_NS,
119
120 /// nRF9160 Non-secure peripheral: Power control 0
121 pub POWER_NS: pac::POWER_NS,
122
123 // nRF9160 Non-secure peripheral: Pulse width modulation unit 0
124 // Used by the RGB LED
125 // pub PWM0_NS: pac::PWM0_NS,
126 //
127 /// nRF9160 Non-secure peripheral: Pulse width modulation unit 1
128 pub PWM1_NS: pac::PWM1_NS,
129
130 /// nRF9160 Non-secure peripheral: Pulse width modulation unit 2
131 pub PWM2_NS: pac::PWM2_NS,
132
133 /// nRF9160 Non-secure peripheral: Pulse width modulation unit 3
134 pub PWM3_NS: pac::PWM3_NS,
135
136 /// nRF9160 Non-secure peripheral: Voltage regulators control 0
137 pub REGULATORS_NS: pac::REGULATORS_NS,
138
139 /// nRF9160 Non-secure peripheral: Real-time counter 0
140 pub RTC0_NS: pac::RTC0_NS,
141
142 /// nRF9160 Non-secure peripheral: Real-time counter 1
143 pub RTC1_NS: pac::RTC1_NS,
144
145 /// nRF9160 Non-secure peripheral: Analog to Digital Converter 0
146 pub SAADC_NS: pac::SAADC_NS,
147
148 /// nRF9160 Non-secure peripheral: Serial Peripheral Interface Master with EasyDMA 0
149 pub SPIM0_NS: pac::SPIM0_NS,
150
151 /// nRF9160 Non-secure peripheral: Serial Peripheral Interface Master with EasyDMA 1
152 pub SPIM1_NS: pac::SPIM1_NS,
153
154 /// nRF9160 Non-secure peripheral: Serial Peripheral Interface Master with EasyDMA 2
155 pub SPIM2_NS: pac::SPIM2_NS,
156
157 /// nRF9160 Non-secure peripheral: Serial Peripheral Interface Master with EasyDMA 3
158 pub SPIM3_NS: pac::SPIM3_NS,
159
160 /// nRF9160 Non-secure peripheral: SPI Slave 0
161 pub SPIS0_NS: pac::SPIS0_NS,
162
163 /// nRF9160 Non-secure peripheral: SPI Slave 1
164 pub SPIS1_NS: pac::SPIS1_NS,
165
166 /// nRF9160 Non-secure peripheral: SPI Slave 2
167 pub SPIS2_NS: pac::SPIS2_NS,
168
169 /// nRF9160 Non-secure peripheral: SPI Slave 3
170 pub SPIS3_NS: pac::SPIS3_NS,
171
172 /// nRF9160 Non-secure peripheral: Timer/Counter 0
173 pub TIMER0_NS: pac::TIMER0_NS,
174
175 /// nRF9160 Non-secure peripheral: Timer/Counter 1
176 pub TIMER1_NS: pac::TIMER1_NS,
177
178 /// nRF9160 Non-secure peripheral: Timer/Counter 2
179 pub TIMER2_NS: pac::TIMER2_NS,
180
181 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 0
182 pub TWIM0_NS: pac::TWIM0_NS,
183
184 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 1
185 pub TWIM1_NS: pac::TWIM1_NS,
186
187 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 2
188 pub TWIM2_NS: pac::TWIM2_NS,
189
190 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 3
191 pub TWIM3_NS: pac::TWIM3_NS,
192
193 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 0
194 pub TWIS0_NS: pac::TWIS0_NS,
195
196 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 1
197 pub TWIS1_NS: pac::TWIS1_NS,
198
199 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 2
200 pub TWIS2_NS: pac::TWIS2_NS,
201
202 /// nRF9160 Non-secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 3
203 pub TWIS3_NS: pac::TWIS3_NS,
204
205 /// nRF9160 Non-secure peripheral: UART with EasyDMA 1
206 pub UARTE1_NS: pac::UARTE1_NS,
207
208 /// nRF9160 Non-secure peripheral: UART with EasyDMA 2
209 pub UARTE2_NS: pac::UARTE2_NS,
210
211 /// nRF9160 Non-secure peripheral: UART with EasyDMA 3
212 pub UARTE3_NS: pac::UARTE3_NS,
213
214 /// nRF9160 Non-secure peripheral: Volatile Memory controller 0
215 pub VMC_NS: pac::VMC_NS,
216
217 /// nRF9160 Non-secure peripheral: Watchdog Timer 0
218 pub WDT_NS: pac::WDT_NS,
219}
220
221/// Contains all the 'secure' mode peripherals. The HAL doesn't support these
222/// yet but at least they're all together.
223#[allow(non_snake_case)]
224pub struct SecurePeripherals {
225 /// nRF9160 Secure peripheral: Clock management 1
226 pub CLOCK_S: pac::CLOCK_S,
227
228 /// nRF9160 Secure peripheral: ARM TrustZone CryptoCell register interface
229 pub CRYPTOCELL_S: pac::CRYPTOCELL_S,
230
231 /// nRF9160 Secure peripheral: Control access port
232 pub CTRL_AP_PERI_S: pac::CTRL_AP_PERI_S,
233
234 /// nRF9160 Secure peripheral: Distributed Programmable Peripheral Interconnect Controller 1
235 pub DPPIC_S: pac::DPPIC_S,
236
237 /// nRF9160 Secure peripheral: Event Generator Unit 1
238 pub EGU0_S: pac::EGU0_S,
239
240 /// nRF9160 Secure peripheral: Event Generator Unit 3
241 pub EGU1_S: pac::EGU1_S,
242
243 /// nRF9160 Secure peripheral: Event Generator Unit 5
244 pub EGU2_S: pac::EGU2_S,
245
246 /// nRF9160 Secure peripheral: Event Generator Unit 7
247 pub EGU3_S: pac::EGU3_S,
248
249 /// nRF9160 Secure peripheral: Event Generator Unit 9
250 pub EGU4_S: pac::EGU4_S,
251
252 /// nRF9160 Secure peripheral: Event Generator Unit 11
253 pub EGU5_S: pac::EGU5_S,
254
255 /// nRF9160 Secure peripheral: Factory Information Configuration Registers
256 pub FICR_S: pac::FICR_S,
257
258 /// nRF9160 Secure peripheral: FPU 1
259 pub FPU_S: pac::FPU_S,
260
261 /// nRF9160 Secure peripheral: GPIO Tasks and Events 0
262 pub GPIOTE0_S: pac::GPIOTE0_S,
263
264 /// nRF9160 Secure peripheral: Inter-IC Sound 1
265 pub I2S_S: pac::I2S_S,
266
267 /// nRF9160 Secure peripheral: Inter Processor Communication 1
268 pub IPC_S: pac::IPC_S,
269
270 /// nRF9160 Secure peripheral: Key management unit 1
271 pub KMU_S: pac::KMU_S,
272
273 /// nRF9160 Secure peripheral: Non-volatile memory controller 1
274 pub NVMC_S: pac::NVMC_S,
275
276 /// nRF9160 Secure peripheral: GPIO Port 1
277 pub P0_S: pac::P0_S,
278
279 /// nRF9160 Secure peripheral: Pulse Density Modulation (Digital Microphone) Interface 1
280 pub PDM_S: pac::PDM_S,
281
282 /// nRF9160 Secure peripheral: Power control 1
283 pub POWER_S: pac::POWER_S,
284
285 /// nRF9160 Secure peripheral: Pulse width modulation unit 1
286 pub PWM0_S: pac::PWM0_S,
287
288 /// nRF9160 Secure peripheral: Pulse width modulation unit 3
289 pub PWM1_S: pac::PWM1_S,
290
291 /// nRF9160 Secure peripheral: Pulse width modulation unit 5
292 pub PWM2_S: pac::PWM2_S,
293
294 /// nRF9160 Secure peripheral: Pulse width modulation unit 7
295 pub PWM3_S: pac::PWM3_S,
296
297 /// nRF9160 Secure peripheral: Voltage regulators control 1
298 pub REGULATORS_S: pac::REGULATORS_S,
299
300 /// nRF9160 Secure peripheral: Real-time counter 1
301 pub RTC0_S: pac::RTC0_S,
302
303 /// nRF9160 Secure peripheral: Real-time counter 3
304 pub RTC1_S: pac::RTC1_S,
305
306 /// nRF9160 Secure peripheral: Analog to Digital Converter 1
307 pub SAADC_S: pac::SAADC_S,
308
309 /// nRF9160 Secure peripheral: Serial Peripheral Interface Master with EasyDMA 1
310 pub SPIM0_S: pac::SPIM0_S,
311
312 /// nRF9160 Secure peripheral: Serial Peripheral Interface Master with EasyDMA 3
313 pub SPIM1_S: pac::SPIM1_S,
314
315 /// nRF9160 Secure peripheral: Serial Peripheral Interface Master with EasyDMA 5
316 pub SPIM2_S: pac::SPIM2_S,
317
318 /// nRF9160 Secure peripheral: Serial Peripheral Interface Master with EasyDMA 7
319 pub SPIM3_S: pac::SPIM3_S,
320
321 /// nRF9160 Secure peripheral: SPI Slave 1
322 pub SPIS0_S: pac::SPIS0_S,
323
324 /// nRF9160 Secure peripheral: SPI Slave 3
325 pub SPIS1_S: pac::SPIS1_S,
326
327 /// nRF9160 Secure peripheral: SPI Slave 5
328 pub SPIS2_S: pac::SPIS2_S,
329
330 /// nRF9160 Secure peripheral: SPI Slave 7
331 pub SPIS3_S: pac::SPIS3_S,
332
333 /// nRF9160 Secure peripheral: System protection unit
334 pub SPU_S: pac::SPU_S,
335
336 /// nRF9160 Secure peripheral: Trace and debug control
337 pub TAD_S: pac::TAD_S,
338
339 /// nRF9160 Secure peripheral: Timer/Counter 1
340 pub TIMER0_S: pac::TIMER0_S,
341
342 /// nRF9160 Secure peripheral: Timer/Counter 3
343 pub TIMER1_S: pac::TIMER1_S,
344
345 /// nRF9160 Secure peripheral: Timer/Counter 5
346 pub TIMER2_S: pac::TIMER2_S,
347
348 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 1
349 pub TWIM0_S: pac::TWIM0_S,
350
351 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 3
352 pub TWIM1_S: pac::TWIM1_S,
353
354 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 5
355 pub TWIM2_S: pac::TWIM2_S,
356
357 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Master Interface with EasyDMA 7
358 pub TWIM3_S: pac::TWIM3_S,
359
360 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 1
361 pub TWIS0_S: pac::TWIS0_S,
362
363 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 3
364 pub TWIS1_S: pac::TWIS1_S,
365
366 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 5
367 pub TWIS2_S: pac::TWIS2_S,
368
369 /// nRF9160 Secure peripheral: I2C compatible Two-Wire Slave Interface with EasyDMA 7
370 pub TWIS3_S: pac::TWIS3_S,
371
372 /// nRF9160 Secure peripheral: UART with EasyDMA 1
373 pub UARTE0_S: pac::UARTE0_S,
374
375 /// nRF9160 Secure peripheral: UART with EasyDMA 3
376 pub UARTE1_S: pac::UARTE1_S,
377
378 /// nRF9160 Secure peripheral: UART with EasyDMA 5
379 pub UARTE2_S: pac::UARTE2_S,
380
381 /// nRF9160 Secure peripheral: UART with EasyDMA 7
382 pub UARTE3_S: pac::UARTE3_S,
383
384 /// nRF9160 Secure peripheral: User information configuration registers User information configuration registers
385 pub UICR_S: pac::UICR_S,
386
387 /// nRF9160 Secure peripheral: Volatile Memory controller 1
388 pub VMC_S: pac::VMC_S,
389
390 /// nRF9160 Secure peripheral: Watchdog Timer 0
391 pub WDT_S: pac::WDT_S,
392}
393
394impl Board {
395 /// Take the peripherals safely
396 ///
397 /// This method will return an instance of the board the first time it is
398 /// called. It will return only `None` on subsequent calls.
399 pub fn take() -> Option<Self> {
400 Some(Self::new(CorePeripherals::take()?, Peripherals::take()?))
401 }
402
403 /// Steal the peripherals
404 ///
405 /// This method produces an instance of the board, regardless of whether
406 /// another instance was create previously.
407 ///
408 /// # Safety
409 ///
410 /// This method can be used to create multiple instances of the board. Those
411 /// instances can interfere with each other, causing all kinds of unexpected
412 /// behavior and circumventing safety guarantees in many ways.
413 ///
414 /// Always use `Board::take`, unless you really know what you're doing.
415 pub unsafe fn steal() -> Self {
416 Self::new(CorePeripherals::steal(), Peripherals::steal())
417 }
418
419 fn new(cp: CorePeripherals, p: Peripherals) -> Self {
420 let pins0 = p0::Parts::new(p.P0_NS);
421
422 // The Thingy:91 features a USB CDC port.
423 // It features HWFC but does not have to use it.
424 // It can transmit a flexible baudrate of up to 1Mbps.
425 let cdc_uart = Uarte::new(
426 p.UARTE0_NS,
427 uarte::Pins {
428 txd: pins0.p0_18.into_push_pull_output(Level::High).degrade(),
429 rxd: pins0.p0_19.into_floating_input().degrade(),
430 cts: Some(pins0.p0_21.into_floating_input().degrade()),
431 rts: Some(pins0.p0_20.into_push_pull_output(Level::High).degrade()),
432 },
433 UartParity::EXCLUDED,
434 UartBaudrate::BAUD115200,
435 );
436
437 Board {
438 cdc_uart,
439
440 pins: Pins {
441 P0_00: pins0.p0_00,
442 P0_01: pins0.p0_01,
443 P0_02: pins0.p0_02,
444 P0_03: pins0.p0_03,
445 P0_04: pins0.p0_04,
446 P0_05: pins0.p0_05,
447 P0_06: pins0.p0_06,
448 P0_07: pins0.p0_07,
449 P0_08: pins0.p0_08,
450 P0_09: pins0.p0_09,
451 P0_10: pins0.p0_10,
452 P0_11: pins0.p0_11,
453 P0_12: pins0.p0_12,
454 P0_13: pins0.p0_13,
455 P0_14: pins0.p0_14,
456 P0_15: pins0.p0_15,
457 P0_16: pins0.p0_16,
458 P0_17: pins0.p0_17,
459 // 18-21 are UARTE0
460 P0_22: pins0.p0_22,
461 P0_23: pins0.p0_23,
462 P0_24: pins0.p0_24,
463 P0_25: pins0.p0_25,
464 // 26 is a button
465 P0_27: pins0.p0_27,
466 P0_28: pins0.p0_28,
467 // 29-31 are LEDs
468 },
469
470 leds: Leds {
471 rgb_led_1: RgbLed::new(
472 Pwm::new(p.PWM0_NS),
473 pins0.p0_29.into_push_pull_output(Level::High).degrade(),
474 pins0.p0_30.into_push_pull_output(Level::High).degrade(),
475 pins0.p0_31.into_push_pull_output(Level::High).degrade(),
476 ),
477 },
478
479 buttons: Buttons {
480 button_1: Button::new(pins0.p0_26.degrade()),
481 },
482
483 // Core peripherals
484 CBP: cp.CBP,
485 CPUID: cp.CPUID,
486 DCB: cp.DCB,
487 DWT: cp.DWT,
488 FPB: cp.FPB,
489 FPU: cp.FPU,
490 ITM: cp.ITM,
491 MPU: cp.MPU,
492 NVIC: cp.NVIC,
493 SCB: cp.SCB,
494 SYST: cp.SYST,
495 TPIU: cp.TPIU,
496
497 // nRF9160 non-secure peripherals
498 CLOCK_NS: p.CLOCK_NS,
499 DPPIC_NS: p.DPPIC_NS,
500 EGU0_NS: p.EGU0_NS,
501 EGU1_NS: p.EGU1_NS,
502 EGU2_NS: p.EGU2_NS,
503 EGU3_NS: p.EGU3_NS,
504 EGU4_NS: p.EGU4_NS,
505 EGU5_NS: p.EGU5_NS,
506 FPU_NS: p.FPU_NS,
507 GPIOTE1_NS: p.GPIOTE1_NS,
508 I2S_NS: p.I2S_NS,
509 IPC_NS: p.IPC_NS,
510 KMU_NS: p.KMU_NS,
511 NVMC_NS: p.NVMC_NS,
512 PDM_NS: p.PDM_NS,
513 POWER_NS: p.POWER_NS,
514 // PWM0_NS: p.PWM0_NS,
515 PWM1_NS: p.PWM1_NS,
516 PWM2_NS: p.PWM2_NS,
517 PWM3_NS: p.PWM3_NS,
518 REGULATORS_NS: p.REGULATORS_NS,
519 RTC0_NS: p.RTC0_NS,
520 RTC1_NS: p.RTC1_NS,
521 SAADC_NS: p.SAADC_NS,
522 SPIM0_NS: p.SPIM0_NS,
523 SPIM1_NS: p.SPIM1_NS,
524 SPIM2_NS: p.SPIM2_NS,
525 SPIM3_NS: p.SPIM3_NS,
526 SPIS0_NS: p.SPIS0_NS,
527 SPIS1_NS: p.SPIS1_NS,
528 SPIS2_NS: p.SPIS2_NS,
529 SPIS3_NS: p.SPIS3_NS,
530 TIMER0_NS: p.TIMER0_NS,
531 TIMER1_NS: p.TIMER1_NS,
532 TIMER2_NS: p.TIMER2_NS,
533 TWIM0_NS: p.TWIM0_NS,
534 TWIM1_NS: p.TWIM1_NS,
535 TWIM2_NS: p.TWIM2_NS,
536 TWIM3_NS: p.TWIM3_NS,
537 TWIS0_NS: p.TWIS0_NS,
538 TWIS1_NS: p.TWIS1_NS,
539 TWIS2_NS: p.TWIS2_NS,
540 TWIS3_NS: p.TWIS3_NS,
541 UARTE1_NS: p.UARTE1_NS,
542 UARTE2_NS: p.UARTE2_NS,
543 UARTE3_NS: p.UARTE3_NS,
544 VMC_NS: p.VMC_NS,
545 WDT_NS: p.WDT_NS,
546 }
547 }
548}
549
550/// The nRF9160 pins that are available on the board
551#[allow(non_snake_case)]
552pub struct Pins {
553 pub P0_00: p0::P0_00<Disconnected>,
554 pub P0_01: p0::P0_01<Disconnected>,
555 pub P0_02: p0::P0_02<Disconnected>,
556 pub P0_03: p0::P0_03<Disconnected>,
557 pub P0_04: p0::P0_04<Disconnected>,
558 pub P0_05: p0::P0_05<Disconnected>,
559 pub P0_06: p0::P0_06<Disconnected>,
560 pub P0_07: p0::P0_07<Disconnected>,
561 pub P0_08: p0::P0_08<Disconnected>,
562 pub P0_09: p0::P0_09<Disconnected>,
563 pub P0_10: p0::P0_10<Disconnected>,
564 pub P0_11: p0::P0_11<Disconnected>,
565 pub P0_12: p0::P0_12<Disconnected>,
566 pub P0_13: p0::P0_13<Disconnected>,
567 pub P0_14: p0::P0_14<Disconnected>,
568 pub P0_15: p0::P0_15<Disconnected>,
569 pub P0_16: p0::P0_16<Disconnected>,
570 pub P0_17: p0::P0_17<Disconnected>,
571 // pub P0_18: p0::P0_18<Disconnected>,
572 // pub P0_19: p0::P0_19<Disconnected>,
573 // pub P0_20: p0::P0_20<Disconnected>,
574 // pub P0_21: p0::P0_21<Disconnected>,
575 pub P0_22: p0::P0_22<Disconnected>,
576 pub P0_23: p0::P0_23<Disconnected>,
577 pub P0_24: p0::P0_24<Disconnected>,
578 pub P0_25: p0::P0_25<Disconnected>,
579 // pub P0_26: p0::P0_26<Disconnected>,
580 pub P0_27: p0::P0_27<Disconnected>,
581 pub P0_28: p0::P0_28<Disconnected>,
582 // pub P0_29: p0::P0_29<Disconnected>,
583 // pub P0_30: p0::P0_30<Disconnected>,
584 // pub P0_31: p0::P0_31<Disconnected>,
585}
586
587/// The LEDs on the Thingy:91 board
588pub struct Leds<T>
589where
590 T: pwm::Instance,
591{
592 pub rgb_led_1: RgbLed<T>,
593}
594
595pub struct RgbLed<T>
596where
597 T: pwm::Instance,
598{
599 pub pwm: Pwm<T>,
600}
601
602impl<T> RgbLed<T>
603where
604 T: pwm::Instance,
605{
606 pub fn new(
607 pwm: Pwm<T>,
608 lightwell_red_pin: Pin<Output<PushPull>>,
609 lightwell_green_pin: Pin<Output<PushPull>>,
610 lightwell_blue_pin: Pin<Output<PushPull>>,
611 ) -> RgbLed<T> {
612 pwm.set_output_pin(pwm::Channel::C0, &lightwell_red_pin)
613 .set_output_pin(pwm::Channel::C1, &lightwell_green_pin)
614 .set_output_pin(pwm::Channel::C2, &lightwell_blue_pin);
615 RgbLed { pwm }
616 }
617}
618
619/// The Buttons on the Thingy:91 board
620pub struct Buttons {
621 /// Thingy:91: Button 1, nRF9160: P0.26
622 pub button_1: Button,
623}
624
625/// A Button on the Thingy:91 board
626pub struct Button(Pin<Input<PullUp>>);
627
628impl Button {
629 fn new<Mode>(pin: Pin<Mode>) -> Self {
630 Button(pin.into_pullup_input())
631 }
632
633 pub fn is_active(&self) -> bool {
634 self.0.is_low().unwrap()
635 }
636}