i2c: flattening structure - remove 'direct'
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Jun 2021 09:32:56 +0000 (11:32 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Jun 2021 09:32:56 +0000 (11:32 +0200)
CMakeLists.txt
include/direct/peripheral_direct_common.h [deleted file]
include/direct/peripheral_direct_i2c.h [deleted file]
include/interface/peripheral_interface_common.h
src/direct/peripheral_i2c_direct.c [deleted file]
src/peripheral_i2c.c

index 84dd024..8fea6c2 100644 (file)
@@ -29,7 +29,6 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 INCLUDE_DIRECTORIES(${INC_DIR}/gdbus)
 INCLUDE_DIRECTORIES(${INC_DIR}/interface)
-INCLUDE_DIRECTORIES(${INC_DIR}/direct)
 
 SET(SRC_DIR src)
 INCLUDE_DIRECTORIES(${SRC_DIR}/gdbus)
@@ -61,7 +60,6 @@ SET(SOURCES src/peripheral_gpio.c
                        src/peripheral_adc.c
                        src/peripheral_uart.c
                        src/peripheral_spi.c
-                       src/direct/peripheral_i2c_direct.c
                        src/interface/peripheral_interface_gpio.c
                        src/interface/peripheral_interface_i2c.c
                        src/interface/peripheral_interface_pwm.c
diff --git a/include/direct/peripheral_direct_common.h b/include/direct/peripheral_direct_common.h
deleted file mode 100644 (file)
index b9459b8..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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_DIRECT_COMMON_H__
-#define __PERIPHERAL_DIRECT_COMMON_H__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <peripheral_io.h>
-
-#include "peripheral_log.h"
-
-#define MAX_ERR_LEN 255
-#define MAX_BUF_LEN 96
-
-#define IF_ERROR_RETURN(expr, func...) \
-       do { \
-               if (expr) { \
-                       int temp = errno; \
-                       func; \
-                       if (temp == EAGAIN) \
-                               return PERIPHERAL_ERROR_TRY_AGAIN; \
-                       char errmsg[MAX_ERR_LEN]; \
-                       strerror_r(temp, errmsg, sizeof(errmsg)); \
-                       _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \
-                       return PERIPHERAL_ERROR_IO_ERROR; \
-               } \
-       } while (0)
-
-#endif /*__PERIPHERAL_DIRECT_COMMON_H__*/
diff --git a/include/direct/peripheral_direct_i2c.h b/include/direct/peripheral_direct_i2c.h
deleted file mode 100644 (file)
index 7887cea..0000000
+++ /dev/null
@@ -1 +0,0 @@
-int peripheral_direct_i2c_open(int bus, int address, int *fd_out);
index d6137ce..10f4552 100644 (file)
@@ -26,6 +26,7 @@
 #include "peripheral_log.h"
 
 #define MAX_ERR_LEN 255
+#define MAX_BUF_LEN 96
 
 #define CHECK_ERROR(expr) \
        do { \
                } \
        } while (0)
 
+#define IF_ERROR_RETURN(expr, func...) \
+       do { \
+               if (expr) { \
+                       int temp = errno; \
+                       func; \
+                       if (temp == EAGAIN) \
+                               return PERIPHERAL_ERROR_TRY_AGAIN; \
+                       char errmsg[MAX_ERR_LEN]; \
+                       strerror_r(temp, errmsg, sizeof(errmsg)); \
+                       _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \
+                       return PERIPHERAL_ERROR_IO_ERROR; \
+               } \
+       } while (0)
+
 typedef struct predefined_type {
        char *type;
        int len;
 } predefined_type_s;
 
-#endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/
\ No newline at end of file
+#endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/
diff --git a/src/direct/peripheral_i2c_direct.c b/src/direct/peripheral_i2c_direct.c
deleted file mode 100644 (file)
index f45a49d..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-#include "peripheral_io.h"
-#include "peripheral_log.h"
-#include "peripheral_interface_i2c.h"
-#include "peripheral_direct_common.h"
-
-
-int peripheral_direct_i2c_open(int bus, int address, int *fd_out)
-{
-       RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
-       RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
-       RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for i2c");
-
-       int ret;
-       int fd;
-       char path[MAX_BUF_LEN] = {0, };
-
-       snprintf(path, MAX_BUF_LEN, "/dev/i2c-%d", bus);
-       fd = open(path, O_RDWR);
-       IF_ERROR_RETURN(fd < 0);
-
-       ret = ioctl(fd, I2C_SLAVE, address);
-       IF_ERROR_RETURN(ret != 0, close(fd));
-
-       *fd_out = fd;
-
-       return PERIPHERAL_ERROR_NONE;
-}
index 329dfb2..a815334 100644 (file)
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/file.h>
+#include <sys/ioctl.h>
 #include <system_info.h>
 
 #include "peripheral_io.h"
 #include "peripheral_handle.h"
 #include "peripheral_interface_i2c.h"
-#include "peripheral_direct_i2c.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c"
@@ -62,6 +62,7 @@ int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flag
        peripheral_i2c_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
        int lock_type = LOCK_EX;
+       char path[MAX_BUF_LEN] = {0, };
 
        RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
@@ -75,12 +76,11 @@ int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flag
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
-       ret = peripheral_direct_i2c_open(bus, address, &handle->fd);
-       if (ret != PERIPHERAL_ERROR_NONE) {
-               _E("Failed to open i2c communication, ret : %d", ret);
-               free(handle);
-               return ret;
-       }
+       snprintf(path, MAX_BUF_LEN, "/dev/i2c-%d", bus);
+       handle->fd = open(path, O_RDWR);
+       IF_ERROR_RETURN(handle->fd < 0, free(handle));
+
+       IF_ERROR_RETURN(ioctl(handle->fd, I2C_SLAVE, address), close(handle->fd); free(handle));
 
        if (flags == PERIPHERAL_OPEN_FLAGS_SHARED)
                lock_type = LOCK_SH;