more cleanup of dead code in main.rs

This commit is contained in:
sigil-03 2025-11-04 12:05:16 -07:00
parent 9e34e77e95
commit f17811cdce

View file

@ -15,7 +15,7 @@ use synthesizer::AppSynthesizers;
mod app;
use app::{
App, Config, Interfaces, Sequences, Services, State, TimerConfig, sequencer::BasicSequence,
sequencer::BasicSequence, App, Config, Interfaces, Sequences, Services, State, TimerConfig,
};
use ch32_hal::{adc::AdcChannel, interrupt::typelevel::Handler, timer::low_level::OutputPolarity};
@ -122,13 +122,8 @@ struct InputFlags {
volume_btn_flag: bool,
light_ctrl_btn_flag: bool,
systick_flag: Flag,
// synth_tick_flag: bool,
}
// impl InputFlags {
// pub fn sense_coin_flag(&self) -> bool {}
// }
impl Default for InputFlags {
fn default() -> Self {
Self {
@ -141,21 +136,6 @@ impl Default for InputFlags {
}
}
// impl InputFlags {
// pub fn set_sense_coin_flag(&mut self, val: bool) {
// self.sense_coin_flag = val;
// }
// pub fn set_main_btn_flag(&mut self, val: bool) {
// self.main_btn_flag = val;
// }
// pub fn set_volume_btn_flag(&mut self, val: bool) {
// self.volume_btn_flag = val;
// }
// pub fn set_light_ctrl_btn_flag(&mut self, val: bool) {
// self.light_ctrl_btn_flag = val;
// }
// }
static mut INPUT_FLAGS: InputFlags = InputFlags {
sense_coin_flag: false,
main_btn_flag: false,
@ -177,46 +157,6 @@ impl Handler<hal::interrupt::typelevel::EXTI7_0> for Test {
}
}
static mut LED: Option<ch32_hal::gpio::Output<'_>> = None;
static mut SYSTICK_COUNT: u32 = 0;
static mut SYNTHESIZERS: Option<AppSynthesizers<'_, ch32_hal::peripherals::TIM1>> = None;
static mut TOGGLE_COUNT: u32 = 0;
static mut TICK_FLAG: bool = false;
static mut SYNTH_TICK_FLAG: bool = false;
static mut NOTE_TICK_FLAG: bool = false;
static mut FREQ: [usize; 2] = [220, 440];
static mut INDEX: usize = 0;
fn flag() -> bool {
unsafe { core::ptr::read_volatile(&raw const TICK_FLAG as *const bool) }
}
fn clear_flag() {
unsafe {
TICK_FLAG = false;
}
}
fn synth_flag() -> bool {
unsafe { core::ptr::read_volatile(&raw const SYNTH_TICK_FLAG as *const bool) }
}
fn clear_synth_flag() {
unsafe {
SYNTH_TICK_FLAG = false;
}
}
fn note_flag() -> bool {
unsafe { core::ptr::read_volatile(&raw const NOTE_TICK_FLAG as *const bool) }
}
fn clear_note_flag() {
unsafe {
NOTE_TICK_FLAG = false;
}
}
#[qingke_rt::interrupt(core)]
fn SysTick() {
let r = &ch32_hal::pac::SYSTICK;
@ -225,31 +165,9 @@ fn SysTick() {
r.sr().write(|w| w.set_cntif(false));
unsafe {
// if let Some(ref mut synthesizers) = SYNTHESIZERS {
// println!("tick");
// synthesizers.tick();
// }
SYNTH_TICK_FLAG = true;
// safe because single-threaded
#[allow(static_mut_refs)]
INPUT_FLAGS.systick_flag.set();
// if SYSTICK_COUNT % 5000 == 0 {
// NOTE_TICK_FLAG = true;
// }
// if SYSTICK_COUNT % 50000 == 0 {
// TICK_FLAG = true;
// // if let Some(ref mut led) = LED {
// // let toggle = TOGGLE_COUNT;
// // // println!("TOGGLE {toggle}");
// // TOGGLE_COUNT += 1;
// // led.toggle();
// // }
// // println!("HERE");
// }
SYSTICK_COUNT = SYSTICK_COUNT.wrapping_add(1);
}
}
@ -290,105 +208,6 @@ bind_interrupts!(struct Irqs {
use insert_coin::TickTimerService;
use insert_coin::{TickService, TickServiceData};
fn debug_main(mut p: hal::Peripherals) -> ! {
// LED0 output setup
use hal::gpio::{Level, Output};
let mut led = Output::new(p.PC3, Level::High, Default::default());
// unsafe {
// LED = Some(led);
// }
println!("pre");
riscv::asm::delay(20_000_000);
println!("post2");
let tick_rate_hz = 100000; // 50khz
// DAC output setup
let dac_pin = PwmPin::new_ch4::<0>(p.PC4);
// let dac_ch = hal::timer::Channel::Ch4;
// PWM timer setup
let mut pwm = SimplePwm::new(
p.TIM1,
None,
None,
None,
Some(dac_pin),
Hertz::khz(500),
CountingMode::default(),
);
let pwm_core = SimplePwmCore::new(pwm);
unsafe {
use qingke_rt::CoreInterrupt;
qingke::pfic::disable_interrupt(CoreInterrupt::SysTick as u8);
}
// === synthesizer setup ===
// unsafe {
// let mut synth = AppSynthesizers::new(tick_rate_hz, pwm_core);
// synth.square.set_freq(440);
// SYNTHESIZERS = Some(synth);
// }
let mut synth = AppSynthesizers::new(tick_rate_hz, pwm_core);
synth.square.set_freq(440);
#[cfg(feature = "enable_print")]
println!("begin loop");
systick_init(tick_rate_hz);
unsafe {
use qingke::interrupt::Priority;
use qingke_rt::CoreInterrupt;
qingke::pfic::set_priority(CoreInterrupt::SysTick as u8, Priority::P15 as u8);
qingke::pfic::enable_interrupt(CoreInterrupt::SysTick as u8);
}
let mut index = 0;
let freqs = [1567, 1396, 1318, 1174, 1046, 987, 880, 783, 698];
// let freqs = [100, 200, 300, 400, 500, 600, 700, 800, 900];
// let freqs = [
// 1000, 990, 980, 970, 960, 950, 940, 930, 920, 910, 900, 890, 880, 870, 860, 850, 840, 830,
// 820, 810, 800, 790, 780, 770, 760, 750, 740, 730, 720, 710, 700, 690, 680, 670, 660, 650,
// 640, 630, 620, 610, 600, 590, 580, 570, 560, 550, 540, 530, 520, 510, 500, 490, 480, 470,
// 460, 450, 440, 430, 420, 410, 400, 390, 380, 370, 360, 350, 340, 330, 320, 310, 300, 290,
// 280, 270, 260, 250, 240, 230, 220, 210, 200, 190, 180, 170, 160, 150, 140, 130, 120, 110,
// 100,
// ];
loop {
if flag() {
clear_flag();
led.toggle();
}
if synth_flag() {
clear_synth_flag();
synth.tick();
}
if note_flag() {
clear_note_flag();
synth.square.set_freq(freqs[index]);
// println!("{}", { freqs[index] });
// println!("{}", freqs[index]);
index += 1;
if index > freqs.len() - 1 {
index = 0;
}
}
// if (unsafe { TICK_FLAG == true }) {
// println!("TICK!");
// led.toggle();
// unsafe {
// TICK_FLAG = false;
// }
// }
}
}
fn app_main(mut p: hal::Peripherals) -> ! {
// === output setup ===