Sending and receiving
=====================
如果你想与你的设备通信,下面的函数API可以使用。参考<linux/i2c.h>。
如果你在plain i2c communicaiton和SMBus level communication之间选择一个,请选择
后者。所有的适配器都理解SMBus level commands,但是不是所有的适配器都理解plain
I2C!
Plain I2C communication
-----------------------
int i2c_master_send(struct i2c_client *client, const char *buf,
int count);
int i2c_master_recv(struct i2c_client *client, char *buf, int count);
这些函数从一个client设备读或写一些字节的数据。client包含了i2c地址,所以你无须
另外指明。第二个参数包含了读/写的buffer,第三个参数包含了读/写的字节数(必须小于
buffer的长度,也应当小于64K(因为msg.len类型为u16)),返回值是读/写的实际字节数。
int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msg,
int num);
这个函数发送一系列消息。每个消息可以是读,也可以是写,或者读写混合。一个
事务处理(transaction)是可以组合的:在事务处理中没有停止位发送。i2c_msg数据结构
包含了每条消息的client address,消息字节和消息本身。
你可以阅读'i2c-protocol'获取更多的i2c protocol信息。
SMBus communication
-------------------
s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data *data);
这是SMBus基础函数。下述的所有函数API基于它实现。不要直接使用这个基础函数!
s32 i2c_smbus_read_byte(struct i2c_client *client);
s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value);
s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command);
s32 i2c_smbus_write_byte_data(struct i2c_client *client,
u8 command, u8 value);
s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command);
s32 i2c_smbus_write_word_data(struct i2c_client *client,
u8 command, u16 value);
s32 i2c_smbus_process_call(struct i2c_client *client,
u8 command, u16 value);
s32 i2c_smbus_read_block_data(struct i2c_client *client,
u8 command, u8 *values);
s32 i2c_smbus_write_block_data(struct i2c_client *client,
u8 command, u8 length, const u8 *values);
s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client,
u8 command, u8 length, u8 *values);
s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
u8 command, u8 length,
const u8 *values);
下面的函数从i2c-core里移除掉了,由于它们没有用户需求。
s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value);
s32 i2c_smbus_block_process_call(struct i2c_client *client,
u8 command, u8 length, u8 *values);
所有的这些函数处理返回一个负值来表示出错。'write'处理返回0表示成功;'read'处理
返回读到的值,block transaction除外(它们返回的是读取的实际字节数)。block
buffers不能超过32字节。
你可以读文件'smbus-protocol'以获取关于SMBus protocol更多的信息。
General purpose routines
========================
下面是之前没有提到的通用函数。
/* Return the adapter number for a specific adapter */
int i2c_adapter_id(struct i2c_adapter *adap);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。