Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/rp2_common/hardware_gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ void gpio_set_irq_enabled(uint gpio, uint32_t events, bool enabled) {
}

void gpio_set_irq_enabled_with_callback(uint gpio, uint32_t events, bool enabled, gpio_irq_callback_t callback) {
// first set callback, then enable the interrupt
gpio_set_irq_callback(callback);
// when enabling, first set callback, then enable the interrupt
// when disabling, first disable the interrupt, then clear callback
if (enabled) gpio_set_irq_callback(callback);
gpio_set_irq_enabled(gpio, events, enabled);
if (!enabled) gpio_set_irq_callback(callback);
if (enabled) irq_set_enabled(IO_IRQ_BANK0, true);
Comment on lines +199 to 204
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function likely to get used in performance-critical code? If it is, perhaps it's worth reducing the branches? 🤔 (or is one of those cases where the compiler is able to do this optimisation automatically?)

Suggested change
// when enabling, first set callback, then enable the interrupt
// when disabling, first disable the interrupt, then clear callback
if (enabled) gpio_set_irq_callback(callback);
gpio_set_irq_enabled(gpio, events, enabled);
if (!enabled) gpio_set_irq_callback(callback);
if (enabled) irq_set_enabled(IO_IRQ_BANK0, true);
// when enabling, first set callback, then enable the interrupt
// when disabling, first disable the interrupt, then clear callback
if (enabled) {
gpio_set_irq_callback(callback);
gpio_set_irq_enabled(gpio, events, enabled);
irq_set_enabled(IO_IRQ_BANK0, true);
} else {
gpio_set_irq_enabled(gpio, events, enabled);
gpio_set_irq_callback(callback);
}

}

Expand Down
Loading