I2C数据传输的三个主要API

i2c data transferi2c 数据传输主要有三个 api
int i2c_master_send(const struct i2c_client *client,const char *buf,int count)
client:i2c 设备对应的 i2c_client。
buf:要发送的数据。
count:要发送的数据字节数,要小于 64kb,以为 i2c_msg 的 len 成员变量是一个 u16(无符号 16 位)类型的数据。
返回值:负值,失败,其他非负值,发送的字节数。
int i2c_master_recv(const struct i2c_client *client,char *buf,int count)
client:i2c 设备对应的 i2c_client。
buf:要接收的数据。
count:要接收的数据字节数,要小于 64kb,以为 i2c_msg 的 len 成员变量是一个 u16(无符号 16 位)类型的数据。
返回值:负值,失败,其他非负值,发送的字节数。
int i2c_transfer(struct i2c_adapter *adap,struct i2c_msg *msgs,int num)
adap:所使用的 i2c 适配器,i2c_client 会保存其对应的 i2c_adapter。
msgs:i2c 要发送的一个或多个消息。
num:消息数量,也就是 msgs 的数量。
返回值:负值,失败,其他非负值,发送的 msgs 数量。
i2c_master_send 和 i2c_master_recv 都是对 i2c_transfer 的封装。因此我们重点研究 i2c_transfer。
其中,adap->algo->master_xfer 由芯片原厂提供。在 mtk 平台,是 mtk_i2c_transfer 函数,不同平台命名不同。
static int mtk_i2c_transfer(struct i2c_adapter *adap,struct i2c_msg msgs[], int num){ int ret; int left_num = num; struct mtk_i2c *i2c = i2c_get_adapdata(adap); //打开时钟 ret = mtk_i2c_clock_enable(i2c); if (ret) return ret; //初始化硬件 mtk_i2c_init_hw(i2c); i2c- >auto_restart = i2c- >dev_comp- >auto_restart; if (i2c- >auto_restart && num == 2) { if (!(msgs[0].flags & i2c_m_rd) && (msgs[1].flags & i2c_m_rd) && msgs[0].addr == msgs[1].addr) { i2c- >auto_restart = 0; } } if (i2c- >auto_restart && num >= 2 && i2c- >speed_hz > max_fs_mode_speed) i2c- >ignore_restart_irq = true; else i2c- >ignore_restart_irq = false; while (left_num--) { if (!msgs- >buf) { dev_dbg(i2c- >dev, data buffer is null.n); ret = -einval; goto err_exit; } if (msgs- >flags & i2c_m_rd) i2c- >op = i2c_master_rd; else i2c- >op = i2c_master_wr; if (!i2c- >auto_restart) { if (num > 1) { /* combined two messages into one transaction */ i2c- >op = i2c_master_wrrd; left_num--; } } /* always use dma mode. */ ret = mtk_i2c_do_transfer(i2c, msgs, num, left_num); if (ret < 0) goto err_exit; msgs++; } /* the return value is number of executed messages */ ret = num;err_exit: mtk_i2c_clock_disable(i2c); return ret;}

商业联合创新中心成立 中国电信与华为开展5G合作!
cpu芯片的作用是什么
军工检测方案商西测测试即将登陆创业板
借助人工智能技术,显示屏也将迎来一轮新变革
柯洁再战人工智能 承认AI计算和判断已经超越他
I2C数据传输的三个主要API
如何选择适合自己的云存储服务
GECAS与以色列航空工业公司联合启动了波音777-300ER客改货项目
使用单片机驱动MAX485/RS485出现发热停止工作要怎么解决?
基于Classic AutoSAR平台进行SOA和以太网的设计
Atheros面向便携推出WLAN和蓝牙智能组合方案
开发工具AP-Tool的MPU写图功能介绍-在RA8889ML3N中的应用
阿里百度小米攻势猛烈 京东、网易智能音箱团队相继解散
油墨的粒度检测检测的重要性
针对HART支持的4mA至20mA输入优化电路设计
高通第一季度芯片销售额超德州仪器
app安全测试方法小百科
十周年的旗舰款iphone8还早,先看看小改款的iphone7s
AI企业普强信息与麒麟软件完成NeoCertify认证 搭建国产化信创数字生态
企业人工智能在工作场所的5大应用