1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 09:45:37 +03:00

Merge pull request #5807 from etracer65/gyro_both_validation

Only allow gyro_to_use = BOTH if both detected gyros are the same type
This commit is contained in:
Michael Keller 2018-05-05 18:34:42 +12:00 committed by GitHub
commit b0ee38d77b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 10 deletions

View file

@ -223,6 +223,22 @@ const busDevice_t *gyroSensorBus(void)
#endif
}
#ifdef USE_GYRO_REGISTER_DUMP
const busDevice_t *gyroSensorBusByDevice(uint8_t whichSensor)
{
#ifdef USE_DUAL_GYRO
if (whichSensor == GYRO_CONFIG_USE_GYRO_2) {
return &gyroSensor2.gyroDev.bus;
} else {
return &gyroSensor1.gyroDev.bus;
}
#else
UNUSED(whichSensor);
return &gyroSensor1.gyroDev.bus;
#endif
}
#endif // USE_GYRO_REGISTER_DUMP
const mpuConfiguration_t *gyroMpuConfiguration(void)
{
#ifdef USE_DUAL_GYRO
@ -433,6 +449,7 @@ static bool gyroInitSensor(gyroSensor_t *gyroSensor)
#endif
const gyroSensor_e gyroHardware = gyroDetect(&gyroSensor->gyroDev);
gyroSensor->gyroDev.gyroHardware = gyroHardware;
if (gyroHardware == GYRO_NONE) {
return false;
}
@ -599,7 +616,21 @@ bool gyroInit(void)
}
gyroHasOverflowProtection = gyroHasOverflowProtection && gyroSensor2.gyroDev.gyroHasOverflowProtection;
}
#endif
#endif // USE_DUAL_GYRO
#ifdef USE_DUAL_GYRO
// Only allow using both gyros simultaneously if they are the same hardware type.
// If the user selected "BOTH" and they are not the same type, then reset to using only the first gyro.
if (gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH) {
if (gyroSensor1.gyroDev.gyroHardware != gyroSensor2.gyroDev.gyroHardware) {
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);
}
}
#endif // USE_DUAL_GYRO
return ret;
}
@ -1257,8 +1288,8 @@ uint16_t gyroAbsRateDps(int axis)
}
#ifdef USE_GYRO_REGISTER_DUMP
uint8_t gyroReadRegister(uint8_t reg)
uint8_t gyroReadRegister(uint8_t whichSensor, uint8_t reg)
{
return mpuGyroReadRegister(gyroSensorBus(), reg);
return mpuGyroReadRegister(gyroSensorBusByDevice(whichSensor), reg);
}
#endif
#endif // USE_GYRO_REGISTER_DUMP

View file

@ -128,4 +128,4 @@ int16_t gyroRateDps(int axis);
bool gyroOverflowDetected(void);
bool gyroYawSpinDetected(void);
uint16_t gyroAbsRateDps(int axis);
uint8_t gyroReadRegister(uint8_t reg);
uint8_t gyroReadRegister(uint8_t whichSensor, uint8_t reg);