use embedded_hal::digital::v2::OutputPin;
use crate::hal::gpio::{gpioc, Output, PushPull};
pub struct Led {
pcx: gpioc::PCx<Output<PushPull>>,
on: bool,
}
impl Led {
pub fn new(mut gpioc: gpioc::Parts) -> Self {
let led = gpioc
.pc13
.into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper);
led.into()
}
pub fn off(&mut self) -> Result<(), ()> {
self.on = false;
self.pcx.set_low()
}
pub fn on(&mut self) -> Result<(), ()> {
self.on = true;
self.pcx.set_high()
}
pub fn is_on(&self) -> bool {
self.on
}
}
pub type LED = gpioc::PC13<Output<PushPull>>;
impl Into<Led> for LED {
fn into(self) -> Led {
Led {
pcx: self.downgrade(),
on: false,
}
}
}