I've tried tons of variations.. but for some reason my the interrupt handler never gets called.
I'm using ESP8266_01. (only GPIO0 and GPIO2 are available).
I can read the GPIOs as input (pulldown/pullup) and set them as output, so my code is not completely off - just can't get the damn interrupts to work.
Here is a very simplified version of what I'm trying to down (stripped down to the bone):
void main_int_handler()
{
printf("main_int_callback!\n");
int i;
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
for (i = 0; i < MAX_PINS; i++)
{
if ((gpio_status & BIT(i)) )
{
printf("triggered on int: %d\n", i);
//disable interrupt
gpio_pin_intr_state_set(GPIO_ID_PIN(i), GPIO_PIN_INTR_DISABLE);
// call func here
//clear interrupt status
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(i));
// restore
gpio_pin_intr_state_set(GPIO_ID_PIN(i), g_arrPins[i].int_mode);
}
}
}
void ICACHE_FLASH_ATTR registerInterrupt(int pin, GPIO_INT_TYPE mode)
{
portENTER_CRITICAL();
// disable open drain
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin)),
GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)));
//clear interrupt status
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin));
// set the mode
gpio_pin_intr_state_set(GPIO_ID_PIN(pin), mode);
portEXIT_CRITICAL();
}
void init()
{
// Register main callback (GPIOs default to INPUT)
gpio_intr_handler_register(main_int_callback);
registerInterrupt(0, GPIO_PIN_INTR_ANYEDGE);
registerInterrupt(2, GPIO_PIN_INTR_ANYEDGE);
}
My handler never gets called. I alternate between GND and VCC for the GPIOs, and while I can read them correctly as input - they never trigger anything.
Any ideas?
Much appreciated!