move synthesizer into app struct

This commit is contained in:
sigil-03 2025-11-05 08:51:11 -07:00
parent b786bf174a
commit d3ccc70782
4 changed files with 87 additions and 26 deletions

View file

@ -75,6 +75,8 @@ pub mod sequencer {
use crate::insert_coin::{
LedService, Service, SimplePwmCore, TickService, TickServiceData, TickTimerService,
};
use crate::synthesizer::SynthesizerService;
pub use settings::Settings;
#[cfg(feature = "enable_print")]
@ -157,10 +159,23 @@ impl Timers {
}
}
// pub struct ServiceConfigs {
// }
// things that sort of don't touch hardware but also do?
// TODO: make this merged with the interfaces maybe
// but also maybe not, since these are things that require servicing
pub struct Services {
pub led0: LedService,
pub led1: LedService,
pub led2: LedService,
pub synth0: SynthesizerService,
}
impl Services {
pub fn tick(&mut self) {
self.synth0.tick();
}
}
pub struct Config {
@ -174,6 +189,7 @@ pub struct Sequences {
pub led2: sequencer::BasicSequence<'static>,
}
// things that touch hardware
pub struct Interfaces {
pub pwm_core: SimplePwmCore<'static, ch32_hal::peripherals::TIM1>,
}
@ -185,8 +201,6 @@ pub struct App {
services: Services,
sequences: Sequences,
interfaces: Interfaces,
// TODO: make this the "sound module" or whatever.
// synthesizers: AppSynthesizers,
}
impl App {
@ -222,6 +236,8 @@ impl App {
self.timers.led2_timer.reset();
self.timers.led2_timer.enable(true);
self.services.synth0.set_freq(440);
}
pub fn set_state(&mut self, state: State) {
@ -238,6 +254,7 @@ impl App {
pub fn tick(&mut self) {
self.timers.tick();
self.services.tick();
}
pub fn service(&mut self) {
@ -309,5 +326,32 @@ impl App {
.write_amplitude(self.services.led2.channel, self.services.led2.amplitude);
self.services.led2.service();
}
if self.services.synth0.need_service() {
let out = self.services.synth0.service();
self.interfaces
.pwm_core
.write_amplitude(ch32_hal::timer::Channel::Ch4, out);
}
}
}
// TODO LIST
//
// AUDIO:
// 1. volume control
// 2. dac switching
//
// LED:
// 1. brightness control
//
// INTERFACE:
// 1. short press handling
// 2. long press handling
// 3. volume press handling
// 4. brightness press handling
//
// SYSTEM:
// 1. deep sleep
// 2. battery voltage monitoring
// 3. battery voltage cutoff