[6/6] fd passing: replace to interface functions 23/160523/4
authorSegwon <segwon.han@samsung.com>
Thu, 16 Nov 2017 12:23:40 +0000 (21:23 +0900)
committerSegwon <segwon.han@samsung.com>
Thu, 16 Nov 2017 13:59:58 +0000 (22:59 +0900)
 - since return value of close interface function is meaningless, return type is modified to void.

Change-Id: I3ef4298ac5a47db29697bdbbca97ecfbc0e20a57
Signed-off-by: Segwon <segwon.han@samsung.com>
15 files changed:
include/interface/peripheral_interface_gpio.h
include/interface/peripheral_interface_i2c.h
include/interface/peripheral_interface_pwm.h
include/interface/peripheral_interface_spi.h
include/interface/peripheral_interface_uart.h
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_i2c.c
src/interface/peripheral_interface_pwm.c
src/interface/peripheral_interface_spi.c
src/interface/peripheral_interface_uart.c
src/peripheral_gpio.c
src/peripheral_i2c.c
src/peripheral_pwm.c
src/peripheral_spi.c
src/peripheral_uart.c

index e5276e55fbcaef4b9133a947c6e271499357336c..140edeafca2a2ff3d92e131a63919422ebf18433 100644 (file)
@@ -21,7 +21,7 @@
 
 #define GPIO_BUFFER_MAX 64
 
-int peripheral_interface_gpio_close(peripheral_gpio_h gpio);
+void peripheral_interface_gpio_close(peripheral_gpio_h gpio);
 int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
 int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
 int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value);
index 5d5eb453e63e935eb7edbea98b9cc42112afbcab..b9a47c6c4bb1a30cc923d96487f833ccd804556f 100644 (file)
@@ -54,7 +54,7 @@ struct i2c_smbus_ioctl_data {
        union i2c_smbus_data *data;
 };
 
-int peripheral_interface_i2c_close(peripheral_i2c_h i2c);
+void peripheral_interface_i2c_close(peripheral_i2c_h i2c);
 int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
 int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
 int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out);
