This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use the Common App Libraries ---> GPIOTE Handler

HI, I want use some GPIO to detect "pin_high_to_low" or " pin_low_to_high". and I think the "app_gpiote.c" might be helpful. but I have been confused by function " sense_level_toggle(*p_user, pins) " , What's the purpose of toggling sense level for specified pin ?

static void sense_level_toggle(gpiote_user_t * p_user, uint32_t pins)
{
    uint32_t pin_no;
    
    for (pin_no = 0; pin_no < NO_OF_PINS; pin_no++)
    {
        uint32_t pin_mask = (1 << pin_no);
        
        if ((pins & pin_mask) != 0)
        {
            uint32_t sense;

            // Invert sensing.
            if ((p_user->sense_high_pins & pin_mask) == 0)
            {
                sense = GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos;
                p_user->sense_high_pins |= pin_mask;
            }
            else
            {
                sense = GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos;
                p_user->sense_high_pins &= ~pin_mask;
            }

            NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk;
            NRF_GPIO->PIN_CNF[pin_no] |= sense;
        }
    }
}

Does that mean if I press a button and then release it , will enter the GPIOTE_IRQHandler() twice . and the same gpiote_event_handler() will be called twice too ?

  • The input pin interrupt will be generated on specific change, from 0-1 or from 1-0 but not 0-1 and 1-0. The toggle mechanism is used to get both interrupts on the same pin. If the current state of pin is 0 then interrupt on 0-1 transition is configured. If the current state is 1 then interrupt on 1-0 is configured.

    Yes you get 2 calls this way, one call when you press the button and another call when you release the button.

Related