Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Compass: add and use AP_COMPASS_LSM303D_ENABLED #22753

Merged
merged 3 commits into from Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion Tools/autotest/test_build_options.py
Expand Up @@ -64,7 +64,10 @@ def __init__(self,
def must_have_defines_for_board(self, board):
'''return a set of defines which must always be enabled'''
must_have_defines = {
"CubeOrange": frozenset(['AP_BARO_MS56XX_ENABLED'])
"CubeOrange": frozenset([
'AP_BARO_MS56XX_ENABLED',
'AP_COMPASS_LSM303D_ENABLED',
tridge marked this conversation as resolved.
Show resolved Hide resolved
])
}
return must_have_defines.get(board, frozenset([]))

Expand Down
6 changes: 6 additions & 0 deletions libraries/AP_Compass/AP_Compass.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions libraries/AP_Compass/AP_Compass.h
Expand Up @@ -415,7 +415,9 @@ friend class AP_Compass_Backend;
// 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,
Expand All @@ -428,7 +430,9 @@ friend class AP_Compass_Backend;
DRIVER_QMC5883L =12,
DRIVER_SITL =13,
DRIVER_MAG3110 =14,
#if AP_COMPASS_IST8308_ENABLED
DRIVER_IST8308 =15,
#endif
DRIVER_RM3100 =16,
DRIVER_MSP =17,
DRIVER_SERIAL =18,
Expand Down
9 changes: 7 additions & 2 deletions libraries/AP_Compass/AP_Compass_LSM303D.cpp
Expand Up @@ -12,13 +12,16 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "AP_Compass_LSM303D.h"

#if AP_COMPASS_LSM303D_ENABLED

#include <utility>

#include <AP_HAL/AP_HAL.h>
#include <AP_Math/AP_Math.h>

#include "AP_Compass_LSM303D.h"

extern const AP_HAL::HAL &hal;

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
Expand Down Expand Up @@ -428,3 +431,5 @@ bool AP_Compass_LSM303D::_mag_set_samplerate(uint16_t frequency)

return true;
}

#endif // AP_COMPASS_LSM303D_ENABLED
6 changes: 6 additions & 0 deletions libraries/AP_Compass/AP_Compass_LSM303D.h
@@ -1,5 +1,9 @@
#pragma once

#include "AP_Compass_config.h"

#if AP_COMPASS_LSM303D_ENABLED

#include <AP_Common/AP_Common.h>
#include <AP_HAL/AP_HAL.h>
#include <AP_HAL/Device.h>
Expand Down Expand Up @@ -53,3 +57,5 @@ class AP_Compass_LSM303D : public AP_Compass_Backend
uint8_t _mag_samplerate;
uint8_t _reg7_expected;
};

#endif // AP_COMPASS_LSM303D_ENABLED
4 changes: 4 additions & 0 deletions libraries/AP_Compass/AP_Compass_config.h
Expand Up @@ -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