From: jino.cho Date: Tue, 11 Jul 2017 11:13:33 +0000 (+0900) Subject: Add a struct for gpio interrupt information X-Git-Tag: submit/tizen/20170713.044725~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=021a2a44080fba0ae9b14750b1b7a454d30e0c16;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Add a struct for gpio interrupt information This patch adds gpio isr callback data deliverd via gpio_isr_cb(). A gpio isr callback data is delivered as a structure, which contains the pin number, the pin value, and the timestamp(ms) when the gpio interrupt occurred. Change-Id: Iee60dc4d33fe856d46fda83c487ed27d8d1fadae Signed-off-by: jino.cho --- diff --git a/include/peripheral_io.h b/include/peripheral_io.h index bba13ca..d697a55 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -73,6 +73,19 @@ typedef enum { PERIPHERAL_GPIO_EDGE_BOTH, /**< Interrupt on rising & falling */ } peripheral_gpio_edge_e; +/** + * @brief Gpio isr callback data delivered via gpio_isr_cb(). + * @details A gpio isr callback data is delivered as a structure, which contains + * the pin number, the pin value, and the timestamp of the gpio interrupt + * in microseconds. + * @since_tizen 4.0 + */ +typedef struct { + int pin; + int value; + unsigned long long timestamp; +} gpio_isr_cb_s; + /** * @brief The handle to the gpio pin * @since_tizen 4.0 @@ -225,12 +238,13 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e * @brief Called when the gpio interrupt is triggered. * @since_tizen 4.0 * + * @param[in] data The gpio isr callback data * @param[in] user_data The user data passed from the callback registration function * * @see peripheral_gpio_register_cb() * @see peripheral_gpio_unregister_cb() */ -typedef void(*gpio_isr_cb)(void *user_data); +typedef void(*gpio_isr_cb)(gpio_isr_cb_s *data, void *user_data); /** * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c index 1c1fb1c..b476e47 100644 --- a/src/peripheral_gdbus_gpio.c +++ b/src/peripheral_gdbus_gpio.c @@ -23,8 +23,14 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -extern int peripheral_gpio_isr_callback(int pin); -void handle_gpio_changed(PeripheralIoGdbusGpio *gpio, gint pin, gint state, gpointer user_data); +extern int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestamp); + +void handle_gpio_changed( + PeripheralIoGdbusGpio *gpio, + gint pin, + gint value, + guint64 timestamp, + gpointer user_data); PeripheralIoGdbusGpio *gpio_proxy = NULL; @@ -68,13 +74,14 @@ void gpio_proxy_deinit() void handle_gpio_changed( PeripheralIoGdbusGpio *gpio, gint pin, - gint state, + gint value, + guint64 timestamp, gpointer user_data) { if (!gpio) return; - peripheral_gpio_isr_callback(pin); + peripheral_gpio_isr_callback(pin, value, timestamp); } int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 6c64b98..8a7ccdf 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -33,18 +33,22 @@ typedef struct { static GList *gpio_isr_list = NULL; -int peripheral_gpio_isr_callback(int pin) +int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestamp) { GList *link; gpio_isr_data_s *isr_data; + gpio_isr_cb_s cb_data; link = gpio_isr_list; while (link) { isr_data = (gpio_isr_data_s*)link->data; if (isr_data->pin == pin) { + cb_data.pin = pin; + cb_data.value = value; + cb_data.timestamp = timestamp; if (isr_data->callback) - isr_data->callback(isr_data->user_data); + isr_data->callback(&cb_data, isr_data->user_data); return PERIPHERAL_ERROR_NONE; } link = g_list_next(link); diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml index 16b3cd2..878fb5c 100644 --- a/src/peripheral_io.xml +++ b/src/peripheral_io.xml @@ -50,7 +50,8 @@ - + + diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 4ccbbe1..cb62e2a 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -103,7 +103,7 @@ error: return ret; } -void gpio_irq_test_isr(void *user_data) +void gpio_irq_test_isr(gpio_isr_cb_s *data, void *user_data) { int pin; peripheral_gpio_h gpio = user_data; @@ -249,7 +249,7 @@ error: #define MMA7455_YOUT8 0x07 //Register for reading the Y-Axis #define MMA7455_ZOUT8 0x08 //Register for reading the Z-Axis -static void i2c_mma7455_isr(void *user_data) +static void i2c_mma7455_isr(gpio_isr_cb_s *data, void *user_data) { peripheral_i2c_h i2c = user_data; uint8_t x_pos, y_pos, z_pos;