humpback-dds/src/blinky.rs

77 lines
1.8 KiB
Rust

#![deny(warnings)]
#![deny(unsafe_code)]
#![no_main]
#![no_std]
extern crate panic_itm;
use cortex_m;
use cortex_m_rt::entry;
use stm32h7xx_hal::hal::digital::v2::OutputPin;
use stm32h7xx_hal::{pac, prelude::*};
use cortex_m_log::println;
use cortex_m_log::{
destination::Itm, printer::itm::InterruptSync as InterruptSyncItm,
};
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
let mut log = InterruptSyncItm::new(Itm::new(cp.ITM));
// Constrain and Freeze power
println!(log, "Setup PWR... ");
let pwr = dp.PWR.constrain();
let vos = pwr.freeze();
// Constrain and Freeze clock
println!(log, "Setup RCC... ");
let rcc = dp.RCC.constrain();
let ccdr = rcc.sys_ck(100.mhz()).freeze(vos, &dp.SYSCFG);
println!(log, "");
println!(log, "stm32h7xx-hal example - Blinky");
println!(log, "");
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB);
let gpioe = dp.GPIOE.split(ccdr.peripheral.GPIOE);
// Configure PE1 as output.
let mut green = gpiob.pb0.into_push_pull_output();
let mut yellow = gpioe.pe1.into_push_pull_output();
let mut red = gpiob.pb14.into_push_pull_output();
// Get the delay provider.
let mut delay = cp.SYST.delay(ccdr.clocks);
let mut num = 0;
loop {
delay.delay_ms(500_u16);
if num & 4 != 0 {
green.set_high().unwrap();
}
else {
green.set_low().unwrap();
}
if num & 2 != 0 {
yellow.set_high().unwrap();
}
else {
yellow.set_low().unwrap();
}
if num & 1 != 0 {
red.set_high().unwrap();
}
else {
red.set_low().unwrap();
}
num = (num + 1) % 8;
}
}