I'm trying to implement debounce when the user clicks a button.
I need to start the debounce timer from within the gpio interrupt. However this leads to a crash.
My code is as follows.
Code: Select all
#include "gpio.h"
#include "esp_common.h"
#include "esp_timer.h"
static os_timer_t some_timer;
static void timer_handler(void* args) {
printf("timer");
}
static void intr_handler() {
portENTER_CRITICAL();
os_timer_disarm(&some_timer);
os_timer_setfn(&some_timer, (os_timer_func_t *)timer_handler, NULL);
os_timer_arm(&some_timer, 3, 1);
portEXIT_CRITICAL();
}
void user_init(void)
{
GPIO_ConfigTypeDef gpio_in_cfg12;
gpio_in_cfg12.GPIO_Pin = GPIO_Pin_12;
gpio_in_cfg12.GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE;
gpio_in_cfg12.GPIO_Mode = GPIO_Mode_Input;
gpio_in_cfg12.GPIO_Pullup = GPIO_PullUp_EN;
gpio_config(&gpio_in_cfg12);
gpio_intr_handler_register(intr_handler, NULL);
_xt_isr_unmask(1 << ETS_GPIO_INUM);
}
The only output I get is:
Code: Select all
ShowCritical:1
Edit: If I start the timer from user_init, everything works as planned.