AP_InertialSensor: MPU6000: be agnostic to I2C bus/address

This decision is better made by the caller rather than polluting the
driver with board-specific details.
This commit is contained in:
Lucas De Marchi 2015-07-28 11:56:34 -03:00 committed by Andrew Tridgell
parent 4d4dac867e
commit c3063f0ab2
3 changed files with 8 additions and 9 deletions

View File

@ -403,7 +403,7 @@ AP_InertialSensor::_detect_backends(void)
#elif HAL_INS_DEFAULT == HAL_INS_MPU60XX_SPI
_add_backend(AP_InertialSensor_MPU6000::detect_spi(*this));
#elif HAL_INS_DEFAULT == HAL_INS_MPU60XX_I2C && HAL_INS_MPU60XX_I2C_BUS == 2
_add_backend(AP_InertialSensor_MPU6000::detect_i2c2(*this));
_add_backend(AP_InertialSensor_MPU6000::detect_i2c(*this, hal.i2c2, HAL_INS_MPU60XX_I2C_ADDR));
#elif HAL_INS_DEFAULT == HAL_INS_PX4 || HAL_INS_DEFAULT == HAL_INS_VRBRAIN
_add_backend(AP_InertialSensor_PX4::detect(*this));
#elif HAL_INS_DEFAULT == HAL_INS_OILPAN

View File

@ -168,11 +168,6 @@ extern const AP_HAL::HAL& hal;
#define int16_val(v, idx) ((int16_t)(((uint16_t)v[2*idx] << 8) | v[2*idx+1]))
#define uint16_val(v, idx)(((uint16_t)v[2*idx] << 8) | v[2*idx+1])
#if !defined(HAL_INS_MPU60XX_I2C_ADDR)
#define HAL_INS_MPU60XX_I2C_ADDR 0x68
#endif
/* SPI bus driver implementation */
AP_MPU6000_BusDriver_SPI::AP_MPU6000_BusDriver_SPI(void) :
@ -416,10 +411,12 @@ AP_InertialSensor_Backend *AP_InertialSensor_MPU6000::detect_spi(AP_InertialSens
return sensor;
}
AP_InertialSensor_Backend *AP_InertialSensor_MPU6000::detect_i2c2(AP_InertialSensor &_imu)
AP_InertialSensor_Backend *AP_InertialSensor_MPU6000::detect_i2c(AP_InertialSensor &_imu,
AP_HAL::I2CDriver *i2c,
uint8_t addr)
{
AP_InertialSensor_MPU6000 *sensor = new AP_InertialSensor_MPU6000(_imu,
new AP_MPU6000_BusDriver_I2C(hal.i2c2, HAL_INS_MPU60XX_I2C_ADDR));
new AP_MPU6000_BusDriver_I2C(i2c, addr));
if (sensor == NULL) {
return NULL;
}

View File

@ -45,7 +45,9 @@ class AP_InertialSensor_MPU6000 : public AP_InertialSensor_Backend
{
public:
AP_InertialSensor_MPU6000(AP_InertialSensor &imu, AP_MPU6000_BusDriver *bus);
static AP_InertialSensor_Backend *detect_i2c2(AP_InertialSensor &_imu);
static AP_InertialSensor_Backend *detect_i2c(AP_InertialSensor &_imu,
AP_HAL::I2CDriver *i2c,
uint8_t addr);
static AP_InertialSensor_Backend *detect_spi(AP_InertialSensor &_imu);
/* update accel and gyro state */