Skip to content

Commit

Permalink
leds: add touch mirror to menu + spi dma hack/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Dec 7, 2023
1 parent 796e67c commit 967290d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
32 changes: 32 additions & 0 deletions firmware/polyvec/src/gw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub trait EurorackPmod {
fn eeprom_serial(&self) -> u32;
fn jack(&self) -> u8;
fn touch(&self) -> [u8; 8];
fn led_set(&self, index: usize, value: i8);
fn led_auto(&self, index: usize);
fn input(&self, index: usize) -> i16;
}

Expand Down Expand Up @@ -62,6 +64,36 @@ macro_rules! eurorack_pmod {
]
}

fn led_set(&self, index: usize, value: i8) {

match index {
0 => self.csr_led0().write(|w| unsafe { w.bits((value as u8) as u32) } ),
1 => self.csr_led1().write(|w| unsafe { w.bits((value as u8) as u32) } ),
2 => self.csr_led2().write(|w| unsafe { w.bits((value as u8) as u32) } ),
3 => self.csr_led3().write(|w| unsafe { w.bits((value as u8) as u32) } ),
4 => self.csr_led4().write(|w| unsafe { w.bits((value as u8) as u32) } ),
5 => self.csr_led5().write(|w| unsafe { w.bits((value as u8) as u32) } ),
6 => self.csr_led6().write(|w| unsafe { w.bits((value as u8) as u32) } ),
7 => self.csr_led7().write(|w| unsafe { w.bits((value as u8) as u32) } ),
_ => panic!("bad index")
}

let mut mode = self.csr_led_mode().read().bits();
mode &= !(1 << index);
self.csr_led_mode().write(|w| unsafe { w.bits(mode) } );
}

fn led_auto(&self, index: usize) {

if index > 7 {
panic!("bad index");
}

let mut mode = self.csr_led_mode().read().bits();
mode |= 1 << index;
self.csr_led_mode().write(|w| unsafe { w.bits(mode) } );
}

fn input(&self, index: usize) -> i16 {
(match index {
0 => self.csr_cal_in0().read().bits(),
Expand Down
13 changes: 10 additions & 3 deletions firmware/polyvec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,23 @@ fn main() -> ! {
state.trace.len_us())
});


let touch = pmod0.touch();

draw::draw_main(&mut disp, opts, voices, &scope_samples, &touch,
draw::draw_main(&mut disp, opts.clone(), voices, &scope_samples, &touch,
irq0_len_us, trace_main.len_us()).ok();

for (n, v) in touch.iter().enumerate() {
if opts.touch.led_mirror.value == opt::TouchLedMirror::MirrorOn {
pmod0.led_set(n, (v >> 1) as i8);
} else {
pmod0.led_auto(n);
}
}

let fb = disp.swap_clear();
fence();
spi_dma.block();
spi_dma.transfer(fb.as_ptr(), fb.len());
spi_dma.block();

trace_main.end(&timer);
}
Expand Down
21 changes: 10 additions & 11 deletions firmware/polyvec/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ pub struct EnumOption<T> {

#[derive(Clone, Copy, PartialEq, EnumIter, IntoStaticStr)]
#[strum(serialize_all = "kebab-case")]
pub enum EnumTest {
ValueA,
ValueB,
ValueC
pub enum TouchLedMirror {
MirrorOff,
MirrorOn,
}

#[derive(Clone, Copy, PartialEq, EnumIter, IntoStaticStr)]
Expand All @@ -65,7 +64,6 @@ pub struct AdsrOptions {
pub struct ScopeOptions {
pub selected: Option<usize>,
pub delay_len: NumOption<u32>,
pub enum_test: EnumOption<EnumTest>,
pub trig_lvl: NumOption<i32>,
pub trig_sns: NumOption<i32>,
}
Expand All @@ -74,6 +72,7 @@ pub struct ScopeOptions {
pub struct TouchOptions {
pub selected: Option<usize>,
pub threshold: NumOption<u8>,
pub led_mirror: EnumOption<TouchLedMirror>,
}

macro_rules! impl_option_view {
Expand Down Expand Up @@ -104,10 +103,10 @@ impl_option_view!(AdsrOptions,
attack_ms, decay_ms, release_ms, resonance);

impl_option_view!(ScopeOptions,
delay_len, enum_test, trig_lvl, trig_sns);
delay_len, trig_lvl, trig_sns);

impl_option_view!(TouchOptions,
threshold);
led_mirror, threshold);


#[derive(Clone)]
Expand Down Expand Up @@ -182,10 +181,6 @@ impl Options {
min: 100,
max: 5000,
},
enum_test: EnumOption{
name: "enumt".into(),
value: EnumTest::ValueA,
},
},
touch: TouchOptions {
selected: None,
Expand All @@ -196,6 +191,10 @@ impl Options {
min: 0,
max: 255,
},
led_mirror: EnumOption{
name: "led".into(),
value: TouchLedMirror::MirrorOff,
},
}
}
}
Expand Down

0 comments on commit 967290d

Please sign in to comment.