2016-03-23 19:01:06 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-03-23 19:01:06 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file Header where utility code can be found for GPIO drivers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GPIO_UTILS_H__
|
|
|
|
#define __GPIO_UTILS_H__
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Generic function to insert or remove a callback from a callback list
|
|
|
|
*
|
|
|
|
* @param callbacks A pointer to the original list of callbacks (can be NULL)
|
|
|
|
* @param callback A pointer of the callback to insert or remove from the list
|
|
|
|
* @param set A boolean indicating insertion or removal of the callback
|
|
|
|
*/
|
|
|
|
static inline void _gpio_manage_callback(sys_slist_t *callbacks,
|
|
|
|
struct gpio_callback *callback,
|
|
|
|
bool set)
|
|
|
|
{
|
|
|
|
__ASSERT(callback, "No callback!");
|
|
|
|
__ASSERT(callback->handler, "No callback handler!");
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
sys_slist_prepend(callbacks, &callback->node);
|
|
|
|
} else {
|
|
|
|
sys_slist_find_and_remove(callbacks, &callback->node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Generic function to go through and fire callback from a callback list
|
|
|
|
*
|
|
|
|
* @param list A pointer on the gpio callback list
|
|
|
|
* @param port A pointer on the gpio driver instance
|
|
|
|
* @param pins The actual pin mask that triggered the interrupt
|
|
|
|
*/
|
|
|
|
static inline void _gpio_fire_callbacks(sys_slist_t *list,
|
|
|
|
struct device *port,
|
2017-04-21 23:03:20 +08:00
|
|
|
u32_t pins)
|
2016-03-23 19:01:06 +08:00
|
|
|
{
|
|
|
|
struct gpio_callback *cb;
|
|
|
|
|
2017-02-08 22:51:31 +08:00
|
|
|
SYS_SLIST_FOR_EACH_CONTAINER(list, cb, node) {
|
2016-03-23 19:01:06 +08:00
|
|
|
if (cb->pin_mask & pins) {
|
|
|
|
__ASSERT(cb->handler, "No callback handler!");
|
|
|
|
cb->handler(port, cb, pins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __GPIO_UTILS_H__ */
|