i2c: implement open() in terms of open_flags()
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Jun 2021 08:41:46 +0000 (10:41 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Jun 2021 08:41:46 +0000 (10:41 +0200)
src/peripheral_i2c.c

index c910306..f27b747 100644 (file)
@@ -55,7 +55,7 @@ static bool __is_feature_supported(void)
        return (i2c_feature == I2C_FEATURE_TRUE ? true : false);
 }
 
-int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
+int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flags, peripheral_i2c_h *i2c)
 {
        peripheral_i2c_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
@@ -82,31 +82,9 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
        return ret;
 }
 
-int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flags, peripheral_i2c_h *i2c)
+int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
 {
-       peripheral_i2c_h handle;
-       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, "Invalid i2c handle");
-       RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
-
-       handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s));
-       if (handle == NULL) {
-               _E("Failed to allocate peripheral_i2c_h");
-               return PERIPHERAL_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = peripheral_direct_i2c_open(bus, address, &handle->fd);
-       if (ret != PERIPHERAL_ERROR_NONE) {
-               _E("Failed to open i2c communication, ret : %d", ret);
-               free(handle);
-               handle = NULL;
-       }
-
-       *i2c = handle;
-
-       return ret;
+       return peripheral_i2c_open_flags(bus, address, PERIPHERAL_OPEN_FLAGS_PRIVATE, i2c);
 }
 
 int peripheral_i2c_close(peripheral_i2c_h i2c)