gpio_intr_enable() unnecessary?

jhennrich
Posts: 1
Joined: Thu Aug 03, 2023 2:18 pm

gpio_intr_enable() unnecessary?

Postby jhennrich » Thu Aug 03, 2023 2:32 pm

1: I just wrote a minimal code example to enable a rising-edge Interrupt for a GPIO using the IDF 5.1. The code works and the Interrupt is detected, however I noticed that calling the function "gpio_intr_enable()" is completely unnecessary:

Code: Select all

    
gpio_num_t gpio_num = GPIO_NUM_0;
// [set gpio_num as input, enable pullups etc.... ] 

gpio_set_intr_type(gpio_num, GPIO_INTR_POSEDGE);
gpio_intr_enable(gpio_num);
gpio_install_isr_service(0);
gpio_isr_handler_add(gpio_num, gpio_isr_handler, (void*) gpio_num);
When I comment out the line "gpio_intr_enable(gpio_num)" the interrupt is still detected.

Another thing I noticed: I can even disable the interrupt using "gpio_intr_disable(gpio_num)" and the Interrupt is still detected:

Code: Select all

    
gpio_num_t gpio_num = GPIO_NUM_0;
// [set gpio_num as input, enable pullups etc.... ] 

gpio_set_intr_type(gpio_num, GPIO_INTR_POSEDGE);
gpio_intr_disable(gpio_num); // DISABLE Interrupt, but still works!
gpio_install_isr_service(0);
gpio_isr_handler_add(gpio_num, gpio_isr_handler, (void*) gpio_num);
Can anyone explain this?

2: I noticed that there are multiple ways to configure the interrupt type for a GPIO:
- esp_err_t gpio_config(const gpio_config_t *pGPIOConfig) --> "gpio_config_t" has a member "gpio_int_type_t intr_type"
- esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type) --> sets intr_type
This seems redundant and I am wondering if one of the functions is intended to be deprecated? Which one should be used?

Best regards

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: gpio_intr_enable() unnecessary?

Postby MicroController » Fri Aug 04, 2023 10:09 pm

jhennrich wrote:
Thu Aug 03, 2023 2:32 pm
Can anyone explain this?
gpio_isr_handler_add(...) implicitly enables the corresponding interrupt.
2: I noticed that there are multiple ways to configure the interrupt type for a GPIO:
- esp_err_t gpio_config(const gpio_config_t *pGPIOConfig) --> "gpio_config_t" has a member "gpio_int_type_t intr_type"
- esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type) --> sets intr_type
This seems redundant and I am wondering if one of the functions is intended to be deprecated? Which one should be used?
gpio_config(...) is used for convenient initialization of GPIO pins, including possibly interrupt settings.
gpio_set_intr_type(...) can be used to (later) modify only the interrupt settings of a GPIO pin w/o having to completely reconfigure the pin via gpio_config(...), potentially causing glitches or the like. If you look at gpio_config()'s code, you'll see that it does a whole lot of stuff for us, which I'm glad I don't have to implement myself, but which I don't necessarily want to run repeatedly each time I modify a single setting of a GPIO.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 89 guests