Remove i2c_set_address() API and rearrange header 79/126779/2
authorHyeongsik Min <hyeongsik.min@samsung.com>
Tue, 25 Apr 2017 05:13:52 +0000 (14:13 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Wed, 26 Apr 2017 02:08:51 +0000 (11:08 +0900)
 - i2c_open() will pass bus and address argument together.
 - Add description for i2c APIs and fix typo.

Change-Id: I1313fbf1fae23d828e1ac001d20f880747404109
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
include/peripheral_dbus.h
include/peripheral_io.h
src/peripheral_dbus.c
src/peripheral_i2c.c
src/peripheral_io.xml
test/peripheral-io-test.c

index 557b296..529128d 100644 (file)
@@ -39,7 +39,6 @@ void gpio_proxy_deinit();
 void i2c_proxy_deinit();
 void pwm_proxy_deinit();
 
-int peripheral_dbus_gpio(peripheral_gpio_h gpio, char * sensorid, char *funcname, int write_value, int *read_value);
 int peripheral_dbus_gpio_open(peripheral_gpio_h gpio);
 int peripheral_dbus_gpio_close(peripheral_gpio_h gpio);
 int peripheral_dbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction);
@@ -49,9 +48,8 @@ int peripheral_dbus_gpio_write(peripheral_gpio_h gpio, int value);
 int peripheral_dbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge);
 int peripheral_dbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
 
-int peripheral_dbus_i2c_init(peripheral_i2c_h i2c, int bus);
-int peripheral_dbus_i2c_stop(peripheral_i2c_h i2c);
-int peripheral_dbus_i2c_set_address(peripheral_i2c_h i2c, int address);
+int peripheral_dbus_i2c_open(peripheral_i2c_h i2c, int bus, int address);
+int peripheral_dbus_i2c_close(peripheral_i2c_h i2c);
 int peripheral_dbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
 int peripheral_dbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
 
index 4458ae6..6c62c1f 100644 (file)
@@ -37,7 +37,7 @@ typedef enum {
        PERIPHERAL_ERROR_NONE                = TIZEN_ERROR_NONE,                /**< Successful */
        PERIPHERAL_ERROR_IO_ERROR            = TIZEN_ERROR_IO_ERROR,            /**< I/O error */
        PERIPHERAL_ERROR_OUT_OF_MEMORY       = TIZEN_ERROR_OUT_OF_MEMORY,       /**< Out of memory */
-       PERIPHERAL_ERROR_PERMISSON_DENIED    = TIZEN_ERROR_PERMISSION_DENIED,   /**< Permission denied */
+       PERIPHERAL_ERROR_PERMISSION_DENIED   = TIZEN_ERROR_PERMISSION_DENIED,   /**< Permission denied */
        PERIPHERAL_ERROR_RESOURCE_BUSY       = TIZEN_ERROR_RESOURCE_BUSY,       /**< Device or resource busy */
        PERIPHERAL_ERROR_INVALID_PARAMETER   = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
        PERIPHERAL_ERROR_NO_DATA             = TIZEN_ERROR_NO_DATA,             /**< No data available */
@@ -49,7 +49,7 @@ typedef enum {
 } peripheral_error_e;
 
 /**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_GPIO_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_GPIO_MODULE
  * @{
  */
 
@@ -90,7 +90,7 @@ typedef struct _peripheral_gpio_s* peripheral_gpio_h;
  * @retval #PERIPHERAL_ERROR_NONE Successful
  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
  * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
- * @retval #PERIPHERAL_ERROR_PERMISSON_DENIED Permission denied
+ * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
  *
@@ -282,20 +282,81 @@ int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin);
 */
 
 /**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_I2C_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_I2C_MODULE
  * @{
  */
 
+/**
+ * @brief The handle to the i2c device
+ * @since_tizen 4.0
+ */
 typedef struct _peripheral_i2c_s *peripheral_i2c_h;
 
-int peripheral_i2c_init(int bus, peripheral_i2c_h *i2c);
-
-int peripheral_i2c_stop(peripheral_i2c_h i2c);
+/**
+ * @brief Initializes i2c communication and creates i2c handle.
+ * @since_tizen 4.0
+ *
+ * @param[in] bus The i2c bus number that the slave device is connected
+ * @param[in] address The address of the slave device
+ * @param[out] i2c The i2c handle is created on success
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
+ *
+ * @see peripheral_i2c_close()
+ */
+int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c);
 
-int peripheral_i2c_set_address(peripheral_i2c_h i2c, int address);
+/**
+ * @brief Destory the i2c handle and release the communication.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The i2c handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ *
+ * @see peripheral_i2c_open()
+ */
+int peripheral_i2c_close(peripheral_i2c_h i2c);
 
+/**
+ * @brief Reads data from the i2c device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in, out] data The address of read buffer
+ * @param[in] length The size of data buffer (in bytes)
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ */
 int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
 
+/**
+ * @brief Write data to the i2c device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in, out] data The address of buffer to write
+ * @param[in] length The size of data buffer (in bytes)
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ */
 int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
 
 
@@ -304,7 +365,7 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
 */
 
 /**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_PWM_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_PWM_MODULE
  * @{
  */
 
