how to identify GPIO interrupt source pin?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

I'm going to use several GPIO pin as Data Input with interrupt by register handler in following function.

gpio_registerForInterrupt(interrupt_handler_mask, application_gpio_interrupt_handler);

Then, in the application_gpio_interrupt_handler(), as the document example is:

void application_gpio_interrupt_handler(void* parameter)

Question 1:

Can the "parameter" be used to identify the pin which trigger an interrupt? and identify that is triggered at falling edge or rising edge?

Or is there any API to identify it? I found gpio_getPortInterruptStatus but not sure this is. 

Question 2:

Do the handler need to clear interrupt by gpio_clearPortInterruptStatus before exit the handler?

Thank you!

0 Likes
1 Solution

You are correct on usage with SDK 2.0.1. But with SDK 1.1.0, there are two ways to ensure that handler recognizes the right GPIO:

1. Use a unique interrupt handler callback for each GPIO (interrupt) you want to handle. For instance, if you want to handle interrupts from P0 and from P15, then use two interrupt handlers, something like this:

UINT16 masks[3] = {(1 << 0), 0, 0};    /// interrupt mask for P0

gpio_registerForInterrupt(masks, application_gpio_interrupt_handler_for_p0, NULL);

masks[0] = 1 << 15;

gpio_registerForInterrupt(masks, application_gpio_interrupt_handler_for_p15, NULL);

// Now configure interrupts for P0 and P15.

So, application_gpio_interrupt_handler_for_p0 will be invoked only if P0 was the interrupt source.

2. Use the same interrupt handler callback for all GPIOs, but use the userdata parameter for demultiplexing.

UINT16 masks[3] = {(1 << 0), 0, 0};    /// interrupt mask for P0

gpio_registerForInterrupt(masks, application_gpio_interrupt_handler, (void*)0);

masks[0] = 1 << 15;

gpio_registerForInterrupt(masks, application_gpio_interrupt_handler, (void*)15);

void application_gpio_interrupt_handler(void* userdata)

{

    UINT32 gpio = (UINT32)userdata;

    switch(gpio)

    {

        case 0:                 /// P0

              break;

        case 15:               /// P15

              break;

    }

}

> in my application I've configure GPIO by bleprofile_GPIOInit(bleprofile_gpio_p_cfg);Will this conflict to  gpio_registerForInterrupt()

This should not in this case, but I recommend that if you use bleprofile_* to configure a GPIO, you should use corresponding bleprofile_* API (mainly because some of these like buttons run state machines underneath). For interrupts from GPIOs, use gpio_*

View solution in original post

5 Replies