linux i2c子系统代码分析6 ---操作函数i2c数据处理函数

下面介绍i2c的数据处理函数

1、 i2c_master_send         在主模式下发送一个信息

kernel/driver/linux/i2c/i2c-core.c

/**
 * i2c_master_send - issue a single I2C message in master transmit mode
 * @client: Handle to slave device
 * @buf: Data that will be written to the slave
 * @count: How many bytes to write, must be less than 64k since msg.len is u16
 *
 * Returns negative errno, or else the number of bytes written.
 */
int i2c_master_send(const struct i2c_client *client, const char *buf, int count)
{
int ret;
struct i2c_adapter *adap = client->adapter;
struct i2c_msg msg;


msg.addr = client->addr;
msg.flags = client->flags & I2C_M_TEN;
msg.len = count;
msg.buf = (char *)buf;


ret = i2c_transfer(adap, &msg, 1);


/* If everything went ok (i.e. 1 msg transmitted), return #bytes
  transmitted, else error code. */
return (ret == 1) ? count : ret;
}

struct i2c_adapter *adap = client->adapter;  获取i2c设备对于适配器

struct i2c_msg msg;
msg.addr = client->addr;
msg.flags = client->flags & I2C_M_TEN;
msg.len = count;
msg.buf = (char *)buf;

以上是给一个i2c消息结构体赋值

i2c_transfer(adap, &msg, 1);    i2c执行一个消息,该函数是发送和接收的通用接口函数


2、i2c_master_recv   i2c主模式下接收一个消息

kernel/driver/linux/i2c/i2c-core.c

/**
 * i2c_master_recv - issue a single I2C message in master receive mode
 * @client: Handle to slave device
 * @buf: Where to store data read from slave
 * @count: How many bytes to read, must be less than 64k since msg.len is u16
 *
 * Returns negative errno, or else the number of bytes read.
 */
int i2c_master_recv(const struct i2c_client *client, char *buf, int count)
{
struct i2c_adapter *adap = client->adapter;
struct i2c_msg msg;
int ret;


msg.addr = client->addr;
msg.flags = client->flags & I2C_M_TEN;
msg.flags |&#

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值