@@ -344,7 +405,7 @@ int peripheral_pwm_get_period(peripheral_pwm_context_h pwm, int *period);
 */
 
 /**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_ADC_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_ADC_MODULE
  * @{
  */
 
@@ -375,7 +436,7 @@ int peripheral_adc_close(peripheral_adc_context_h dev);
 */
 
 /**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_UART_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_UART_MODULE
  * @{
  */
 struct _peripheral_uart_s {
@@ -412,7 +473,7 @@ int peripheral_uart_write(peripheral_uart_context_h hnd, const char *buf, unsign
 */
 
 /**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_SPI_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_SPI_MODULE
  * @{
  */
 
index 3c32644..9cf8af5 100644 (file)
@@ -271,16 +271,17 @@ int peripheral_dbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_e
        return ret;
 }
 
-int peripheral_dbus_i2c_init(peripheral_i2c_h i2c, int bus)
+int peripheral_dbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
 {
        GError *error = NULL;
        peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
 
        if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
 
-       if (peripheral_io_gdbus_i2c_call_init_sync(
+       if (peripheral_io_gdbus_i2c_call_open_sync(
                        i2c_proxy,
                        bus,
+                       address,
                        &i2c->fd,
                        &ret,
                        NULL,
@@ -293,38 +294,16 @@ int peripheral_dbus_i2c_init(peripheral_i2c_h i2c, int bus)
        return ret;
 }
 
-int peripheral_dbus_i2c_stop(peripheral_i2c_h i2c)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_i2c_call_stop_sync(
-                       i2c_proxy,
-                       i2c->fd,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_i2c_set_address(peripheral_i2c_h i2c, int address)
+int peripheral_dbus_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 (peripheral_io_gdbus_i2c_call_set_address_sync(
+       if (peripheral_io_gdbus_i2c_call_close_sync(
                        i2c_proxy,
                        i2c->fd,
-                       address,
                        &ret,
                        NULL,
                        &error) == FALSE) {
@@ -333,9 +312,6 @@ int peripheral_dbus_i2c_set_address(peripheral_i2c_h i2c, int address)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
-       if (ret != PERIPHERAL_ERROR_NONE)
-               _E("%s failed, ret = %d", __func__, ret);
-
        return ret;
 }
 
index 2f1981d..23a33f0 100644 (file)
@@ -24,7 +24,7 @@
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 
-int peripheral_i2c_init(int bus, 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;
@@ -32,7 +32,6 @@ int peripheral_i2c_init(int bus, peripheral_i2c_h *i2c)
        if (bus < 0)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       /* Initialize peripheral_i2c_h */
        handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s));
 
        if (handle == NULL) {
@@ -42,7 +41,7 @@ int peripheral_i2c_init(int bus, peripheral_i2c_h *i2c)
 
        i2c_proxy_init();
 
-       ret = peripheral_dbus_i2c_init(handle, bus);
+       ret = peripheral_dbus_i2c_open(handle, bus, address);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("[PERIPHERAL] I2C init error\n");
@@ -54,13 +53,13 @@ int peripheral_i2c_init(int bus, peripheral_i2c_h *i2c)
        return ret;
 }
 
-int peripheral_i2c_stop(peripheral_i2c_h i2c)
+int peripheral_i2c_close(peripheral_i2c_h i2c)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
        if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_i2c_stop(i2c);
+       ret = peripheral_dbus_i2c_close(i2c);
        gpio_proxy_deinit();
 
        free(i2c);
@@ -69,13 +68,6 @@ int peripheral_i2c_stop(peripheral_i2c_h i2c)
        return ret;
 }
 
-int peripheral_i2c_set_address(peripheral_i2c_h i2c, int address)
-{
-       if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
-
-       return peripheral_dbus_i2c_set_address(i2c, address);
-}
-
 int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length)
 {
        int ret = PERIPHERAL_ERROR_NONE;
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 c9b4609..048d136 100644 (file)
@@ -84,16 +84,11 @@ int i2c_test(void)
        if (scanf("%d", &bus_num) < 0)
                return 0;
 
-       if ((peripheral_i2c_init(bus_num, &i2c)) != 0) {
-               printf("Failed to initialize I2C device\n");
+       if ((peripheral_i2c_open(bus_num, GY30_ADDR, &i2c)) != 0) {
+               printf("Failed to open I2C communication\n");
                return 0;
        }
 
-       if (peripheral_i2c_set_address(i2c, GY30_ADDR) != 0) {
-               printf("Failed to set address\n");
-               goto error;
-       }
-
        buf[0] = GY30_CONT_HIGH_RES_MODE;
        if (peripheral_i2c_write(i2c, buf, 1) != 0) {
                printf("Failed to write\n");
@@ -108,11 +103,11 @@ int i2c_test(void)
                printf("Result [%d]\n", result);
        }
 
-       peripheral_i2c_stop(i2c);
+       peripheral_i2c_close(i2c);
        return 1;
 
 error:
-       peripheral_i2c_stop(i2c);
+       peripheral_i2c_close(i2c);
        return 0;
 }