diff options
| author | Dien-Nhung Nguyen-Phu <kein@kienlab.com> | 2024-06-09 19:31:52 +0700 |
|---|---|---|
| committer | Dien-Nhung Nguyen-Phu <kein@kienlab.com> | 2024-06-13 13:46:49 +0700 |
| commit | 3ababf9fdfbdc9c6e51e7a23c8ff727fe183bd29 (patch) | |
| tree | c660eb1fdd8c8c15cf11e1b97a29b27fbf5617ea /src | |
| parent | 316ce879fd555d19d8a69b726f7c8fee7333f277 (diff) | |
btn: add entering power-off mode
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -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();
}
}
|