zephyr/drivers/gpio/gpio_utils.h
Kumar Gala ccad5bf3e3 drivers: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I08f51e2bfd475f6245771c1bd2df7ffc744c48c4
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 10:06:48 -05:00

58 lines
1.4 KiB
C

/*
* Copyright (c) 2016 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @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,
u32_t pins)
{
struct gpio_callback *cb;
SYS_SLIST_FOR_EACH_CONTAINER(list, cb, node) {
if (cb->pin_mask & pins) {
__ASSERT(cb->handler, "No callback handler!");
cb->handler(port, cb, pins);
}
}
}
#endif /* __GPIO_UTILS_H__ */