Remove i2c_set_address() API 10/126810/3
authorHyeongsik Min <hyeongsik.min@samsung.com>
Tue, 25 Apr 2017 05:53:38 +0000 (14:53 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Wed, 26 Apr 2017 05:44:44 +0000 (14:44 +0900)
i2c_open() will pass bus and address argument together.

Change-Id: Iedd94d1554bc17764f64b1d31ca6e8c10ad87111
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
src/daemon/peripheral_bus.c
src/daemon/peripheral_bus_i2c.c
src/daemon/peripheral_bus_i2c.h
src/daemon/peripheral_io.xml
src/interface/i2c.c

index 9d5686f..5915167 100644 (file)
@@ -150,10 +150,11 @@ gboolean handle_gpio_set_edge_mode(
        return true;
 }
 
-gboolean handle_i2c_init(
+gboolean handle_i2c_open(
                PeripheralIoGdbusI2c *i2c,
                GDBusMethodInvocation *invocation,
                gint bus,
+               gint address,
                gint fd,
                gpointer user_data)
 {
@@ -161,14 +162,13 @@ gboolean handle_i2c_init(
        struct _peripheral_i2c_s st_i2c;
 
        // TODO: Create i2c instance
-
-       ret = peripheral_bus_i2c_init(&st_i2c, bus);
-       peripheral_io_gdbus_i2c_complete_init(i2c, invocation, st_i2c.fd, ret);
+       ret = peripheral_bus_i2c_open(&st_i2c, bus, address);
+       peripheral_io_gdbus_i2c_complete_open(i2c, invocation, st_i2c.fd, ret);
 
        return true;
 }
 
-gboolean handle_i2c_stop(
+gboolean handle_i2c_close(
                PeripheralIoGdbusI2c *i2c,
                GDBusMethodInvocation *invocation,
                gint fd,
@@ -179,26 +179,8 @@ gboolean handle_i2c_stop(
 
        st_i2c.fd = fd;
 
-       ret = peripheral_bus_i2c_stop(&st_i2c);
-       peripheral_io_gdbus_i2c_complete_stop(i2c, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_i2c_set_address(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               gint fd,
-               gint addr,
-               gpointer user_data)
-{
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       struct _peripheral_i2c_s st_i2c;
-
-       st_i2c.fd = fd;
-
-       ret = peripheral_bus_i2c_set_address(&st_i2c, addr);
-       peripheral_io_gdbus_i2c_complete_set_address(i2c, invocation, ret);
+       ret = peripheral_bus_i2c_close(&st_i2c);
+       peripheral_io_gdbus_i2c_complete_close(i2c, invocation, ret);
 
        return true;
 }
@@ -471,16 +453,12 @@ static gboolean __i2c_init(GDBusConnection *connection)
        /* Add interface to default object path */
        i2c_skeleton = peripheral_io_gdbus_i2c_skeleton_new();
        g_signal_connect(i2c_skeleton,
-                       "handle-init",
-                       G_CALLBACK(handle_i2c_init),
-                       NULL);
-       g_signal_connect(i2c_skeleton,
-                       "handle-stop",
-                       G_CALLBACK(handle_i2c_stop),
+                       "handle-open",
+                       G_CALLBACK(handle_i2c_open),
                        NULL);
        g_signal_connect(i2c_skeleton,
-                       "handle-set-address",
-                       G_CALLBACK(handle_i2c_set_address),
+                       "handle-close",
+                       G_CALLBACK(handle_i2c_close),
                        NULL);
        g_signal_connect(i2c_skeleton,
                        "handle-read",
index 8b82ef5..f2c8bca 100644 (file)
 #include "i2c.h"
 #include "peripheral_common.h"
 
-int peripheral_bus_i2c_init(peripheral_i2c_h i2c, int bus)
+int peripheral_bus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
 {
-       return i2c_open(bus, &i2c->fd);
-}
+       int ret;
+
+       if ((ret = i2c_open(bus, &i2c->fd)) < 0)
+               return ret;
 
-int peripheral_bus_i2c_set_address(peripheral_i2c_h i2c, int address)
-{
        return i2c_set_address(i2c->fd, address);
 }
 
@@ -44,7 +44,7 @@ int peripheral_bus_i2c_write(peripheral_i2c_h i2c, int length, unsigned char * d
        return i2c_write(i2c->fd, data, length);
 }
 
-int peripheral_bus_i2c_stop(peripheral_i2c_h i2c)
+int peripheral_bus_i2c_close(peripheral_i2c_h i2c)
 {
        return i2c_close(i2c->fd);
 }
index c4a3a77..87b1ed3 100644 (file)
 #ifndef __PERIPHERAL_BUS_I2C_H__
 #define __PERIPHERAL_BUS_I2C_H__
 
-int peripheral_bus_i2c_init(peripheral_i2c_h i2c, int bus);
+int peripheral_bus_i2c_open(peripheral_i2c_h i2c, int bus, int address);
 int peripheral_bus_i2c_set_address(peripheral_i2c_h i2c, int address);
 int peripheral_bus_i2c_read(peripheral_i2c_h i2c, int length, unsigned char * data);
 int peripheral_bus_i2c_write(peripheral_i2c_h i2c, int length, unsigned char * data);
-int peripheral_bus_i2c_stop(peripheral_i2c_h i2c);
+int peripheral_bus_i2c_close(peripheral_i2c_h i2c);
 
 #endif /* __PERIPHERAL_BUS_I2C_H__ */
index a99cbbc..cbda49b 100644 (file)
                </method>
        </interface>
        <interface name="org.tizen.peripheral_io.i2c">
-               <method name="Init">
+               <method name="Open">
                        <arg type="i" name="bus" direction="in"/>
+                       <arg type="i" name="address" direction="in"/>
                        <arg type="i" name="fd" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
-               <method name="Stop">
-                       <arg type="i" name="fd" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="SetAddress">
+               <method name="Close">
                        <arg type="i" name="fd" direction="in"/>
-                       <arg type="i" name="address" direction="in"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
                <method name="Read">
index bfd23c7..2573477 100644 (file)
@@ -49,7 +49,7 @@ int i2c_open(int bus, int *fd)
 
 int i2c_close(int fd)
 {
-       if (fd == NULL) return -EINVAL;
+       if (fd < 0) return -EINVAL;
        close(fd);
 
        return 0;
@@ -59,7 +59,7 @@ int i2c_set_address(int fd, int address)
 {
        int status;
 
-       _D("I2C SLAVE address = [%x]", address);
+       _D("slave address : %x", address);
        status = ioctl(fd, I2C_SLAVE, address);
 
        if (status < 0) {