use gd32vf103xx_hal::{ gpio::{Floating, Input, Output, PushPull, Pxx, State, gpioa::PA7}, }; use embedded_hal::digital::v2::OutputPin; pub struct LED { pin: Pxx>, state: State, } impl LED { pub fn new(pin: PA7>) -> 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(); } } }