index f8875bfcb4a3fc9cba12bf782cfa9138f55aef2b..2e26223e834486a5c501d3b06798b118770e86ad 100644 (file)
@@ -28,7 +28,7 @@
 * @param[in] pin pwm pin number
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_pwm_close(peripheral_pwm_h pwm);
+void peripheral_interface_pwm_close(peripheral_pwm_h pwm);
 
 /**
 * @brief pwm_set_period() sets the pwm period.
index 801c3248c8015dbf5d5acb16b3cb273eab171e37..7667bd2326d5c9d542617129c2db261a57a56ca2 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "peripheral_interface_common.h"
 
-int peripheral_interface_spi_close(peripheral_spi_h spi);
+void peripheral_interface_spi_close(peripheral_spi_h spi);
 int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
 int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order);
 int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits);
index c4c82ec29550d53ecc14e4ab09a14b4ba825bdee..fb446381ac6d96735f79b2c1481c21a5fd7f4ec8 100644 (file)
@@ -25,7 +25,7 @@
 * @param[in] file_hndl handle of uart_context
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_uart_close(peripheral_uart_h uart);
+void peripheral_interface_uart_close(peripheral_uart_h uart);
 
 /**
 * @brief uart_flush() flushes uart buffer.
index fc677b690bc911711ad4855d62d5d830f8ba7f83..00b911b43daf91ae0c260c34668d52cc1abd5fa5 100644 (file)
@@ -79,20 +79,11 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_gpio_close(peripheral_gpio_h gpio)
+void peripheral_interface_gpio_close(peripheral_gpio_h gpio)
 {
-       int ret;
-
-       ret = close(gpio->fd_direction);
-       CHECK_ERROR(ret != 0);
-
-       ret = close(gpio->fd_edge);
-       CHECK_ERROR(ret != 0);
-
-       ret = close(gpio->fd_value);
-       CHECK_ERROR(ret != 0);
-
-       return PERIPHERAL_ERROR_NONE;
+       close(gpio->fd_direction);
+       close(gpio->fd_edge);
+       close(gpio->fd_value);
 }
 
 int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio)
index b90ee4dc4b208da914fd04b447b55a376dc011c0..e887a375c5869220daf0af877c83bf52243049bc 100644 (file)
 
 #include "peripheral_interface_i2c.h"
 
-int peripheral_interface_i2c_close(peripheral_i2c_h i2c)
+void peripheral_interface_i2c_close(peripheral_i2c_h i2c)
 {
-       int ret = close(i2c->fd);
-       CHECK_ERROR(ret != 0);
-
-       return PERIPHERAL_ERROR_NONE;
+       close(i2c->fd);
 }
 
 int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
index 96d3dcee23afa1df1f40f519072f0609c6483819..35fdc697f85bb0f47d12b9de9692d9530bf0941e 100644 (file)
 
 #include "peripheral_interface_pwm.h"
 
-int peripheral_interface_pwm_close(peripheral_pwm_h pwm)
+void peripheral_interface_pwm_close(peripheral_pwm_h pwm)
 {
-       int ret;
-
-       ret = close(pwm->fd_period);
-       CHECK_ERROR(ret != 0);
-
-       ret = close(pwm->fd_duty_cycle);
-       CHECK_ERROR(ret != 0);
-
-       ret = close(pwm->fd_polarity);
-       CHECK_ERROR(ret != 0);
-
-       ret = close(pwm->fd_enable);
-       CHECK_ERROR(ret != 0);
-
-       return PERIPHERAL_ERROR_NONE;
+       close(pwm->fd_period);
+       close(pwm->fd_duty_cycle);
+       close(pwm->fd_polarity);
+       close(pwm->fd_enable);
 }
 
 int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, uint32_t period)
index d59f45eaacdb63ffa48b96082209aab6c0388bbe..15baf4bdbace458932bcfde22e6720206a052ae5 100644 (file)
 
 #include "peripheral_interface_spi.h"
 
-int peripheral_interface_spi_close(peripheral_spi_h spi)
+void peripheral_interface_spi_close(peripheral_spi_h spi)
 {
-       int ret = close(spi->fd);
-       CHECK_ERROR(ret != 0);
-
-       return PERIPHERAL_ERROR_NONE;
+       close(spi->fd);
 }
 
 int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
index e3f18144b89f1cad971df21625e4f5b0f4fe4c32..eadef4a9289aa0e96b57ffd6addf76bff536832a 100644 (file)
@@ -29,16 +29,10 @@ static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = {
 
 static const int byteinfo[4] = {CS5, CS6, CS7, CS8};
 
-int peripheral_interface_uart_close(peripheral_uart_h uart)
+void peripheral_interface_uart_close(peripheral_uart_h uart)
 {
-       int ret;
-
        peripheral_interface_uart_flush(uart);
-
-       ret = close(uart->fd);
-       CHECK_ERROR(ret != 0);
-
-       return PERIPHERAL_ERROR_NONE;
+       close(uart->fd);
 }
 
 int peripheral_interface_uart_flush(peripheral_uart_h uart)
index 152be9a538ba51370c8550901c40dc7566a5a7cf..229c831f15da58b9fff3fc561edd99c081767541 100644 (file)
@@ -18,8 +18,9 @@
 #include <system_info.h>
 
 #include "peripheral_io.h"
-#include "peripheral_gdbus_gpio.h"
 #include "peripheral_handle.h"
+#include "peripheral_gdbus_gpio.h"
+#include "peripheral_interface_gpio.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio"
@@ -88,8 +89,12 @@ int peripheral_gpio_close(peripheral_gpio_h gpio)
 
        /* call gpio_close */
        ret = peripheral_gdbus_gpio_close();
-       if (ret != PERIPHERAL_ERROR_NONE)
+       if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to close the gpio pin, ret : %d", ret);
+               return ret;
+       }
+
+       peripheral_interface_gpio_close(gpio);
 
        free(gpio);
        gpio = NULL;
@@ -102,16 +107,11 @@ int peripheral_gpio_close(peripheral_gpio_h gpio)
  */
 int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF((direction < PERIPHERAL_GPIO_DIRECTION_IN) || (direction > PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid direction input");
 
-       /* call gpio_set_direction */
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_gpio_set_direction(gpio, direction);
 }
 
 /**
@@ -119,16 +119,11 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
  */
 int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF((edge < PERIPHERAL_GPIO_EDGE_NONE) || (edge > PERIPHERAL_GPIO_EDGE_BOTH), PERIPHERAL_ERROR_INVALID_PARAMETER, "edge input is invalid");
 
-       /* call gpio_set_edge_mode */
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_gpio_set_edge_mode(gpio, edge);
 }
 
 /**
@@ -167,16 +162,11 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio)
  */
 int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid");
 
