/** @file power.c * @brief Power management implementation. */ #include "power.h" #include "regs.h" #include #include /* P0.02 on XIAO BLE - adjust to match your schematic */ #define BUTTON_PIN 2u void power_init(void) { /* DC/DC converter has lower quiescent current than the LDO */ NRF_POWER->DCDCEN = 1u; NRF_GPIOTE->CONFIG[0] = (gpiote_config_t){ .bit = { .MODE = GPIOTE_MODE_EVENT, .PSEL = BUTTON_PIN, .PORT = 0u, .POLARITY = GPIOTE_POL_LOTOHI, }}.reg; NRF_GPIOTE->INTENSET = (gpiote_inten_t){.bit.IN0 = 1u}.reg; NVIC_EnableIRQ(GPIOTE_IRQn); } void power_sleep_until_button(void) { NRF_POWER->TASKS_LOWPWR = 1u; __WFI(); } void GPIOTE_IRQHandler(void) { NRF_GPIOTE->EVENTS_IN[0] = 0u; }