do interrupt handling for sleep
This commit is contained in:
parent
935129baed
commit
a7cd209989
3 changed files with 93 additions and 46 deletions
|
|
@ -372,16 +372,18 @@ impl App {
|
||||||
pub fn service(&mut self) {
|
pub fn service(&mut self) {
|
||||||
// timers
|
// timers
|
||||||
if self.timers.sp_timer.need_service() {
|
if self.timers.sp_timer.need_service() {
|
||||||
self.timers.batt_adc_timer.service();
|
self.timers.sp_timer.service();
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("sp service");
|
println!("sp service");
|
||||||
self.timers.sp_timer.reset();
|
self.timers.sp_timer.reset();
|
||||||
|
self.main_button_short_press();
|
||||||
}
|
}
|
||||||
if self.timers.lp_timer.need_service() {
|
if self.timers.lp_timer.need_service() {
|
||||||
self.timers.batt_adc_timer.service();
|
self.timers.lp_timer.service();
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("lp service");
|
println!("lp service");
|
||||||
self.timers.lp_timer.reset();
|
self.timers.lp_timer.reset();
|
||||||
|
self.main_button_long_press();
|
||||||
}
|
}
|
||||||
if self.timers.batt_adc_timer.need_service() {
|
if self.timers.batt_adc_timer.need_service() {
|
||||||
self.timers.batt_adc_timer.service();
|
self.timers.batt_adc_timer.service();
|
||||||
|
|
@ -470,7 +472,7 @@ impl App {
|
||||||
|
|
||||||
if self.services.sample_player.need_service() {
|
if self.services.sample_player.need_service() {
|
||||||
self.services.sample_player.service();
|
self.services.sample_player.service();
|
||||||
let out = self.services.sample_player.get_amplitude() / 2;
|
let out = self.services.sample_player.get_amplitude() / 5;
|
||||||
self.interfaces
|
self.interfaces
|
||||||
.pwm_core
|
.pwm_core
|
||||||
.write_amplitude(ch32_hal::timer::Channel::Ch4, out as u8);
|
.write_amplitude(ch32_hal::timer::Channel::Ch4, out as u8);
|
||||||
|
|
@ -480,6 +482,20 @@ impl App {
|
||||||
|
|
||||||
// interfaces to the app (for buttons, etc.)
|
// interfaces to the app (for buttons, etc.)
|
||||||
impl App {
|
impl App {
|
||||||
|
pub fn shut_down(&mut self) {
|
||||||
|
self.interfaces
|
||||||
|
.pwm_core
|
||||||
|
.write_amplitude(self.services.led0.channel, 0);
|
||||||
|
self.interfaces
|
||||||
|
.pwm_core
|
||||||
|
.write_amplitude(self.services.led1.channel, 0);
|
||||||
|
self.interfaces
|
||||||
|
.pwm_core
|
||||||
|
.write_amplitude(self.services.led2.channel, 0);
|
||||||
|
self.interfaces
|
||||||
|
.pwm_core
|
||||||
|
.disable(ch32_hal::timer::Channel::Ch4);
|
||||||
|
}
|
||||||
pub fn volume_button(&mut self) {
|
pub fn volume_button(&mut self) {
|
||||||
self.settings.volume.next();
|
self.settings.volume.next();
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
|
|
@ -498,26 +514,29 @@ impl App {
|
||||||
self.timers.lp_timer.reset();
|
self.timers.lp_timer.reset();
|
||||||
self.timers.sp_timer.enable(true);
|
self.timers.sp_timer.enable(true);
|
||||||
self.timers.lp_timer.enable(true);
|
self.timers.lp_timer.enable(true);
|
||||||
|
self.main_button_click();
|
||||||
}
|
}
|
||||||
pub fn main_button_release(&mut self) {
|
pub fn main_button_release(&mut self) {
|
||||||
// TODO
|
// TODO
|
||||||
#[cfg(feature = "enable_print")]
|
// #[cfg(feature = "enable_print")]
|
||||||
println!("main button release");
|
// println!("main button release");
|
||||||
match (
|
// let timers = (
|
||||||
self.timers.sp_timer.is_enabled(),
|
// self.timers.sp_timer.is_enabled(),
|
||||||
self.timers.lp_timer.is_enabled(),
|
// self.timers.lp_timer.is_enabled(),
|
||||||
) {
|
// );
|
||||||
// click
|
|
||||||
(true, true) => self.main_button_click(),
|
|
||||||
// short press
|
|
||||||
(false, true) => self.main_button_short_press(),
|
|
||||||
// long press
|
|
||||||
(false, false) => self.main_button_long_press(),
|
|
||||||
// anything else is not possible
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
self.timers.sp_timer.reset();
|
self.timers.sp_timer.reset();
|
||||||
self.timers.lp_timer.reset();
|
self.timers.lp_timer.reset();
|
||||||
|
// match timers {
|
||||||
|
// // click
|
||||||
|
// (true, true) => self.main_button_click(),
|
||||||
|
// // short press
|
||||||
|
// (false, true) => self.main_button_short_press(),
|
||||||
|
// // long press
|
||||||
|
// (false, false) => self.main_button_long_press(),
|
||||||
|
// // anything else is not possible
|
||||||
|
// _ => {}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
pub fn coin_detect(&mut self) {
|
pub fn coin_detect(&mut self) {
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ impl<'d, T: GeneralInstance16bit> SimplePwmCore<'d, T> {
|
||||||
self.pwm.borrow_mut().set_duty(ch, dc);
|
self.pwm.borrow_mut().set_duty(ch, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn disable(&self, ch: Channel) {
|
pub fn disable(&self, ch: Channel) {
|
||||||
// self.pwm.borrow_mut().disable(ch);
|
self.pwm.borrow_mut().disable(ch);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub struct SimplePwmHandle<T: GeneralInstance16Bit> {
|
// pub struct SimplePwmHandle<T: GeneralInstance16Bit> {
|
||||||
|
|
|
||||||
|
|
@ -246,8 +246,8 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
||||||
DebouncedGPIO::new(light_ctrl_btn_pin.degrade(), core_config.tick_rate_hz, 100);
|
DebouncedGPIO::new(light_ctrl_btn_pin.degrade(), core_config.tick_rate_hz, 100);
|
||||||
|
|
||||||
let timer_config = TimerConfig {
|
let timer_config = TimerConfig {
|
||||||
sp_timer_ms: 2000,
|
sp_timer_ms: 1000,
|
||||||
lp_timer_ms: 5000,
|
lp_timer_ms: 3000,
|
||||||
batt_adc_timer_ms: 10000,
|
batt_adc_timer_ms: 10000,
|
||||||
usb_adc_timer_ms: 10000,
|
usb_adc_timer_ms: 10000,
|
||||||
led0_timer_ms: 100,
|
led0_timer_ms: 100,
|
||||||
|
|
@ -418,29 +418,57 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
||||||
|
|
||||||
app.service();
|
app.service();
|
||||||
|
|
||||||
// match app.get_state() {
|
match app.get_state() {
|
||||||
// // enter standby
|
// enter standby
|
||||||
// app::State::DeepSleep => {
|
app::State::DeepSleep => {
|
||||||
// unsafe { system::enter_standby() };
|
app.shut_down();
|
||||||
// loop {
|
|
||||||
// riscv::asm::wfi();
|
loop {
|
||||||
// let mut config = hal::Config::default();
|
unsafe { system::enter_standby() };
|
||||||
// config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
|
unsafe {
|
||||||
// unsafe {
|
#[allow(static_mut_refs)]
|
||||||
// hal::rcc::init(config.rcc);
|
INPUT_FLAGS.sense_coin_flag.clear();
|
||||||
// }
|
#[allow(static_mut_refs)]
|
||||||
// unsafe {
|
INPUT_FLAGS.main_btn_flag.clear();
|
||||||
// #[allow(static_mut_refs)]
|
}
|
||||||
// if INPUT_FLAGS.sense_coin_flag.active() {
|
riscv::asm::wfi();
|
||||||
// app.set_state(State::Active);
|
let mut config = hal::Config::default();
|
||||||
// break;
|
config.rcc = hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI;
|
||||||
// }
|
unsafe {
|
||||||
// };
|
hal::rcc::init(config.rcc);
|
||||||
// }
|
}
|
||||||
// }
|
unsafe {
|
||||||
// // for everything else, don't do anything
|
#[allow(static_mut_refs)]
|
||||||
// _ => {}
|
if INPUT_FLAGS.sense_coin_flag.active()
|
||||||
// }
|
|| (INPUT_FLAGS.main_btn_flag.active()
|
||||||
|
&& main_btn_input.is_high_immediate())
|
||||||
|
{
|
||||||
|
unsafe {
|
||||||
|
use hal::pac::Interrupt;
|
||||||
|
use qingke::interrupt::Priority;
|
||||||
|
use qingke_rt::CoreInterrupt;
|
||||||
|
|
||||||
|
system::clear_interrupt(2, 6);
|
||||||
|
|
||||||
|
qingke::pfic::set_priority(
|
||||||
|
CoreInterrupt::SysTick as u8,
|
||||||
|
Priority::P15 as u8,
|
||||||
|
);
|
||||||
|
|
||||||
|
qingke::pfic::enable_interrupt(Interrupt::EXTI7_0 as u8);
|
||||||
|
qingke::pfic::enable_interrupt(CoreInterrupt::SysTick as u8);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.set_state(State::Active);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for everything else, don't do anything
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// // if adc1_timer.need_service() {
|
// // if adc1_timer.need_service() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue