From cbd1264f909bb60e52f903152418af4b8513bacb Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 27 Jan 2023 15:09:50 +1100 Subject: [PATCH] AP_Compass: add and use AP_COMPASS_LSM303D_ENABLED --- libraries/AP_Compass/AP_Compass.cpp | 6 ++++++ libraries/AP_Compass/AP_Compass.h | 2 ++ libraries/AP_Compass/AP_Compass_LSM303D.cpp | 9 +++++++-- libraries/AP_Compass/AP_Compass_LSM303D.h | 6 ++++++ libraries/AP_Compass/AP_Compass_config.h | 4 ++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Compass/AP_Compass.cpp b/libraries/AP_Compass/AP_Compass.cpp index 62b821efed..b986c4c4e5 100644 --- a/libraries/AP_Compass/AP_Compass.cpp +++ b/libraries/AP_Compass/AP_Compass.cpp @@ -1353,11 +1353,15 @@ void Compass::_detect_backends(void) case AP_BoardConfig::PX4_BOARD_PIXHAWK: ADD_BACKEND(DRIVER_HMC5843, AP_Compass_HMC5843::probe(hal.spi->get_device(HAL_COMPASS_HMC5843_NAME), false, ROTATION_PITCH_180)); +#if AP_COMPASS_LSM303D_ENABLED ADD_BACKEND(DRIVER_LSM303D, AP_Compass_LSM303D::probe(hal.spi->get_device(HAL_INS_LSM9DS0_A_NAME), ROTATION_NONE)); +#endif break; case AP_BoardConfig::PX4_BOARD_PIXHAWK2: +#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 // 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)); @@ -1401,7 +1405,9 @@ void Compass::_detect_backends(void) case AP_BoardConfig::PX4_BOARD_MINDPXV2: ADD_BACKEND(DRIVER_HMC5843, AP_Compass_HMC5843::probe(GET_I2C_DEVICE(0, HAL_COMPASS_HMC5843_I2C_ADDR), false, ROTATION_YAW_90)); +#if AP_COMPASS_LSM303D_ENABLED ADD_BACKEND(DRIVER_LSM303D, AP_Compass_LSM303D::probe(hal.spi->get_device(HAL_INS_LSM9DS0_A_NAME), ROTATION_PITCH_180_YAW_270)); +#endif break; default: diff --git a/libraries/AP_Compass/AP_Compass.h b/libraries/AP_Compass/AP_Compass.h index 074b94ead4..92a4919c2b 100644 --- a/libraries/AP_Compass/AP_Compass.h +++ b/libraries/AP_Compass/AP_Compass.h @@ -415,7 +415,9 @@ private: // enum of drivers for COMPASS_TYPEMASK enum DriverType { DRIVER_HMC5843 =0, +#if AP_COMPASS_LSM303D_ENABLED DRIVER_LSM303D =1, +#endif DRIVER_AK8963 =2, DRIVER_BMM150 =3, DRIVER_LSM9DS1 =4, diff --git a/libraries/AP_Compass/AP_Compass_LSM303D.cpp b/libraries/AP_Compass/AP_Compass_LSM303D.cpp index ec5910e8b7..c3a2e68217 100644 --- a/libraries/AP_Compass/AP_Compass_LSM303D.cpp +++ b/libraries/AP_Compass/AP_Compass_LSM303D.cpp @@ -12,13 +12,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + +#include "AP_Compass_LSM303D.h" + +#if AP_COMPASS_LSM303D_ENABLED + #include #include #include -#include "AP_Compass_LSM303D.h" - extern const AP_HAL::HAL &hal; #if CONFIG_HAL_BOARD == HAL_BOARD_LINUX @@ -428,3 +431,5 @@ bool AP_Compass_LSM303D::_mag_set_samplerate(uint16_t frequency) return true; } + +#endif // AP_COMPASS_LSM303D_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_LSM303D.h b/libraries/AP_Compass/AP_Compass_LSM303D.h index 7c72d41ede..328e0477e0 100644 --- a/libraries/AP_Compass/AP_Compass_LSM303D.h +++ b/libraries/AP_Compass/AP_Compass_LSM303D.h @@ -1,5 +1,9 @@ #pragma once +#include "AP_Compass_config.h" + +#if AP_COMPASS_LSM303D_ENABLED + #include #include #include @@ -53,3 +57,5 @@ private: uint8_t _mag_samplerate; uint8_t _reg7_expected; }; + +#endif // AP_COMPASS_LSM303D_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_config.h b/libraries/AP_Compass/AP_Compass_config.h index d10af7e9d8..37a6f97893 100644 --- a/libraries/AP_Compass/AP_Compass_config.h +++ b/libraries/AP_Compass/AP_Compass_config.h @@ -37,3 +37,7 @@ #ifndef AP_COMPASS_IST8308_ENABLED #define AP_COMPASS_IST8308_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED #endif + +#ifndef AP_COMPASS_LSM303D_ENABLED +#define AP_COMPASS_LSM303D_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED +#endif