- 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>
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);
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);
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 */
} peripheral_error_e;
/**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_GPIO_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_GPIO_MODULE
* @{
*/
* @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
*
*/
/**
- * @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);
*/
/**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_PWM_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_PWM_MODULE
* @{
*/
*/
/**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_ADC_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_ADC_MODULE
* @{
*/
*/
/**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_UART_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_UART_MODULE
* @{
*/
struct _peripheral_uart_s {
*/
/**
- * @addtogroup CAPI_SYSTEM_PERPHERAL_SPI_MODULE
+ * @addtogroup CAPI_SYSTEM_PERIPHERAL_SPI_MODULE
* @{
*/
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,
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) {
return PERIPHERAL_ERROR_UNKNOWN;
}
- if (ret != PERIPHERAL_ERROR_NONE)
- _E("%s failed, ret = %d", __func__, ret);
-
return ret;
}
#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;
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) {
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");
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);
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;
</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">
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");
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;
}