From 22feb3c08a2a23895d28d7e0f30354c825e9434e Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 1 Feb 2023 23:53:43 +1100 Subject: [PATCH] AP_Compass: add and use AP_COMPASS_AK8963_ENABLED --- libraries/AP_Compass/AP_Compass.cpp | 12 ++++++++++++ libraries/AP_Compass/AP_Compass.h | 2 ++ libraries/AP_Compass/AP_Compass_AK8963.cpp | 8 +++++++- libraries/AP_Compass/AP_Compass_AK8963.h | 6 ++++++ libraries/AP_Compass/AP_Compass_config.h | 4 ++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Compass/AP_Compass.cpp b/libraries/AP_Compass/AP_Compass.cpp index 08db770f74..2d9647ebb2 100644 --- a/libraries/AP_Compass/AP_Compass.cpp +++ b/libraries/AP_Compass/AP_Compass.cpp @@ -1368,9 +1368,11 @@ void Compass::_detect_backends(void) #if AP_COMPASS_LSM303D_ENABLED ADD_BACKEND(DRIVER_LSM303D, AP_Compass_LSM303D::probe(hal.spi->get_device(HAL_INS_LSM9DS0_EXT_A_NAME), ROTATION_YAW_270)); #endif +#if AP_COMPASS_AK8963_ENABLED // we run the AK8963 only on the 2nd MPU9250, which leaves the // first MPU9250 to run without disturbance at high rate ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(1, ROTATION_YAW_270)); +#endif ADD_BACKEND(DRIVER_AK09916, AP_Compass_AK09916::probe_ICM20948(0, ROTATION_ROLL_180_YAW_90)); break; @@ -1387,25 +1389,35 @@ void Compass::_detect_backends(void) break; case AP_BoardConfig::PX4_BOARD_SP01: +#if AP_COMPASS_AK8963_ENABLED ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(1, ROTATION_NONE)); +#endif break; case AP_BoardConfig::PX4_BOARD_PIXHAWK_PRO: +#if AP_COMPASS_AK8963_ENABLED ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(0, ROTATION_ROLL_180_YAW_90)); +#endif ADD_BACKEND(DRIVER_LIS3MDL, AP_Compass_LIS3MDL::probe(hal.spi->get_device(HAL_COMPASS_LIS3MDL_NAME), false, ROTATION_NONE)); break; case AP_BoardConfig::PX4_BOARD_PHMINI: +#if AP_COMPASS_AK8963_ENABLED ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(0, ROTATION_ROLL_180)); +#endif break; case AP_BoardConfig::PX4_BOARD_AUAV21: +#if AP_COMPASS_AK8963_ENABLED ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(0, ROTATION_ROLL_180_YAW_90)); +#endif break; case AP_BoardConfig::PX4_BOARD_PH2SLIM: +#if AP_COMPASS_AK8963_ENABLED ADD_BACKEND(DRIVER_AK8963, AP_Compass_AK8963::probe_mpu9250(0, ROTATION_YAW_270)); +#endif break; case AP_BoardConfig::PX4_BOARD_MINDPXV2: diff --git a/libraries/AP_Compass/AP_Compass.h b/libraries/AP_Compass/AP_Compass.h index deb7b6fd05..65d74dd44c 100644 --- a/libraries/AP_Compass/AP_Compass.h +++ b/libraries/AP_Compass/AP_Compass.h @@ -420,7 +420,9 @@ private: #if AP_COMPASS_LSM303D_ENABLED DRIVER_LSM303D =1, #endif +#if AP_COMPASS_AK8963_ENABLED DRIVER_AK8963 =2, +#endif DRIVER_BMM150 =3, DRIVER_LSM9DS1 =4, DRIVER_LIS3MDL =5, diff --git a/libraries/AP_Compass/AP_Compass_AK8963.cpp b/libraries/AP_Compass/AP_Compass_AK8963.cpp index bdb79f81ac..4c4ced9e3f 100644 --- a/libraries/AP_Compass/AP_Compass_AK8963.cpp +++ b/libraries/AP_Compass/AP_Compass_AK8963.cpp @@ -12,13 +12,17 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + +#include "AP_Compass_AK8963.h" + +#if AP_COMPASS_AK8963_ENABLED + #include #include #include #include -#include "AP_Compass_AK8963.h" #include #define AK8963_I2C_ADDR 0x0c @@ -400,3 +404,5 @@ uint32_t AP_AK8963_BusDriver_Auxiliary::get_bus_id(void) const { return _bus->get_bus_id(); } + +#endif // AP_COMPASS_AK8963_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_AK8963.h b/libraries/AP_Compass/AP_Compass_AK8963.h index f754da8d81..7b61768d84 100644 --- a/libraries/AP_Compass/AP_Compass_AK8963.h +++ b/libraries/AP_Compass/AP_Compass_AK8963.h @@ -1,5 +1,9 @@ #pragma once +#include "AP_Compass_config.h" + +#if AP_COMPASS_AK8963_ENABLED + #include #include #include @@ -136,3 +140,5 @@ private: AuxiliaryBusSlave *_slave; bool _started; }; + +#endif // AP_COMPASS_AK8963_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_config.h b/libraries/AP_Compass/AP_Compass_config.h index b522ef95b2..9aea7c9b32 100644 --- a/libraries/AP_Compass/AP_Compass_config.h +++ b/libraries/AP_Compass/AP_Compass_config.h @@ -34,6 +34,10 @@ #define AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED AP_COMPASS_BACKEND_DEFAULT_ENABLED #endif +#ifndef AP_COMPASS_AK8963_ENABLED +#define AP_COMPASS_AK8963_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED +#endif + #ifndef AP_COMPASS_HMC5843_ENABLED #define AP_COMPASS_HMC5843_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED #endif