From b26d771c9f2c4028e3ff16a2b267242f35bdf06c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 10 Feb 2023 12:48:02 +1100 Subject: [PATCH] AP_Compass: add and use AP_COMPASS_IST8310_ENABLED --- libraries/AP_Compass/AP_Compass.cpp | 6 ++++-- libraries/AP_Compass/AP_Compass.h | 2 ++ libraries/AP_Compass/AP_Compass_IST8310.cpp | 4 ++++ libraries/AP_Compass/AP_Compass_IST8310.h | 7 ++++++- libraries/AP_Compass/AP_Compass_config.h | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libraries/AP_Compass/AP_Compass.cpp b/libraries/AP_Compass/AP_Compass.cpp index f31655cdfb..14a7f5986b 100644 --- a/libraries/AP_Compass/AP_Compass.cpp +++ b/libraries/AP_Compass/AP_Compass.cpp @@ -1168,7 +1168,7 @@ void Compass::_probe_external_i2c_compasses(void) #endif #endif -#if AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED || defined(HAL_USE_I2C_MAG_IST8310) +#if AP_COMPASS_IST8310_ENABLED // IST8310 on external and internal bus if (AP_BoardConfig::get_board_type() != AP_BoardConfig::PX4_BOARD_FMUV5 && AP_BoardConfig::get_board_type() != AP_BoardConfig::PX4_BOARD_FMUV6) { @@ -1195,7 +1195,7 @@ void Compass::_probe_external_i2c_compasses(void) #endif } } -#endif +#endif // AP_COMPASS_IST8310_ENABLED #if AP_COMPASS_IST8308_ENABLED // external i2c bus @@ -1380,6 +1380,7 @@ void Compass::_detect_backends(void) case AP_BoardConfig::PX4_BOARD_FMUV5: case AP_BoardConfig::PX4_BOARD_FMUV6: +#if AP_COMPASS_IST8310_ENABLED FOREACH_I2C_EXTERNAL(i) { ADD_BACKEND(DRIVER_IST8310, AP_Compass_IST8310::probe(GET_I2C_DEVICE(i, HAL_COMPASS_IST8310_I2C_ADDR), true, ROTATION_ROLL_180_YAW_90)); @@ -1388,6 +1389,7 @@ void Compass::_detect_backends(void) ADD_BACKEND(DRIVER_IST8310, AP_Compass_IST8310::probe(GET_I2C_DEVICE(i, HAL_COMPASS_IST8310_I2C_ADDR), false, ROTATION_ROLL_180_YAW_90)); } +#endif // AP_COMPASS_IST8310_ENABLED break; case AP_BoardConfig::PX4_BOARD_SP01: diff --git a/libraries/AP_Compass/AP_Compass.h b/libraries/AP_Compass/AP_Compass.h index 6799eb06c5..b484f62652 100644 --- a/libraries/AP_Compass/AP_Compass.h +++ b/libraries/AP_Compass/AP_Compass.h @@ -429,7 +429,9 @@ private: DRIVER_LSM9DS1 =4, DRIVER_LIS3MDL =5, DRIVER_AK09916 =6, +#if AP_COMPASS_IST8310_ENABLED DRIVER_IST8310 =7, +#endif DRIVER_ICM20948 =8, DRIVER_MMC3416 =9, DRIVER_UAVCAN =11, diff --git a/libraries/AP_Compass/AP_Compass_IST8310.cpp b/libraries/AP_Compass/AP_Compass_IST8310.cpp index 7a0769761d..be982a93c6 100644 --- a/libraries/AP_Compass/AP_Compass_IST8310.cpp +++ b/libraries/AP_Compass/AP_Compass_IST8310.cpp @@ -18,6 +18,8 @@ */ #include "AP_Compass_IST8310.h" +#if AP_COMPASS_IST8310_ENABLED + #include #include @@ -236,3 +238,5 @@ void AP_Compass_IST8310::read() { drain_accumulated_samples(_instance); } + +#endif // AP_COMPASS_IST8310_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_IST8310.h b/libraries/AP_Compass/AP_Compass_IST8310.h index e206c94961..abc01e0df8 100644 --- a/libraries/AP_Compass/AP_Compass_IST8310.h +++ b/libraries/AP_Compass/AP_Compass_IST8310.h @@ -16,12 +16,15 @@ */ #pragma once +#include "AP_Compass_config.h" + +#if AP_COMPASS_IST8310_ENABLED + #include #include #include #include -#include "AP_Compass.h" #include "AP_Compass_Backend.h" #ifndef HAL_COMPASS_IST8310_I2C_ADDR @@ -56,3 +59,5 @@ private: bool _ignore_next_sample; bool _force_external; }; + +#endif // AP_COMPASS_IST8310_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_config.h b/libraries/AP_Compass/AP_Compass_config.h index 28043bc619..41f643ace5 100644 --- a/libraries/AP_Compass/AP_Compass_config.h +++ b/libraries/AP_Compass/AP_Compass_config.h @@ -59,6 +59,10 @@ #define AP_COMPASS_IST8308_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED #endif +#ifndef AP_COMPASS_IST8310_ENABLED +#define AP_COMPASS_IST8310_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