From 1f80b456f3748b9361a80f461f9fb9399d1bf93e Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 14 Mar 2019 20:43:35 +0100 Subject: [PATCH] add nucleo-f429zi board leds --- src/led.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 13 +++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/led.rs diff --git a/src/led.rs b/src/led.rs new file mode 100644 index 0000000..7524c95 --- /dev/null +++ b/src/led.rs @@ -0,0 +1,46 @@ +use embedded_hal::digital::OutputPin; +use stm32f4xx_hal::gpio::{ + Output, PushPull, + gpiob::{PB0, PB7, PB14}, +}; + +type GreenPin = PB0>; +type BluePin = PB7>; +type RedPin = PB14>; + +pub struct Led { + pin: PIN, +} + +impl Led { + fn new(pin: PIN) -> Self { + Led { pin } + } + + pub fn on(&mut self) { + self.pin.set_high(); + } + + pub fn off(&mut self) { + self.pin.set_low(); + } +} + + +impl Led { + pub fn green(pin: GreenPin) -> Self { + Self::new(pin) + } +} + +impl Led { + pub fn blue(pin: BluePin) -> Self { + Self::new(pin) + } +} + +impl Led { + pub fn red(pin: RedPin) -> Self { + Self::new(pin) + } +} diff --git a/src/main.rs b/src/main.rs index 7d22169..664e536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,8 @@ mod net; mod server; use server::Server; mod timer; +mod led; +use led::Led; const OUTPUT_INTERVAL: u32 = 1000; @@ -81,6 +83,10 @@ fn main() -> ! { let gpioc = dp.GPIOC.split(); let gpiog = dp.GPIOG.split(); + let mut led_green = Led::green(gpiob.pb0.into_push_pull_output()); + let mut led_blue = Led::blue(gpiob.pb7.into_push_pull_output()); + let mut led_red = Led::red(gpiob.pb14.into_push_pull_output()); + info!("ADC init"); adc_input::setup(&mut cp.NVIC, dp.ADC1, gpioa.pa3); @@ -99,23 +105,30 @@ fn main() -> ! { let mut last_output = 0_u32; loop { + led_red.on(); let now = timer::now().0; let instant = Instant::from_millis(now as i64); server.poll(instant); if now - last_output >= OUTPUT_INTERVAL { + led_blue.on(); let adc_value = adc_input::read(); adc_value.map(|adc_value| { write!(server, "t={},pa3={}\r\n", now, adc_value).unwrap(); }); last_output = now; + led_blue.off(); } // Update watchdog wd.feed(); + led_red.off(); + // Wait for interrupts // if net.is_pending() { + led_green.on(); wfi(); + led_green.off(); // } } })