-       /* call gpio_read */
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_gpio_read(gpio, value);
 }
 
 /**
@@ -184,14 +174,9 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
  */
 int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
        RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid");
 
-       /* call gpio_write */
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_gpio_write(gpio, value);
 }
index f3a8c5a9de25dfa4a04e325e4dd4a62632f86852..3d9b90868a3bbcf057361768050c81971ccc28a5 100644 (file)
@@ -18,8 +18,9 @@
 #include <system_info.h>
 
 #include "peripheral_io.h"
-#include "peripheral_gdbus_i2c.h"
 #include "peripheral_handle.h"
+#include "peripheral_gdbus_i2c.h"
+#include "peripheral_interface_i2c.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c"
@@ -65,19 +66,18 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
        RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s));
-
        if (handle == NULL) {
                _E("Failed to allocate peripheral_i2c_h");
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        ret = peripheral_gdbus_i2c_open(handle, bus, address);
-
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to open i2c communication, ret : %d", ret);
                free(handle);
                handle = NULL;
        }
+
        *i2c = handle;
 
        return ret;
@@ -91,8 +91,12 @@ int peripheral_i2c_close(peripheral_i2c_h i2c)
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
 
        ret = peripheral_gdbus_i2c_close();
-       if (ret != PERIPHERAL_ERROR_NONE)
+       if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to close i2c communcation, ret : %d", ret);
+               return ret;
+       }
+
+       peripheral_interface_i2c_close(i2c);
 
        free(i2c);
        i2c = NULL;
@@ -102,76 +106,52 @@ int peripheral_i2c_close(peripheral_i2c_h i2c)
 
 int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_i2c_read(i2c, data, length);
 }
 
 int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_i2c_write(i2c, data, length);
 }
 
 int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_i2c_read_register_byte(i2c, reg, data);
 }
 
 int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_i2c_write_register_byte(i2c, reg, data);
 }
 
 int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_i2c_read_register_word(i2c, reg, data);
 }
 
 int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_i2c_write_register_word(i2c, reg, data);
 }
index f418ac53b5aca454f6b0d89981bea9308ac967a9..51ad72bb2272d812dcd216a7c25aaf9038b29496 100644 (file)
@@ -18,8 +18,9 @@
 #include <system_info.h>
 
 #include "peripheral_io.h"
-#include "peripheral_gdbus_pwm.h"
 #include "peripheral_handle.h"
+#include "peripheral_gdbus_pwm.h"
+#include "peripheral_interface_pwm.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm"
@@ -57,19 +58,18 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm)
 
        /* Initialize */
        handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s));
-
        if (handle == NULL) {
                _E("Failed to allocate peripheral_pwm_h");
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        ret = peripheral_gdbus_pwm_open(handle, chip, pin);
-
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to open PWM chip : %d, pin : %d", chip, pin);
                free(handle);
                handle = NULL;
        }
+
        *pwm = handle;
 
        return ret;
@@ -82,59 +82,49 @@ int peripheral_pwm_close(peripheral_pwm_h pwm)
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
-       if ((ret = peripheral_gdbus_pwm_close()) < 0)
+       ret = peripheral_gdbus_pwm_close();
+       if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to close PWM chip, continuing anyway, ret : %d", ret);
+               return ret;
+       }
+
+       peripheral_interface_pwm_close(pwm);
 
        free(pwm);
+       pwm = NULL;
 
        return ret;
 }
 
 int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_pwm_set_period(pwm, period_ns);
 }
 
 int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_pwm_set_duty_cycle(pwm, duty_cycle_ns);
 }
 
 int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
        RETVM_IF((polarity < PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) || (polarity > PERIPHERAL_PWM_POLARITY_ACTIVE_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid polarity parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_pwm_set_polarity(pwm, polarity);
 }
 
 int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_pwm_set_enable(pwm, enable);
 }
index 862e4d904e78d22082f8ac7b42121d335a0dbbb9..0014893b6dd8aeaace388fee20f7772fcdda02de 100644 (file)
@@ -18,8 +18,9 @@
 #include <system_info.h>
 
 #include "peripheral_io.h"
