Skip to content

Commit 1c42cab

Browse files
authored
Merge pull request #214 from tessel/jon-int-fix
Fix order of mux and extint set
2 parents d1b7f16 + 695d18f commit 1c42cab

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

firmware/port.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,21 @@ ExecStatus port_begin_cmd(PortData *p) {
386386
u8 mode = (p->arg[0] >> 4) & 0x07;
387387

388388
if (port_pin_supports_interrupt(p, pin)) {
389-
eic_config(p->port->gpio[pin], mode);
389+
// If we are setting an interrupt
390390
if (mode != 0) {
391+
// Ensure the pin is configured as an external interrupt
391392
pin_mux_eic(p->port->gpio[pin]);
393+
// Set the type of interrupt we need (ie low, fall, etc.)
394+
eic_config(p->port->gpio[pin], mode);
395+
// If we are removing interrupts
392396
} else {
397+
// First disable the interrupts
398+
eic_config(p->port->gpio[pin], mode);
399+
// Then set the pin back as GPIO
400+
// It is important to do this in the above order to avoid
401+
// the case where the interrupt is disabled and pin set as
402+
// GPIO in one call, and the interrupt enabled in the next
403+
// (which could immediately fire depending on GPIO state)
393404
pin_gpio(p->port->gpio[pin]);
394405
}
395406
}

0 commit comments

Comments
 (0)