use stm32f1xx_hal::{ gpio::{Cr, CRL, Floating, Input, Output, PushPull, gpiob::PB2}, }; enum State { Low, High, } type LEDPin = PB2; pub struct LED { pin: LEDPin>, state: State, } #[allow(unused)] impl LED { pub fn new(pin: LEDPin>, cr: &mut Cr) -> Self { let mut p = pin.into_push_pull_output(cr); p.set_low(); 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(); } pub fn off(&mut self) { self.state = State::Low; self.pin.set_low(); } pub fn toggle(&mut self) { if self.is_on() { self.off(); } else { self.on(); } } }