#ifndef ARDUINO_ARCH_ESP32
#error "This sketch is written for use with ESP32 boards."
#endif
#define I0 (GPIO_NUM_18) // use GPIO18
#define I1 (GPIO_NUM_19) // use GPIO19
#ifdef ARDUINO_LOLIN32_LITE
#define O (GPIO_NUM_22) // GPIO22 on WeMos Lolin32 Lite
#else
#define O (GPIO_NUM_2) // GPIO2 on ESP32 DevKit V1
#endif
// see: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html
IRAM_ATTR void isr( void* arg ) { // execute the ISR from Instruction RAM (IRAM)
// Read both the logic level at both pins (I0 and I1)
uint32_t value = gpio_get_level(I0) ^ gpio_get_level(I1);
// Update the logic level of the output puin (O)
(void) gpio_set_level( O, value );
}
void setup() {
// Configure the GPIO pins for the I0 and I1 input pins.
gpio_config_t io_conf;
io_conf.pin_bit_mask = (1ULL << I0) | (1ULL << I1);
// Select pin input direction.
io_conf.mode = GPIO_MODE_INPUT;
// Disable internal pull-up and pull-down
io_conf.pull_down_en = (gpio_pulldown_t)0;
io_conf.pull_up_en = (gpio_pullup_t)0;
// Enable pin interrupt for interrupt type: any edge
io_conf.intr_type = (gpio_int_type_t)GPIO_INTR_ANYEDGE;
// Install an ISR service used to manage the GPIO interrupts.
// (using the default interrupt flag: 0)
gpio_install_isr_service( 0 );
// Set the isr handler for each specific gpio pin.
gpio_isr_handler_add( I0 /*gpio_num*/, isr /*isr_handler*/, (void*) I0 /*arg*/ );
gpio_isr_handler_add( I1 /*gpio_num*/, isr /*isr_handler*/, (void*) I1 /*arg*/ );
// Configure the GPIO pins with the given settings.
gpio_config( &io_conf );
// Configure the GPIO pin for the O output pin.
io_conf.intr_type = (gpio_int_type_t)GPIO_PIN_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << O);
io_conf.pull_down_en = (gpio_pulldown_t)0;
io_conf.pull_up_en = (gpio_pullup_t)0;
gpio_config( &io_conf );
// Write 0 (LOW) to the output pin
gpio_set_level( O, 0 );
}
void loop() {
yield();
}