SITL: correct I2C multi-bus support

This commit is contained in:
Peter Barker 2021-01-03 13:35:30 +11:00 committed by Peter Barker
parent 21ffa4d259
commit e5fd661caf

View File

@ -98,16 +98,18 @@ int I2C::ioctl_rdwr(i2c_rdwr_ioctl_data *data)
for (uint8_t i=0; i<data->nmsgs; i++) {
const i2c_msg &msg = data->msgs[i];
const uint8_t addr = msg.addr;
const uint8_t bus = msg.bus;
bool handled = false;
for (auto dev_at_address : i2c_devices) {
// where's the bus check?!
if (dev_at_address.addr == addr) {
ret = dev_at_address.device.rdwr(data);
for (auto &dev_at_address : i2c_devices) {
if (dev_at_address.addr == addr &&
dev_at_address.bus == bus) {
handled = true;
ret = dev_at_address.device.rdwr(data);
break; // uniqueness of addr/bus device is ensured in init()
}
}
if (!handled) {
::fprintf(stderr, "Unhandled i2c message: bus=%u addr=0x%02x flags=%u len=%u\n", msg.bus, msg.addr, msg.flags, msg.len);
// ::fprintf(stderr, "Unhandled i2c message: bus=%u addr=0x%02x flags=%u len=%u\n", msg.bus, msg.addr, msg.flags, msg.len);
return -1; // ?!
}
}