ESP-IDF GPIO interrupt minimal example

#include <driver/gpio.h>

void IRAM_ATTR myGPIOInterrupt(void* arg) {
  (void)arg; // Ignore arg
  // Do something useful here
  ESP_EARLY_LOGE(TAG, "GPIO interrupt\n");
}

void app_main() {

  gpio_num_t gpio_num = GPIO_NUM_2;
  gpio_config_t io_conf = {};
  io_conf.intr_type = GPIO_INTR_NEGEDGE;
  io_conf.mode = GPIO_MODE_INPUT;
  io_conf.pin_bit_mask = BIT64(gpio_num);
  io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
  io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
  // Configure the pin
  ESP_ERROR_CHECK(gpio_config(&io_conf));
  // Configure the interrupt
  gpio_install_isr_service(0 /* No flags */); // Call this only once !!
  ESP_ERROR_CHECK(gpio_isr_handler_add(gpio_num, myGPIOInterrupt, nullptr));

  while (true) {
    // Do something useful here
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}