add ability for main button sound
This commit is contained in:
parent
10a38f9bbc
commit
60d6aaecd6
2 changed files with 22 additions and 16 deletions
|
|
@ -550,22 +550,16 @@ impl App {
|
||||||
pub fn shut_down(&mut self) {
|
pub fn shut_down(&mut self) {
|
||||||
self.interfaces
|
self.interfaces
|
||||||
.pwm_core
|
.pwm_core
|
||||||
.disable(ch32_hal::timer::Channel::Ch1);
|
.write_amplitude(self.services.led0.channel, 0);
|
||||||
self.interfaces
|
self.interfaces
|
||||||
.pwm_core
|
.pwm_core
|
||||||
.disable(ch32_hal::timer::Channel::Ch2);
|
.write_amplitude(self.services.led1.channel, 0);
|
||||||
self.interfaces
|
crate::riscv::asm::delay(20_000_000);
|
||||||
.pwm_core
|
|
||||||
.disable(ch32_hal::timer::Channel::Ch3);
|
|
||||||
self.interfaces
|
|
||||||
.pwm_core
|
|
||||||
.disable(ch32_hal::timer::Channel::Ch4);
|
|
||||||
|
|
||||||
self.interfaces.pwm_core.pwm.borrow().shutdown();
|
self.interfaces.pwm_core.pwm.borrow().shutdown();
|
||||||
self.interfaces.adc_core.shutdown();
|
self.interfaces.adc_core.shutdown();
|
||||||
|
|
||||||
self.interfaces.amp.disable();
|
self.interfaces.amp.disable();
|
||||||
crate::riscv::asm::delay(20_000_000);
|
|
||||||
}
|
}
|
||||||
pub fn volume_button(&mut self) {
|
pub fn volume_button(&mut self) {
|
||||||
self.settings.volume.next();
|
self.settings.volume.next();
|
||||||
|
|
@ -629,7 +623,7 @@ impl App {
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
impl App {
|
impl App {
|
||||||
fn main_button_click(&mut self) {
|
pub fn main_button_click(&mut self) {
|
||||||
// TODO
|
// TODO
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("click");
|
println!("click");
|
||||||
|
|
|
||||||
|
|
@ -268,10 +268,6 @@ fn app_main(mut p: hal::Peripherals) {
|
||||||
let led1_pin = PwmPin::new_ch1::<0>(p.PD2);
|
let led1_pin = PwmPin::new_ch1::<0>(p.PD2);
|
||||||
let led1_ch = hal::timer::Channel::Ch1;
|
let led1_ch = hal::timer::Channel::Ch1;
|
||||||
|
|
||||||
// // LED2 output setup
|
|
||||||
// let led2_pin = PwmPin::new_ch2::<0>(p.PA1);
|
|
||||||
// let led2_ch = hal::timer::Channel::Ch2;
|
|
||||||
|
|
||||||
// DAC output setup
|
// DAC output setup
|
||||||
let dac_pin = PwmPin::new_ch4::<0>(p.PC4);
|
let dac_pin = PwmPin::new_ch4::<0>(p.PC4);
|
||||||
// let dac_ch = hal::timer::Channel::Ch4;
|
// let dac_ch = hal::timer::Channel::Ch4;
|
||||||
|
|
@ -290,14 +286,16 @@ fn app_main(mut p: hal::Peripherals) {
|
||||||
|
|
||||||
pwm.set_polarity(led0_ch, OutputPolarity::ActiveHigh);
|
pwm.set_polarity(led0_ch, OutputPolarity::ActiveHigh);
|
||||||
pwm.set_polarity(led1_ch, OutputPolarity::ActiveLow);
|
pwm.set_polarity(led1_ch, OutputPolarity::ActiveLow);
|
||||||
|
let mut pwm_core = SimplePwmCore::new(pwm);
|
||||||
|
pwm_core.write_amplitude(led0_ch, 0);
|
||||||
|
pwm_core.write_amplitude(led1_ch, 0);
|
||||||
|
|
||||||
// pwm.set_polarity(led2_ch, OutputPolarity::ActiveLow);
|
// pwm.set_polarity(led2_ch, OutputPolarity::ActiveLow);
|
||||||
|
|
||||||
let tick_rate_hz = 50000;
|
let tick_rate_hz = 50000;
|
||||||
|
|
||||||
let core_config = CoreConfig::new(tick_rate_hz);
|
let core_config = CoreConfig::new(tick_rate_hz);
|
||||||
|
|
||||||
let pwm_core = SimplePwmCore::new(pwm);
|
|
||||||
|
|
||||||
// === input setup ===
|
// === input setup ===
|
||||||
|
|
||||||
// adc
|
// adc
|
||||||
|
|
@ -401,6 +399,17 @@ fn app_main(mut p: hal::Peripherals) {
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
let need_sound = unsafe {
|
||||||
|
#[allow(static_mut_refs)]
|
||||||
|
if INPUT_FLAGS.main_btn_flag.active() {
|
||||||
|
#[allow(static_mut_refs)]
|
||||||
|
INPUT_FLAGS.main_btn_flag.clear();
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// init systick
|
// init systick
|
||||||
systick_init(tick_rate_hz);
|
systick_init(tick_rate_hz);
|
||||||
|
|
||||||
|
|
@ -432,6 +441,9 @@ fn app_main(mut p: hal::Peripherals) {
|
||||||
let mut light_ctrl_btn_prev = light_ctrl_btn_input.is_high_immediate();
|
let mut light_ctrl_btn_prev = light_ctrl_btn_input.is_high_immediate();
|
||||||
|
|
||||||
app.init();
|
app.init();
|
||||||
|
if need_sound {
|
||||||
|
app.main_button_click();
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
// system servicing
|
// system servicing
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue