From 895ddee16a843859a104002466aeaabde40b5883 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 11 Oct 2023 12:47:15 +1300 Subject: [PATCH] i2c_spi_buses: method to count instances per bus Signed-off-by: Julian Oes --- platforms/common/i2c_spi_buses.cpp | 13 +++++++++++++ .../include/px4_platform_common/i2c_spi_buses.h | 1 + 2 files changed, 14 insertions(+) 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();