打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
i2c_get_clientdata I2C driver编写指导二:编写i2c client driver指南

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);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Linux设备驱动之I2C架构分析
linux内核I2C体系结构(注意结构体原型)
LINUX的IIC驱动从这开始(二)
i2c设备驱动实例分析
I2C 的 4 个结构体
linux下S3C2440–I2C驱动学习之四“i2c
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服