proton_c/
led.rs

1use embedded_hal::digital::v2::OutputPin;
2use crate::hal::gpio::{gpioc, Output, PushPull};
3
4/// Abstraction for the only LED on the board
5pub struct Led {
6    pcx: gpioc::PCx<Output<PushPull>>,
7    on: bool,
8}
9
10impl Led {
11    /// Initializes the LED
12    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    /// Turns the LED off
21    pub fn off(&mut self) -> Result<(), ()> {
22        self.on = false;
23        self.pcx.set_low()
24    }
25
26    /// Turns the LED on
27    pub fn on(&mut self) -> Result<(), ()> {
28        self.on = true;
29        self.pcx.set_high()
30    }
31
32    /// Check the LED
33    pub fn is_on(&self) -> bool {
34        self.on
35    }
36}
37
38/// The only LED on the board
39pub 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}