keycard-pro/app/pwr.c

48 lines
705 B
C
Raw Normal View History

2023-08-30 14:27:16 +00:00
#include "FreeRTOS.h"
#include "task.h"
#include "app_tasks.h"
2023-09-05 09:14:20 +00:00
#include "core/settings.h"
2023-08-22 12:37:29 +00:00
#include "hal.h"
2023-09-05 09:14:20 +00:00
#include "pwr.h"
static void pwr_graceful_shutdown() {
while(hal_flash_busy()) {
;
}
2023-08-22 12:37:29 +00:00
2023-09-05 09:14:20 +00:00
settings_commit();
2023-08-22 12:51:15 +00:00
}
2023-08-22 12:37:29 +00:00
void pwr_reboot() {
2023-09-05 09:14:20 +00:00
pwr_graceful_shutdown();
2023-08-22 12:51:15 +00:00
hal_reboot();
2023-08-22 12:37:29 +00:00
}
void pwr_shutdown() {
2023-09-05 09:14:20 +00:00
pwr_graceful_shutdown();
2023-08-22 12:37:29 +00:00
hal_gpio_set(GPIO_PWR_KILL, GPIO_SET);
}
void pwr_usb_plugged() {
2023-08-29 06:49:51 +00:00
hal_usb_start();
2023-08-30 14:27:16 +00:00
vTaskResume(APP_TASK(usb));
2023-08-22 12:37:29 +00:00
}
void pwr_usb_unplugged() {
2023-08-30 14:27:16 +00:00
vTaskSuspend(APP_TASK(usb));
2023-08-29 06:49:51 +00:00
hal_usb_stop();
2023-08-22 12:37:29 +00:00
}
void pwr_smartcard_inserted() {
pwr_reboot();
}
void pwr_smartcard_removed() {
pwr_shutdown();
}
2023-09-14 02:53:53 +00:00
void pwr_inactivity_timer_elapsed() {
//pwr_shutdown();
}