Browse Source

AP_HAL_SITL: add support for multiple i2c buses

zr-v5.1
Peter Barker 5 years ago committed by Peter Barker
parent
commit
bddea9e046
  1. 5
      libraries/AP_HAL_SITL/I2CDevice.cpp
  2. 1
      libraries/AP_HAL_SITL/I2CDevice.h

5
libraries/AP_HAL_SITL/I2CDevice.cpp

@ -101,6 +101,9 @@ I2CBus I2CDeviceManager::buses[NUM_SITL_I2C_BUSES] {}; @@ -101,6 +101,9 @@ I2CBus I2CDeviceManager::buses[NUM_SITL_I2C_BUSES] {};
I2CDeviceManager::I2CDeviceManager()
{
for (uint8_t i=0; i<ARRAY_SIZE(buses); i++) {
buses[i].bus = i;
}
}
AP_HAL::OwnPtr<AP_HAL::I2CDevice>
@ -132,6 +135,7 @@ I2CDevice::I2CDevice(I2CBus &bus, uint8_t address) @@ -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, @@ -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<uint8_t*>(send);

1
libraries/AP_HAL_SITL/I2CDevice.h

@ -81,6 +81,7 @@ public: @@ -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;

Loading…
Cancel
Save