From 2f92805c1a0424b3707bc92c9b9f026ada234a47 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Fri, 14 Nov 2025 15:08:40 -0700 Subject: [PATCH] add USB check for powerup --- ch32v-insert-coin/src/app.rs | 10 ++++++++++ ch32v-insert-coin/src/main.rs | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ch32v-insert-coin/src/app.rs b/ch32v-insert-coin/src/app.rs index 482c354..56162b1 100644 --- a/ch32v-insert-coin/src/app.rs +++ b/ch32v-insert-coin/src/app.rs @@ -648,6 +648,16 @@ impl App { pub fn get_state(&self) -> State { self.state } + pub fn should_wake(&self) -> bool { + if self.interfaces.usb.powered() { + return true; + } else { + if self.interfaces.adc_core.get_average() > 421 { + return true; + } + } + return false; + } } // TODO LIST diff --git a/ch32v-insert-coin/src/main.rs b/ch32v-insert-coin/src/main.rs index 0bb8271..8e8a6dc 100644 --- a/ch32v-insert-coin/src/main.rs +++ b/ch32v-insert-coin/src/main.rs @@ -526,9 +526,10 @@ fn app_main(mut p: hal::Peripherals) -> ! { } unsafe { #[allow(static_mut_refs)] - if INPUT_FLAGS.sense_coin_flag.active() + if (INPUT_FLAGS.sense_coin_flag.active() || (INPUT_FLAGS.main_btn_flag.active() - && main_btn_input.is_high_immediate()) + && main_btn_input.is_high_immediate())) + && app.should_wake() { unsafe { use hal::pac::Interrupt;