My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/hardware/devices/euro-yesman-1u/src/main.rs

66 lines
1.9 KiB

#![no_std]
#![no_main]
use cortex_m_rt::entry;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use stm32f1xx_hal::{delay::Delay, pac, prelude::*};
// Halt the MCU when panic
#[allow(unused_imports)]
use panic_halt;
mod seq;
pub use seq::{LayerSelect, SeqLayer, Sequencer};
#[entry]
fn main() -> ! {
// Grab handles for the underlying hardware objects
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
// Initialise GPIOC via the HAL
let mut rcc = dp.RCC.constrain();
let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
// Create an LED output
let mut led1 = gpioa.pa1.into_push_pull_output(&mut gpioa.crl);
let mut led2 = gpioa.pa2.into_push_pull_output(&mut gpioa.crl);
let mut led3 = gpioa.pa3.into_push_pull_output(&mut gpioa.crl);
let mut led4 = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
// Create a button input
let btn1 = gpiob.pb0.into_pull_down_input(&mut gpiob.crl);
let btn2 = gpiob.pb1.into_pull_down_input(&mut gpiob.crl);
let btn3 = gpiob.pb2.into_pull_down_input(&mut gpiob.crl);
let btn4 = gpiob.pb3.into_pull_down_input(&mut gpiob.crl);
// Initialize the delay object with the MCU frequency
let mut flash = dp.FLASH.constrain();
let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(48.mhz())
.pclk1(24.mhz())
.freeze(&mut flash.acr);
let mut delay = Delay::new(cp.SYST, clocks);
// Now go blinkenlights
loop {
set_led(&btn1, &mut led1);
set_led(&btn2, &mut led2);
set_led(&btn3, &mut led3);
set_led(&btn4, &mut led4);
delay.delay_ms(5_u16);
}
}
fn set_led<'k, I: InputPin, O: OutputPin>(i: &'k I, o: &'k mut O) {
if let Ok(true) = i.is_high() {
o.set_low().ok();
} else {
o.set_high().ok();
}
}