大家好最近弄v3s 的i2c ,发现在内核对从地址是这么处理的
/* 7-1bits addr, xxxx_xxx0 */
addr = (i2c->msg[i2c->msg_idx].addr & 0x7f) << 1;
,这要是我的从地址是0x70 , 写的时候变成了0xe0, 没法控制设备啊。我把地址强制成0x70,就可以了,这什么意思?这驱动有问题?按理说不应该啊。
static void sunxi_i2c_addr_byte(struct sunxi_i2c *i2c)
{
unsigned char addr = 0;
unsigned char tmp = 0;
if (i2c->msg[i2c->msg_idx].flags & I2C_M_TEN) {
/* 0111_10xx,ten bits address--9:8bits */
tmp = 0x78 | ( ( (i2c->msg[i2c->msg_idx].addr)>>8 ) & 0x03);
addr = tmp << 1;//1111_0xx0
/* how about the second part of ten bits addr? Answer: deal at twi_core_process() */
}
else {
/* 7-1bits addr, xxxx_xxx0 */
addr = (i2c->msg[i2c->msg_idx].addr & 0x7f) << 1;
}
/* read, default value is write */
if (i2c->msg[i2c->msg_idx].flags & I2C_M_RD) {
addr |= 1;
}
离线