Add i2c_write_byte, i2c_read_byte API 47/131547/4
authorHyeongsik Min <hyeongsik.min@samsung.com>
Tue, 30 May 2017 02:25:18 +0000 (11:25 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Wed, 31 May 2017 01:28:03 +0000 (10:28 +0900)
In order to provide for single byte communication, this patch adds
peripheral_i2c_write_byte() and peripheral_i2c_read_byte() APIs.

Change-Id: I0b1404fc1571f6d21ab7bfa5ceb9a76cb8a3e936
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
include/peripheral_io.h
src/peripheral_i2c.c

index c68ff98223893efda1bbabc3b9cdaf941a152344..7517d2adaf8aa166082e9068e4554d238ed78990 100644 (file)
@@ -332,7 +332,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c);
  * @since_tizen 4.0
  *
  * @param[in] i2c The handle to the i2c device
- * @param[in, out] data The address of read buffer
+ * @param[out] data The address of data buffer to read
  * @param[in] length The size of data buffer (in bytes)
  *
  * @return 0 on success, otherwise a negative error value
@@ -348,7 +348,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
  * @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] data The address of data buffer to write
  * @param[in] length The size of data buffer (in bytes)
  *
  * @return 0 on success, otherwise a negative error value
@@ -359,6 +359,34 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
  */
 int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
 
+/**
+ * @brief Reads single byte data from the i2c device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[out] data The address of data buffer to read
+ *
+ * @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_byte(peripheral_i2c_h i2c, uint8_t *data);
+/**
+ * @brief Write single byte data to the i2c device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in] data The byte value to write
+ *
+ * @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_byte(peripheral_i2c_h i2c, uint8_t data);
 
 /**
 * @}
index fee3a321a6278224bceca0f9fa6a4e7198dbc628..969e18b8dbc6e149199ffab42718e8cb546695f0 100644 (file)
@@ -89,3 +89,21 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length)
 
        return peripheral_gdbus_i2c_write(i2c, data, length);
 }
+
+int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+       ret = peripheral_gdbus_i2c_read(i2c, data, 0x1);
+
+       return ret;
+}
+
+int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data)
+{
+       if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+
+       return peripheral_gdbus_i2c_write(i2c, &data, 0x1);
+}