aboutsummaryrefslogtreecommitdiffstats
path: root/src/led.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/led.rs')
-rw-r--r--src/led.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/led.rs b/src/led.rs
index 536121b..788ec81 100644
--- a/src/led.rs
+++ b/src/led.rs
@@ -1,17 +1,23 @@
-use gd32vf103xx_hal::{
- gpio::{Floating, Input, Output, PushPull, Pxx, State, gpioa::PA7},
+use stm32f1xx_hal::{
+ gpio::{Cr, CRL, Floating, Input, Output, PushPull, gpiob::PB2},
};
-use embedded_hal::digital::v2::OutputPin;
+
+enum State {
+ Low,
+ High,
+}
+
+type LEDPin<MODE> = PB2<MODE>;
pub struct LED {
- pin: Pxx<Output<PushPull>>,
+ pin: LEDPin<Output<PushPull>>,
state: State,
}
impl LED {
- pub fn new(pin: PA7<Input<Floating>>) -> Self {
- let mut p = pin.into_push_pull_output().downgrade();
- p.set_low().ok();
+ pub fn new(pin: LEDPin<Input<Floating>>, cr: &mut Cr<CRL, 'B'>) -> Self {
+ let mut p = pin.into_push_pull_output(cr);
+ p.set_low();
Self { pin: p, state: State::Low }
}
@@ -24,12 +30,12 @@ impl LED {
pub fn on(&mut self) {
self.state = State::High;
- self.pin.set_high().ok();
+ self.pin.set_high();
}
pub fn off(&mut self) {
self.state = State::Low;
- self.pin.set_low().ok();
+ self.pin.set_low();
}
pub fn toggle(&mut self) {