1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![no_std]
pub mod board_pins;
use nrf52840_hal::gpio::p0::P0_11;
use nrf52840_hal::gpio::p1::P1_12;
use nrf52840_hal::gpio::{Input, Output, PullUp, PushPull, Disconnected, Level};
use nrf52840_hal::prelude::*;
pub struct ModeButton {
pin: P0_11<Input<PullUp>>,
}
impl ModeButton {
pub fn new(pin: P0_11<Disconnected>) -> Self {
ModeButton {
pin: pin.into_pullup_input(),
}
}
pub fn is_held_down(&self) -> bool {
self.pin.is_low().unwrap()
}
}
pub struct Led {
pin: P1_12<Output<PushPull>>,
}
impl Led {
pub fn new(pin: P1_12<Disconnected>) -> Self {
Led {
pin: pin.into_push_pull_output(Level::Low),
}
}
pub fn on(&mut self) {
self.pin.set_high().unwrap();
}
pub fn off(&mut self) {
self.pin.set_low().unwrap();
}
}