Skip to content

Commit

Permalink
Fix BMI160 gate and optimize directives (betaflight#13237)
Browse files Browse the repository at this point in the history
* Add BMI160 gate and other defines

* Fix make test

* Remove redundant directives
  • Loading branch information
haslinghuis authored and davidbitton committed Feb 5, 2024
1 parent 099137d commit cdb6ea9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/sensors/acceleration_init.c
Expand Up @@ -240,7 +240,7 @@ bool accDetect(accDev_t *dev, accelerationSensor_e accHardwareToUse)
case ACC_ICM20608G:
#if defined(USE_ACC_MPU6500) || defined(USE_ACC_SPI_MPU6500)
#ifdef USE_ACC_SPI_MPU6500
if (mpu6500AccDetect(dev) || mpu6500SpiAccDetect(dev)) {
if (mpu6500SpiAccDetect(dev)) {
#else
if (mpu6500AccDetect(dev)) {
#endif
Expand Down
28 changes: 9 additions & 19 deletions src/main/sensors/gyro_init.c
Expand Up @@ -75,7 +75,8 @@
#if !defined(USE_GYRO_L3G4200D) && !defined(USE_GYRO_MPU3050) && !defined(USE_GYRO_MPU6050) && \
!defined(USE_GYRO_MPU6500) && !defined(USE_GYRO_SPI_ICM20689) && !defined(USE_GYRO_SPI_MPU6000) && \
!defined(USE_GYRO_SPI_MPU6500) && !defined(USE_GYRO_SPI_MPU9250) && !defined(USE_GYRO_L3GD20) && \
!defined(USE_GYRO_SPI_ICM42605) && !defined(USE_GYRO_SPI_ICM42688P) && !defined(USE_ACCGYRO_BMI270) && \
!defined(USE_GYRO_SPI_ICM42605) && !defined(USE_GYRO_SPI_ICM42688P) && \
!defined(USE_ACCGYRO_BMI160) && !defined(USE_ACCGYRO_BMI270) && \
!defined(USE_ACCGYRO_LSM6DSV16X) && !defined(USE_ACCGYRO_LSM6DSO) && !defined(USE_VIRTUAL_GYRO)
#error At least one USE_GYRO device definition required
#endif
Expand Down Expand Up @@ -409,7 +410,7 @@ STATIC_UNIT_TESTED gyroHardware_e gyroDetect(gyroDev_t *dev)
case GYRO_ICM20602:
case GYRO_ICM20608G:
#ifdef USE_GYRO_SPI_MPU6500
if (mpu6500GyroDetect(dev) || mpu6500SpiGyroDetect(dev)) {
if (mpu6500SpiGyroDetect(dev)) {
#else
if (mpu6500GyroDetect(dev)) {
#endif
Expand Down Expand Up @@ -540,22 +541,13 @@ STATIC_UNIT_TESTED gyroHardware_e gyroDetect(gyroDev_t *dev)

static bool gyroDetectSensor(gyroSensor_t *gyroSensor, const gyroDeviceConfig_t *config)
{
#if defined(USE_GYRO_MPU6050) || defined(USE_GYRO_MPU3050) || defined(USE_GYRO_MPU6500) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU6000) \
|| defined(USE_ACC_MPU6050) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_SPI_ICM20601) || defined(USE_GYRO_SPI_ICM20649) \
|| defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_L3GD20) || defined(USE_ACCGYRO_BMI160) || defined(USE_ACCGYRO_BMI270) \
|| defined(USE_ACCGYRO_LSM6DSO) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_LSM6DSV16X)

#ifdef USE_VIRTUAL_GYRO
UNUSED(config);
#else
bool gyroFound = mpuDetect(&gyroSensor->gyroDev, config);

#if !defined(USE_VIRTUAL_GYRO) // Allow resorting to virtual accgyro if defined
if (!gyroFound) {
return false;
}
#else
UNUSED(gyroFound);
#endif
#else
UNUSED(config);
#endif

const gyroHardware_e gyroHardware = gyroDetect(&gyroSensor->gyroDev);
Expand All @@ -566,12 +558,10 @@ static bool gyroDetectSensor(gyroSensor_t *gyroSensor, const gyroDeviceConfig_t

static void gyroPreInitSensor(const gyroDeviceConfig_t *config)
{
#if defined(USE_GYRO_MPU6050) || defined(USE_GYRO_MPU3050) || defined(USE_GYRO_MPU6500) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU6000) \
|| defined(USE_ACC_MPU6050) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_SPI_ICM20601) || defined(USE_GYRO_SPI_ICM20649) \
|| defined(USE_GYRO_SPI_ICM20689) || defined(USE_ACCGYRO_BMI160) || defined(USE_ACCGYRO_BMI270) || defined(USE_ACCGRYO_LSM6DSO)
mpuPreInit(config);
#else
#ifdef USE_VIRTUAL_GYRO
UNUSED(config);
#else
mpuPreInit(config);
#endif
}

Expand Down

0 comments on commit cdb6ea9

Please sign in to comment.