Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly enable / disable InterruptIn Edges detection #4676

Merged
merged 4 commits into from
Jul 17, 2017
Merged
Changes from 3 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
22 changes: 20 additions & 2 deletions targets/TARGET_STM/gpio_irq_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ static void handle_interrupt_in(uint32_t irq_index, uint32_t max_num_pin_line)
if (__HAL_GPIO_EXTI_GET_FLAG(pin) != RESET) {
__HAL_GPIO_EXTI_CLEAR_FLAG(pin);

if (gpio_channel->channel_ids[gpio_idx] == 0)
if (gpio_channel->channel_ids[gpio_idx] == 0) {
continue;
}

// Check which edge has generated the irq
if ((gpio->IDR & pin) == 0) {
irq_handler(gpio_channel->channel_ids[gpio_idx], IRQ_FALL);
} else {
irq_handler(gpio_channel->channel_ids[gpio_idx], IRQ_RISE);
}
return;
}
}
}
error("Unexpected Spurious interrupt, index %d\r\n", irq_index);
}


Expand Down Expand Up @@ -254,18 +257,23 @@ void gpio_irq_free(gpio_irq_t *obj)

void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
{
/* Enable / Disable Edge triggered interrupt and store event */
if (event == IRQ_RISE) {
if (enable) {
LL_EXTI_EnableRisingTrig_0_31(1 << STM_PIN(obj->pin));
obj->event |= IRQ_RISE;
} else {
LL_EXTI_DisableRisingTrig_0_31(1 << STM_PIN(obj->pin));
obj->event &= ~IRQ_RISE;
}
}
if (event == IRQ_FALL) {
if (enable) {
LL_EXTI_EnableFallingTrig_0_31(1 << STM_PIN(obj->pin));
obj->event |= IRQ_FALL;
} else {
LL_EXTI_DisableFallingTrig_0_31(1 << STM_PIN(obj->pin));
obj->event &= ~IRQ_FALL;
}
}
}
Expand All @@ -284,14 +292,24 @@ void gpio_irq_enable(gpio_irq_t *obj)

LL_EXTI_EnableIT_0_31(1 << pin_index);

/* Restore previous edge interrupt configuration if applicable */
if (obj->event & IRQ_RISE) {
LL_EXTI_EnableRisingTrig_0_31(1 << STM_PIN(obj->pin));
}
if (obj->event & IRQ_FALL) {
LL_EXTI_EnableFallingTrig_0_31(1 << STM_PIN(obj->pin));
Copy link
Contributor

Choose a reason for hiding this comment

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

misaligned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had forgotten that one ... done now !


}

NVIC_EnableIRQ(obj->irq_n);
}

void gpio_irq_disable(gpio_irq_t *obj)
{
/* Clear EXTI line configuration */
LL_EXTI_DisableRisingTrig_0_31(1 << STM_PIN(obj->pin));
LL_EXTI_DisableFallingTrig_0_31(1 << STM_PIN(obj->pin));
LL_EXTI_DisableIT_0_31(1 << STM_PIN(obj->pin));
NVIC_DisableIRQ(obj->irq_n);
NVIC_ClearPendingIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}