/* Function for enabling event on pin (if not yet enabled) or disabling the event if no other user requires it.  */
static void pin_event_enable(uint32_t pin, bool enable)
/* Function for enabling event on pin (if not yet enabled) or disabling the event if no other user requires it.  */
static void pin_event_enable(uint32_t pin, bool enable)
{
    uint32_t i;
    uint32_t pin_mask = 1UL << pin;
    bool enabled = false;
    for (i = 0; i < m_user_count; i++)
    {
        if (mp_users[i].enabled && (mp_users[i].pins_mask & pin_mask))
        {
            enabled = true;
            break;
        }
    }
    if (!enabled)
    {
        if (enable)
        {
            m_last_pins_state = nrf_gpio_pins_read();
            nrf_drv_gpiote_in_event_enable(pin, true);
        }
        else
        {
            nrf_drv_gpiote_in_event_disable(pin);
        }
    }
}