Skip to content

Commit

Permalink
Cleanup MPU6500 I2C/SPI sensor detection logic by using a boolean to
Browse files Browse the repository at this point in the history
indicate if the sensor was detected.  Removes some duplicate code.
  • Loading branch information
hydra committed Feb 25, 2016
1 parent 76fb8a4 commit 6db0ce7
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/main/sensors/initialisation.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ bool fakeAccDetect(acc_t *acc)

bool detectGyro(void)
{
bool sensorDetected;
UNUSED(sensorDetected); // avoid unused-variable warning on some targets.

gyroSensor_e gyroHardware = GYRO_DEFAULT;
gyroAlign = ALIGN_DEFAULT;

Expand Down Expand Up @@ -283,12 +280,7 @@ bool detectGyro(void)

case GYRO_MPU6500:
#ifdef USE_GYRO_MPU6500
#ifdef USE_GYRO_SPI_MPU6500
sensorDetected = mpu6500GyroDetect(&gyro) || mpu6500SpiGyroDetect(&gyro);
#else
sensorDetected = mpu6500GyroDetect(&gyro);
#endif
if (sensorDetected) {
if (mpu6500GyroDetect(&gyro)) {
gyroHardware = GYRO_MPU6500;
#ifdef GYRO_MPU6500_ALIGN
gyroAlign = GYRO_MPU6500_ALIGN;
Expand All @@ -297,6 +289,16 @@ bool detectGyro(void)
break;
}
#endif

#ifdef USE_GYRO_SPI_MPU6500
if (mpu6500SpiGyroDetect(&gyro)) {
gyroHardware = GYRO_MPU6500;
#ifdef GYRO_MPU6500_ALIGN
gyroAlign = GYRO_MPU6500_ALIGN;
#endif
break;
}
#endif
; // fallthrough

case GYRO_FAKE:
Expand Down Expand Up @@ -418,12 +420,17 @@ static void detectAcc(accelerationSensor_e accHardwareToUse)
; // fallthrough
case ACC_MPU6500:
#ifdef USE_ACC_MPU6500
#ifdef USE_ACC_SPI_MPU6500
sensorDetected = mpu6500AccDetect(&acc) || mpu6500SpiAccDetect(&acc);
#else
sensorDetected = mpu6500AccDetect(&acc);
if (mpu6500AccDetect(&acc)) {
#ifdef ACC_MPU6500_ALIGN
accAlign = ACC_MPU6500_ALIGN;
#endif
if (sensorDetected) {
accHardware = ACC_MPU6500;
break;
}
#endif

#ifdef USE_ACC_SPI_MPU6500
if (mpu6500SpiAccDetect(&acc)) {
#ifdef ACC_MPU6500_ALIGN
accAlign = ACC_MPU6500_ALIGN;
#endif
Expand Down

0 comments on commit 6db0ce7

Please sign in to comment.