MPU9250: Separate mpu and mag resets

This commit is contained in:
Dennis Shtatnov 2017-07-19 23:28:41 -04:00 committed by David Sidrane
parent 03e11c4d18
commit 2e85a4363e
2 changed files with 36 additions and 11 deletions

View File

@ -292,7 +292,7 @@ MPU9250::init()
goto out;
}
if (reset() != OK) {
if (reset_mpu() != OK) {
PX4_ERR("Exiting! Device failed to take initialization");
goto out;
}
@ -340,6 +340,17 @@ MPU9250::init()
return ret;
}
if (_whoami == MPU_WHOAMI_9250) {
ret = _mag->ak8963_reset();
}
if (ret != OK) {
DEVICE_DEBUG("mag reset failed");
return ret;
}
_accel_class_instance = register_class_devname(ACCEL_BASE_DEVICE_PATH);
measure();
@ -378,13 +389,31 @@ int MPU9250::reset()
// Hold off sampling until done (100 MS will be shortened)
state = px4_enter_critical_section();
_reset_wait = hrt_absolute_time() + 100000;
px4_leave_critical_section(state);
int ret;
ret = reset_mpu();
if (ret == OK && _whoami == MPU_WHOAMI_9250) {
ret = _mag->ak8963_reset();
}
state = px4_enter_critical_section();
_reset_wait = hrt_absolute_time() + 10;
px4_leave_critical_section(state);
return ret;
}
int MPU9250::reset_mpu()
{
write_reg(MPUREG_PWR_MGMT_1, BIT_H_RESET);
write_checked_reg(MPUREG_PWR_MGMT_1, MPU_CLK_SEL_AUTO);
write_checked_reg(MPUREG_PWR_MGMT_2, 0);
px4_leave_critical_section(state);
usleep(1000);
@ -453,15 +482,6 @@ int MPU9250::reset()
}
}
if (all_ok && _whoami == MPU_WHOAMI_9250) {
all_ok = _mag->ak8963_reset() == OK;
}
state = px4_enter_critical_section();
_reset_wait = hrt_absolute_time() + 10;
px4_leave_critical_section(state);
return all_ok ? OK : -EIO;
}

View File

@ -375,6 +375,11 @@ private:
int reset();
/**
* Resets the main chip (excluding the magnetometer if any).
*/
int reset_mpu();
#if defined(USE_I2C)
/**