-#include "peripheral_gdbus_spi.h"
 #include "peripheral_handle.h"
+#include "peripheral_gdbus_spi.h"
+#include "peripheral_interface_spi.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi"
@@ -56,19 +57,18 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi)
 
        /* Initialize */
        handle = (peripheral_spi_h)calloc(1, sizeof(struct _peripheral_spi_s));
-
        if (handle == NULL) {
                _E("Failed to allocate peripheral_spi_h");
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        ret = peripheral_gdbus_spi_open(handle, bus, cs);
-
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("SPI open error (%d, %d)", bus, cs);
                free(handle);
                handle = NULL;
        }
+
        *spi = handle;
 
        return ret;
@@ -82,99 +82,76 @@ int peripheral_spi_close(peripheral_spi_h spi)
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
 
        ret = peripheral_gdbus_spi_close();
-       if (ret < PERIPHERAL_ERROR_NONE)
+       if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to close SPI device, continuing anyway, ret : %d", ret);
+               return ret;
+       }
+
+       peripheral_interface_spi_close(spi);
 
        free(spi);
+       spi = NULL;
 
        return ret;
 }
 
 int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_set_mode(spi, mode);
 }
 
 int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF((bit_order < PERIPHERAL_SPI_BIT_ORDER_MSB) || (bit_order > PERIPHERAL_SPI_BIT_ORDER_LSB), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid bit order parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_set_bit_order(spi, bit_order);
 }
 
 int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_set_bits_per_word(spi, bits);
 }
 
 int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_set_frequency(spi, freq_hz);
 }
 
 int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_read(spi, data, length);
 }
 
 int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_write(spi, data, length);
 }
 
 int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
        RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_spi_transfer(spi, txdata, rxdata, length);
 }
index 988dd38dfd92279483d9ac8ee0cea7ec4158a7fb..e66856c3ce23c9fd9a4d9d6e233f66e16840b763 100644 (file)
@@ -18,8 +18,9 @@
 #include <system_info.h>
 
 #include "peripheral_io.h"
-#include "peripheral_gdbus_uart.h"
 #include "peripheral_handle.h"
+#include "peripheral_gdbus_uart.h"
+#include "peripheral_interface_uart.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart"
@@ -58,19 +59,18 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart)
        RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number");
 
        handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s));
-
        if (handle == NULL) {
                _E("Failed to allocate peripheral_uart_h");
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        ret = peripheral_gdbus_uart_open(handle, port);
-
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to open uart port, ret : %d", ret);
                free(handle);
                handle = NULL;
        }
+
        *uart = handle;
 
        return ret;
@@ -87,8 +87,12 @@ int peripheral_uart_close(peripheral_uart_h uart)
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
 
        ret = peripheral_gdbus_uart_close();
-       if (ret < PERIPHERAL_ERROR_NONE)
+       if (ret != PERIPHERAL_ERROR_NONE) {
                _E("Failed to close uart communication, continuing anyway, ret : %d", ret);
+               return ret;
+       }
+
+       peripheral_interface_uart_close(uart);
 
        free(uart);
        uart = NULL;
@@ -101,72 +105,51 @@ int peripheral_uart_close(peripheral_uart_h uart)
  */
 int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_set_baud_rate(uart, baud);
 }
 
 int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_set_byte_size(uart, byte_size);
 }
 
 int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_set_parity(uart, parity);
 }
 
 int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((stop_bits < PERIPHERAL_UART_STOP_BITS_1BIT) || (stop_bits > PERIPHERAL_UART_STOP_BITS_2BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_set_stop_bits(uart, stop_bits);
 }
 
-
 /**
  * @brief Sets baudrate of the uart device.
  */
 int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF((sw_flow_control < PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) || (sw_flow_control > PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid sw_flow_control parameter");
        RETVM_IF((hw_flow_control < PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) || (hw_flow_control > PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid hw_flow_control parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_set_flow_control(uart, sw_flow_control, hw_flow_control);
 }
 
 /**
@@ -174,15 +157,11 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof
  */
 int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_read(uart, data, length);
 }
 
 /**
@@ -190,13 +169,9 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length)
  */
 int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
        RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
-       // TODO : replace interface function
-
-       return ret;
+       return peripheral_interface_uart_write(uart, data, length);
 }