From 503baca692cf21f5f652d9418b2efce068fc45a5 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 13:24:37 +0900 Subject: [PATCH 01/16] i2c: remove unused interface function that peripheral_interface_i2c_set_address() Change-Id: I277e99134c27a411614aac9502c700ab83f04c3e Signed-off-by: Segwon --- include/interface/peripheral_interface_i2c.h | 1 - src/interface/peripheral_interface_i2c.c | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 67c7019..41326d6 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -58,7 +58,6 @@ struct i2c_smbus_ioctl_data { }; int peripheral_interface_i2c_close(peripheral_i2c_h i2c); -int peripheral_interface_i2c_set_address(peripheral_i2c_h i2c, int address); 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_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data); diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index cc703fe..6b235ff 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -46,24 +46,6 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) return 0; } -int peripheral_interface_i2c_set_address(peripheral_i2c_h i2c, int address) -{ - int status; - - _D("fd : %d, slave address : 0x%x", i2c->fd, address); - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(i2c->fd, I2C_SLAVE, address); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set slave address(%x), fd : %d, errmsg : %s", address, i2c->fd, errmsg); - return status; - } - - return 0; -} - int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { int status; -- 2.7.4 From 91cec9be39189285a4532ee6e1f9a36187b46e45 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 15:55:58 +0900 Subject: [PATCH 02/16] interface: use the CHECK_ERROR macro for error set by system call - created a peripheral_interface_common.h file and implemented error macro - macro name : CHECK_ERROR Signed-off-by: Segwon Change-Id: I5d1167ab2d7aa3e5e3b22ef2192efbd68b1f17bc --- include/interface/peripheral_interface_common.h | 32 +++++++ src/interface/peripheral_interface_gpio.c | 36 ++------ src/interface/peripheral_interface_i2c.c | 29 ++---- src/interface/peripheral_interface_pwm.c | 41 ++------- src/interface/peripheral_interface_spi.c | 57 ++---------- src/interface/peripheral_interface_uart.c | 112 ++++-------------------- 6 files changed, 81 insertions(+), 226 deletions(-) create mode 100644 include/interface/peripheral_interface_common.h diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h new file mode 100644 index 0000000..33a8d39 --- /dev/null +++ b/include/interface/peripheral_interface_common.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __PERIPHERAL_INTERFACE_COMMON_H__ +#define __PERIPHERAL_INTERFACE_COMMON_H__ + +#define CHECK_ERROR(val) \ + do { \ + if (val < 0) { \ + if (errno == EAGAIN) \ + return -EAGAIN; \ + char errmsg[255]; \ + strerror_r(errno, errmsg, sizeof(errmsg)); \ + _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \ + return -EIO; \ + } \ + } while (0) + +#endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/ \ No newline at end of file diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index e2ce235..7d4ef2f 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -22,6 +22,7 @@ #include #include +#include "peripheral_interface_common.h" #include "peripheral_interface_gpio.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -43,10 +44,7 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g return -EIO; } - if (status <= 0) { - _E("Error: gpio direction set error\n"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -68,10 +66,7 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g return -EIO; } - if (status <= 0) { - _E("Error: gpio edge set error\n"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -89,10 +84,7 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) return -EIO; } - if (status <= 0) { - _E("Error: gpio write error\n"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -103,10 +95,7 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) char gpio_buf[GPIO_BUFFER_MAX] = {0, }; len = read(gpio->fd_value, &gpio_buf, 1); - if (len <= 0) { - _E("Error: gpio read error \n"); - return -EIO; - } + CHECK_ERROR(len); if (0 == strncmp(gpio_buf, "1", strlen("1"))) *value = 1; @@ -125,22 +114,13 @@ int peripheral_interface_gpio_close(peripheral_gpio_h gpio) int status; status = close(gpio->fd_direction); - if (status < 0) { - _E("Error: gpio direction fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); status = close(gpio->fd_edge); - if (status < 0) { - _E("Error: gpio edge fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); status = close(gpio->fd_value); - if (status < 0) { - _E("Error: gpio value fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); return 0; } diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 6b235ff..fadbf63 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -22,6 +22,7 @@ #include #include +#include "peripheral_interface_common.h" #include "peripheral_interface_i2c.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -36,12 +37,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); status = close(i2c->fd); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d", i2c->fd); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -53,12 +49,7 @@ int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); status = read(i2c->fd, data, length); - if (status != length) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("i2c read failed, fd : %d, errmsg : %s", i2c->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -70,12 +61,7 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); status = write(i2c->fd, data, length); - if (status != length) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("i2c write failed fd : %d, errmsg : %s", i2c->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -87,12 +73,7 @@ int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); status = ioctl(i2c->fd, I2C_SMBUS, data); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("i2c transaction failed fd : %d, errmsg : %s", i2c->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index 822332b..faefc1a 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -22,6 +22,7 @@ #include #include +#include "peripheral_interface_common.h" #include "peripheral_interface_pwm.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -37,28 +38,16 @@ int peripheral_interface_pwm_close(peripheral_pwm_h pwm) int status; status = close(pwm->fd_period); - if (status < 0) { - _E("Error: pwm period fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); status = close(pwm->fd_duty_cycle); - if (status < 0) { - _E("Error: pwm duty cycle fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); status = close(pwm->fd_polarity); - if (status < 0) { - _E("Error: pwm polarity fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); status = close(pwm->fd_enable); - if (status < 0) { - _E("Error: pwm enable fd close error \n"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -70,10 +59,7 @@ int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, uint32_t period) len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period); status = write(pwm->fd_period, pwm_buf, len); - if (status < 0) { - _E("Failed to set period"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -85,10 +71,7 @@ int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_ len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle); status = write(pwm->fd_duty_cycle, pwm_buf, len); - if (status < 0) { - _E("Failed to set duty cycle"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -106,10 +89,7 @@ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_p return -EINVAL; } - if (status <= 0) { - _E("Failed to set polarity"); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -121,10 +101,7 @@ int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable) len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable); status = write(pwm->fd_enable, pwm_buf, len); - if (status < 0) { - _E("Failed to set enable"); - return -EIO; - } + CHECK_ERROR(status); return 0; } diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index ddc643c..1c83726 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -23,6 +23,7 @@ #include #include +#include "peripheral_interface_common.h" #include "peripheral_interface_spi.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -40,12 +41,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); status = close(spi->fd); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d", spi->fd); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -58,12 +54,7 @@ int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set mode(%d) : %s", mode, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -76,12 +67,7 @@ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", bit_order, spi->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -94,12 +80,7 @@ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bit RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set bits(%d), fd : %d, errmsg : %s", bits, spi->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -112,12 +93,7 @@ int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set frequency(%d), fd : %d, errmsg : %s", freq, spi->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -134,12 +110,7 @@ int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t xfer.len = length; status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to read data, fd : %d, length : %d, errmsg : %s", spi->fd, length, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -156,12 +127,7 @@ int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_ xfer.len = length; status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to write data(%d) : %s", length, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -181,12 +147,7 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint xfer.len = length; status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to exchange data(%d) : %s", length, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 4933ab4..a0f9637 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -24,6 +24,7 @@ #include #include +#include "peripheral_interface_common.h" #include "peripheral_interface_uart.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -65,20 +66,10 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) } status = peripheral_interface_uart_flush(uart); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); status = close(uart->fd); - if (status < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg); - return -EIO; - } + CHECK_ERROR(status); return 0; } @@ -93,12 +84,7 @@ int peripheral_interface_uart_flush(peripheral_uart_h uart) } ret = tcflush(uart->fd, TCIOFLUSH); - if (ret < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcflush failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); return 0; } @@ -122,12 +108,8 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u } ret = tcgetattr(uart->fd, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcgetattr failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); + tio.c_cflag = peripheral_uart_br[baud]; tio.c_iflag = IGNPAR; tio.c_oflag = 0; @@ -137,12 +119,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcsetattr failed, errmsg: %s", errmsg); - return -1; - } + CHECK_ERROR(ret); return 0; } @@ -165,12 +142,8 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u } ret = tcgetattr(uart->fd, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcgetattr failed, errmsg: %s", errmsg); - return -1; - } + CHECK_ERROR(ret); + /* set byte size */ tio.c_cflag &= ~CSIZE; @@ -179,12 +152,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcsetattr failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); return 0; } @@ -202,12 +170,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart } ret = tcgetattr(uart->fd, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcgetattr failed, errmsg: %s", errmsg); - return -1; - } + CHECK_ERROR(ret); /* set parity info */ switch (parity) { @@ -228,12 +191,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcsetattr failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); return 0; } @@ -251,12 +209,7 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u } ret = tcgetattr(uart->fd, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcgetattr failed, errmsg: %s", errmsg); - return -1; - } + CHECK_ERROR(ret); /* set stop bit */ switch (stop_bits) { @@ -273,12 +226,7 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcsetattr failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); return 0; } @@ -296,12 +244,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera } ret = tcgetattr(uart->fd, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcgetattr failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); if (rtscts == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) tio.c_cflag |= CRTSCTS; @@ -318,12 +261,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera return -EINVAL; ret = tcsetattr(uart->fd, TCSANOW, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcsetattr failed, errmsg : %s", errmsg); - return -1; - } + CHECK_ERROR(ret); return 0; } @@ -338,14 +276,7 @@ int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_ } ret = read(uart->fd, (void *)buf, length); - if (ret <= 0) { - if (errno == EAGAIN) - return -EAGAIN; - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("read failed, errmsg : %s", errmsg); - return -EIO; - } + CHECK_ERROR(ret); return ret; } @@ -360,14 +291,7 @@ int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32 } ret = write(uart->fd, buf, length); - if (ret <= 0) { - if (errno == EAGAIN) - return -EAGAIN; - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("write failed, errmsg : %s", errmsg); - return -EIO; - } + CHECK_ERROR(ret); return ret; } -- 2.7.4 From 04503068e5448f9b551778212a58302087e53fe8 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 17:54:05 +0900 Subject: [PATCH 03/16] gdbus: move gdbus files to top level gdbus folder Change-Id: If08e00e576cb8bdb099a740768870a6bdcf41d8b Signed-off-by: Segwon --- CMakeLists.txt | 17 +++++++++-------- include/{ => gdbus}/peripheral_gdbus.h | 0 include/{ => gdbus}/peripheral_gdbus_gpio.h | 0 include/{ => gdbus}/peripheral_gdbus_i2c.h | 0 include/{ => gdbus}/peripheral_gdbus_pwm.h | 0 include/{ => gdbus}/peripheral_gdbus_spi.h | 0 include/{ => gdbus}/peripheral_gdbus_uart.h | 0 src/{ => gdbus}/peripheral_gdbus_gpio.c | 0 src/{ => gdbus}/peripheral_gdbus_i2c.c | 0 src/{ => gdbus}/peripheral_gdbus_pwm.c | 0 src/{ => gdbus}/peripheral_gdbus_spi.c | 0 src/{ => gdbus}/peripheral_gdbus_uart.c | 0 src/{ => gdbus}/peripheral_io.xml | 0 src/peripheral_gpio.c | 2 +- 14 files changed, 10 insertions(+), 9 deletions(-) rename include/{ => gdbus}/peripheral_gdbus.h (100%) rename include/{ => gdbus}/peripheral_gdbus_gpio.h (100%) rename include/{ => gdbus}/peripheral_gdbus_i2c.h (100%) rename include/{ => gdbus}/peripheral_gdbus_pwm.h (100%) rename include/{ => gdbus}/peripheral_gdbus_spi.h (100%) rename include/{ => gdbus}/peripheral_gdbus_uart.h (100%) rename src/{ => gdbus}/peripheral_gdbus_gpio.c (100%) rename src/{ => gdbus}/peripheral_gdbus_i2c.c (100%) rename src/{ => gdbus}/peripheral_gdbus_pwm.c (100%) rename src/{ => gdbus}/peripheral_gdbus_spi.c (100%) rename src/{ => gdbus}/peripheral_gdbus_uart.c (100%) rename src/{ => gdbus}/peripheral_io.xml (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 335e42a..9b17fa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,15 @@ SET(VERSION ${version}) FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS " \\ - --generate-c-code ${CMAKE_SOURCE_DIR}/src/peripheral_io_gdbus \\ + --generate-c-code ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io_gdbus \\ --c-namespace PeripheralIoGdbus \\ --interface-prefix org.tizen.peripheral_io. \\ - ${CMAKE_SOURCE_DIR}/src/peripheral_io.xml \\ + ${CMAKE_SOURCE_DIR}/src/gdbus/peripheral_io.xml \\ ") SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) +INCLUDE_DIRECTORIES(${INC_DIR}/gdbus) INCLUDE_DIRECTORIES(${INC_DIR}/interface) INCLUDE(FindPkgConfig) @@ -53,12 +54,12 @@ SET(SOURCES src/peripheral_gpio.c src/interface/peripheral_interface_pwm.c src/interface/peripheral_interface_spi.c src/interface/peripheral_interface_uart.c - src/peripheral_gdbus_gpio.c - src/peripheral_gdbus_i2c.c - src/peripheral_gdbus_pwm.c - src/peripheral_gdbus_uart.c - src/peripheral_gdbus_spi.c - src/peripheral_io_gdbus.c) + src/gdbus/peripheral_gdbus_gpio.c + src/gdbus/peripheral_gdbus_i2c.c + src/gdbus/peripheral_gdbus_pwm.c + src/gdbus/peripheral_gdbus_uart.c + src/gdbus/peripheral_gdbus_spi.c + src/gdbus/peripheral_io_gdbus.c) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) diff --git a/include/peripheral_gdbus.h b/include/gdbus/peripheral_gdbus.h similarity index 100% rename from include/peripheral_gdbus.h rename to include/gdbus/peripheral_gdbus.h diff --git a/include/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h similarity index 100% rename from include/peripheral_gdbus_gpio.h rename to include/gdbus/peripheral_gdbus_gpio.h diff --git a/include/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h similarity index 100% rename from include/peripheral_gdbus_i2c.h rename to include/gdbus/peripheral_gdbus_i2c.h diff --git a/include/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h similarity index 100% rename from include/peripheral_gdbus_pwm.h rename to include/gdbus/peripheral_gdbus_pwm.h diff --git a/include/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h similarity index 100% rename from include/peripheral_gdbus_spi.h rename to include/gdbus/peripheral_gdbus_spi.h diff --git a/include/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h similarity index 100% rename from include/peripheral_gdbus_uart.h rename to include/gdbus/peripheral_gdbus_uart.h diff --git a/src/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c similarity index 100% rename from src/peripheral_gdbus_gpio.c rename to src/gdbus/peripheral_gdbus_gpio.c diff --git a/src/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c similarity index 100% rename from src/peripheral_gdbus_i2c.c rename to src/gdbus/peripheral_gdbus_i2c.c diff --git a/src/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c similarity index 100% rename from src/peripheral_gdbus_pwm.c rename to src/gdbus/peripheral_gdbus_pwm.c diff --git a/src/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c similarity index 100% rename from src/peripheral_gdbus_spi.c rename to src/gdbus/peripheral_gdbus_spi.c diff --git a/src/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c similarity index 100% rename from src/peripheral_gdbus_uart.c rename to src/gdbus/peripheral_gdbus_uart.c diff --git a/src/peripheral_io.xml b/src/gdbus/peripheral_io.xml similarity index 100% rename from src/peripheral_io.xml rename to src/gdbus/peripheral_io.xml diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 408ed0a..c80e9c9 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -19,12 +19,12 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" #include "peripheral_common.h" #include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" -- 2.7.4 From 3f5e52ec5533ad263a83eb43f87f0d93904a71e3 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 19:58:32 +0900 Subject: [PATCH 04/16] [4/6] fd passing: get file descriptor list from daemon through gdbus - save the received fds to handle. - it only receive fds when the open function is run. Change-Id: Iaa3c87adaab0254c519b2f695068ae79850e3a23 Signed-off-by: Segwon --- src/gdbus/peripheral_gdbus_gpio.c | 31 +++++++++++++++++++++++++++++++ src/gdbus/peripheral_gdbus_i2c.c | 15 +++++++++++++++ src/gdbus/peripheral_gdbus_pwm.c | 39 +++++++++++++++++++++++++++++++++++++++ src/gdbus/peripheral_gdbus_spi.c | 15 +++++++++++++++ src/gdbus/peripheral_gdbus_uart.c | 15 +++++++++++++++ src/gdbus/peripheral_io.xml | 5 +++++ 6 files changed, 120 insertions(+) diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 42025de..52fce3e 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,10 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" +#define GPIO_FD_INDEX_DIRECTION 0 +#define GPIO_FD_INDEX_EDGE 1 +#define GPIO_FD_INDEX_VALUE 2 + extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); static PeripheralIoGdbusGpio *gpio_proxy = NULL; @@ -77,14 +82,17 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; + GUnixFDList *fd_list = NULL; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; if (peripheral_io_gdbus_gpio_call_open_sync( gpio_proxy, gpio->pin, + NULL, &gpio->handle, &ret, + &fd_list, NULL, &error) == FALSE) { _E("Error in %s() : %s", __func__, error->message); @@ -92,6 +100,29 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) return PERIPHERAL_ERROR_UNKNOWN; } + gpio->fd_direction = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_DIRECTION, &error); + if (gpio->fd_direction < 0) { + _E("Failed to get fd for gpio direction : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + gpio->fd_edge = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_EDGE, &error); + if (gpio->fd_edge < 0) { + _E("Failed to get fd for gpio edge : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + gpio->fd_value = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_VALUE, &error); + if (gpio->fd_value < 0) { + _E("Failed to get fd for gpio value : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + g_object_unref(fd_list); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index e0a39ac..a3290ab 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,8 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" +#define I2C_FD_INDEX 0 + static PeripheralIoGdbusI2c *i2c_proxy = NULL; void i2c_proxy_init(void) @@ -56,6 +59,7 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GUnixFDList *fd_list = NULL; if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; @@ -63,8 +67,10 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) i2c_proxy, bus, address, + NULL, &i2c->handle, &ret, + &fd_list, NULL, &error) == FALSE) { _E("Error in %s() : %s", __func__, error->message); @@ -72,6 +78,15 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) return PERIPHERAL_ERROR_UNKNOWN; } + i2c->fd = g_unix_fd_list_get(fd_list, I2C_FD_INDEX, &error); + if (i2c->fd < 0) { + _E("Failed to get fd for i2c : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + g_object_unref(fd_list); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index e1fdae9..1eb3435 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,11 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" +#define PWM_FD_INDEX_PERIOD 0 +#define PWM_FD_INDEX_DUTY_CYCLE 1 +#define PWM_FD_INDEX_POLARITY 2 +#define PWM_FD_INDEX_ENABLE 3 + static PeripheralIoGdbusPwm *pwm_proxy = NULL; void pwm_proxy_init(void) @@ -56,6 +62,7 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GUnixFDList *fd_list = NULL; if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; @@ -63,8 +70,10 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) pwm_proxy, chip, pin, + NULL, &pwm->handle, &ret, + &fd_list, NULL, &error) == FALSE) { _E("%s", error->message); @@ -72,6 +81,36 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) return PERIPHERAL_ERROR_UNKNOWN; } + pwm->fd_period = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_PERIOD, &error); + if (pwm->fd_period < 0) { + _E("Failed to get fd for pwm period : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + pwm->fd_duty_cycle = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_DUTY_CYCLE, &error); + if (pwm->fd_duty_cycle < 0) { + _E("Failed to get fd for pwm duty cycle : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + pwm->fd_polarity = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_POLARITY, &error); + if (pwm->fd_polarity < 0) { + _E("Failed to get fd for pwm polarity : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + pwm->fd_enable = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_ENABLE, &error); + if (pwm->fd_enable < 0) { + _E("Failed to get fd for pwm enable : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + g_object_unref(fd_list); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index cc7a8a5..2959835 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,8 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" +#define SPI_FD_INDEX 0 + static PeripheralIoGdbusSpi *spi_proxy = NULL; void spi_proxy_init(void) @@ -56,6 +59,7 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GUnixFDList *fd_list = NULL; if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; @@ -63,8 +67,10 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) spi_proxy, bus, cs, + NULL, &spi->handle, &ret, + &fd_list, NULL, &error) == FALSE) { _E("%s", error->message); @@ -72,6 +78,15 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) return PERIPHERAL_ERROR_UNKNOWN; } + spi->fd = g_unix_fd_list_get(fd_list, SPI_FD_INDEX, &error); + if (spi->fd < 0) { + _E("Failed to get fd for spi : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + g_object_unref(fd_list); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 78bc0c0..e7e57b6 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,8 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" +#define UART_FD_INDEX 0 + static PeripheralIoGdbusUart *uart_proxy = NULL; void uart_proxy_init(void) @@ -56,14 +59,17 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; + GUnixFDList *fd_list = NULL; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; if (peripheral_io_gdbus_uart_call_open_sync( uart_proxy, port, + NULL, &uart->handle, &ret, + &fd_list, NULL, &error) == FALSE) { _E("Error in %s() : %s", __func__, error->message); @@ -71,6 +77,15 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) return PERIPHERAL_ERROR_UNKNOWN; } + uart->fd = g_unix_fd_list_get(fd_list, UART_FD_INDEX, &error); + if (uart->fd < 0) { + _E("Failed to get fd for uart : %s", error->message); + g_error_free(error); + ret = PERIPHERAL_ERROR_UNKNOWN; + } + + g_object_unref(fd_list); + return ret; } diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 466efac..30ceaa6 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -2,6 +2,7 @@ + @@ -46,6 +47,7 @@ + @@ -83,6 +85,7 @@ + @@ -115,6 +118,7 @@ + @@ -168,6 +172,7 @@ + -- 2.7.4 From bbbec795a3b6a1def61758f532a3f3133d32a116 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 20:22:09 +0900 Subject: [PATCH 05/16] [5/6] fd passing: remove unnecessary gdbus functions. Change-Id: Ic2c0ae84608851344191606101dcef82df3786de Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_gpio.h | 6 - include/gdbus/peripheral_gdbus_i2c.h | 3 - include/gdbus/peripheral_gdbus_pwm.h | 4 - include/gdbus/peripheral_gdbus_spi.h | 7 -- include/gdbus/peripheral_gdbus_uart.h | 7 -- src/gdbus/peripheral_gdbus_gpio.c | 148 +----------------------- src/gdbus/peripheral_gdbus_i2c.c | 98 +--------------- src/gdbus/peripheral_gdbus_pwm.c | 90 +-------------- src/gdbus/peripheral_gdbus_spi.c | 208 +--------------------------------- src/gdbus/peripheral_gdbus_uart.c | 183 +----------------------------- src/gdbus/peripheral_io.xml | 167 --------------------------- src/peripheral_gpio.c | 118 +------------------ src/peripheral_i2c.c | 46 +++----- src/peripheral_pwm.c | 24 ++-- src/peripheral_spi.c | 43 +++---- src/peripheral_uart.c | 49 +++----- 16 files changed, 62 insertions(+), 1139 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index 39c67c5..f9e35e6 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -22,11 +22,5 @@ void gpio_proxy_deinit(void); int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); -int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); -int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value); -int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 7b2b899..30604c7 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -22,8 +22,5 @@ void i2c_proxy_deinit(void); int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); -int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); -int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); -int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out); #endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index f6d4c1c..0ce6159 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -22,9 +22,5 @@ void pwm_proxy_deinit(void); int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); -int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period); -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns); -int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity); -int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index 7ab743a..d6be9b5 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -21,12 +21,5 @@ void spi_proxy_deinit(); int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); int peripheral_gdbus_spi_close(peripheral_spi_h spi); -int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); -int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb); -int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz); -int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length); -int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length); -int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index 15b5d06..d19440c 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -21,12 +21,5 @@ void uart_proxy_deinit(); int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); int peripheral_gdbus_uart_close(peripheral_uart_h uart); -int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud); -int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size); -int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity); -int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits); -int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); -int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length); -int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length); #endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 52fce3e..17a7f2f 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -28,19 +28,8 @@ #define GPIO_FD_INDEX_EDGE 1 #define GPIO_FD_INDEX_VALUE 2 -extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); - static PeripheralIoGdbusGpio *gpio_proxy = NULL; -static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data) -{ - int err = PERIPHERAL_ERROR_NONE; - if (!gpio) - err = PERIPHERAL_ERROR_IO_ERROR; - - peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err); -} - void gpio_proxy_init(void) { GError *error = NULL; @@ -62,11 +51,6 @@ void gpio_proxy_init(void) g_error_free(error); return; } - - g_signal_connect(gpio_proxy, - "interrupted-cb", - G_CALLBACK(__peripheral_gpio_interrupted_cb), - NULL); } void gpio_proxy_deinit() @@ -145,134 +129,4 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) } return ret; -} - -int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_direction_sync( - gpio_proxy, - gpio->handle, - direction, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( - gpio_proxy, - gpio->handle, - edge, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_set_interrupted_cb_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_unset_interrupted_cb_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_read_sync( - gpio_proxy, - gpio->handle, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_write_sync( - gpio_proxy, - gpio->handle, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} +} \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index a3290ab..63fda68 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -109,100 +109,4 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) } return ret; -} - -int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_read_sync( - i2c_proxy, - i2c->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(data_array); - - return ret; -} - -int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *g_data; - int i = 0; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - g_data = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_i2c_call_write_sync( - i2c_proxy, - i2c->handle, - length, - g_data, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_i2c_call_smbus_ioctl_sync( - i2c_proxy, - i2c->handle, - read_write, - command, - size, - data_in, - data_out, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} +} \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 1eb3435..f512e2c 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -133,92 +133,4 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) } return ret; -} - -int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_period_sync( - pwm_proxy, - pwm->handle, - period, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( - pwm_proxy, - pwm->handle, - duty_cycle_ns, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_polarity_sync( - pwm_proxy, - pwm->handle, - polarity, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_set_enable_sync( - pwm_proxy, - pwm->handle, - enable, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} +} \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index 2959835..e286f40 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -109,210 +109,4 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi) } return ret; -} - -int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_mode_sync( - spi_proxy, - spi->handle, - (guchar)mode, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_bit_order_sync( - spi_proxy, - spi->handle, - lsb, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync( - spi_proxy, - spi->handle, - bits, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_frequency_sync( - spi_proxy, - spi->handle, - freq_hz, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (spi_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_read_sync( - spi_proxy, - spi->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(data_array); - - return ret; -} - -int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *data_array; - int i = 0; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - data_array = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_spi_call_write_sync( - spi_proxy, - spi->handle, - length, - data_array, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *rx_data_array; - GVariant *tx_data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (spi_proxy == NULL || !rx_data || !tx_data) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", tx_data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - tx_data_array = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_spi_call_transfer_sync( - spi_proxy, - spi->handle, - length, - tx_data_array, - &rx_data_array, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - i = 0; - g_variant_get(rx_data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - rx_data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(rx_data_array); - - return ret; -} +} \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index e7e57b6..16111dd 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -108,185 +108,4 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart) } return ret; -} - -int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_baud_rate_sync( - uart_proxy, - uart->handle, - baud, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_byte_size_sync( - uart_proxy, - uart->handle, - byte_size, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_parity_sync( - uart_proxy, - uart->handle, - parity, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_stop_bits_sync( - uart_proxy, - uart->handle, - stop_bits, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) -{ - GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_set_flow_control_sync( - uart_proxy, - uart->handle, - xonxoff, - rtscts, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariant *data_array; - GVariantIter *iter; - guint8 str; - int i = 0; - - if (uart_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_uart_call_read_sync( - uart_proxy, - uart->handle, - length, - &data_array, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - g_variant_get(data_array, "a(y)", &iter); - while (g_variant_iter_loop(iter, "(y)", &str)) { - data[i] = str; - if (i++ == length) break; - } - g_variant_iter_free(iter); - g_variant_unref(data_array); - - return ret; -} - -int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - GVariantBuilder *builder; - GVariant *g_data; - int i = 0; - - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); - - for (i = 0; i < length; i++) - g_variant_builder_add(builder, "(y)", data[i]); - g_variant_builder_add(builder, "(y)", 0x00); - - g_data = g_variant_new("a(y)", builder); - g_variant_builder_unref(builder); - - if (peripheral_io_gdbus_uart_call_write_sync( - uart_proxy, - uart->handle, - length, - g_data, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} +} \ No newline at end of file diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 30ceaa6..00c49e7 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -11,39 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -57,31 +24,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - @@ -95,26 +37,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -127,48 +49,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -182,52 +62,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index c80e9c9..a66cbaa 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -48,87 +48,6 @@ static bool __is_feature_supported() return (gpio_feature == GPIO_FEATURE_TRUE ? true : false); } -typedef struct { - peripheral_gpio_h handle; - peripheral_gpio_interrupted_cb callback; - void *user_data; -} interrupted_cb_info_s; - -static GList *interrupted_cb_info_list = NULL; - -int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int error) -{ - GList *link; - interrupted_cb_info_s *cb_info; - - link = interrupted_cb_info_list; - while (link) { - cb_info = (interrupted_cb_info_s*)link->data; - if (cb_info->handle->pin == pin) { - if (cb_info->callback) - cb_info->callback(cb_info->handle, error, cb_info->user_data); - return PERIPHERAL_ERROR_NONE; - } - link = g_list_next(link); - } - - return PERIPHERAL_ERROR_NONE; -} - -static int __interrupted_cb_info_list_append(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) -{ - GList *link; - interrupted_cb_info_s *cb_info = NULL; - - link = interrupted_cb_info_list; - while (link) { - interrupted_cb_info_s *tmp; - tmp = (interrupted_cb_info_s*)link->data; - if (tmp->handle == gpio) { - cb_info = tmp; - break; - } - link = g_list_next(link); - } - - if (cb_info == NULL) { - cb_info = (interrupted_cb_info_s*)calloc(1, sizeof(interrupted_cb_info_s)); - if (cb_info == NULL) { - _E("failed to allocate interrupted_cb_info_s"); - return PERIPHERAL_ERROR_OUT_OF_MEMORY; - } - - interrupted_cb_info_list = g_list_append(interrupted_cb_info_list, cb_info); - } - - cb_info->handle = gpio; - cb_info->callback = callback; - cb_info->user_data = user_data; - - return PERIPHERAL_ERROR_NONE; -} - -static int __interrupted_cb_info_list_remove(peripheral_gpio_h gpio) -{ - GList *link; - interrupted_cb_info_s *cb_info; - - link = interrupted_cb_info_list; - while (link) { - cb_info = (interrupted_cb_info_s*)link->data; - - if (cb_info->handle == gpio) { - interrupted_cb_info_list = g_list_remove_link(interrupted_cb_info_list, link); - free(link->data); - g_list_free(link); - break; - } - link = g_list_next(link); - } - - return PERIPHERAL_ERROR_NONE; -} - /** * @brief Initializes(export) gpio pin and creates gpio handle. */ @@ -200,9 +119,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct 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 */ - ret = peripheral_gdbus_gpio_set_direction(gpio, direction); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set gpio direction, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -220,9 +137,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e 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 */ - ret = peripheral_gdbus_gpio_set_edge_mode(gpio, edge); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set edge mode of the gpio pin, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -238,16 +153,7 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL"); - ret = peripheral_gdbus_gpio_set_interrupted_cb(gpio, callback, user_data); - if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to set gpio interrupted cb, ret : %d", ret); - return ret; - } - - /* set isr */ - ret = __interrupted_cb_info_list_append(gpio, callback, user_data); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to append gpio interrupt callback info, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -262,15 +168,7 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) 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"); - ret = peripheral_gdbus_gpio_unset_interrupted_cb(gpio); - if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to unset gpio interrupt callback, ret : %d", ret); - return ret; - } - - ret = __interrupted_cb_info_list_remove(gpio); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to remove gpio interrupt callback info, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -287,9 +185,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid"); /* call gpio_read */ - ret = peripheral_gdbus_gpio_read(gpio, (int *)value); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read value of the gpio pin, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -306,9 +202,7 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value) RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid"); /* call gpio_write */ - ret = peripheral_gdbus_gpio_write(gpio, (int)value); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write to the gpio pin, ret : %d", ret); + // TODO : replace interface function return ret; } diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 5d32bf3..60e0c59 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -90,7 +90,7 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) int peripheral_i2c_close(peripheral_i2c_h i2c) { - int ret; + 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"); @@ -108,96 +108,76 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int ret; + 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"); - ret = peripheral_gdbus_i2c_read(i2c, data, (int)length); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read data from device, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int ret; + 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"); - ret = peripheral_gdbus_i2c_write(i2c, data, (int)length); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write data to device, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data) { - int ret; - uint16_t w_data, dummy = 0; + 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"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, dummy, &w_data); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Smbus transaction failed, ret : %d", ret); - - *data = (uint8_t)w_data; + // TODO : replace interface function return ret; } int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data) { - int ret; - uint16_t dummy = 0; + 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"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Smbus transaction failed, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data) { - int ret; - uint16_t dummy = 0, data_out; + 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"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, dummy, &data_out); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Smbus transaction failed, ret : %d", ret); - - *data = data_out; + // TODO : replace interface function return ret; } int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data) { - int ret; - uint16_t dummy = 0; + 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"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, data, &dummy); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Smbus transaction failed, ret : %d", ret); + // TODO : replace interface function return ret; } diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index fdd0de7..1329bf1 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -98,57 +98,49 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) { - int ret; + 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"); - ret = peripheral_gdbus_pwm_set_period(pwm, (int)period_ns); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set period, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) { - int ret; + 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"); - ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, (int)duty_cycle_ns); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set duty cycle, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { - int ret; + 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"); - ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set polarity, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable) { - int ret; + 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"); - ret = peripheral_gdbus_pwm_set_enable(pwm, enable); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set enable, ret : %d", ret); + // TODO : replace interface function return ret; } diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 34e777c..b25dee4 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -99,104 +99,89 @@ int peripheral_spi_close(peripheral_spi_h spi) int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - int ret; + 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"); - ret = peripheral_gdbus_spi_set_mode(spi, mode); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set mode, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - int ret; + 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"); - bool lsb = (bit_order == PERIPHERAL_SPI_BIT_ORDER_LSB) ? true : false; - ret = peripheral_gdbus_spi_set_bit_order(spi, lsb); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set lsb first, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - int ret; + 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"); - ret = peripheral_gdbus_spi_set_bits_per_word(spi, (unsigned char)bits); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set bits per word, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) { - int ret; + 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"); - ret = peripheral_gdbus_spi_set_frequency(spi, (unsigned int)freq_hz); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set frequency, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) { - int ret; + 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"); - ret = peripheral_gdbus_spi_read(spi, data, (int)length); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read from spi device, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) { - int ret; + 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"); - ret = peripheral_gdbus_spi_write(spi, data, (int)length); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write to spi device, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length) { - int ret; + 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"); - ret = peripheral_gdbus_spi_transfer(spi, txdata, rxdata, (int)length); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read and write, ret : %d", ret); + // TODO : replace interface function return ret; } diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 10ef561..70d711a 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -54,7 +54,7 @@ static bool __is_feature_supported() int peripheral_uart_open(int port, peripheral_uart_h *uart) { peripheral_uart_h handle; - int ret; + 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, "Invalid uart handle"); @@ -86,7 +86,7 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart) */ int peripheral_uart_close(peripheral_uart_h uart) { - int ret; + 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"); @@ -107,60 +107,52 @@ 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; + 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"); - ret = peripheral_gdbus_uart_set_baud_rate(uart, baud); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set baudrate, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { - int ret; + 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"); - ret = peripheral_gdbus_uart_set_byte_size(uart, byte_size); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set uart mode, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { - int ret; + 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"); - ret = peripheral_gdbus_uart_set_parity(uart, parity); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set uart mode, ret : %d", ret); + // TODO : replace interface function return ret; } int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) { - int ret; + 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"); - ret = peripheral_gdbus_uart_set_stop_bits(uart, stop_bits); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set uart mode, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -171,19 +163,14 @@ int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_b */ 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; + 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"); - bool xonxoff = (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF) ? true : false; - bool rtscts = (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) ? true : false; - - ret = peripheral_gdbus_uart_set_flow_control(uart, xonxoff, rtscts); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set flocontrol, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -193,15 +180,13 @@ 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; + 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"); - ret = peripheral_gdbus_uart_read(uart, data, (int)length); - if (ret < PERIPHERAL_ERROR_NONE) - _E("Failed to read from uart device, ret : %d", ret); + // TODO : replace interface function return ret; } @@ -211,15 +196,13 @@ 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; + 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"); - ret = peripheral_gdbus_uart_write(uart, data, (int)length); - if (ret < PERIPHERAL_ERROR_NONE) - _E("Failed to write to uart device, ret : %d", ret); + // TODO : replace interface function return ret; } -- 2.7.4 From 2841452b5dfca59cee77e1bb749013a8244a9306 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 22:13:29 +0900 Subject: [PATCH 06/16] gdbus: refactor gdbus proxy functions - changed to static - proxy init function has been modified to return error. Change-Id: I220d66e31d19c4cd7e27caa18f2c5cd2cba19b00 Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_gpio.h | 3 --- include/gdbus/peripheral_gdbus_i2c.h | 3 --- include/gdbus/peripheral_gdbus_pwm.h | 3 --- include/gdbus/peripheral_gdbus_spi.h | 3 --- include/gdbus/peripheral_gdbus_uart.h | 3 --- src/gdbus/peripheral_gdbus_gpio.c | 27 +++++++++++++++++++-------- src/gdbus/peripheral_gdbus_i2c.c | 26 +++++++++++++++++++++----- src/gdbus/peripheral_gdbus_pwm.c | 26 +++++++++++++++++++++----- src/gdbus/peripheral_gdbus_spi.c | 26 +++++++++++++++++++++----- src/gdbus/peripheral_gdbus_uart.c | 27 +++++++++++++++++++++------ src/peripheral_gpio.c | 4 ---- src/peripheral_i2c.c | 3 --- src/peripheral_pwm.c | 3 --- src/peripheral_spi.c | 3 --- src/peripheral_uart.c | 3 --- 15 files changed, 103 insertions(+), 60 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index f9e35e6..3fd5307 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -17,9 +17,6 @@ #ifndef __PERIPHERAL_GDBUS_GPIO_H__ #define __PERIPHERAL_GDBUS_GPIO_H__ -void gpio_proxy_init(void); -void gpio_proxy_deinit(void); - int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 30604c7..0670442 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -17,9 +17,6 @@ #ifndef __PERIPHERAL_GDBUS_I2C_H__ #define __PERIPHERAL_GDBUS_I2C_H__ -void i2c_proxy_init(void); -void i2c_proxy_deinit(void); - int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index 0ce6159..148e938 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -17,9 +17,6 @@ #ifndef __PERIPHERAL_GDBUS_PWM_H__ #define __PERIPHERAL_GDBUS_PWM_H__ -void pwm_proxy_init(void); -void pwm_proxy_deinit(void); - int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index d6be9b5..8a6ac61 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -16,9 +16,6 @@ #ifndef __PERIPHERAL_GDBUS_SPI_H_ #define __PERIPHERAL_GDBUS_SPI_H_ -void spi_proxy_init(void); -void spi_proxy_deinit(); - int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); int peripheral_gdbus_spi_close(peripheral_spi_h spi); diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index d19440c..175452c 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -16,9 +16,6 @@ #ifndef __PERIPHERAL_GDBUS_UART_H_ #define __PERIPHERAL_GDBUS_UART_H_ -void uart_proxy_init(void); -void uart_proxy_deinit(); - int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); int peripheral_gdbus_uart_close(peripheral_uart_h uart); diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 17a7f2f..ca5badd 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -30,13 +30,14 @@ static PeripheralIoGdbusGpio *gpio_proxy = NULL; -void gpio_proxy_init(void) +static int __gpio_proxy_init() { GError *error = NULL; if (gpio_proxy != NULL) { + _E("Gpio proxy is already created"); g_object_ref(gpio_proxy); - return; + return PERIPHERAL_ERROR_NONE; } gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync( @@ -46,16 +47,19 @@ void gpio_proxy_init(void) PERIPHERAL_GDBUS_GPIO_PATH, NULL, &error); + if (gpio_proxy == NULL) { - _E("Can not create gpio proxy : %s", error->message); + _E("Failed to create gpio proxy : %s", error->message); g_error_free(error); - return; + return PERIPHERAL_ERROR_UNKNOWN; } + + return PERIPHERAL_ERROR_NONE; } -void gpio_proxy_deinit() +static void __gpio_proxy_deinit() { - if (gpio_proxy) { + if (gpio_proxy != NULL) { g_object_unref(gpio_proxy); if (!G_IS_OBJECT(gpio_proxy)) gpio_proxy = NULL; @@ -68,7 +72,9 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) gint32 ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + ret = __gpio_proxy_init(); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; if (peripheral_io_gdbus_gpio_call_open_sync( gpio_proxy, @@ -115,7 +121,10 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + if (gpio_proxy == NULL) { + _E("Can't try to gpio close because gpio proxy is NULL."); + return PERIPHERAL_ERROR_UNKNOWN; + } if (peripheral_io_gdbus_gpio_call_close_sync( gpio_proxy, @@ -128,5 +137,7 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) return PERIPHERAL_ERROR_UNKNOWN; } + __gpio_proxy_deinit(); + return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 63fda68..b10b10f 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -28,13 +28,14 @@ static PeripheralIoGdbusI2c *i2c_proxy = NULL; -void i2c_proxy_init(void) +static int __i2c_proxy_init() { GError *error = NULL; if (i2c_proxy != NULL) { + _E("I2c proxy is already created"); g_object_ref(i2c_proxy); - return; + return PERIPHERAL_ERROR_NONE; } i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync( @@ -44,9 +45,17 @@ void i2c_proxy_init(void) PERIPHERAL_GDBUS_I2C_PATH, NULL, &error); + + if (i2c_proxy == NULL) { + _E("Failed to create i2c proxy : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; } -void i2c_proxy_deinit() +static void __i2c_proxy_deinit() { if (i2c_proxy) { g_object_unref(i2c_proxy); @@ -61,7 +70,9 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + ret = __i2c_proxy_init(); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; if (peripheral_io_gdbus_i2c_call_open_sync( i2c_proxy, @@ -95,7 +106,10 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + if (i2c_proxy == NULL) { + _E("Can't try to i2c close because i2c proxy is NULL."); + return PERIPHERAL_ERROR_UNKNOWN; + } if (peripheral_io_gdbus_i2c_call_close_sync( i2c_proxy, @@ -108,5 +122,7 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) return PERIPHERAL_ERROR_UNKNOWN; } + __i2c_proxy_deinit(); + return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index f512e2c..3279d15 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -31,13 +31,14 @@ static PeripheralIoGdbusPwm *pwm_proxy = NULL; -void pwm_proxy_init(void) +static int __pwm_proxy_init() { GError *error = NULL; if (pwm_proxy != NULL) { + _E("Pwm proxy is already created"); g_object_ref(pwm_proxy); - return; + return PERIPHERAL_ERROR_NONE; } pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync( @@ -47,9 +48,17 @@ void pwm_proxy_init(void) PERIPHERAL_GDBUS_PWM_PATH, NULL, &error); + + if (pwm_proxy == NULL) { + _E("Failed to create pwm proxy : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; } -void pwm_proxy_deinit() +static void __pwm_proxy_deinit() { if (pwm_proxy) { g_object_unref(pwm_proxy); @@ -64,7 +73,9 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + ret = __pwm_proxy_init(); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; if (peripheral_io_gdbus_pwm_call_open_sync( pwm_proxy, @@ -119,7 +130,10 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + if (pwm_proxy == NULL) { + _E("Can't try to pwm close because pwm proxy is NULL."); + return PERIPHERAL_ERROR_UNKNOWN; + } if (peripheral_io_gdbus_pwm_call_close_sync( pwm_proxy, @@ -132,5 +146,7 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) return PERIPHERAL_ERROR_UNKNOWN; } + __pwm_proxy_deinit(); + return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index e286f40..80e267a 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -28,13 +28,14 @@ static PeripheralIoGdbusSpi *spi_proxy = NULL; -void spi_proxy_init(void) +static int __spi_proxy_init() { GError *error = NULL; if (spi_proxy != NULL) { + _E("Spi proxy is already created"); g_object_ref(spi_proxy); - return; + return PERIPHERAL_ERROR_NONE; } spi_proxy = peripheral_io_gdbus_spi_proxy_new_for_bus_sync( @@ -44,9 +45,17 @@ void spi_proxy_init(void) PERIPHERAL_GDBUS_SPI_PATH, NULL, &error); + + if (spi_proxy == NULL) { + _E("Failed to create spi proxy : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; } -void spi_proxy_deinit() +static void __spi_proxy_deinit() { if (spi_proxy) { g_object_unref(spi_proxy); @@ -61,7 +70,9 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + ret = __spi_proxy_init(); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; if (peripheral_io_gdbus_spi_call_open_sync( spi_proxy, @@ -95,7 +106,10 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi) GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + if (spi_proxy == NULL) { + _E("Can't try to spi close because spi proxy is NULL."); + return PERIPHERAL_ERROR_UNKNOWN; + } if (peripheral_io_gdbus_spi_call_close_sync( spi_proxy, @@ -108,5 +122,7 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi) return PERIPHERAL_ERROR_UNKNOWN; } + __spi_proxy_deinit(); + return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 16111dd..99620b6 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -28,13 +28,14 @@ static PeripheralIoGdbusUart *uart_proxy = NULL; -void uart_proxy_init(void) +static int __uart_proxy_init() { GError *error = NULL; if (uart_proxy != NULL) { + _E("Uart proxy is already created"); g_object_ref(uart_proxy); - return; + return PERIPHERAL_ERROR_NONE; } uart_proxy = peripheral_io_gdbus_uart_proxy_new_for_bus_sync( @@ -44,9 +45,17 @@ void uart_proxy_init(void) PERIPHERAL_GDBUS_UART_PATH, NULL, &error); + + if (uart_proxy == NULL) { + _E("Failed to create uart proxy : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; } -void uart_proxy_deinit() +static void __uart_proxy_deinit() { if (uart_proxy) { g_object_unref(uart_proxy); @@ -61,7 +70,9 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + ret = __uart_proxy_init(); + if (ret != PERIPHERAL_ERROR_NONE) + return ret; if (peripheral_io_gdbus_uart_call_open_sync( uart_proxy, @@ -94,8 +105,10 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart) GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - + if (uart_proxy == NULL) { + _E("Can't try to uart close because uart proxy is NULL."); + return PERIPHERAL_ERROR_UNKNOWN; + } if (peripheral_io_gdbus_uart_call_close_sync( uart_proxy, uart->handle, @@ -107,5 +120,7 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart) return PERIPHERAL_ERROR_UNKNOWN; } + __uart_proxy_deinit(); + return ret; } \ No newline at end of file diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index a66cbaa..6a03a5a 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -69,8 +69,6 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) } handle->pin = gpio_pin; - gpio_proxy_init(); - ret = peripheral_gdbus_gpio_open(handle); if (ret != PERIPHERAL_ERROR_NONE) { @@ -99,7 +97,6 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) ret = peripheral_gdbus_gpio_close(gpio); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close the gpio pin, ret : %d", ret); - gpio_proxy_deinit(); free(gpio); gpio = NULL; @@ -124,7 +121,6 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct return ret; } - /** * @brief Sets the edge mode of the gpio pin. */ diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 60e0c59..d729356 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -74,8 +74,6 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - i2c_proxy_init(); - ret = peripheral_gdbus_i2c_open(handle, bus, address); if (ret != PERIPHERAL_ERROR_NONE) { @@ -98,7 +96,6 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) ret = peripheral_gdbus_i2c_close(i2c); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close i2c communcation, ret : %d", ret); - i2c_proxy_deinit(); free(i2c); i2c = NULL; diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 1329bf1..e21bcbb 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -66,8 +66,6 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - pwm_proxy_init(); - ret = peripheral_gdbus_pwm_open(handle, chip, pin); if (ret != PERIPHERAL_ERROR_NONE) { @@ -90,7 +88,6 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0) _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); - pwm_proxy_deinit(); free(pwm); return ret; diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index b25dee4..68e9761 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -66,8 +66,6 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi) return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - spi_proxy_init(); - ret = peripheral_gdbus_spi_open(handle, bus, cs); if (ret != PERIPHERAL_ERROR_NONE) { @@ -91,7 +89,6 @@ int peripheral_spi_close(peripheral_spi_h spi) if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to close SPI device, continuing anyway, ret : %d", ret); - spi_proxy_deinit(); free(spi); return ret; diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 70d711a..ad58c0c 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -67,8 +67,6 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart) return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - uart_proxy_init(); - ret = peripheral_gdbus_uart_open(handle, port); if (ret != PERIPHERAL_ERROR_NONE) { @@ -94,7 +92,6 @@ int peripheral_uart_close(peripheral_uart_h uart) ret = peripheral_gdbus_uart_close(uart); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to close uart communication, continuing anyway, ret : %d", ret); - uart_proxy_deinit(); free(uart); uart = NULL; -- 2.7.4 From 3ab40f8b2bb51572a4263ea0821fe27bd1dbc9e0 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 22:27:05 +0900 Subject: [PATCH 07/16] gdbus: add check error in gdbus functions when gdbus request to daemon for open/close, it can receive return value TRUE with ret that it is not PERIPEHRAL_ERROR_NONE. In the case of requesting open to daemon, getting fd from list is meaningless. In the case of requesting close to daemon, proxy deinit function must not be run. Change-Id: I6ca7b1c98a15ca17159123903cd9d8ebe57c353c Signed-off-by: Segwon --- src/gdbus/peripheral_gdbus_gpio.c | 16 +++++++++++----- src/gdbus/peripheral_gdbus_i2c.c | 19 ++++++++++++------- src/gdbus/peripheral_gdbus_pwm.c | 18 ++++++++++++------ src/gdbus/peripheral_gdbus_spi.c | 18 ++++++++++++------ src/gdbus/peripheral_gdbus_uart.c | 19 +++++++++++++------ 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index ca5badd..d03ceda 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -68,8 +68,8 @@ static void __gpio_proxy_deinit() int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) { + int ret; GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __gpio_proxy_init(); @@ -85,11 +85,15 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) &fd_list, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to gpio open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + gpio->fd_direction = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_DIRECTION, &error); if (gpio->fd_direction < 0) { _E("Failed to get fd for gpio direction : %s", error->message); @@ -118,8 +122,8 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) { _E("Can't try to gpio close because gpio proxy is NULL."); @@ -132,12 +136,14 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) &ret, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to gpio close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __gpio_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __gpio_proxy_deinit(); return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index b10b10f..5ee8906 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -66,8 +66,8 @@ static void __i2c_proxy_deinit() int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __i2c_proxy_init(); @@ -84,16 +84,19 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) &fd_list, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to i2c open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + i2c->fd = g_unix_fd_list_get(fd_list, I2C_FD_INDEX, &error); if (i2c->fd < 0) { _E("Failed to get fd for i2c : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; } g_object_unref(fd_list); @@ -103,8 +106,8 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (i2c_proxy == NULL) { _E("Can't try to i2c close because i2c proxy is NULL."); @@ -117,12 +120,14 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) &ret, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to i2c close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __i2c_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __i2c_proxy_deinit(); return ret; -} \ No newline at end of file +} diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 3279d15..eb26bf5 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -69,8 +69,8 @@ static void __pwm_proxy_deinit() int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __pwm_proxy_init(); @@ -87,11 +87,15 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) &fd_list, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to pwm open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + pwm->fd_period = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_PERIOD, &error); if (pwm->fd_period < 0) { _E("Failed to get fd for pwm period : %s", error->message); @@ -127,8 +131,8 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (pwm_proxy == NULL) { _E("Can't try to pwm close because pwm proxy is NULL."); @@ -141,12 +145,14 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) &ret, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to pwm close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __pwm_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __pwm_proxy_deinit(); return ret; -} \ No newline at end of file +} diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index 80e267a..d58edfe 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -66,8 +66,8 @@ static void __spi_proxy_deinit() int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __spi_proxy_init(); @@ -84,11 +84,15 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) &fd_list, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to spi open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + spi->fd = g_unix_fd_list_get(fd_list, SPI_FD_INDEX, &error); if (spi->fd < 0) { _E("Failed to get fd for spi : %s", error->message); @@ -103,8 +107,8 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) int peripheral_gdbus_spi_close(peripheral_spi_h spi) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (spi_proxy == NULL) { _E("Can't try to spi close because spi proxy is NULL."); @@ -117,12 +121,14 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi) &ret, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to spi close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __spi_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __spi_proxy_deinit(); return ret; -} \ No newline at end of file +} diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 99620b6..985f2b4 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -66,8 +66,8 @@ static void __uart_proxy_deinit() int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __uart_proxy_init(); @@ -83,11 +83,15 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) &fd_list, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to uart open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + uart->fd = g_unix_fd_list_get(fd_list, UART_FD_INDEX, &error); if (uart->fd < 0) { _E("Failed to get fd for uart : %s", error->message); @@ -102,25 +106,28 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) int peripheral_gdbus_uart_close(peripheral_uart_h uart) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) { _E("Can't try to uart close because uart proxy is NULL."); return PERIPHERAL_ERROR_UNKNOWN; } + if (peripheral_io_gdbus_uart_call_close_sync( uart_proxy, uart->handle, &ret, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to uart close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __uart_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __uart_proxy_deinit(); return ret; -} \ No newline at end of file +} -- 2.7.4 From 2f57c46d2d36e7de3cfbb4af31b6f1722b753d13 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 10:57:02 +0900 Subject: [PATCH 08/16] gdbus: change 'peripheral_gdbus.h' file name to 'peripheral_gdbus_common.h' - for match with interface Change-Id: Ib6f2ee970976462c4b52d9a028a8ac956d17b80a Signed-off-by: Segwon --- include/gdbus/{peripheral_gdbus.h => peripheral_gdbus_common.h} | 6 +++--- src/gdbus/peripheral_gdbus_gpio.c | 2 +- src/gdbus/peripheral_gdbus_i2c.c | 2 +- src/gdbus/peripheral_gdbus_pwm.c | 2 +- src/gdbus/peripheral_gdbus_spi.c | 2 +- src/gdbus/peripheral_gdbus_uart.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename include/gdbus/{peripheral_gdbus.h => peripheral_gdbus_common.h} (90%) diff --git a/include/gdbus/peripheral_gdbus.h b/include/gdbus/peripheral_gdbus_common.h similarity index 90% rename from include/gdbus/peripheral_gdbus.h rename to include/gdbus/peripheral_gdbus_common.h index ff726de..685efdb 100644 --- a/include/gdbus/peripheral_gdbus.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __PERIPHERAL_GDBUS_H__ -#define __PERIPHERAL_GDBUS_H__ +#ifndef __PERIPHERAL_GDBUS_COMMON_H__ +#define __PERIPHERAL_GDBUS_COMMON_H__ #include @@ -26,4 +26,4 @@ #define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi" #define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io" -#endif /* __PERIPHERAL_GDBUS_H__ */ +#endif /* __PERIPHERAL_GDBUS_COMMON_H__ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index d03ceda..f5e6b0b 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 5ee8906..767332b 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index eb26bf5..e9b501b 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index d58edfe..2d07cd3 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 985f2b4..32d7992 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -- 2.7.4 From 26cf17a8048b905ce1ce236fe4cd5294b903df4f Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 11:03:38 +0900 Subject: [PATCH 09/16] including : move the '#include' duplicate written to common file Change-Id: I5926833c5cef4f5d82bcca78164289562b53c2ca Signed-off-by: Segwon --- CMakeLists.txt | 3 +++ include/gdbus/peripheral_gdbus_common.h | 9 +++++++++ include/gdbus/peripheral_gdbus_gpio.h | 2 ++ include/gdbus/peripheral_gdbus_i2c.h | 2 ++ include/gdbus/peripheral_gdbus_pwm.h | 2 ++ include/gdbus/peripheral_gdbus_spi.h | 3 +++ include/gdbus/peripheral_gdbus_uart.h | 3 +++ include/interface/peripheral_interface_common.h | 11 +++++++++++ include/interface/peripheral_interface_gpio.h | 2 +- include/interface/peripheral_interface_i2c.h | 4 +--- include/interface/peripheral_interface_pwm.h | 2 +- include/interface/peripheral_interface_spi.h | 2 +- include/interface/peripheral_interface_uart.h | 4 +--- src/gdbus/peripheral_gdbus_gpio.c | 10 +--------- src/gdbus/peripheral_gdbus_i2c.c | 10 +--------- src/gdbus/peripheral_gdbus_pwm.c | 10 +--------- src/gdbus/peripheral_gdbus_spi.c | 10 +--------- src/gdbus/peripheral_gdbus_uart.c | 10 +--------- src/interface/peripheral_interface_gpio.c | 11 ----------- src/interface/peripheral_interface_i2c.c | 9 --------- src/interface/peripheral_interface_pwm.c | 11 ----------- src/interface/peripheral_interface_spi.c | 9 --------- src/interface/peripheral_interface_uart.c | 11 ----------- 23 files changed, 45 insertions(+), 105 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b17fa7..7fd0979 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ INCLUDE_DIRECTORIES(${INC_DIR}) INCLUDE_DIRECTORIES(${INC_DIR}/gdbus) INCLUDE_DIRECTORIES(${INC_DIR}/interface) +SET(SRC_DIR src) +INCLUDE_DIRECTORIES(${SRC_DIR}/gdbus) + INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) FOREACH(flag ${${fw_name}_CFLAGS}) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index 685efdb..9a8450e 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -13,10 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_GDBUS_COMMON_H__ #define __PERIPHERAL_GDBUS_COMMON_H__ #include +#include +#include +#include + +#include "peripheral_io.h" +#include "peripheral_internal.h" +#include "peripheral_common.h" +#include "peripheral_io_gdbus.h" #define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" #define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index 3fd5307..c63aeba 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -17,6 +17,8 @@ #ifndef __PERIPHERAL_GDBUS_GPIO_H__ #define __PERIPHERAL_GDBUS_GPIO_H__ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 0670442..e1b1722 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -17,6 +17,8 @@ #ifndef __PERIPHERAL_GDBUS_I2C_H__ #define __PERIPHERAL_GDBUS_I2C_H__ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index 148e938..70a4b02 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -17,6 +17,8 @@ #ifndef __PERIPHERAL_GDBUS_PWM_H__ #define __PERIPHERAL_GDBUS_PWM_H__ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index 8a6ac61..94b2242 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_GDBUS_SPI_H_ #define __PERIPHERAL_GDBUS_SPI_H_ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); int peripheral_gdbus_spi_close(peripheral_spi_h spi); diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index 175452c..bf7af68 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_GDBUS_UART_H_ #define __PERIPHERAL_GDBUS_UART_H_ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); int peripheral_gdbus_uart_close(peripheral_uart_h uart); diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 33a8d39..a69254e 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -17,6 +17,17 @@ #ifndef __PERIPHERAL_INTERFACE_COMMON_H__ #define __PERIPHERAL_INTERFACE_COMMON_H__ +#include +#include +#include +#include +#include +#include + +#include "peripheral_io.h" +#include "peripheral_internal.h" +#include "peripheral_common.h" + #define CHECK_ERROR(val) \ do { \ if (val < 0) { \ diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index cc68e92..ff3a794 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -17,7 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_GPIO_H__ #define __PERIPHERAL_INTERFACE_GPIO_H__ -#include "peripheral_io.h" +#include "peripheral_interface_common.h" #define SYSFS_GPIO_DIR "/sys/class/gpio" #define GPIO_BUFFER_MAX 64 diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 41326d6..6e3dc23 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -17,9 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_I2C_H__ #define __PERIPHERAL_INTERFACE_I2C_H__ -#include - -#include "peripheral_io.h" +#include "peripheral_interface_common.h" #define SYSFS_I2C_DIR "/dev/i2c" #define I2C_BUFFER_MAX 64 diff --git a/include/interface/peripheral_interface_pwm.h b/include/interface/peripheral_interface_pwm.h index 0867663..f37b40d 100644 --- a/include/interface/peripheral_interface_pwm.h +++ b/include/interface/peripheral_interface_pwm.h @@ -17,7 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_PWM_H__ #define __PERIPHERAL_INTERFACE_PWM_H__ -#include "peripheral_io.h" +#include "peripheral_interface_common.h" /** * @brief pwm_close() deinit pwm pin. diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h index d7a471d..801c324 100644 --- a/include/interface/peripheral_interface_spi.h +++ b/include/interface/peripheral_interface_spi.h @@ -17,7 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_SPI_H__ #define __PERIPHERAL_INTERFACE_SPI_H__ -#include "peripheral_io.h" +#include "peripheral_interface_common.h" int peripheral_interface_spi_close(peripheral_spi_h spi); int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h index 4648ae1..c4c82ec 100644 --- a/include/interface/peripheral_interface_uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -17,9 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_UART_H__ #define __PERIPHERAL_INTERFACE_UART_H__ -#include "peripheral_io.h" - -#include +#include "peripheral_interface_common.h" /** * @brief uart_close() closes uart port. diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index f5e6b0b..c8a6d8c 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_gpio.h" #define GPIO_FD_INDEX_DIRECTION 0 #define GPIO_FD_INDEX_EDGE 1 diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 767332b..29ba888 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_i2c.h" #define I2C_FD_INDEX 0 diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index e9b501b..48ff164 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_pwm.h" #define PWM_FD_INDEX_PERIOD 0 #define PWM_FD_INDEX_DUTY_CYCLE 1 diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index 2d07cd3..fce5a41 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_spi.h" #define SPI_FD_INDEX 0 diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 32d7992..852e244 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_uart.h" #define UART_FD_INDEX 0 diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 7d4ef2f..950de19 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -14,18 +14,7 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include - -#include "peripheral_interface_common.h" #include "peripheral_interface_gpio.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define MAX_ERR_LEN 255 diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index fadbf63..87be206 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -14,18 +14,9 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include -#include "peripheral_interface_common.h" #include "peripheral_interface_i2c.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define MAX_ERR_LEN 255 diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index faefc1a..bbfeefb 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -14,18 +14,7 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include - -#include "peripheral_interface_common.h" #include "peripheral_interface_pwm.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define SYSFS_PWM_PATH "/sys/class/pwm" diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index 1c83726..e8a0fc6 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -14,19 +14,10 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include #include -#include "peripheral_interface_common.h" #include "peripheral_interface_spi.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define SYSFS_SPI_DIR "/dev/spidev" #define SYSFS_SPI_BUFSIZ "/sys/module/spidev/parameters/bufsiz" diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index a0f9637..4944bb9 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -14,20 +14,9 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include -#include -#include -#include "peripheral_interface_common.h" #include "peripheral_interface_uart.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define PATH_BUF_MAX 64 #define UART_BUF_MAX 16 -- 2.7.4 From ca21b2731e07b6de6423a591a3c33afba2210f7f Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 11:59:38 +0900 Subject: [PATCH 10/16] handle: change file name 'peripheral_internal.h' to 'peripheral_handle.h' - the word 'internal' does not mean defining a handle structure. Change-Id: Ica3650be46eb2285aaa543b1aadd3ae0a0f822cf Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_common.h | 2 +- include/interface/peripheral_interface_common.h | 2 +- include/{peripheral_internal.h => peripheral_handle.h} | 6 +++--- src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) rename include/{peripheral_internal.h => peripheral_handle.h} (92%) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index 9a8450e..ed8c397 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -23,7 +23,7 @@ #include #include "peripheral_io.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #include "peripheral_common.h" #include "peripheral_io_gdbus.h" diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index a69254e..f0bd657 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -25,7 +25,7 @@ #include #include "peripheral_io.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #include "peripheral_common.h" #define CHECK_ERROR(val) \ diff --git a/include/peripheral_internal.h b/include/peripheral_handle.h similarity index 92% rename from include/peripheral_internal.h rename to include/peripheral_handle.h index 5c62dee..be8a066 100644 --- a/include/peripheral_internal.h +++ b/include/peripheral_handle.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PERIPHERAL_INTERNAL_H__ -#define __PERIPHERAL_INTERNAL_H__ +#ifndef __PERIPHERAL_HANDLE_H__ +#define __PERIPHERAL_HANDLE_H__ /** * @brief Internal struct for gpio context @@ -63,4 +63,4 @@ struct _peripheral_spi_s { int fd; }; -#endif /* __PERIPHERAL_INTERNAL_H__ */ +#endif /* __PERIPHERAL_HANDLE_H__ */ diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 6a03a5a..06806ec 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -24,7 +24,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index d729356..89c1674 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_i2c.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c" diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index e21bcbb..c671ff4 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_pwm.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm" diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 68e9761..0a9e95e 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -24,7 +24,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_spi.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi" diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index ad58c0c..0d67c98 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_uart.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart" -- 2.7.4 From 53da683cf99b7be5ba4e8bec3d060f6593a59cbe Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 15:52:34 +0900 Subject: [PATCH 11/16] including: remove unnecessary header files Change-Id: Ice8e09e5654bbc2e94d5c41b5e1d5d86e5b78239 Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_common.h | 1 - include/interface/peripheral_interface_common.h | 3 --- include/peripheral_common.h | 2 +- src/peripheral_gpio.c | 4 ---- src/peripheral_i2c.c | 3 --- src/peripheral_pwm.c | 3 --- src/peripheral_spi.c | 4 ---- src/peripheral_uart.c | 3 --- 8 files changed, 1 insertion(+), 22 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index ed8c397..6885a61 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -17,7 +17,6 @@ #ifndef __PERIPHERAL_GDBUS_COMMON_H__ #define __PERIPHERAL_GDBUS_COMMON_H__ -#include #include #include #include diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index f0bd657..8cb2ed8 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -19,9 +19,6 @@ #include #include -#include -#include -#include #include #include "peripheral_io.h" diff --git a/include/peripheral_common.h b/include/peripheral_common.h index 19352be..c5702d3 100644 --- a/include/peripheral_common.h +++ b/include/peripheral_common.h @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_COMMON_H__ #define __PERIPHERAL_COMMON_H__ -#include #include #undef LOG_TAG diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 06806ec..5992d16 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -14,12 +14,8 @@ * limitations under the License. */ -#include #include -#include -#include #include -#include #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 89c1674..c61374b 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -14,10 +14,7 @@ * limitations under the License. */ -#include #include -#include -#include #include #include "peripheral_io.h" diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index c671ff4..74f807a 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -14,10 +14,7 @@ * limitations under the License. */ -#include #include -#include -#include #include #include "peripheral_io.h" diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 0a9e95e..61d3b79 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -14,11 +14,7 @@ * limitations under the License. */ -#include "peripheral_io.h" - -#include #include -#include #include #include "peripheral_io.h" diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 0d67c98..d63c100 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -14,10 +14,7 @@ * limitations under the License. */ -#include #include -#include -#include #include #include "peripheral_io.h" -- 2.7.4 From 2db5b00566952b5d6fe2cfa42ef386248d5327ff Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:24:33 +0900 Subject: [PATCH 12/16] log: change file name "peripheral_common.h" to "peripheral_log.h" Change-Id: I96c150951c7cb2c5517b305e00909b0bca5cacff Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_common.h | 2 +- include/interface/peripheral_interface_common.h | 2 +- include/{peripheral_common.h => peripheral_log.h} | 0 src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename include/{peripheral_common.h => peripheral_log.h} (100%) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index 6885a61..62b0717 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -23,8 +23,8 @@ #include "peripheral_io.h" #include "peripheral_handle.h" -#include "peripheral_common.h" #include "peripheral_io_gdbus.h" +#include "peripheral_log.h" #define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" #define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 8cb2ed8..2646cc6 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_handle.h" -#include "peripheral_common.h" +#include "peripheral_log.h" #define CHECK_ERROR(val) \ do { \ diff --git a/include/peripheral_common.h b/include/peripheral_log.h similarity index 100% rename from include/peripheral_common.h rename to include/peripheral_log.h diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 5992d16..040d862 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index c61374b..e89e401 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_i2c.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c" diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 74f807a..fb1ed14 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_pwm.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm" diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 61d3b79..13c2b05 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_spi.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi" diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index d63c100..d7d3577 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_uart.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart" -- 2.7.4 From d934f33cca753b515853713c844369ca5e8e6e22 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:40:18 +0900 Subject: [PATCH 13/16] interface: do not check if fd is negative - it is checked by the caller. - the check is meaningless even if handle is not opened. Change-Id: Id22083b04f4e95a0788a32f1cbc2929c08dd8c31 Signed-off-by: Segwon --- src/interface/peripheral_interface_i2c.c | 25 ++-------- src/interface/peripheral_interface_spi.c | 41 ++-------------- src/interface/peripheral_interface_uart.c | 81 ++----------------------------- 3 files changed, 12 insertions(+), 135 deletions(-) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 87be206..d0a9985 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -22,12 +22,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) { - int status; - - _D("fd : %d", i2c->fd); - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); - - status = close(i2c->fd); + int status = close(i2c->fd); CHECK_ERROR(status); return 0; @@ -35,11 +30,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = read(i2c->fd, data, length); + int status = read(i2c->fd, data, length); CHECK_ERROR(status); return 0; @@ -47,11 +38,7 @@ int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = write(i2c->fd, data, length); + int status = write(i2c->fd, data, length); CHECK_ERROR(status); return 0; @@ -59,11 +46,7 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = ioctl(i2c->fd, I2C_SMBUS, data); + int status = ioctl(i2c->fd, I2C_SMBUS, data); CHECK_ERROR(status); return 0; diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index e8a0fc6..bf68c50 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -26,12 +26,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) { - int status; - - _D("fd : %d", spi->fd); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = close(spi->fd); + int status = close(spi->fd); CHECK_ERROR(status); return 0; @@ -39,12 +34,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - int status; - - _D("fd : %d, mode : %d", spi->fd, mode); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); + int status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); CHECK_ERROR(status); return 0; @@ -52,12 +42,7 @@ int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - int status; - - _D("fd : %d, lsb : %d", spi->fd, bit_order); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + int status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); CHECK_ERROR(status); return 0; @@ -65,12 +50,7 @@ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - int status; - - _D("fd : %d, bits : %d", spi->fd, bits); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); + int status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); CHECK_ERROR(status); return 0; @@ -78,12 +58,7 @@ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bit int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) { - int status; - - _D("fd : %d, freq : %d", spi->fd, freq); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); + int status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); CHECK_ERROR(status); return 0; @@ -94,8 +69,6 @@ int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.rx_buf = (unsigned long)rxbuf; xfer.len = length; @@ -111,8 +84,6 @@ int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_ int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.tx_buf = (unsigned long)txbuf; xfer.len = length; @@ -128,8 +99,6 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - if (!txbuf || !rxbuf) return -EINVAL; memset(&xfer, 0, sizeof(xfer)); diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 4944bb9..36131a1 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -47,13 +47,6 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) { int status; - _D("file_hndl : %d", uart->fd); - - if (uart->fd < 0) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - status = peripheral_interface_uart_flush(uart); CHECK_ERROR(status); @@ -65,14 +58,7 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) int peripheral_interface_uart_flush(peripheral_uart_h uart) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = tcflush(uart->fd, TCIOFLUSH); + int ret = tcflush(uart->fd, TCIOFLUSH); CHECK_ERROR(ret); return 0; @@ -83,19 +69,6 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, baud : %d", uart->fd, baud); - - memset(&tio, 0, sizeof(tio)); - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (baud > PERIPHERAL_UART_BAUD_RATE_230400) { - _E("Invalid parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -118,22 +91,9 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, bytesize : %d", uart->fd, byte_size); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT) { - _E("Invalid bytesize parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); - /* set byte size */ tio.c_cflag &= ~CSIZE; tio.c_cflag |= byteinfo[byte_size]; @@ -151,13 +111,6 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart int ret; struct termios tio; - _D("file_hndl : %d, parity : %d", uart->fd, parity); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -190,13 +143,6 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, stopbits : %d", uart->fd, stop_bits); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -225,13 +171,6 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int ret; struct termios tio; - _D("file_hndl : %d, xonxoff : %d, rtscts : %d", uart->fd, xonxoff, rtscts); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -257,14 +196,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = read(uart->fd, (void *)buf, length); + int ret = read(uart->fd, (void *)buf, length); CHECK_ERROR(ret); return ret; @@ -272,14 +204,7 @@ int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_ int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = write(uart->fd, buf, length); + int ret = write(uart->fd, buf, length); CHECK_ERROR(ret); return ret; -- 2.7.4 From 8ea72de00628c59ded9892af841c6395df28d16e Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:55:08 +0900 Subject: [PATCH 14/16] i2c: replace 'i2c_smbus_ioctl()' with another functions. - do not use 'i2c_smbus_ioctl_data' structure in caller. - remove : i2c_smbus_ioctl() - add : peripheral_interface_i2c_read_register_byte() - add : peripheral_interface_i2c_write_register_byte() - add : peripheral_interface_i2c_read_register_word() - add : peripheral_interface_i2c_write_register_word() Change-Id: Ia73f3febcf1412a5101a83b2106a0d7c695a2ce4 Signed-off-by: Segwon --- include/interface/peripheral_interface_i2c.h | 7 ++- src/interface/peripheral_interface_i2c.c | 84 +++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 6e3dc23..b10fc1a 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -58,6 +58,9 @@ struct i2c_smbus_ioctl_data { int 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_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data); +int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out); +int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in); +int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out); +int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in); -#endif/* __PERIPHERAL_INTERFACE_I2C_H__ */ +#endif /* __PERIPHERAL_INTERFACE_I2C_H__ */ diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index d0a9985..3fcb083 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -44,10 +44,90 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t return 0; } -int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) +int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out) { - int status = ioctl(i2c->fd, I2C_SMBUS, data); + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_READ; + data_arg.size = I2C_SMBUS_BYTE_DATA; + data_arg.data = &data; + data_arg.command = reg; + + status = ioctl(fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); + *data_out = data.byte; + return 0; } + +int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in) +{ + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_WRITE; + data_arg.size = I2C_SMBUS_BYTE_DATA; + data_arg.data = &data; + data_arg.command = reg; + + data.byte = data_in; + + status = ioctl(fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(status); + + return 0; +} + +int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out) +{ + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_READ; + data_arg.size = I2C_SMBUS_WORD_DATA; + data_arg.data = &data; + data_arg.command = reg; + + status = ioctl(fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(status); + + *data_out = data.word; + + return 0; +} + +int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in) +{ + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_WRITE; + data_arg.size = I2C_SMBUS_WORD_DATA; + data_arg.data = &data; + data_arg.command = reg; + + data.word = data_in; + + statis = ioctl(fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(status); + + return 0; +} \ No newline at end of file -- 2.7.4 From dd481b5bdd30ddea722900ac75b922bcf19219f9 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 13:10:10 +0900 Subject: [PATCH 15/16] spi: fix a build error due to missed before patch Signed-off-by: Segwon Change-Id: I34d0b37fab426cae2cc0210ca7a9a7b8101a5598 --- src/interface/peripheral_interface_i2c.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 3fcb083..0963682 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -58,7 +58,7 @@ int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t re data_arg.data = &data; data_arg.command = reg; - status = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); *data_out = data.byte; @@ -82,7 +82,7 @@ int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t r data.byte = data_in; - status = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); return 0; @@ -102,7 +102,7 @@ int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t re data_arg.data = &data; data_arg.command = reg; - status = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); *data_out = data.word; @@ -126,7 +126,7 @@ int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t r data.word = data_in; - statis = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); return 0; -- 2.7.4 From 8e3667aa19274b9dc41d3499da4203ee4e186d58 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 13:15:27 +0900 Subject: [PATCH 16/16] interface: remove +1 length when writing a char array Signed-off-by: Segwon Change-Id: I7bbbe2f8698ee1fb90268af6f6ca8c0eaf8edb38 --- src/interface/peripheral_interface_gpio.c | 18 +++++++++--------- src/interface/peripheral_interface_pwm.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 950de19..b8361fb 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -23,11 +23,11 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g int status; if (direction == PERIPHERAL_GPIO_DIRECTION_IN) - status = write(gpio->fd_direction, "in", strlen("in")+1); + status = write(gpio->fd_direction, "in", strlen("in")); else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH) - status = write(gpio->fd_direction, "high", strlen("high")+1); + status = write(gpio->fd_direction, "high", strlen("high")); else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW) - status = write(gpio->fd_direction, "low", strlen("low")+1); + status = write(gpio->fd_direction, "low", strlen("low")); else { _E("Error: gpio direction is wrong\n"); return -EIO; @@ -43,13 +43,13 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g int status; if (edge == PERIPHERAL_GPIO_EDGE_NONE) - status = write(gpio->fd_edge, "none", strlen("none")+1); + status = write(gpio->fd_edge, "none", strlen("none")); else if (edge == PERIPHERAL_GPIO_EDGE_RISING) - status = write(gpio->fd_edge, "rising", strlen("rising")+1); + status = write(gpio->fd_edge, "rising", strlen("rising")); else if (edge == PERIPHERAL_GPIO_EDGE_FALLING) - status = write(gpio->fd_edge, "falling", strlen("falling")+1); + status = write(gpio->fd_edge, "falling", strlen("falling")); else if (edge == PERIPHERAL_GPIO_EDGE_BOTH) - status = write(gpio->fd_edge, "both", strlen("both")+1); + status = write(gpio->fd_edge, "both", strlen("both")); else { _E("Error: gpio edge is wrong\n"); return -EIO; @@ -65,9 +65,9 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) int status; if (value == 1) - status = write(gpio->fd_value, "1", strlen("1")+1); + status = write(gpio->fd_value, "1", strlen("1")); else if (value == 0) - status = write(gpio->fd_value, "0", strlen("0")+1); + status = write(gpio->fd_value, "0", strlen("0")); else { _E("Error: gpio write value error \n"); return -EIO; diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index bbfeefb..d01776d 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -70,9 +70,9 @@ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_p int status; if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) - status = write(pwm->fd_polarity, "normal", strlen("normal")+1); + status = write(pwm->fd_polarity, "normal", strlen("normal")); else if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_LOW) - status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1); + status = write(pwm->fd_polarity, "inversed", strlen("inversed")); else { _E("Invalid pwm polarity : %d", polarity); return -EINVAL; -- 2.7.4