From 48b836904b32759f38c83d8f58cbfe7f6449d4dd Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Thu, 6 Nov 2025 09:02:08 -0700 Subject: [PATCH] add support for multi-sequence --- ch32v-insert-coin/src/app.rs | 15 ++++++++++++--- ch32v-insert-coin/src/main.rs | 12 ++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ch32v-insert-coin/src/app.rs b/ch32v-insert-coin/src/app.rs index b1befab..47194e3 100644 --- a/ch32v-insert-coin/src/app.rs +++ b/ch32v-insert-coin/src/app.rs @@ -295,6 +295,7 @@ pub struct Sequences { pub led0: sequencer::BasicSequence<'static>, pub led1: sequencer::BasicSequence<'static>, pub led2: sequencer::BasicSequence<'static>, + pub audio: [&'static [sequencer::SequenceEntry]; 2], } // things that touch hardware @@ -345,7 +346,7 @@ impl App { self.timers.led2_timer.reset(); self.timers.led2_timer.enable(true); - self.services.synth0.set_freq(440); + self.services.synth0.set_freq(1); self.services.synth0.disable(); } @@ -521,7 +522,15 @@ impl App { // TODO #[cfg(feature = "enable_print")] println!("click"); - self.services.sequencer.play_sequence(&crate::TEST_SEQ, 1); + self.services + .sequencer + .play_sequence(self.sequences.audio[self.settings.button_sound_index], 1); + + self.settings.button_sound_index += 1; + if self.settings.button_sound_index > self.sequences.audio.len() - 1 { + self.settings.button_sound_index = 0; + } + self.services.synth0.enable(); // TODO: @@ -554,7 +563,7 @@ impl App { // 2. dac switching // 3. amp_en control // 4. write sequences -// 5. sample player start disabled +// 6. multiple sequences // // LED: // diff --git a/ch32v-insert-coin/src/main.rs b/ch32v-insert-coin/src/main.rs index 9fc0841..bb0678a 100644 --- a/ch32v-insert-coin/src/main.rs +++ b/ch32v-insert-coin/src/main.rs @@ -50,6 +50,17 @@ pub static TEST_SEQ: [app::sequencer::SequenceEntry; 2] = [ }, ]; +pub static TEST_SEQ1: [app::sequencer::SequenceEntry; 2] = [ + SequenceEntry { + frequency_hz: 440, + duration_ms: 100, + }, + SequenceEntry { + frequency_hz: 220, + duration_ms: 100, + }, +]; + #[derive(Debug)] struct Flag { value: bool, @@ -288,6 +299,7 @@ fn app_main(mut p: hal::Peripherals) -> ! { led0: BasicSequence::new(&LED0_SEQ), led1: BasicSequence::new(&LED0_SEQ), led2: BasicSequence::new(&LED0_SEQ), + audio: [&TEST_SEQ, &TEST_SEQ1], }; let app_interfaces = Interfaces { pwm_core };