euro-yesman: add basic sequencer structures

wip/yesman
Katharina Fey 3 years ago
parent 6dcf150b1f
commit 05bd516c81
Signed by: kookie
GPG Key ID: 90734A9E619C8A6C
  1. 16
      hardware/euro-yesman/src/main.rs
  2. 66
      hardware/euro-yesman/src/seq.rs

@ -9,6 +9,8 @@ use stm32f1xx_hal::{delay::Delay, pac, prelude::*};
#[allow(unused_imports)]
use panic_halt;
mod seq;
pub use seq::{LayerSelect, SeqLayer, Sequencer};
#[entry]
fn main() -> ! {
@ -25,19 +27,19 @@ fn main() -> ! {
// Initialize the delay object with the MCU frequency
let mut flash = dp.FLASH.constrain();
let clocks = rcc.cfgr.sysclk(8.mhz()).freeze(&mut flash.acr);
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 {
led.set_high().ok();
delay.delay_ms(500_u16);
led.set_low().ok();
delay.delay_ms(1000_u16);
led.set_high().ok();
delay.delay_ms(250_u16);
led.set_low().ok();
delay.delay_ms(125_u16);
delay.delay_ms(1000_u16);
}
}

@ -0,0 +1,66 @@
/// Represent a single layer on the sequencer
pub struct SeqLayer {
/// List of steps that are either on or off
steps: [bool; 16],
/// The length of the sequence to loop
length: u8,
}
impl SeqLayer {
/// Get the step by index, wrapping around if the index is beyond the length
fn step(&self, idx: u8) -> bool {
let nidx = idx % self.length;
self.steps[nidx as usize]
}
fn set(&mut self, idx: usize, val: bool) {
self.steps[idx] = val;
}
}
/// Indicate which layer is selected
pub enum LayerSelect {
A,
B,
C,
D,
}
/// Main sequencer state structure
pub struct Sequencer {
a: SeqLayer,
b: SeqLayer,
c: SeqLayer,
d: SeqLayer,
active_layer: LayerSelect,
active_step: u8,
}
impl Sequencer {
/// Step to the next step, wrapping around at 16
pub fn step(&mut self) {
self.active_step %= self.active_step;
}
/// Get the current step for all four layers
pub fn get(&self) -> (bool, bool, bool, bool) {
let i = self.active_step;
(
self.a.step(i),
self.b.step(i),
self.c.step(i),
self.d.step(i),
)
}
/// Edit a step of the active layer
pub fn edit(&mut self, idx: usize, val: bool) {
assert!(idx <= 16);
match self.active_layer {
LayerSelect::A => self.a.set(idx, val),
LayerSelect::B => self.b.set(idx, val),
LayerSelect::C => self.c.set(idx, val),
LayerSelect::D => self.d.set(idx, val),
}
}
}
Loading…
Cancel
Save