AP_Compass: add support for ICM20948 I2C variant and rename existing one as SPI variant

Author: Charles Villard <charlesvillard10@gmail.com>
Author: Buzz <davidbuzz@gmail.com>
This commit is contained in:
Buzz 2021-10-27 18:06:32 +10:00 committed by Andrew Tridgell
parent 98849a3998
commit 8d9f161b40
2 changed files with 34 additions and 2 deletions

View File

@ -168,8 +168,15 @@ fail:
return nullptr;
}
// un-named, assume SPI for compat
AP_Compass_Backend *AP_Compass_AK09916::probe_ICM20948(uint8_t inv2_instance,
enum Rotation rotation)
{
return probe_ICM20948_SPI(inv2_instance,rotation);
}
AP_Compass_Backend *AP_Compass_AK09916::probe_ICM20948_SPI(uint8_t inv2_instance,
enum Rotation rotation)
{
#if HAL_INS_ENABLED
AP_InertialSensor &ins = AP::ins();
@ -192,6 +199,26 @@ AP_Compass_Backend *AP_Compass_AK09916::probe_ICM20948(uint8_t inv2_instance,
#endif
}
AP_Compass_Backend *AP_Compass_AK09916::probe_ICM20948_I2C(uint8_t inv2_instance,
enum Rotation rotation)
{
AP_InertialSensor &ins = AP::ins();
AP_AK09916_BusDriver *bus =
new AP_AK09916_BusDriver_Auxiliary(ins, HAL_INS_INV2_I2C, inv2_instance, HAL_COMPASS_AK09916_I2C_ADDR);
if (!bus) {
return nullptr;
}
AP_Compass_AK09916 *sensor = new AP_Compass_AK09916(bus, false, rotation);
if (!sensor || !sensor->init()) {
delete sensor;
return nullptr;
}
return sensor;
}
bool AP_Compass_AK09916::init()
{
AP_HAL::Semaphore *bus_sem = _bus->get_semaphore();

View File

@ -54,8 +54,13 @@ public:
bool force_external,
enum Rotation rotation);
/* Probe for AK09916 on auxiliary bus of ICM20948, connected through SPI */
static AP_Compass_Backend *probe_ICM20948(uint8_t mpu9250_instance,
/* Probe for AK09916 on auxiliary bus of ICM20948, connected through SPI by default */
static AP_Compass_Backend *probe_ICM20948(uint8_t mpu9250_instance, enum Rotation rotation);
static AP_Compass_Backend *probe_ICM20948_SPI(uint8_t mpu9250_instance,
enum Rotation rotation);
/* Probe for AK09916 on auxiliary bus of ICM20948, connected through I2C */
static AP_Compass_Backend *probe_ICM20948_I2C(uint8_t mpu9250_instance,
enum Rotation rotation);
static constexpr const char *name = "AK09916";