blob: 536121b6b1906572df6d72e7ec60a53ceb811863 (
plain)
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
|
use gd32vf103xx_hal::{
gpio::{Floating, Input, Output, PushPull, Pxx, State, gpioa::PA7},
};
use embedded_hal::digital::v2::OutputPin;
pub struct LED {
pin: Pxx<Output<PushPull>>,
state: State,
}
impl LED {
pub fn new(pin: PA7<Input<Floating>>) -> Self {
let mut p = pin.into_push_pull_output().downgrade();
p.set_low().ok();
Self { pin: p, state: State::Low }
}
pub fn is_on(&self) -> bool {
match self.state {
State::High => true,
State::Low => false,
}
}
pub fn on(&mut self) {
self.state = State::High;
self.pin.set_high().ok();
}
pub fn off(&mut self) {
self.state = State::Low;
self.pin.set_low().ok();
}
pub fn toggle(&mut self) {
if self.is_on() {
self.off();
} else {
self.on();
}
}
}
|