Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
b35b1cd883 update LED "off" state to be 2% PWM 2025-11-21 14:01:04 -07:00
6f67bc11de add ability to set max volume pct 2025-11-21 12:00:42 -07:00
2 changed files with 18 additions and 7 deletions

View file

@ -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,
}
}
@ -430,13 +436,13 @@ impl App {
}
if self.timers.led0_timer.need_service() {
let out = match self.settings.brightness {
Level::Off => 0,
Level::Off => 2,
Level::Low => 5,
Level::Medium => 25,
Level::High => 75,
Level::Maximum => {
self.sequences.led0.next();
self.sequences.led0.get_value() / 6
core::cmp::max(self.sequences.led0.get_value() / 6, 2)
}
};
@ -447,13 +453,13 @@ impl App {
}
if self.timers.led1_timer.need_service() {
let out = match self.settings.brightness {
Level::Off => 0,
Level::Off => 2,
Level::Low => 5,
Level::Medium => 25,
Level::High => 75,
Level::Maximum => {
self.sequences.led1.next();
self.sequences.led1.get_value() / 6
core::cmp::max(self.sequences.led1.get_value() / 6, 2)
}
};
self.timers.led1_timer.service();
@ -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);

View file

@ -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