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

85 lines
2.3 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 io;
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.pb5.into_pull_down_input(&mut gpiob.crl);
let btn4 = gpiob.pb6.into_pull_down_input(&mut gpiob.crl);
// Eurorack clock input/ gate output
let clk = gpiob.pb7.into_pull_down_input(&mut gpiob.crl);
let gate = gpiob.pb8.into_push_pull_output(&mut gpiob.crh);
// Setup the I/O states
let mut io = io::Io {
led1,
led2,
led3,
led4,
btn1,
btn2,
btn3,
btn4,
btn1_last: false,
btn2_last: false,
btn3_last: false,
btn4_last: false,
clk,
clk_last: false,
gate,
};
let mut seq = Sequencer::default();
// 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);
loop {
// Update sequencer state based on inputs
io.update_sequence(&mut seq);
// Write out gate CV
io.update_cv(&mut seq);
// Wait 5ms until we do it again
delay.delay_ms(5_u16);
}
}