From d1577cb349661404dbcc2a5f15e47ae63ba02d77 Mon Sep 17 00:00:00 2001 From: Hyeongsik Min Date: Wed, 19 Apr 2017 19:36:34 +0900 Subject: [PATCH] Rearrange the order of gpio API functions Change-Id: I3cfbc14654c35e47d141bc43e41507906a36242d Signed-off-by: Hyeongsik Min --- include/peripheral_io.h | 129 +++++++++++++++++++++------------------ src/peripheral_gpio.c | 132 +++++++++++++++++++--------------------- 2 files changed, 133 insertions(+), 128 deletions(-) diff --git a/include/peripheral_io.h b/include/peripheral_io.h index e998f45..7b164c0 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -58,8 +58,9 @@ typedef enum { */ typedef enum { PERIPHERAL_GPIO_DIRECTION_IN = 0, /**< Input Mode */ - PERIPHERAL_GPIO_DIRECTION_OUT, /**< Output mode and this implies "low" output value */ - PERIPHERAL_GPIO_DIRECTION_OUT_HIGH, /**< Output mode and value also be written as "high" */ + PERIPHERAL_GPIO_DIRECTION_OUT, /**< Output mode with low value */ + PERIPHERAL_GPIO_DIRECTION_OUT_LOW = PERIPHERAL_GPIO_DIRECTION_OUT, /**< Same as above */ + PERIPHERAL_GPIO_DIRECTION_OUT_HIGH, /**< Output mode with high value */ } peripheral_gpio_direction_e; /** @@ -79,21 +80,10 @@ typedef enum { typedef struct _peripheral_gpio_s* peripheral_gpio_h; /** - * @brief Called when the gpio interrupt is triggered. - * @since_tizen 4.0 - * - * @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); - -/** - * @brief Initilizes(export) gpio pin and creates gpio handle. + * @brief Initializes(export) gpio pin and creates gpio handle. * @since_tizen 4.0 * - * @param[in] gpio_pin The gpio pin number what you want to use + * @param[in] gpio_pin The gpio pin number * @param[out] gpio The gpio handle is created on success * * @return 0 on success, otherwise a negative error value @@ -109,7 +99,7 @@ typedef void(*gpio_isr_cb)(void *user_data); int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio); /** - * @brief Release the gpio handle and finalize(unexport) the gpio pin. + * @brief Releases the gpio handle and finalize(unexport) the gpio pin. * @since_tizen 4.0 * * @param[in] gpio The handle to the gpio pin to release @@ -126,11 +116,11 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio); int peripheral_gpio_close(peripheral_gpio_h gpio); /** - * @brief Sets direction of the gpio pin. + * @brief Gets direction of the gpio. * @since_tizen 4.0 * - * @param[in] gpio The handle to the gpio pin to set - * @param[in] direction The direction type of the gpio pin + * @param[in] gpio The handle to the gpio pin + * @param[out] value The direction(value) type of the gpio * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -138,15 +128,17 @@ int peripheral_gpio_close(peripheral_gpio_h gpio); * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_gpio_set_direction() */ -int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); +int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); /** - * @brief Sets the edge mode of the gpio pin. + * @brief Sets direction of the gpio pin. * @since_tizen 4.0 * * @param[in] gpio The handle to the gpio pin to set - * @param[in] edge The edge type of the gpio pin + * @param[in] direction Direction(value) type of the gpio pin * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -155,46 +147,50 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); +int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); /** - * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. + * @brief Reads value of the gpio. * @since_tizen 4.0 * - * @param[in] gpio The handle to the gpio pin to set - * @param[in] edge The edge type of the gpio pin - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function + * @param[in] gpio The handle to the gpio pin + * @param[out] value The value of the gpio (zero or non-zero) * * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successfu - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parametera + * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_gpio_set_edge_mode() - * @see peripheral_gpio_unregister_cb() + * @see peripheral_gpio_write() */ -int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); +int peripheral_gpio_read(peripheral_gpio_h gpio, int *value); /** - * @brief Unregisters the callback function for the gpio handler. + * @brief Writes value to the gpio. * @since_tizen 4.0 * * @param[in] gpio The handle to the gpio pin + * @param[in] value Value to be written to the gpio (muse be zero or non-zero) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_gpio_register_cb() + * @see peripheral_gpio_read() */ -int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio); +int peripheral_gpio_write(peripheral_gpio_h gpio, int value); /** - * @brief Reads the gpio value. + * @brief Gets the edge mode of the gpio. * @since_tizen 4.0 * * @param[in] gpio The handle to the gpio pin - * @param[out] value The result of the gpio + * @param[out] gpio_pin The edge mode of the gpio * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -202,15 +198,17 @@ int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio); * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_gpio_set_edge_mode() */ -int peripheral_gpio_read(peripheral_gpio_h gpio, int *value); +int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); /** - * @brief Writes the gpio value. + * @brief Sets the edge mode of the gpio pin. * @since_tizen 4.0 * - * @param[in] gpio The handle to the gpio pin - * @param[in] value The value to be written to the gpio + * @param[in] gpio The handle to the gpio pin to set + * @param[in] edge The edge mode of the gpio pin * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -218,53 +216,66 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, int *value); * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_gpio_get_edge_mode() */ -int peripheral_gpio_write(peripheral_gpio_h gpio, int value); +int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); /** - * @brief Gets direction of the gpio. + * @brief Called when the gpio interrupt is triggered. * @since_tizen 4.0 * - * @param[in] gpio The handle to the gpio pin - * @param[out] value The value to be written to the gpio + * @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); + +/** + * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. + * @since_tizen 4.0 + * + * @param[in] gpio The handle to the gpio pin to set + * @param[in] edge The edge type of the gpio pin + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_gpio_set_edge_mode() + * @see peripheral_gpio_unregister_cb() */ -int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); +int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); /** - * @brief Gets pin number of the gpio. + * @brief Unregisters the callback function for the gpio handler. * @since_tizen 4.0 * * @param[in] gpio The handle to the gpio pin - * @param[out] gpio_pin The number of the gpio * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see peripheral_gpio_register_cb() */ -int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin); +int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio); /** - * @brief Gets edge mode of the gpio. + * @brief Gets pin number of the gpio handle. * @since_tizen 4.0 * * @param[in] gpio The handle to the gpio pin - * @param[out] gpio_pin The number of the gpio + * @param[out] gpio_pin The pin number of the gpio * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); +int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin); /** * @} diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 7f10182..8d23ff9 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -24,12 +24,8 @@ #include "peripheral_common.h" #include "peripheral_internal.h" -#ifdef __cplusplus -extern "C" { -#endif - /** - * @brief Initializes gpio_context, based on Gpio pin. + * @brief Initializes(export) gpio pin and creates gpio handle. */ #define GPIO_NAME "gpio" @@ -71,6 +67,7 @@ exit: /** * @brief Closes the gpio_context. + * @brief Releases the gpio handle and finalize(unexport) the gpio pin. */ int peripheral_gpio_close(peripheral_gpio_h gpio) { @@ -92,9 +89,9 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) } /** - * @brief Sets Gpio direction. + * @brief Gets direction of the gpio. */ -int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) +int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) { int ret = PERIPHERAL_ERROR_NONE; @@ -102,23 +99,19 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - if (direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH) { - ret = PERIPHERAL_ERROR_INVALID_PARAMETER; - } else { - if (gpio->direction != direction) { - gpio->direction = direction; - ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "SET_DIR", 0 , 0); - } - } - /* call gpio_set_direction */ + ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "GET_DIR", 0 , 0); + + if (ret == PERIPHERAL_ERROR_NONE) + (*direction) = gpio->direction; return ret; } + /** - * @brief Sets the edge mode on the Gpio. + * @brief Sets direction of the gpio pin. */ -int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) +int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { int ret = PERIPHERAL_ERROR_NONE; @@ -126,46 +119,21 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - if (edge > PERIPHERAL_GPIO_EDGE_FALLING) { + if (direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH) { ret = PERIPHERAL_ERROR_INVALID_PARAMETER; } else { - if (gpio->edge != edge) { - gpio->edge = edge; - ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "SET_EDGE", 0 , 0); + if (gpio->direction != direction) { + gpio->direction = direction; + ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "SET_DIR", 0 , 0); } } - /* call gpio_set_edge_mode */ + /* call gpio_set_direction */ return ret; } /** - * @brief Registers event handler callback for interrupt. - */ -int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) -{ - /* check validation of gpio context handle */ - if (gpio == NULL) - return PERIPHERAL_ERROR_INVALID_PARAMETER; - - //TODO - return PERIPHERAL_ERROR_INVALID_OPERATION; -} - -/** - * @brief Unregisters event handler callback for interrupt. - */ -int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio) -{ - /* check validation of gpio context handle */ - if (gpio == NULL) - return PERIPHERAL_ERROR_INVALID_PARAMETER; - //TODO - return PERIPHERAL_ERROR_INVALID_OPERATION; -} - -/** - * @brief Reads the gpio value. + * @brief Reads value of the gpio. */ int peripheral_gpio_read(peripheral_gpio_h gpio, int *val) { @@ -184,7 +152,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, int *val) } /** - * @brief Writes to the gpio value. + * @brief Writes value to the gpio. */ int peripheral_gpio_write(peripheral_gpio_h gpio, int value) { @@ -204,9 +172,9 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, int value) } /** - * @brief Gets a direction of the Gpio. + * @brief Gets the edge mode of the gpio. */ -int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) +int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) { int ret = PERIPHERAL_ERROR_NONE; @@ -214,47 +182,73 @@ int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direct if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "GET_DIR", 0 , 0); + ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "GET_EDGE", 0 , 0); if (ret == PERIPHERAL_ERROR_NONE) - (*direction) = gpio->direction; + (*edge) = gpio->edge; return ret; } /** - * @brief Gets a pin number of the Gpio. + * @brief Sets the edge mode of the gpio pin. */ -int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin) +int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { + int ret = PERIPHERAL_ERROR_NONE; + /* check validation of gpio context handle */ if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - *gpio_pin = gpio->pin; + if (edge > PERIPHERAL_GPIO_EDGE_FALLING) { + ret = PERIPHERAL_ERROR_INVALID_PARAMETER; + } else { + if (gpio->edge != edge) { + gpio->edge = edge; + ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "SET_EDGE", 0 , 0); + } + } + /* call gpio_set_edge_mode */ - return PERIPHERAL_ERROR_NONE; + return ret; } /** - * @brief Gets a edge mode of the Gpio. + * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. */ -int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) +int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) { - int ret = PERIPHERAL_ERROR_NONE; - /* check validation of gpio context handle */ if (gpio == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER; - ret = peripheral_dbus_gpio(gpio, GPIO_NAME, "GET_EDGE", 0 , 0); - - if (ret == PERIPHERAL_ERROR_NONE) - (*edge) = gpio->edge; + //TODO + return PERIPHERAL_ERROR_INVALID_OPERATION; +} - return ret; +/** + * @brief Unregisters the callback function for the gpio handler. + */ +int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio) +{ + /* check validation of gpio context handle */ + if (gpio == NULL) + return PERIPHERAL_ERROR_INVALID_PARAMETER; + //TODO + return PERIPHERAL_ERROR_INVALID_OPERATION; } -#ifdef __cplusplus +/** + * @brief Gets pin number of the gpio handle. + */ +int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin) +{ + /* check validation of gpio context handle */ + if (gpio == NULL) + return PERIPHERAL_ERROR_INVALID_PARAMETER; + + *gpio_pin = gpio->pin; + + return PERIPHERAL_ERROR_NONE; } -#endif -- 2.34.1