From cdb6ea92765f3c3360da9b651b6fb448f5e41245 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sun, 31 Dec 2023 23:37:01 +0100 Subject: [PATCH] Fix BMI160 gate and optimize directives (#13237) * Add BMI160 gate and other defines * Fix make test * Remove redundant directives --- src/main/sensors/acceleration_init.c | 2 +- src/main/sensors/gyro_init.c | 28 +++++++++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/sensors/acceleration_init.c b/src/main/sensors/acceleration_init.c index b5900314686..9c38460dbc3 100644 --- a/src/main/sensors/acceleration_init.c +++ b/src/main/sensors/acceleration_init.c @@ -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 diff --git a/src/main/sensors/gyro_init.c b/src/main/sensors/gyro_init.c index 8b2edba8058..7369495eec9 100644 --- a/src/main/sensors/gyro_init.c +++ b/src/main/sensors/gyro_init.c @@ -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 @@ -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 @@ -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); @@ -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 }