add amp_en control
This commit is contained in:
parent
1c2823eb1b
commit
8ea4b4401e
2 changed files with 33 additions and 2 deletions
|
|
@ -309,6 +309,7 @@ pub struct Sequences {
|
||||||
pub struct Interfaces {
|
pub struct Interfaces {
|
||||||
pub pwm_core: SimplePwmCore<'static, ch32_hal::peripherals::TIM1>,
|
pub pwm_core: SimplePwmCore<'static, ch32_hal::peripherals::TIM1>,
|
||||||
pub adc_core: crate::AdcCore,
|
pub adc_core: crate::AdcCore,
|
||||||
|
pub amp: crate::Amplifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
|
|
@ -502,10 +503,14 @@ impl App {
|
||||||
} else {
|
} else {
|
||||||
self.services.sequencer.disable();
|
self.services.sequencer.disable();
|
||||||
self.services.synth0.disable();
|
self.services.synth0.disable();
|
||||||
|
self.interfaces.amp.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.services.synth0.need_service() {
|
if self.services.synth0.need_service() {
|
||||||
|
if !self.interfaces.amp.enabled() {
|
||||||
|
self.interfaces.amp.enable();
|
||||||
|
}
|
||||||
let 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,
|
||||||
|
|
@ -540,6 +545,7 @@ impl App {
|
||||||
self.interfaces
|
self.interfaces
|
||||||
.pwm_core
|
.pwm_core
|
||||||
.disable(ch32_hal::timer::Channel::Ch4);
|
.disable(ch32_hal::timer::Channel::Ch4);
|
||||||
|
self.interfaces.amp.disable();
|
||||||
}
|
}
|
||||||
pub fn volume_button(&mut self) {
|
pub fn volume_button(&mut self) {
|
||||||
self.settings.volume.next();
|
self.settings.volume.next();
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,27 @@ use crate::app::sequencer::{DynamicSequence, SequenceEntry};
|
||||||
|
|
||||||
static LED0_SEQ: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
static LED0_SEQ: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
||||||
|
|
||||||
|
pub struct Amplifier {
|
||||||
|
amp_en: Output<'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Amplifier {
|
||||||
|
pub fn new(amp_en: Output<'static>) -> Self {
|
||||||
|
let mut amp = Self { amp_en };
|
||||||
|
amp.disable();
|
||||||
|
amp
|
||||||
|
}
|
||||||
|
pub fn enable(&mut self) {
|
||||||
|
self.amp_en.set_low();
|
||||||
|
}
|
||||||
|
pub fn disable(&mut self) {
|
||||||
|
self.amp_en.set_high();
|
||||||
|
}
|
||||||
|
pub fn enabled(&self) -> bool {
|
||||||
|
!self.amp_en.is_set_high()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use hal::adc::Adc;
|
use hal::adc::Adc;
|
||||||
use hal::peripherals::{ADC1, PD4};
|
use hal::peripherals::{ADC1, PD4};
|
||||||
|
|
||||||
|
|
@ -271,7 +292,7 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
||||||
let extra_io_2 = p.PD3;
|
let extra_io_2 = p.PD3;
|
||||||
|
|
||||||
let mut amp_en_output = Output::new(amp_en, Level::Low, Default::default());
|
let mut amp_en_output = Output::new(amp_en, Level::Low, Default::default());
|
||||||
amp_en_output.set_low();
|
let amp = Amplifier::new(amp_en_output);
|
||||||
|
|
||||||
// set up interrupts
|
// set up interrupts
|
||||||
unsafe { system::init_gpio_irq(sense_coin_pin.pin(), sense_coin_pin.port(), true, false) };
|
unsafe { system::init_gpio_irq(sense_coin_pin.pin(), sense_coin_pin.port(), true, false) };
|
||||||
|
|
@ -335,7 +356,11 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
||||||
audio: &SEQUENCE_LIST,
|
audio: &SEQUENCE_LIST,
|
||||||
};
|
};
|
||||||
|
|
||||||
let app_interfaces = Interfaces { pwm_core, adc_core };
|
let app_interfaces = Interfaces {
|
||||||
|
pwm_core,
|
||||||
|
adc_core,
|
||||||
|
amp,
|
||||||
|
};
|
||||||
|
|
||||||
let mut app = App::new(app_config, app_services, app_sequences, app_interfaces);
|
let mut app = App::new(app_config, app_services, app_sequences, app_interfaces);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue