1use embedded_hal::digital::v2::OutputPin;
2use crate::hal::gpio::{gpioc, Output, PushPull};
3
4pub struct Led {
6 pcx: gpioc::PCx<Output<PushPull>>,
7 on: bool,
8}
9
10impl Led {
11 pub fn new(mut gpioc: gpioc::Parts) -> Self {
13 let led = gpioc
14 .pc13
15 .into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper);
16
17 led.into()
18 }
19
20 pub fn off(&mut self) -> Result<(), ()> {
22 self.on = false;
23 self.pcx.set_low()
24 }
25
26 pub fn on(&mut self) -> Result<(), ()> {
28 self.on = true;
29 self.pcx.set_high()
30 }
31
32 pub fn is_on(&self) -> bool {
34 self.on
35 }
36}
37
38pub type LED = gpioc::PC13<Output<PushPull>>;
40
41impl Into<Led> for LED {
42 fn into(self) -> Led {
43 Led {
44 pcx: self.downgrade(),
45 on: false,
46 }
47 }
48}