From c12e3337d4be71bfd3618bdfc4e27a1c614b8fac Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 21:23:40 +0900 Subject: [PATCH] [6/6] fd passing: replace to interface functions - since return value of close interface function is meaningless, return type is modified to void. Change-Id: I3ef4298ac5a47db29697bdbbca97ecfbc0e20a57 Signed-off-by: Segwon --- include/interface/peripheral_interface_gpio.h | 2 +- include/interface/peripheral_interface_i2c.h | 2 +- include/interface/peripheral_interface_pwm.h | 2 +- include/interface/peripheral_interface_spi.h | 2 +- include/interface/peripheral_interface_uart.h | 2 +- src/interface/peripheral_interface_gpio.c | 17 ++------- src/interface/peripheral_interface_i2c.c | 7 +--- src/interface/peripheral_interface_pwm.c | 21 +++------- src/interface/peripheral_interface_spi.c | 7 +--- src/interface/peripheral_interface_uart.c | 10 +---- src/peripheral_gpio.c | 37 ++++++------------ src/peripheral_i2c.c | 48 +++++++---------------- src/peripheral_pwm.c | 38 +++++++----------- src/peripheral_spi.c | 55 ++++++++------------------- src/peripheral_uart.c | 55 ++++++++------------------- 15 files changed, 90 insertions(+), 215 deletions(-) diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index e5276e5..140edea 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -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); diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 5d5eb45..b9a47c6 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -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); diff --git a/include/interface/peripheral_interface_pwm.h b/include/interface/peripheral_interface_pwm.h index f8875bf..2e26223 100644 --- a/include/interface/peripheral_interface_pwm.h +++ b/include/interface/peripheral_interface_pwm.h @@ -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. diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h index 801c324..7667bd2 100644 --- a/include/interface/peripheral_interface_spi.h +++ b/include/interface/peripheral_interface_spi.h @@ -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); diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h index c4c82ec..fb44638 100644 --- a/include/interface/peripheral_interface_uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -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. diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index fc677b6..00b911b 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -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) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index b90ee4d..e887a37 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -18,12 +18,9 @@ #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) diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index 96d3dce..35fdc69 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -16,23 +16,12 @@ #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) diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index d59f45e..15baf4b 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -19,12 +19,9 @@ #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) diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index e3f1814..eadef4a 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -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) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 152be9a..229c831 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -18,8 +18,9 @@ #include #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); } diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index f3a8c5a..3d9b908 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -18,8 +18,9 @@ #include #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); } diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index f418ac5..51ad72b 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -18,8 +18,9 @@ #include #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); } diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 862e4d9..0014893 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -18,8 +18,9 @@ #include #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); } diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 988dd38..e66856c 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -18,8 +18,9 @@ #include #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); } -- 2.7.4