diff --git a/platforms/common/i2c_spi_buses.cpp b/platforms/common/i2c_spi_buses.cpp index bc910c11de..0f327884c6 100644 --- a/platforms/common/i2c_spi_buses.cpp +++ b/platforms/common/i2c_spi_buses.cpp @@ -392,6 +392,19 @@ int BusInstanceIterator::runningInstancesCount() const return num_instances; } +int BusInstanceIterator::runningInstancesOnBusCount() const +{ + int num_instances = 0; + + for (const auto &modules : i2c_spi_module_instances) { + if (modules->_bus == bus() && strcmp(modules->_module_name, _module_name) == 0) { + ++num_instances; + } + } + + return num_instances; +} + I2CSPIInstance *BusInstanceIterator::instance() const { if (_current_instance == i2c_spi_module_instances.end()) { diff --git a/platforms/common/include/px4_platform_common/i2c_spi_buses.h b/platforms/common/include/px4_platform_common/i2c_spi_buses.h index aa6dc90703..0ca599a57e 100644 --- a/platforms/common/include/px4_platform_common/i2c_spi_buses.h +++ b/platforms/common/include/px4_platform_common/i2c_spi_buses.h @@ -229,6 +229,7 @@ public: I2CSPIBusOption configuredBusOption() const { return _bus_option; } int runningInstancesCount() const; + int runningInstancesOnBusCount() const; bool next();