diff options
author | Brian Cully <bjc@kublai.com> | 2022-10-25 12:20:32 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2022-10-25 12:20:32 -0400 |
commit | 0c4eb964b015961e3c90e45ef498f6c7f89eddba (patch) | |
tree | b0cc3b540e7123b45da044c73d1f47f98ce010ef /src/led.rs | |
parent | 0f80c612d59c855a99073e583db339fe6a42b883 (diff) | |
download | luchie-0c4eb964b015961e3c90e45ef498f6c7f89eddba.tar.gz luchie-0c4eb964b015961e3c90e45ef498f6c7f89eddba.zip |
convert to gd32f303 (stm32f103) bluepill variant
Diffstat (limited to 'src/led.rs')
-rw-r--r-- | src/led.rs | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -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) { |