add some sequences

This commit is contained in:
sigil-03 2025-11-06 10:53:57 -07:00
parent 48b836904b
commit 1bdb68c0d4
3 changed files with 542 additions and 48 deletions

View file

@ -16,6 +16,10 @@ use debounced_gpio::DebouncedGPIO;
mod synthesizer;
use synthesizer::SynthesizerService;
// sequences
mod sequences;
use sequences::SEQUENCE_LIST;
mod app;
use app::{
sequencer::BasicSequence, App, Config, Interfaces, Sequences, Services, State, TimerConfig,
@ -39,27 +43,6 @@ use qingke::riscv;
use crate::app::sequencer::{DynamicSequence, SequenceEntry};
static LED0_SEQ: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
pub static TEST_SEQ: [app::sequencer::SequenceEntry; 2] = [
SequenceEntry {
frequency_hz: 440,
duration_ms: 1000,
},
SequenceEntry {
frequency_hz: 220,
duration_ms: 1000,
},
];
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 {
@ -284,7 +267,7 @@ fn app_main(mut p: hal::Peripherals) -> ! {
let sample_player = DacService::new(ch32_hal::timer::Channel::Ch4, dac_service_data);
sample_player.load_data(coin_sound);
let sequencer = app::sequencer::DynamicSequence::new(&TEST_SEQ, tick_rate_hz);
let sequencer = app::sequencer::DynamicSequence::new(&SEQUENCE_LIST[0], tick_rate_hz);
let app_services = Services {
led0: LedService::new(led0_ch),
@ -299,7 +282,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],
audio: &SEQUENCE_LIST,
};
let app_interfaces = Interfaces { pwm_core };
@ -431,29 +414,29 @@ fn app_main(mut p: hal::Peripherals) -> ! {
app.service();
match app.get_state() {
// enter standby
app::State::DeepSleep => {
unsafe { system::enter_standby() };
loop {
riscv::asm::wfi();
let mut config = hal::Config::default();
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
unsafe {
hal::rcc::init(config.rcc);
}
unsafe {
#[allow(static_mut_refs)]
if INPUT_FLAGS.sense_coin_flag.active() {
app.set_state(State::Active);
break;
}
};
}
}
// for everything else, don't do anything
_ => {}
}
// match app.get_state() {
// // enter standby
// app::State::DeepSleep => {
// unsafe { system::enter_standby() };
// loop {
// riscv::asm::wfi();
// let mut config = hal::Config::default();
// config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
// unsafe {
// hal::rcc::init(config.rcc);
// }
// unsafe {
// #[allow(static_mut_refs)]
// if INPUT_FLAGS.sense_coin_flag.active() {
// app.set_state(State::Active);
// break;
// }
// };
// }
// }
// // for everything else, don't do anything
// _ => {}
// }
}
}
// // if adc1_timer.need_service() {