From fe9461242e06aa8f74328ff1c7931990f5cd0687 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 14 Feb 2023 14:10:39 +1100 Subject: [PATCH] AP_Compass: add and use AP_COMPASS_LSM9DS1_ENABLED --- libraries/AP_Compass/AP_Compass.h | 2 ++ libraries/AP_Compass/AP_Compass_LSM9DS1.cpp | 9 ++++----- libraries/AP_Compass/AP_Compass_LSM9DS1.h | 7 ++++++- libraries/AP_Compass/AP_Compass_config.h | 4 ++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Compass/AP_Compass.h b/libraries/AP_Compass/AP_Compass.h index b484f62652..18966f3e64 100644 --- a/libraries/AP_Compass/AP_Compass.h +++ b/libraries/AP_Compass/AP_Compass.h @@ -426,7 +426,9 @@ private: #if AP_COMPASS_BMM150_ENABLED DRIVER_BMM150 =3, #endif +#if AP_COMPASS_LSM9DS1_ENABLED DRIVER_LSM9DS1 =4, +#endif DRIVER_LIS3MDL =5, DRIVER_AK09916 =6, #if AP_COMPASS_IST8310_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_LSM9DS1.cpp b/libraries/AP_Compass/AP_Compass_LSM9DS1.cpp index 3fb407e2d7..eeebe00fdc 100644 --- a/libraries/AP_Compass/AP_Compass_LSM9DS1.cpp +++ b/libraries/AP_Compass/AP_Compass_LSM9DS1.cpp @@ -1,13 +1,10 @@ +#include "AP_Compass_LSM9DS1.h" -#include -#include +#if AP_COMPASS_LSM9DS1_ENABLED #include #include -#include "AP_Compass_LSM9DS1.h" - - #define LSM9DS1M_OFFSET_X_REG_L_M 0x05 #define LSM9DS1M_OFFSET_X_REG_H_M 0x06 #define LSM9DS1M_OFFSET_Y_REG_L_M 0x07 @@ -234,3 +231,5 @@ void AP_Compass_LSM9DS1::_register_modify(uint8_t reg, uint8_t clearbits, uint8_ val |= setbits; _register_write(reg, val); } + +#endif diff --git a/libraries/AP_Compass/AP_Compass_LSM9DS1.h b/libraries/AP_Compass/AP_Compass_LSM9DS1.h index 587c598a0c..2cb91c74c6 100644 --- a/libraries/AP_Compass/AP_Compass_LSM9DS1.h +++ b/libraries/AP_Compass/AP_Compass_LSM9DS1.h @@ -1,11 +1,14 @@ #pragma once +#include "AP_Compass_config.h" + +#if AP_COMPASS_LSM9DS1_ENABLED + #include #include #include #include -#include "AP_Compass.h" #include "AP_Compass_Backend.h" class AP_Compass_LSM9DS1 : public AP_Compass_Backend @@ -40,3 +43,5 @@ private: float _scaling; enum Rotation _rotation; }; + +#endif diff --git a/libraries/AP_Compass/AP_Compass_config.h b/libraries/AP_Compass/AP_Compass_config.h index 41f643ace5..4e1e89f71c 100644 --- a/libraries/AP_Compass/AP_Compass_config.h +++ b/libraries/AP_Compass/AP_Compass_config.h @@ -66,3 +66,7 @@ #ifndef AP_COMPASS_LSM303D_ENABLED #define AP_COMPASS_LSM303D_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED #endif + +#ifndef AP_COMPASS_LSM9DS1_ENABLED +#define AP_COMPASS_LSM9DS1_ENABLED AP_COMPASS_I2C_BACKEND_DEFAULT_ENABLED +#endif