MPU6K driver improvements

This commit is contained in:
Lorenz Meier
2016-08-18 12:55:54 +02:00
parent 1efe011522
commit 3d1f1522d9
+6 -21
View File
@@ -517,10 +517,6 @@ MPU6000::MPU6000(device::Device *interface, const char *path_accel, const char *
_last_accel{}, _last_accel{},
_got_duplicate(false) _got_duplicate(false)
{ {
#if defined(USE_I2C)
// work_cancel in stop_cycle called from the dtor will explode if we don't do this...
memset(&_work, 0, sizeof(_work));
#endif
// disable debug() calls // disable debug() calls
_debug_enabled = false; _debug_enabled = false;
@@ -711,10 +707,10 @@ int MPU6000::reset()
write_checked_reg(MPUREG_PWR_MGMT_1, MPU_CLK_SEL_PLLGYROZ); write_checked_reg(MPUREG_PWR_MGMT_1, MPU_CLK_SEL_PLLGYROZ);
up_udelay(1000); up_udelay(1000);
#if defined(USE_I2C) if (is_i2c()) {
// Enable I2C bus (recommended on datasheet)
if (!is_i2c()) write_checked_reg(MPUREG_USER_CTRL, 0);
#endif } else
{ {
// Disable I2C bus (recommended on datasheet) // Disable I2C bus (recommended on datasheet)
write_checked_reg(MPUREG_USER_CTRL, BIT_I2C_IF_DIS); write_checked_reg(MPUREG_USER_CTRL, BIT_I2C_IF_DIS);
@@ -1359,10 +1355,8 @@ MPU6000::ioctl(struct file *filp, int cmd, unsigned long arg)
them. This prevents aliasing due to a beat between the them. This prevents aliasing due to a beat between the
stm32 clock and the mpu6000 clock stm32 clock and the mpu6000 clock
*/ */
#if defined(USE_I2C)
if (!is_i2c()) if (!is_i2c())
#endif
{ {
_call.period = _call_interval - MPU6000_TIMER_REDUCTION; _call.period = _call_interval - MPU6000_TIMER_REDUCTION;
} }
@@ -1669,40 +1663,31 @@ MPU6000::start()
_accel_reports->flush(); _accel_reports->flush();
_gyro_reports->flush(); _gyro_reports->flush();
#if defined(USE_I2C)
if (_use_hrt) { if (_use_hrt) {
#endif
/* start polling at the specified rate */ /* start polling at the specified rate */
hrt_call_every(&_call, hrt_call_every(&_call,
1000, 1000,
_call_interval - MPU6000_TIMER_REDUCTION, _call_interval - MPU6000_TIMER_REDUCTION,
(hrt_callout)&MPU6000::measure_trampoline, this); (hrt_callout)&MPU6000::measure_trampoline, this);
#if defined(USE_I2C)
} else { } else {
/* schedule a cycle to start things */ /* schedule a cycle to start things */
work_queue(HPWORK, &_work, (worker_t)&MPU6000::cycle_trampoline, this, 1); work_queue(HPWORK, &_work, (worker_t)&MPU6000::cycle_trampoline, this, 1);
} }
#endif
} }
void void
MPU6000::stop() MPU6000::stop()
{ {
#if defined(USE_I2C)
if (_use_hrt) { if (_use_hrt) {
#endif
hrt_cancel(&_call); hrt_cancel(&_call);
#if defined(USE_I2C)
} else { } else {
_call_interval = 0;
work_cancel(HPWORK, &_work); work_cancel(HPWORK, &_work);
} }
#endif
/* reset internal states */ /* reset internal states */
memset(_last_accel, 0, sizeof(_last_accel)); memset(_last_accel, 0, sizeof(_last_accel));
@@ -2638,7 +2623,7 @@ mpu6000_main(int argc, char *argv[])
/* /*
* Print driver information. * Print driver information.
*/ */
if (!strcmp(verb, "info")) { if (!strcmp(verb, "info") || !strcmp(verb, "status")) {
mpu6000::info(busid); mpu6000::info(busid);
} }