add coin button handling and move coin dac inside app

This commit is contained in:
sigil-03 2025-11-05 11:42:27 -07:00
parent 930d10218f
commit c8c42c0194
5 changed files with 81 additions and 57 deletions

View file

@ -96,7 +96,7 @@ pub mod sequencer {
}
use crate::insert_coin::{
LedService, Service, SimplePwmCore, TickService, TickServiceData, TickTimerService,
DacService, LedService, Service, SimplePwmCore, TickService, TickServiceData, TickTimerService,
};
use crate::synthesizer::SynthesizerService;
@ -193,11 +193,13 @@ pub struct Services {
pub led1: LedService,
pub led2: LedService,
pub synth0: SynthesizerService,
pub sample_player: DacService<'static>,
}
impl Services {
pub fn tick(&mut self) {
self.synth0.tick();
self.sample_player.tick();
}
}
@ -352,9 +354,17 @@ impl App {
if self.services.synth0.need_service() {
let out = self.services.synth0.service() / self.settings.volume.as_volume_divisor();
// self.interfaces
// .pwm_core
// .write_amplitude(ch32_hal::timer::Channel::Ch4, out);
}
if self.services.sample_player.need_service() {
self.services.sample_player.service();
let out = self.services.sample_player.get_amplitude();
self.interfaces
.pwm_core
.write_amplitude(ch32_hal::timer::Channel::Ch4, out);
.write_amplitude(ch32_hal::timer::Channel::Ch4, out as u8);
}
}
}
@ -374,8 +384,10 @@ impl App {
pub fn main_button(&mut self) {
// TODO
}
pub fn coin_detect(&mut self) {
// TODO
pub fn coin_detect(&self) {
#[cfg(feature = "enable_print")]
println!("coin detect");
self.services.sample_player.play_sample();
}
}
@ -390,8 +402,6 @@ impl App {
// INTERFACE:
// 1. short press handling
// 2. long press handling
// 3. volume press handling
// 4. brightness press handling
//
// SYSTEM:
// 1. deep sleep
@ -401,3 +411,4 @@ impl App {
// STRETCH TODO LIST
// 1. clean up edge detector
// 2. better handling for pwm scaling (brightness / volume)
// 3. better interrupt handling structs