Commit 581f7565 authored by Markus Lassila's avatar Markus Lassila Committed by Benjamin Cabé
Browse files

drivers: gpio_nrfx: Free channel when changing mode

Fix an issue where calling gpio_pin_interrupt_configure
with edge mode and later calling it with level mode, did
not release the allocated gpiote channel.

Repeating the above sequence caused us to run out of
gpiote channels.

Signed-off-by: default avatarMarkus Lassila <markus.lassila@nordicsemi.no>
parent b155c0dc
Loading
Loading
Loading
Loading
+9 −0
Changes for drivers/gpio/gpio_nrfx.c: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -444,6 +444,15 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port,
		}

		trigger_config.p_in_channel = &ch;
	} else {
		/* If edge mode with channel was previously used and we are changing to sense or
		 * level triggered, we must free the channel.
		 */
		err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch);
		if (err == NRFX_SUCCESS) {
			err = nrfx_gpiote_channel_free(&cfg->gpiote, ch);
			__ASSERT_NO_MSG(err == NRFX_SUCCESS);
		}
	}

	err = nrfx_gpiote_input_configure(&cfg->gpiote, abs_pin, &input_pin_config);