当前仅显示指定条件回帖 [ 展开查看全部 ]
文件名称:
i2c.md
所在目录:
Openharmony v1.0 / docs / docs-en / api / api-SmartVision-Devices
文件大小:
16.51 KB
下载地址:
文本预览:
# 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
## Data Structures
## Enumerations
## Functions
## **Details**
## **Enumeration Type Documentation**
## I2cFlag
```
enum [I2cFlag](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.
## **Function Documentation**
## I2cClose\(\)
```
void I2cClose (struct [DevHandle](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:**
## I2cOpen\(\)
```
struct [DevHandle](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:**
**Returns:**
Returns the pointer to the [DevHandle](devhandle.md) of the I2C controller if the operation is successful; returns **NULL** otherwise.
## I2cTransfer\(\)
```
int32_t I2cTransfer (struct [DevHandle](devhandle.md) * handle, struct [I2cMsg](i2cmsg.md) * msgs, int16_t count )
```
**Description:**
Launches a custom transfer to an I2C device.
**Parameters:**
**Returns:**
Returns the number of transferred message structures if the operation is successful; returns a negative value otherwise.
**See also:**
[I2cMsg](i2cmsg.md)
**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.
## **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
Declares the standard I2C interface functions. |
## Data Structures
Defines the I2C transfer message used during custom transfers. |
## Enumerations
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
I2cOpen (int16_t number) | struct DevHandle * Obtains the handle of an I2C controller. |
I2cClose (struct DevHandle *handle) | Releases the handle of an I2C controller. |
I2cTransfer (struct DevHandle *handle, struct I2cMsg *msgs, int16_t count) | Launches a custom transfer to an I2C device. |
## **Details**
## **Enumeration Type Documentation**
## I2cFlag
```
enum [I2cFlag](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.
## **Function Documentation**
## I2cClose\(\)
```
void I2cClose (struct [DevHandle](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:**
handle | Indicates the pointer to the device handle of the I2C controller. |
## I2cOpen\(\)
```
struct [DevHandle](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:**
number | Indicates the I2C controller ID. |
**Returns:**
Returns the pointer to the [DevHandle](devhandle.md) of the I2C controller if the operation is successful; returns **NULL** otherwise.
## I2cTransfer\(\)
```
int32_t I2cTransfer (struct [DevHandle](devhandle.md) * handle, struct [I2cMsg](i2cmsg.md) * msgs, int16_t count )
```
**Description:**
Launches a custom transfer to an I2C device.
**Parameters:**
handle | Indicates the pointer to the device handle of the I2C controller obtained via I2cOpen. |
msgs | Indicates the pointer to the I2C transfer message structure array. |
count | Indicates 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](i2cmsg.md)
**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.
点赞
回复
X