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

periph/gpio: add gpio_update_int() class of functions #13925

Closed
wants to merge 4 commits into from

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented Apr 22, 2020

Contribution description

It can be desirable to change the function or behavior associated with a GPIO interrupt.
Currently this can only be achieved by calling gpio_init_int() again, which not only does lots of unnecessary and possibly time-consuming work, but also forces to expose the GPIO configuration to callers that only want to change the callback argument.

As proposed in #12082 (comment) this introduces three new functions:

void gpio_update_int(gpio_t pin, gpio_cb_t cb, void *arg);
void gpio_update_cb(gpio_t pin, gpio_cb_t cb);
void gpio_update_arg(gpio_t pin, void *arg);

gpio_init_int() must have been called successfully before on pin, so no error checking is needed which greatly simplifies the implementation.

If the API is acceptable, I will update the remaining GPIO drivers.

  • stm32f1/periph/gpio.c
  • mips_pic32_common/periph/gpio.c
  • lpc1768/periph/gpio.c
  • stm32_common/periph/gpio.c
  • efm32/periph/gpio.c
  • native/periph/gpio.c
  • lm4f120/periph/gpio.c
  • fe310/periph/gpio.c
  • esp8266/periph/gpio.c
  • msp430fxyz/periph/gpio.c
  • cc26xx_cc13xx/periph/gpio.c
  • cc2538/periph/gpio.c
  • esp32/periph/gpio.c
  • lpc2387/periph/gpio.c
  • kinetis/periph/gpio.c
  • atmega_common/periph/gpio.c
  • sam0_common/periph/gpio.c
  • nrf5x_common/periph/gpio.c
  • sam3/periph/gpio.c
  • ezr32wg/periph/gpio.c

Testing procedure

The following program should alternate between the two messages with each press of a button.

#include <stdio.h>
#include "periph/gpio.h"
#include "board.h"

static char* messages[] = {
    "Hello IRQ!",
    "Goodby IRQ!"
};

static void _irq_handler(void *arg)
{
    puts(arg);
    gpio_update_cb(BTN0_PIN, arg == messages[0] ? messages[1] : messages[0]);
}

int main(void)
{
    gpio_init_int(BTN0_PIN, GPIO_IN, GPIO_RISING, _irq_handler, messages[0]);
    return 0;
}

Issues/PRs references

alternative to #12082

@benpicco benpicco added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: cpu Area: CPU/MCU ports State: demonstrator State: This PR (loosely) demonstrates a concept and is not necessarily meant to be merged. labels Apr 22, 2020
@gschorcht
Copy link
Contributor

@benpicco I would prefer to have only one function since each additional function will increase the RAM required for the driver interface gpio_driver_t in PR #14602.

@gschorcht
Copy link
Contributor

What is the reason for having three different functions?

@benpicco
Copy link
Contributor Author

Was suggested by @maribu to make the API easier to use / implement: #12082 (comment)

But at that point function pointers in RAM were not a concern yet, with the old API if a function was not used by the application the linker would just throw it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports State: demonstrator State: This PR (loosely) demonstrates a concept and is not necessarily meant to be merged. State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants