aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrançois Cartegnie <281376+fcartegnie@users.noreply.github.com>2024-06-13 15:31:18 +0700
committerGitHub <noreply@github.com>2024-06-13 15:31:18 +0700
commit98a741d93323da0e9199ceafbcc6ea8a6b57e932 (patch)
tree49c82eba3141fb9cbc7a4720a885e86cd574e18f /src
parent52a062067688388c768c9889e9afc2032cefe5ca (diff)
parent3ababf9fdfbdc9c6e51e7a23c8ff727fe183bd29 (diff)
Merge pull request #16 from kienvo/power-off
Add entering power-off mode
Diffstat (limited to 'src')
-rw-r--r--src/main.c47
1 files changed, 47 insertions, 0 deletions
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();
}
}