mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Fix crash when first or second gyro is not detected.
Firmware now silently uses the one it does find. User can detect this by looking at the `diff` output.
This commit is contained in:
parent
f4ce78f939
commit
b7417a6d3d
1 changed files with 35 additions and 11 deletions
|
@ -516,24 +516,49 @@ bool gyroInit(void)
|
||||||
}
|
}
|
||||||
firstArmingCalibrationWasStarted = false;
|
firstArmingCalibrationWasStarted = false;
|
||||||
|
|
||||||
bool ret = false;
|
enum {
|
||||||
|
NO_GYROS_DETECTED = 0,
|
||||||
|
DETECTED_GYRO_1 = (1 << 0),
|
||||||
|
DETECTED_GYRO_2 = (1 << 1),
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t detectionFlags = NO_GYROS_DETECTED;
|
||||||
|
|
||||||
gyroToUse = gyroConfig()->gyro_to_use;
|
gyroToUse = gyroConfig()->gyro_to_use;
|
||||||
|
|
||||||
if (gyroToUse == GYRO_CONFIG_USE_GYRO_1 || gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH) {
|
if (gyroToUse == GYRO_CONFIG_USE_GYRO_1 || gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH) {
|
||||||
ret = gyroInitSensor(&gyroSensor1, gyroDeviceConfig(0));
|
if (gyroInitSensor(&gyroSensor1, gyroDeviceConfig(0))) {
|
||||||
if (!ret) {
|
gyroHasOverflowProtection = gyroHasOverflowProtection && gyroSensor1.gyroDev.gyroHasOverflowProtection;
|
||||||
return false; // TODO handle failure of first gyro detection better. - Perhaps update the config to use second gyro then indicate a new failure mode and reboot.
|
detectionFlags |= DETECTED_GYRO_1;
|
||||||
}
|
}
|
||||||
gyroHasOverflowProtection = gyroHasOverflowProtection && gyroSensor1.gyroDev.gyroHasOverflowProtection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_MULTI_GYRO
|
#ifdef USE_MULTI_GYRO
|
||||||
if (gyroToUse == GYRO_CONFIG_USE_GYRO_2 || gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH) {
|
if (gyroToUse == GYRO_CONFIG_USE_GYRO_2 || gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH) {
|
||||||
ret = gyroInitSensor(&gyroSensor2, gyroDeviceConfig(1));
|
if (gyroInitSensor(&gyroSensor2, gyroDeviceConfig(1))) {
|
||||||
if (!ret) {
|
gyroHasOverflowProtection = gyroHasOverflowProtection && gyroSensor2.gyroDev.gyroHasOverflowProtection;
|
||||||
return false; // TODO handle failure of second gyro detection better. - Perhaps update the config to use first gyro then indicate a new failure mode and reboot.
|
detectionFlags |= DETECTED_GYRO_2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH && detectionFlags != (DETECTED_GYRO_1 | DETECTED_GYRO_2)) {
|
||||||
|
// at least one gyro is missing.
|
||||||
|
|
||||||
|
if (detectionFlags & DETECTED_GYRO_1) {
|
||||||
|
gyroToUse = GYRO_CONFIG_USE_GYRO_1;
|
||||||
|
gyroConfigMutable()->gyro_to_use = GYRO_CONFIG_USE_GYRO_1;
|
||||||
|
detectedSensors[SENSOR_INDEX_GYRO] = gyroSensor1.gyroDev.gyroHardware;
|
||||||
|
sensorsSet(SENSOR_GYRO);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detectionFlags & DETECTED_GYRO_2) {
|
||||||
|
gyroToUse = GYRO_CONFIG_USE_GYRO_2;
|
||||||
|
gyroConfigMutable()->gyro_to_use = GYRO_CONFIG_USE_GYRO_2;
|
||||||
|
detectedSensors[SENSOR_INDEX_GYRO] = gyroSensor2.gyroDev.gyroHardware;
|
||||||
|
sensorsSet(SENSOR_GYRO);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
gyroHasOverflowProtection = gyroHasOverflowProtection && gyroSensor2.gyroDev.gyroHasOverflowProtection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only allow using both gyros simultaneously if they are the same hardware type.
|
// Only allow using both gyros simultaneously if they are the same hardware type.
|
||||||
|
@ -544,12 +569,11 @@ bool gyroInit(void)
|
||||||
gyroConfigMutable()->gyro_to_use = GYRO_CONFIG_USE_GYRO_1;
|
gyroConfigMutable()->gyro_to_use = GYRO_CONFIG_USE_GYRO_1;
|
||||||
detectedSensors[SENSOR_INDEX_GYRO] = gyroSensor1.gyroDev.gyroHardware;
|
detectedSensors[SENSOR_INDEX_GYRO] = gyroSensor1.gyroDev.gyroHardware;
|
||||||
sensorsSet(SENSOR_GYRO);
|
sensorsSet(SENSOR_GYRO);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ret;
|
return detectionFlags != NO_GYROS_DETECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_DYN_LPF
|
#ifdef USE_DYN_LPF
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue