RK3568平台(I2C篇)i2c_transfer接口详解
一.IIC读写接口
/* bh1750读数据 */
static int bh1750_read_regs(struct bh1750_device *dev, void *val, int len)
{
int ret = 0;
struct i2c_client *client = (struct i2c_client *)dev->private_data;
struct i2c_msg msgs[1] = {
[0] = { //寄存器的值
.addr = client->addr,
.flags = I2C_M_RD,
.buf = val,
.len = len,
}
};
ret = i2c_transfer(client->adapter, msgs, 1);
if (ret != 1) {
printk("i2c rd failed=%d len=%d\n",ret, len);
ret = -EINVAL;
} else {
ret = 0;
}
return ret;
}
/* bh1750写数据 */
static int bh1750_write_regs(struct bh1750_device *dev, u8 *buf, u8 len)
{
struct
原文地址:https://blog.csdn.net/weixin_49303682/article/details/143809257
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!