Tizen Native API  5.0

The I2C API provides functions to control I2C peripherals connected to the IoT device.

Required Header

#include <peripheral_io.h>

Overview

This I2C API provides functions to control I2C peripherals connected to the IoT device.

Realted Features

This API is related with the following feature:

It is recommended to use features in your application for reliability.

You can check if a IoT device supports the related features for this API
by using System Information, and control your application's actions accordingly.

To ensure your application is only running on the IoT device with specific features,
please define the features in your manifest file using the manifest editor in the SDK.

More details on featuring your application can be found from Feature Element.

Functions

int peripheral_i2c_open (int bus, int address, peripheral_i2c_h *i2c)
 Opens an I2C slave device.
int peripheral_i2c_close (peripheral_i2c_h i2c)
 Closes an I2C slave device.
int peripheral_i2c_read (peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
 Reads the bytes data from the I2C slave device.
int peripheral_i2c_write (peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
 Writes the bytes data to the I2C slave device.
int peripheral_i2c_read_register_byte (peripheral_i2c_h i2c, uint8_t reg, uint8_t *data)
 Reads single byte data from the register of the I2C slave device.
int peripheral_i2c_write_register_byte (peripheral_i2c_h i2c, uint8_t reg, uint8_t data)
 Writes single byte data to the register of the I2C slave device.
int peripheral_i2c_read_register_word (peripheral_i2c_h i2c, uint8_t reg, uint16_t *data)
 Reads word data from the register of the I2C slave device.
int peripheral_i2c_write_register_word (peripheral_i2c_h i2c, uint8_t reg, uint16_t data)
 Writes word data to the register of the I2C slave device.

Typedefs

typedef struct _peripheral_i2c_s * peripheral_i2c_h
 The handle of the I2C slave device.

Typedef Documentation

typedef struct _peripheral_i2c_s* peripheral_i2c_h

The handle of the I2C slave device.

Since :
4.0

Function Documentation

Closes an I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Precondition:
peripheral_i2c_open()
int peripheral_i2c_open ( int  bus,
int  address,
peripheral_i2c_h i2c 
)

Opens an I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Remarks:
i2c should be released with peripheral_i2c_close()
Parameters:
[in]busThe I2C bus number that the slave device is connected
[in]addressThe address of the slave device
[out]i2cThe I2C handle is created on success
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_NO_DEVICEDevice does not exist or is removed
PERIPHERAL_ERROR_OUT_OF_MEMORYMemory allocation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_RESOURCE_BUSYDevice is in use
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
Postcondition:
peripheral_i2c_close()
int peripheral_i2c_read ( peripheral_i2c_h  i2c,
uint8_t *  data,
uint32_t  length 
)

Reads the bytes data from the I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
[out]dataThe data buffer to read
[in]lengthThe size of data buffer (in bytes)
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_i2c_write()
int peripheral_i2c_read_register_byte ( peripheral_i2c_h  i2c,
uint8_t  reg,
uint8_t *  data 
)

Reads single byte data from the register of the I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
[in]regThe register address of the I2C slave device to read
[out]dataThe single byte data to read
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_i2c_write_register_byte()
int peripheral_i2c_read_register_word ( peripheral_i2c_h  i2c,
uint8_t  reg,
uint16_t *  data 
)

Reads word data from the register of the I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
[in]regThe register address of the I2C slave device to read
[out]dataThe word(2 bytes) data to read
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_i2c_write_register_word()
int peripheral_i2c_write ( peripheral_i2c_h  i2c,
uint8_t *  data,
uint32_t  length 
)

Writes the bytes data to the I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
[in]dataThe data buffer to write
[in]lengthThe size of data buffer (in bytes)
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_i2c_read()
int peripheral_i2c_write_register_byte ( peripheral_i2c_h  i2c,
uint8_t  reg,
uint8_t  data 
)

Writes single byte data to the register of the I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
[in]regThe register address of the I2C slave device to write
[in]dataThe single byte data to write
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_i2c_read_register_byte()
int peripheral_i2c_write_register_word ( peripheral_i2c_h  i2c,
uint8_t  reg,
uint16_t  data 
)

Writes word data to the register of the I2C slave device.

Warning:
This is not for use by third-party applications.
Since :
4.0
Privilege Level:
platform
Privilege:
http://tizen.org/privilege/peripheralio
Parameters:
[in]i2cThe I2C handle
[in]regThe register address of the I2C slave device to write
[in]dataThe word(2 bytes) data to write
Returns:
0 on success, otherwise a negative error value
Return values:
PERIPHERAL_ERROR_NONESuccessful
PERIPHERAL_ERROR_IO_ERRORI/O operation failed
PERIPHERAL_ERROR_PERMISSION_DENIEDPermission denied
PERIPHERAL_ERROR_INVALID_PARAMETERInvalid parameter
PERIPHERAL_ERROR_NOT_SUPPORTEDNot supported
PERIPHERAL_ERROR_UNKNOWNUnknown internal error
See also:
peripheral_i2c_read_register_word()