From: Hyeongsik Min Date: Tue, 30 May 2017 02:25:18 +0000 (+0900) Subject: Add i2c_write_byte, i2c_read_byte API X-Git-Tag: submit/tizen/20170602.034029~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6402d036ce0b37a062d9d6506c75081f7d22cdaa;p=platform%2Fcore%2Fapi%2Fperipheral-io.git Add i2c_write_byte, i2c_read_byte API 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 --- diff --git a/include/peripheral_io.h b/include/peripheral_io.h index c68ff98..7517d2a 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -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); /** * @} diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index fee3a32..969e18b 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -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); +}