diff --git a/libraries/AP_Compass/AP_Compass.h b/libraries/AP_Compass/AP_Compass.h
index d57d7f801e..74050904c0 100644
--- a/libraries/AP_Compass/AP_Compass.h
+++ b/libraries/AP_Compass/AP_Compass.h
@@ -453,7 +453,9 @@ private:
#if AP_COMPASS_SITL_ENABLED
DRIVER_SITL =13,
#endif
+#if AP_COMPASS_MAG3110_ENABLED
DRIVER_MAG3110 =14,
+#endif
#if AP_COMPASS_IST8308_ENABLED
DRIVER_IST8308 =15,
#endif
diff --git a/libraries/AP_Compass/AP_Compass_MAG3110.cpp b/libraries/AP_Compass/AP_Compass_MAG3110.cpp
index 37cc16761c..69ae611c82 100644
--- a/libraries/AP_Compass/AP_Compass_MAG3110.cpp
+++ b/libraries/AP_Compass/AP_Compass_MAG3110.cpp
@@ -12,14 +12,16 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+#include "AP_Compass_MAG3110.h"
+
+#if AP_COMPASS_MAG3110_ENABLED
+
#include
#include
#include
#include
-#include "AP_Compass_MAG3110.h"
-
extern const AP_HAL::HAL &hal;
@@ -219,3 +221,5 @@ void AP_Compass_MAG3110::read()
drain_accumulated_samples(_compass_instance);
}
+
+#endif // AP_COMPASS_MAG3110_ENABLED
diff --git a/libraries/AP_Compass/AP_Compass_MAG3110.h b/libraries/AP_Compass/AP_Compass_MAG3110.h
index 41b27b12e1..80167ba38d 100644
--- a/libraries/AP_Compass/AP_Compass_MAG3110.h
+++ b/libraries/AP_Compass/AP_Compass_MAG3110.h
@@ -1,5 +1,9 @@
#pragma once
+#include "AP_Compass_config.h"
+
+#if AP_COMPASS_MAG3110_ENABLED
+
#include
#include
#include
@@ -44,3 +48,5 @@ private:
uint8_t _compass_instance;
bool _initialised;
};
+
+#endif // AP_COMPASS_MAG3110_ENABLED
diff --git a/libraries/AP_Compass/AP_Compass_config.h b/libraries/AP_Compass/AP_Compass_config.h
index 0332e7f1fa..a42fe8126b 100644
--- a/libraries/AP_Compass/AP_Compass_config.h
+++ b/libraries/AP_Compass/AP_Compass_config.h
@@ -83,6 +83,10 @@
#define AP_COMPASS_LSM9DS1_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED
#endif
+#ifndef AP_COMPASS_MAG3110_ENABLED
+#define AP_COMPASS_MAG3110_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED
+#endif
+
#ifndef AP_COMPASS_MMC3416_ENABLED
#define AP_COMPASS_MMC3416_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED
#endif