I am using SDK 15.2 with Segger Studio
I am using an external button on pin 4 to enter sleep mode on a long press and wake up the device.
I am able to enter sleep mode, but as soon as I release the button it wakes up. I have tried to unitialized the pin and set it as sensing pin.
Below I have attached what I have been working on.
void button_timerout_handler(void * p_context) {
uint32_t err_code;
static uint32_t cnt;
if(app_button_is_pushed(0)) {
cnt++;
if(cnt >= LONG_PRESS(LONG_PRESS_WAIT)) {
cnt = 0;
NRF_LOG_INFO("Long Press");
nrf_drv_gpiote_in_uninit(BUTTON_PIN_4);
nrf_gpio_cfg_sense_input(BUTTON_PIN_4, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
// Go to system-off mode (this function will not return; wakeup will cause a reset).
err_code = sd_power_system_off();
APP_ERROR_CHECK(err_code);
}
else {
err_code = app_timer_start(m_button_action,
APP_TIMER_TICKS(BUTTON_STATE_POLL_INTERVAL_MS),
NULL);
APP_ERROR_CHECK(err_code);
}
}
else {
cnt = 0;
NRF_LOG_INFO("Short Press");
}
}
static void button_event_handler(uint8_t pin_no, uint8_t action) {
uint32_t err_code;
if((pin_no == BUTTON_PIN_4) && (action == APP_BUTTON_PUSH)) {
err_code = app_timer_start(m_button_action,
APP_TIMER_TICKS(BUTTON_STATE_POLL_INTERVAL_MS),
NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("Button Pressed!");
}
}
static const app_button_cfg_t buttons[NUM_BUTTONS] = {
{BUTTON_PIN_4, APP_BUTTON_ACTIVE_HIGH, NRF_GPIO_PIN_PULLUP, button_event_handler},
};
static void button_init(void){
uint32_t err_code;
err_code = app_button_init((app_button_cfg_t *)buttons, NUM_BUTTONS, BUTTON_DELAY);
APP_ERROR_CHECK(err_code);
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);
// Enable timer for long button press detect
err_code = app_timer_create(&m_button_action, APP_TIMER_MODE_SINGLE_SHOT, button_timerout_handler);
APP_ERROR_CHECK(err_code);
}
Thank you for your time.