add nucleo-f429zi board leds
This commit is contained in:
parent
edc440cceb
commit
1f80b456f3
|
@ -0,0 +1,46 @@
|
|||
use embedded_hal::digital::OutputPin;
|
||||
use stm32f4xx_hal::gpio::{
|
||||
Output, PushPull,
|
||||
gpiob::{PB0, PB7, PB14},
|
||||
};
|
||||
|
||||
type GreenPin = PB0<Output<PushPull>>;
|
||||
type BluePin = PB7<Output<PushPull>>;
|
||||
type RedPin = PB14<Output<PushPull>>;
|
||||
|
||||
pub struct Led<PIN> {
|
||||
pin: PIN,
|
||||
}
|
||||
|
||||
impl<PIN: OutputPin> Led<PIN> {
|
||||
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<GreenPin> {
|
||||
pub fn green(pin: GreenPin) -> Self {
|
||||
Self::new(pin)
|
||||
}
|
||||
}
|
||||
|
||||
impl Led<BluePin> {
|
||||
pub fn blue(pin: BluePin) -> Self {
|
||||
Self::new(pin)
|
||||
}
|
||||
}
|
||||
|
||||
impl Led<RedPin> {
|
||||
pub fn red(pin: RedPin) -> Self {
|
||||
Self::new(pin)
|
||||
}
|
||||
}
|
13
src/main.rs
13
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();
|
||||
// }
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue