From c5dc9c961df3356fb01371cffa2e0cd75f3bfa29 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Thu, 2 Dec 2021 10:03:05 -0800 Subject: [PATCH] add new dio handlers, consolidate DIO handlers to single function --- main/esp32-lora.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main/esp32-lora.c b/main/esp32-lora.c index 9bc0d2b..de5a936 100644 --- a/main/esp32-lora.c +++ b/main/esp32-lora.c @@ -446,7 +446,7 @@ void lora32_read_data(lora32_cfg_t *lora, uint8_t *data) { } } -static void IRAM_ATTR lora32_on_dio0(void *arg) { +static void IRAM_ATTR lora32_on_dio(void *arg) { xQueueSend(dio_event_queue, arg, (TickType_t)0); } @@ -551,14 +551,18 @@ uint8_t lora32_init(lora32_cfg_t *lora) { if(lora->receive != NULL) { ESP_LOGI(TAG, "Setting GPIO Interrupt"); + // TODO check at least one DIOx pin is not NULL + io_conf.intr_type = GPIO_PIN_INTR_POSEDGE; - io_conf.pin_bit_mask = (1ULL << lora->dio0); + io_conf.pin_bit_mask = ((1ULL << lora->dio0) | (1ULL << lora->dio1) | (1ULL << lora->dio2)); io_conf.mode = GPIO_MODE_INPUT; io_conf.pull_down_en = 0; io_conf.pull_up_en = 0; gpio_config(&io_conf); gpio_set_intr_type(lora->dio0, GPIO_INTR_POSEDGE); + gpio_set_intr_type(lora->dio1, GPIO_INTR_POSEDGE); + gpio_set_intr_type(lora->dio2, GPIO_INTR_POSEDGE); // the DIO interrupt handling for every device is done from one task if(dio_task_handle == NULL) { @@ -575,7 +579,14 @@ uint8_t lora32_init(lora32_cfg_t *lora) { // add ISR handler to the global service started (once) above ESP_LOGI(TAG, "Installing ISR handler for GPIO%d", lora->dio0); - gpio_isr_handler_add(lora->dio0, lora32_on_dio0, lora); + if(lora->dio0 > -1) + gpio_isr_handler_add(lora->dio0, lora32_on_dio, (void*)lora); + + if(lora->dio1 > -1) + gpio_isr_handler_add(lora->dio1, lora32_on_dio, (void*)lora); + + if(lora->dio2 > -1) + gpio_isr_handler_add(lora->dio2, lora32_on_dio, (void*)lora); } return 1;