From adc44e6496e5dd9aedb3a25e26c9a0d30519e6d9 Mon Sep 17 00:00:00 2001 From: Matthew Blue <matthew.blue.neuro@gmail.com> Date: Thu, 28 Jun 2018 16:06:36 -0400 Subject: [PATCH] cpu/atmega_common: misc gpio interrupt fixes --- cpu/atmega_common/periph/gpio.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cpu/atmega_common/periph/gpio.c b/cpu/atmega_common/periph/gpio.c index f86067c31b..52f1b9431a 100644 --- a/cpu/atmega_common/periph/gpio.c +++ b/cpu/atmega_common/periph/gpio.c @@ -150,6 +150,7 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, { int8_t int_num = _int_num(pin); + /* mode not supported */ if ((mode != GPIO_IN) && (mode != GPIO_IN_PU)) { return -1; } @@ -159,19 +160,20 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, return -1; } + /* flank not supported */ + if (flank > GPIO_RISING) { + return -1; + } + gpio_init(pin, mode); /* clear global interrupt flag */ cli(); /* enable interrupt number int_num */ + EIFR |= (1 << int_num); EIMSK |= (1 << int_num); - /* configure the flank */ - if (flank > GPIO_RISING) { - return -1; - } - /* apply flank to interrupt number int_num */ if (int_num < 4) { EICRA &= ~(0x3 << (int_num * 2)); @@ -196,6 +198,7 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, void gpio_irq_enable(gpio_t pin) { + EIFR |= (1 << _int_num(pin)); EIMSK |= (1 << _int_num(pin)); } -- GitLab