From 3ababf9fdfbdc9c6e51e7a23c8ff727fe183bd29 Mon Sep 17 00:00:00 2001 From: Dien-Nhung Nguyen-Phu Date: Sun, 9 Jun 2024 19:31:52 +0700 Subject: btn: add entering power-off mode --- src/main.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main.c b/src/main.c index ef4bfc7..6110e2a 100644 --- a/src/main.c +++ b/src/main.c @@ -87,6 +87,52 @@ void draw_testfb() } } +void poweroff() +{ + // Stop wasting energy + GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_Floating); + GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_Floating); + + // Configure wake-up + GPIOA_ModeCfg(KEY1_PIN, GPIO_ModeIN_PD); + GPIOA_ITModeCfg(KEY1_PIN, GPIO_ITMode_RiseEdge); + PFIC_EnableIRQ(GPIO_A_IRQn); + PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay); + + /* Good bye */ + LowPower_Shutdown(0); +} + +void handle_mode_transition() +{ + static int prev_mode; + if (prev_mode == mode) return; + + switch (mode) + { + case DOWNLOAD: + // Disable fb transition while in download mode + btn_onOnePress(KEY2, NULL); + + // Take control of the current fb to display + // the Bluetooth animation + while (mode == DOWNLOAD) { + /* Animation and Bluetooth will be placed here */ + } + // If not being flashed, pressing KEY1 again will + // make the badge goes off: + + // fallthrough + case POWER_OFF: + poweroff(); + break; + + default: + break; + } + prev_mode = mode; +} + int main() { SetSysClock(CLK_SOURCE_PLL_60MHz); @@ -114,6 +160,7 @@ int main() } DelayMs(200); } + handle_mode_transition(); } } -- cgit v1.2.3