From bddea9e04628a45249497c3fe63f3e77214e7850 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 19 Aug 2020 14:57:37 +1000 Subject: [PATCH] AP_HAL_SITL: add support for multiple i2c buses --- libraries/AP_HAL_SITL/I2CDevice.cpp | 5 +++++ libraries/AP_HAL_SITL/I2CDevice.h | 1 + 2 files changed, 6 insertions(+) diff --git a/libraries/AP_HAL_SITL/I2CDevice.cpp b/libraries/AP_HAL_SITL/I2CDevice.cpp index 2dde8a5b83..6faf733f75 100644 --- a/libraries/AP_HAL_SITL/I2CDevice.cpp +++ b/libraries/AP_HAL_SITL/I2CDevice.cpp @@ -101,6 +101,9 @@ I2CBus I2CDeviceManager::buses[NUM_SITL_I2C_BUSES] {}; I2CDeviceManager::I2CDeviceManager() { + for (uint8_t i=0; i @@ -132,6 +135,7 @@ I2CDevice::I2CDevice(I2CBus &bus, uint8_t address) : _bus(bus) , _address(address) { + ::fprintf(stderr, "bus.bus=%u address=0x%02x\n", bus.bus, address); set_device_bus(bus.bus); set_device_address(address); } @@ -159,6 +163,7 @@ bool I2CDevice::_transfer(const uint8_t *send, uint32_t send_len, unsigned nmsgs = 0; if (send && send_len != 0) { + msgs[nmsgs].bus = _bus.bus; msgs[nmsgs].addr = _address; msgs[nmsgs].flags = 0; msgs[nmsgs].buf = const_cast(send); diff --git a/libraries/AP_HAL_SITL/I2CDevice.h b/libraries/AP_HAL_SITL/I2CDevice.h index 034967e5d3..2a414bcf69 100644 --- a/libraries/AP_HAL_SITL/I2CDevice.h +++ b/libraries/AP_HAL_SITL/I2CDevice.h @@ -81,6 +81,7 @@ public: #define I2C_M_RD 1 #define I2C_RDWR 0 struct i2c_msg { + uint8_t bus; uint8_t addr; uint8_t flags; uint8_t *buf;