int MainStateMachine::shutdown_device() {
// Disable all peripherals
// ...
SystemController::shutdown();
return 0;
}
K_WORK_DEFINE(SystemController::shutdown_work,
SystemController::shutdown_main_thread);
void SystemController::shutdown(void) {
k_work_submit(&shutdown_work); // -> Call from main thread
}
void SystemController::shutdown_main_thread(struct k_work *work) {
/* Configure to generate PORT event (wakeup) on button 1 press. */
nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_sense_set(BUTTON_PIN, NRF_GPIO_PIN_SENSE_LOW);
//wake up from sleep mode if external voltage is applied
NRF_LPCOMP->REFSEL = LPCOMP_REFSEL_REFSEL_Ref3_16Vdd;
NRF_LPCOMP->PSEL = LPCOMP_PSEL_PSEL_AnalogInput6;
NRF_LPCOMP->ANADETECT = 1; // UP, Generate ANADETECT on upward crossing only
NRF_LPCOMP->ENABLE = 1;
NRF_LPCOMP->TASKS_START = 1;
k_msleep(10);
nrf_power_system_off(NRF_POWER);
// Should never be reached
}