Commit 4a134d21 authored by robert-hh's avatar robert-hh Committed by Damien George

nrf/modules/machine/pin: Disable IRQ with pin.irq(handler=None).

Before, the input was still set to `pin.irq()` mode, only the handler was
disabled.  That prevented switching the pin between input and output mode.
Signed-off-by: default avatarrobert-hh <robert@hammelrath.com>
parent 5e80416e
......@@ -537,19 +537,24 @@ static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
nrfx_gpiote_pin_t pin = self->pin;
nrfx_gpiote_in_config_t config = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
if (args[ARG_trigger].u_int == NRF_GPIOTE_POLARITY_LOTOHI) {
config.sense = NRF_GPIOTE_POLARITY_LOTOHI;
} else if (args[ARG_trigger].u_int == NRF_GPIOTE_POLARITY_HITOLO) {
config.sense = NRF_GPIOTE_POLARITY_HITOLO;
}
config.pull = NRF_GPIO_PIN_PULLUP;
if (args[ARG_handler].u_obj != mp_const_none) {
nrfx_gpiote_in_config_t config = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
if (args[ARG_trigger].u_int == NRF_GPIOTE_POLARITY_LOTOHI) {
config.sense = NRF_GPIOTE_POLARITY_LOTOHI;
} else if (args[ARG_trigger].u_int == NRF_GPIOTE_POLARITY_HITOLO) {
config.sense = NRF_GPIOTE_POLARITY_HITOLO;
}
config.pull = NRF_GPIO_PIN_PULLUP;
config.skip_gpio_setup = true;
nrfx_err_t err_code = nrfx_gpiote_in_init(pin, &config, pin_common_irq_handler);
if (err_code == NRFX_ERROR_INVALID_STATE) {
// Re-init if already configured.
nrfx_err_t err_code = nrfx_gpiote_in_init(pin, &config, pin_common_irq_handler);
if (err_code == NRFX_ERROR_INVALID_STATE) {
// Re-init if already configured.
nrfx_gpiote_in_uninit(pin);
nrfx_gpiote_in_init(pin, &config, pin_common_irq_handler);
}
} else {
nrfx_gpiote_in_uninit(pin);
nrfx_gpiote_in_init(pin, &config, pin_common_irq_handler);
}
MP_STATE_PORT(pin_irq_handlers)[pin] = args[ARG_handler].u_obj;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment