I want to know in the ISR if it's rising or falling edge.
How to do that?
If I just read the GPIO status in the ISR, it's almost always 0, even on a rising edge.
Example:
#define PIN GPIO_NUM_5
gpio_set_intr_type(PIN, GPIO_INTR_POSEDGE); // <<<< Rising edge only!
gpio_set_direction(PIN, GPIO_MODE_INPUT);
gpio_pullup_en(PIN);
gpio_isr_handler_add(PIN, gpio_sda_handler, (void *) PIN);
static void gpio_handler(void *arg)
{
uint32_t x = gpio_get_level(PIN);
xQueueSendFromISR(gpio_evt_queue, &x, NULL);
}
static void gpio_task(void *arg)
{
uint32_t x;
for (;;) {
if (xQueueReceive(gpio_evt_queue, &x, portMAX_DELAY)) {
ESP_LOGI(TAG, "GPIO[%d] intr, val: %d\n", PIN, x & 1);
}
}
}
Output:
I (32183) i2c-tools: GPIO[5] intr, val: 0
I (32183) i2c-tools: GPIO[5] intr, val: 0
I (32193) i2c-tools: GPIO[5] intr, val: 1
I (32193) i2c-tools: GPIO[5] intr, val: 0
I (32203) i2c-tools: GPIO[5] intr, val: 0
Do I need some kind of delay? If so, how much? Is it OK to delay in the ISR?