From f3ac43614cf70eb8f0f82fa542d82b2b7cb772ef Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Sat, 15 Nov 2025 15:22:24 -0700 Subject: [PATCH] fix amp_en --- ch32v-insert-coin/src/app.rs | 11 +++-- ch32v-insert-coin/src/main.rs | 75 +---------------------------------- 2 files changed, 6 insertions(+), 80 deletions(-) diff --git a/ch32v-insert-coin/src/app.rs b/ch32v-insert-coin/src/app.rs index e2af3ef..d5ab28a 100644 --- a/ch32v-insert-coin/src/app.rs +++ b/ch32v-insert-coin/src/app.rs @@ -346,6 +346,8 @@ impl App { pub fn init(&mut self) { // self.timers.init(); + self.interfaces.amp.enable(); + self.timers.batt_adc_timer.reset(); self.timers.batt_adc_timer.enable(true); @@ -367,10 +369,11 @@ impl App { // self.timers.led2_timer.reset(); // self.timers.led2_timer.enable(true); - self.services.synth0.set_freq(1); + // self.services.synth0.set_freq(1); self.services.synth0.disable(); - self.services.sequencer.disable(); + + crate::riscv::asm::delay(2_500_000); } pub fn set_state(&mut self, state: State) { @@ -519,14 +522,10 @@ impl App { } else { self.services.sequencer.disable(); self.services.synth0.disable(); - self.interfaces.amp.disable(); } } if self.services.synth0.need_service() { - if !self.interfaces.amp.enabled() { - self.interfaces.amp.enable(); - } let out = match self.services.synth0.service() { Some(value) => value / 6 / self.settings.volume.as_volume_divisor(), None => 0, diff --git a/ch32v-insert-coin/src/main.rs b/ch32v-insert-coin/src/main.rs index 989a3ff..7517136 100644 --- a/ch32v-insert-coin/src/main.rs +++ b/ch32v-insert-coin/src/main.rs @@ -527,23 +527,12 @@ fn app_main(mut p: hal::Peripherals) { } } } -// // if adc1_timer.need_service() { -// // let val = adc.convert(&mut batt_monitor_pin, hal::adc::SampleTime::CYCLES241); -// // let val = adc.convert(&mut usb_detect_pin, hal::adc::SampleTime::CYCLES241); -// // #[cfg(feature = "enable_print")] -// // println!("ADC value: {}", val); - -// // adc1_timer.reset(); -// // adc1_timer.enable(true); -// // } -// } use ch32_hal::timer::low_level::{OutputCompareMode, Timer}; use ch32_hal::timer::Channel; // fn shutdown_main(p: Peripherals) { fn shutdown_main(p: hal::Peripherals) { - // drop(p.TIM1); // LED0 output setup let led0_pin = OutputOpenDrain::new(p.PC3, Level::Low, Default::default()); let led1_pin = OutputOpenDrain::new(p.PD2, Level::High, Default::default()); @@ -559,78 +548,16 @@ fn shutdown_main(p: hal::Peripherals) { let main_btn_pin = p.PD6; unsafe { system::init_gpio_irq(sense_coin_pin.pin(), sense_coin_pin.port(), true, false) }; - unsafe { system::init_gpio_irq(main_btn_pin.pin(), main_btn_pin.port(), true, true) }; + unsafe { system::init_gpio_irq(main_btn_pin.pin(), main_btn_pin.port(), true, false) }; let sense_coin_pin = Input::new(sense_coin_pin, Pull::None); let main_btn_pin = Input::new(main_btn_pin, Pull::None); - let mut t = Timer::new(p.TIM1); - // // t.stop(); - // // t.enable_channel(ch32_hal::timer::Channel::Ch1, false); - // // t.enable_channel(ch32_hal::timer::Channel::Ch2, false); - // // t.enable_channel(ch32_hal::timer::Channel::Ch3, false); - // // t.enable_channel(ch32_hal::timer::Channel::Ch4, false); - // // t.enable_update_interrupt(false); - // // t.set_moe(false); - - t.set_counting_mode(CountingMode::default()); - t.set_frequency(Hertz::khz(300)); - t.enable_outputs(); - t.start(); - - [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4] - .iter() - .for_each(|&channel| { - t.set_output_compare_mode(channel, OutputCompareMode::PwmMode1); - t.set_output_compare_preload(channel, true); - t.set_compare_value(channel, 1000); - t.enable_channel(channel, true); - }); - - // [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4] - // .iter() - // .for_each(|&channel| { - // t.set_output_compare_mode(channel, OutputCompareMode::PwmMode1); - // t.set_output_compare_preload(channel, false); - // t.enable_channel(channel, false); - // }); - - // t.stop(); - // t.disable_outputs() - - // PWM timer setup - // let mut pwm = SimplePwm::new( - // p.TIM1, - // None, - // // Some(led2_pin), - // None, - // None, - // None, - // Hertz::hz(1), - // CountingMode::default(), - // ); - // drop(pwm); - - // pwm.disable(); - riscv::asm::delay(1_000_000); - // let sense_coin_pin = p.PC2; - // let main_btn_pin = p.PD6; - // let volume_btn_pin = p.PC6; - // let light_ctrl_btn_pin = p.PC7; unsafe { system::enter_standby() }; riscv::asm::wfi(); - // t.set_moe(false); - // // pwm.shutdown(); - - // riscv::asm::delay(1_000_000); - - // unsafe { system::enter_standby() }; - // riscv::asm::wfi(); - // let mut b = t.get_compare_value(Channel::Ch1); - // b += 1; // loop { // unsafe { // #[allow(static_mut_refs)]