From a9808211aeb98545d431a18e4a2fa8e3b2bd8218 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Fri, 28 Oct 2022 16:31:22 -0400 Subject: led: remove module, it's unnecessary --- src/led.rs | 50 -------------------------------------------------- src/main.rs | 10 ++++------ 2 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 src/led.rs (limited to 'src') diff --git a/src/led.rs b/src/led.rs deleted file mode 100644 index ba32fe0..0000000 --- a/src/led.rs +++ /dev/null @@ -1,50 +0,0 @@ -use stm32f1xx_hal::gpio::{gpiob::PB2, Cr, Floating, Input, Output, PushPull, CRL}; - -enum State { - Low, - High, -} - -type LEDPin = PB2; - -pub struct LED { - pin: LEDPin>, - state: State, -} - -#[allow(unused)] -impl LED { - pub fn new(pin: LEDPin>, cr: &mut Cr) -> Self { - let mut p = pin.into_push_pull_output(cr); - p.set_low(); - Self { - pin: p, - state: State::Low, - } - } - - pub fn is_on(&self) -> bool { - match self.state { - State::High => true, - State::Low => false, - } - } - - pub fn on(&mut self) { - self.state = State::High; - self.pin.set_high(); - } - - pub fn off(&mut self) { - self.state = State::Low; - self.pin.set_low(); - } - - pub fn toggle(&mut self) { - if self.is_on() { - self.off(); - } else { - self.on(); - } - } -} diff --git a/src/main.rs b/src/main.rs index 1697001..8c2bac1 100755 --- a/src/main.rs +++ b/src/main.rs @@ -4,11 +4,9 @@ //extern crate panic_semihosting; mod cirque; -mod led; mod log; use cirque::Cirque; -use led::LED; use cortex_m::{ asm::{bkpt, wfi}, @@ -43,7 +41,8 @@ fn main() -> ! { assert!(clocks.usbclk_valid()); let mut gpiob = dp.GPIOB.split(); - let mut led = LED::new(gpiob.pb2, &mut gpiob.crl); + let mut led = gpiob.pb2.into_push_pull_output(&mut gpiob.crl); + led.set_low(); let mut afio = dp.AFIO.constrain(); let mut gpioa = dp.GPIOA.split(); @@ -141,7 +140,7 @@ fn main() -> ! { match serial.read(&mut buf) { Ok(count) if count > 0 => { - led.on(); + led.set_high(); // Echo back in upper case for c in buf[0..count].iter_mut() { @@ -159,11 +158,10 @@ fn main() -> ! { _ => {} } } + led.set_low(); } _ => {} } - - led.off(); } } -- cgit v1.2.3