Merge pull request #16 from kienvo/power-off

Add entering power-off mode
This commit is contained in:
François Cartegnie
2024-06-13 15:31:18 +07:00
committed by GitHub

View File

@@ -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();
}
}