AP_Compass: added AK09918 support

minor update over AK09916
This commit is contained in:
Andrew Tridgell 2021-10-06 07:12:27 +11:00
parent 32731e2cd0
commit 613f970870
3 changed files with 13 additions and 4 deletions

View File

@ -50,6 +50,7 @@ extern const AP_HAL::HAL &hal;
#define ICM_WHOAMI_VAL 0xEA
#define AK09916_Device_ID 0x09
#define AK09918_Device_ID 0x0c
#define AK09916_MILLIGAUSS_SCALE 10.0f
extern const AP_HAL::HAL &hal;
@ -227,7 +228,7 @@ bool AP_Compass_AK09916::init()
_initialized = true;
/* register the compass instance in the frontend */
_bus->set_device_type(DEVTYPE_AK09916);
_bus->set_device_type(_devtype);
if (!register_compass(_bus->get_bus_id(), _compass_instance)) {
goto fail;
}
@ -315,9 +316,15 @@ bool AP_Compass_AK09916::_check_id()
uint8_t deviceid = 0;
/* Read AK09916's id */
if (_bus->register_read(REG_DEVICE_ID, &deviceid) &&
deviceid == AK09916_Device_ID) {
return true;
if (_bus->register_read(REG_DEVICE_ID, &deviceid)) {
switch (deviceid) {
case AK09916_Device_ID:
_devtype = DEVTYPE_AK09916;
return true;
case AK09918_Device_ID:
_devtype = DEVTYPE_AK09918;
return true;
}
}
}

View File

@ -82,6 +82,7 @@ private:
uint8_t _compass_instance;
bool _initialized;
enum Rotation _rotation;
enum AP_Compass_Backend::DevTypes _devtype;
};

View File

@ -65,6 +65,7 @@ public:
DEVTYPE_RM3100 = 0x11,
DEVTYPE_RM3100_2 = 0x12, // unused, past mistake
DEVTYPE_MMC5883 = 0x13,
DEVTYPE_AK09918 = 0x14,
};
#if HAL_MSP_COMPASS_ENABLED