Compare commits

..

No commits in common. "max-volume-cap" and "main" have entirely different histories.

2 changed files with 7 additions and 18 deletions

View file

@ -186,7 +186,6 @@ pub use settings::Settings;
// #[cfg(feature = "enable_print")] // #[cfg(feature = "enable_print")]
use ch32_hal::println; use ch32_hal::println;
#[derive(Clone)]
pub struct TimerConfig { pub struct TimerConfig {
pub sp_timer_ms: usize, pub sp_timer_ms: usize,
pub lp_timer_ms: usize, pub lp_timer_ms: usize,
@ -298,11 +297,9 @@ impl Services {
} }
} }
#[derive(Clone)]
pub struct Config { pub struct Config {
pub system_tick_rate_hz: usize, pub system_tick_rate_hz: usize,
pub timers: TimerConfig, pub timers: TimerConfig,
pub max_volume_pct: u8,
} }
pub struct Sequences { pub struct Sequences {
@ -327,7 +324,6 @@ pub struct App {
services: Services, services: Services,
sequences: Sequences, sequences: Sequences,
interfaces: Interfaces, interfaces: Interfaces,
config: Config,
} }
use settings::Level; use settings::Level;
@ -339,15 +335,13 @@ impl App {
interfaces: Interfaces, interfaces: Interfaces,
settings: Settings, settings: Settings,
) -> Self { ) -> Self {
let tmr_cfg = config.clone();
Self { Self {
state: State::default(), state: State::default(),
settings, settings,
timers: Timers::new(tmr_cfg.timers, tmr_cfg.system_tick_rate_hz), timers: Timers::new(config.timers, config.system_tick_rate_hz),
services, services,
sequences, sequences,
interfaces, interfaces,
config,
} }
} }
@ -436,13 +430,13 @@ impl App {
} }
if self.timers.led0_timer.need_service() { if self.timers.led0_timer.need_service() {
let out = match self.settings.brightness { let out = match self.settings.brightness {
Level::Off => 2, Level::Off => 0,
Level::Low => 5, Level::Low => 5,
Level::Medium => 25, Level::Medium => 25,
Level::High => 75, Level::High => 75,
Level::Maximum => { Level::Maximum => {
self.sequences.led0.next(); self.sequences.led0.next();
core::cmp::max(self.sequences.led0.get_value() / 6, 2) self.sequences.led0.get_value() / 6
} }
}; };
@ -453,13 +447,13 @@ impl App {
} }
if self.timers.led1_timer.need_service() { if self.timers.led1_timer.need_service() {
let out = match self.settings.brightness { let out = match self.settings.brightness {
Level::Off => 2, Level::Off => 0,
Level::Low => 5, Level::Low => 5,
Level::Medium => 25, Level::Medium => 25,
Level::High => 75, Level::High => 75,
Level::Maximum => { Level::Maximum => {
self.sequences.led1.next(); self.sequences.led1.next();
core::cmp::max(self.sequences.led1.get_value() / 6, 2) self.sequences.led1.get_value() / 6
} }
}; };
self.timers.led1_timer.service(); self.timers.led1_timer.service();
@ -533,14 +527,10 @@ impl App {
} }
if self.services.synth0.need_service() { if self.services.synth0.need_service() {
let mut out = match self.services.synth0.service() { let out = match self.services.synth0.service() {
Some(value) => value / 6 / self.settings.volume.as_volume_divisor(), Some(value) => value / 6 / self.settings.volume.as_volume_divisor(),
None => 0, None => 0,
}; };
if out > self.config.max_volume_pct {
out = self.config.max_volume_pct;
}
self.interfaces self.interfaces
.pwm_core .pwm_core
.write_amplitude(ch32_hal::timer::Channel::Ch4, out); .write_amplitude(ch32_hal::timer::Channel::Ch4, out);

View file

@ -42,7 +42,7 @@ use qingke::riscv;
use crate::app::sequencer::{DynamicSequence, SequenceEntry}; use crate::app::sequencer::{DynamicSequence, SequenceEntry};
static LED0_SEQ: [u8; 8] = [5u8, 20u8, 45u8, 60u8, 75u8, 60u8, 45u8, 20u8]; static LED0_SEQ: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
pub struct Usb { pub struct Usb {
usb_pin: Input<'static>, usb_pin: Input<'static>,
@ -371,7 +371,6 @@ fn app_main(mut p: hal::Peripherals, app_settings: Settings) -> Settings {
let app_config = Config { let app_config = Config {
system_tick_rate_hz: tick_rate_hz, system_tick_rate_hz: tick_rate_hz,
timers: timer_config, timers: timer_config,
max_volume_pct: 10,
}; };
// DAC servicer setup // DAC servicer setup