AP_HAL: added I2C bus mask functions and macros

This commit is contained in:
Andrew Tridgell 2018-06-21 13:08:58 +10:00 committed by Randy Mackay
parent 8516fa43c2
commit 44685bbb7b
2 changed files with 35 additions and 0 deletions

View File

@ -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<<i)&_bmask)
#define FOREACH_I2C_INTERNAL(i) for (uint32_t _bmask=hal.i2c_mgr->get_bus_mask_internal(), i=0; i<32; i++) if ((1U<<i)&_bmask)
#define FOREACH_I2C(i) for (uint32_t _bmask=hal.i2c_mgr->get_bus_mask(), i=0; i<32; i++) if ((1U<<i)&_bmask)
}

View File

@ -382,3 +382,16 @@
#ifndef HAL_BOARD_CAN_IFACE_NAME
#define HAL_BOARD_CAN_IFACE_NAME "can0"
#endif
// if bus masks are not setup above then use these defaults
#ifndef HAL_LINUX_I2C_BUS_MASK
#define HAL_LINUX_I2C_BUS_MASK 0x1f
#endif
#ifndef HAL_LINUX_I2C_INTERNAL_BUS_MASK
#define HAL_LINUX_I2C_INTERNAL_BUS_MASK 0x01
#endif
#ifndef HAL_LINUX_I2C_EXTERNAL_BUS_MASK
#define HAL_LINUX_I2C_EXTERNAL_BUS_MASK 0x1E
#endif