add ability to set max volume pct
This commit is contained in:
parent
3265325d28
commit
6f67bc11de
2 changed files with 14 additions and 3 deletions
|
|
@ -186,6 +186,7 @@ pub use settings::Settings;
|
|||
// #[cfg(feature = "enable_print")]
|
||||
use ch32_hal::println;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TimerConfig {
|
||||
pub sp_timer_ms: usize,
|
||||
pub lp_timer_ms: usize,
|
||||
|
|
@ -297,9 +298,11 @@ impl Services {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
pub system_tick_rate_hz: usize,
|
||||
pub timers: TimerConfig,
|
||||
pub max_volume_pct: u8,
|
||||
}
|
||||
|
||||
pub struct Sequences {
|
||||
|
|
@ -324,6 +327,7 @@ pub struct App {
|
|||
services: Services,
|
||||
sequences: Sequences,
|
||||
interfaces: Interfaces,
|
||||
config: Config,
|
||||
}
|
||||
|
||||
use settings::Level;
|
||||
|
|
@ -335,13 +339,15 @@ impl App {
|
|||
interfaces: Interfaces,
|
||||
settings: Settings,
|
||||
) -> Self {
|
||||
let tmr_cfg = config.clone();
|
||||
Self {
|
||||
state: State::default(),
|
||||
settings,
|
||||
timers: Timers::new(config.timers, config.system_tick_rate_hz),
|
||||
timers: Timers::new(tmr_cfg.timers, tmr_cfg.system_tick_rate_hz),
|
||||
services,
|
||||
sequences,
|
||||
interfaces,
|
||||
config,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -527,10 +533,14 @@ impl App {
|
|||
}
|
||||
|
||||
if self.services.synth0.need_service() {
|
||||
let out = match self.services.synth0.service() {
|
||||
let mut out = match self.services.synth0.service() {
|
||||
Some(value) => value / 6 / self.settings.volume.as_volume_divisor(),
|
||||
None => 0,
|
||||
};
|
||||
|
||||
if out > self.config.max_volume_pct {
|
||||
out = self.config.max_volume_pct;
|
||||
}
|
||||
self.interfaces
|
||||
.pwm_core
|
||||
.write_amplitude(ch32_hal::timer::Channel::Ch4, out);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ use qingke::riscv;
|
|||
|
||||
use crate::app::sequencer::{DynamicSequence, SequenceEntry};
|
||||
|
||||
static LED0_SEQ: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
||||
static LED0_SEQ: [u8; 8] = [5u8, 20u8, 45u8, 60u8, 75u8, 60u8, 45u8, 20u8];
|
||||
|
||||
pub struct Usb {
|
||||
usb_pin: Input<'static>,
|
||||
|
|
@ -371,6 +371,7 @@ fn app_main(mut p: hal::Peripherals, app_settings: Settings) -> Settings {
|
|||
let app_config = Config {
|
||||
system_tick_rate_hz: tick_rate_hz,
|
||||
timers: timer_config,
|
||||
max_volume_pct: 10,
|
||||
};
|
||||
|
||||
// DAC servicer setup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue