Code: Select all
#define GPIO_INPUT_WIEGAND_0 39//39
#define GPIO_INPUT_WIEGAND_1 35//35
void InitInterrupts(){
gpio_config_t io_conf = { };
//interrupt of rising edge
io_conf.intr_type = GPIO_INTR_DISABLE; //GPIO_INTR_NEGEDGE
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = (1ULL << GPIO_INPUT_WIEGAND_0);
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
//interrupt of rising edge
io_conf.intr_type = GPIO_INTR_DISABLE; //GPIO_INTR_NEGEDGE
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = (1ULL << GPIO_INPUT_WIEGAND_1);
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(40, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task_wiegand, "gpio_wiegand", 2048, NULL, 10,
&TaskHandle_xtask_wiegand);
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_INPUT_WIEGAND_1, gpio_isr_handler,
(void*) GPIO_INPUT_WIEGAND_1);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_INPUT_WIEGAND_0, gpio_isr_handler,
(void*) GPIO_INPUT_WIEGAND_0);
gpio_set_intr_type(GPIO_NUM_39, GPIO_INTR_NEGEDGE);
gpio_intr_enable(GPIO_NUM_39);
gpio_set_intr_type(GPIO_NUM_35, GPIO_INTR_NEGEDGE);
gpio_intr_enable(GPIO_NUM_35);
}