From 281a1b6569b97d1de5b2c6a295f75b3f5aec1e41 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 21 Jun 2018 13:08:58 +1000 Subject: [PATCH] AP_HAL: added I2C bus mask functions and macros --- libraries/AP_HAL/I2CDevice.h | 22 ++++++++++++++++++++++ libraries/AP_HAL/board/linux.h | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/libraries/AP_HAL/I2CDevice.h b/libraries/AP_HAL/I2CDevice.h index 28dca3e59d..55a58bff39 100644 --- a/libraries/AP_HAL/I2CDevice.h +++ b/libraries/AP_HAL/I2CDevice.h @@ -89,6 +89,28 @@ public: // Not implemented return nullptr; } + + /* + get mask of bus numbers for all configured I2C buses + */ + virtual uint32_t get_bus_mask(void) const { return 0x0F; } + + /* + get mask of bus numbers for all configured external I2C buses + */ + virtual uint32_t get_bus_mask_external(void) const { return 0x0F; } + + /* + get mask of bus numbers for all configured internal I2C buses + */ + virtual uint32_t get_bus_mask_internal(void) const { return 0x01; } }; +/* + convenient macros for iterating over I2C bus numbers + */ +#define FOREACH_I2C_EXTERNAL(i) for (uint32_t _bmask=hal.i2c_mgr->get_bus_mask_external(), i=0; i<32; i++) if ((1U<get_bus_mask_internal(), i=0; i<32; i++) if ((1U<get_bus_mask(), i=0; i<32; i++) if ((1U<