I2C

Overview

Provides standard Inter-Integrated Circuit (I2C) interfaces.

This module allows a driver to perform operations on an I2C controller for accessing devices on the I2C bus, including creating and destroying I2C controller handles as well as reading and writing data.

Since:

1.0

Summary

Files

File Name

Description

i2c_if.h

Declares the standard I2C interface functions.

Data Structures

Data Structure Name

Description

I2cMsg

Defines the I2C transfer message used during custom transfers.

Enumerations

Enumeration Name

Description

I2cFlag {   I2C_FLAG_READ = (0x1 << 0), I2C_FLAG_ADDR_10BIT = (0x1 << 4), I2C_FLAG_READ_NO_ACK = (0x1 << 11), I2C_FLAG_IGNORE_NO_ACK = (0x1 << 12),   I2C_FLAG_NO_START = (0x1 << 14), I2C_FLAG_STOP = (0x1 << 15) }

Enumerates flags used for transferring I2C messages.

Functions

Function Name

Description

I2cOpen (int16_t number)

struct DevHandle 

Obtains the handle of an I2C controller.

I2cClose (struct DevHandle handle)

void 

Releases the handle of an I2C controller.

I2cTransfer (struct DevHandlehandle, struct I2cMsgmsgs, int16_t count)

int32_t 

Launches a custom transfer to an I2C device.

Details

Enumeration Type Documentation

I2cFlag

  1. enum[I2cFlag]($api-api-SmartVision-Devices-I2C.md#ga32b58f021632085445d80c80e382a546)

Description:

Enumerates flags used for transferring I2C messages.

Multiple flags can be used to jointly control a single I2C message transfer. If a bit is set to 1, the corresponding feature is enabled. If a bit is set to 0, the corresponding feature is disabled.

Enumerator

Description

I2C_FLAG_READ 

Read flag. The value 1 indicates the read operation, and 0 indicates the write operation.

I2C_FLAG_ADDR_10BIT 

10-bit addressing flag. The value 1 indicates that a 10-bit address is used.

I2C_FLAG_READ_NO_ACK 

Non-ACK read flag. The value 1 indicates that no ACK signal is sent during the read process.

I2C_FLAG_IGNORE_NO_ACK 

Ignoring no-ACK flag. The value 1 indicates that the non-ACK signal is ignored.

I2C_FLAG_NO_START 

No START condition flag. The value 1 indicates that there is no START condition for the message transfer.

I2C_FLAG_STOP 

STOP condition flag. The value 1 indicates that the current transfer ends with a STOP condition.

Function Documentation

I2cClose()

  1. void I2cClose (struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle)

Description:

Releases the handle of an I2C controller.

If you no longer need to access the I2C controller, you should call this function to close its handle so as to release unused memory resources.

Parameters:

Name

Description

handleIndicates the pointer to the device handle of the I2C controller.

I2cOpen()

  1. struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* I2cOpen (int16_t number)

Description:

Obtains the handle of an I2C controller.

You must call this function before accessing the I2C bus.

Parameters:

Name

Description

numberIndicates the I2C controller ID.

Returns:

Returns the pointer to the DevHandle of the I2C controller if the operation is successful; returns NULL otherwise.

I2cTransfer()

  1. int32_t I2cTransfer (struct[DevHandle]($api-api-SmartVision-Devices-DevHandle.md)* handle,struct[I2cMsg]($api-api-SmartVision-Devices-I2cMsg.md)* msgs,int16_t count )

Description:

Launches a custom transfer to an I2C device.

Parameters:

Name

Description

handleIndicates the pointer to the device handle of the I2C controller obtained via I2cOpen.
msgsIndicates the pointer to the I2C transfer message structure array.
countIndicates the length of the message structure array.

Returns:

Returns the number of transferred message structures if the operation is successful; returns a negative value otherwise.

See also:

I2cMsg

Attention:

This function does not limit the number of message structures specified by count or the data length of each message structure. The specific I2C controller determines the maximum number and data length allowed.