fix(platforms/i2c): report current bus, not filter, in iterator external() (#27346)

I2CBusIterator::external() was returning px4_i2c_bus_external(_bus),
where _bus is the constructor filter argument (the user's -b value,
which defaults to -1 when no bus is specified). When a driver was
started with -I and no -b (e.g. iis2mdc -I start, bmp388 -I start),
_bus stayed -1, px4_i2c_bus_external(-1) fell through to its "not
found" fallback that returns true, and the boot log printed
"on I2C bus 4 (external)" for sensors sitting on an internal bus.

Pass bus().bus instead so the result reflects the bus the iterator
is currently positioned on. This mirrors SPIBusIterator::external()
and restores the pre-8080ca966a8 semantics.

Device::external() (the override used by sensors status and
calibration) already used the device id's bus number, so only the
boot-time print was wrong.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
Jacob Dahl
2026-05-15 21:19:59 -04:00
committed by GitHub
parent 88d1c51e91
commit 239947a100
@@ -84,7 +84,7 @@ public:
int externalBusIndex() const { return _external_bus_counter; }
bool external() const { return px4_i2c_bus_external(_bus); }
bool external() const { return px4_i2c_bus_external(bus().bus); }
private:
const FilterType _filter;