diff options
Diffstat (limited to 'src-riscv/led.rs')
-rw-r--r-- | src-riscv/led.rs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/src-riscv/led.rs b/src-riscv/led.rs deleted file mode 100644 index 536121b..0000000 --- a/src-riscv/led.rs +++ /dev/null @@ -1,42 +0,0 @@ -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(); - } - } -} |