mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
AK09916: add support for AK09918
The AK09918 seems to only differ in the WHO_AM_I ID. Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
@@ -78,6 +78,7 @@ bool AK09916::Reset()
|
|||||||
void AK09916::print_status()
|
void AK09916::print_status()
|
||||||
{
|
{
|
||||||
I2CSPIDriverBase::print_status();
|
I2CSPIDriverBase::print_status();
|
||||||
|
PX4_INFO("Variant: %s", _is_ak09918 ? "AK09918" : "AK09916");
|
||||||
|
|
||||||
perf_print_counter(_reset_perf);
|
perf_print_counter(_reset_perf);
|
||||||
perf_print_counter(_bad_register_perf);
|
perf_print_counter(_bad_register_perf);
|
||||||
@@ -94,15 +95,21 @@ int AK09916::probe()
|
|||||||
const uint8_t WIA2 = RegisterRead(Register::WIA2);
|
const uint8_t WIA2 = RegisterRead(Register::WIA2);
|
||||||
|
|
||||||
if ((WIA1 == Company_ID) && (WIA2 == Device_ID)) {
|
if ((WIA1 == Company_ID) && (WIA2 == Device_ID)) {
|
||||||
|
_is_ak09918 = false;
|
||||||
|
return PX4_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((WIA1 == Company_ID) && (WIA2 == Device_ID_AK09918)) {
|
||||||
|
_is_ak09918 = true;
|
||||||
return PX4_OK;
|
return PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WIA1 != Company_ID) {
|
if (WIA1 != Company_ID) {
|
||||||
DEVICE_DEBUG("unexpected WIA1 0x%02x", WIA1);
|
PX4_DEBUG("unexpected WIA1 0x%02x", WIA1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WIA2 != Device_ID) {
|
if (WIA2 != Device_ID && WIA2 != Device_ID_AK09918) {
|
||||||
DEVICE_DEBUG("unexpected WIA2 0x%02x", WIA2);
|
PX4_DEBUG("unexpected WIA2 0x%02x", WIA2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,25 +131,28 @@ void AK09916::RunImpl()
|
|||||||
ScheduleDelayed(100_ms);
|
ScheduleDelayed(100_ms);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE::WAIT_FOR_RESET:
|
case STATE::WAIT_FOR_RESET: {
|
||||||
if ((RegisterRead(Register::WIA1) == Company_ID) && (RegisterRead(Register::WIA2) == Device_ID)) {
|
uint8_t device_id = _is_ak09918 ? Device_ID_AK09918 : Device_ID;
|
||||||
// if reset succeeded then configure
|
|
||||||
_state = STATE::CONFIGURE;
|
|
||||||
ScheduleDelayed(100_ms);
|
|
||||||
|
|
||||||
} else {
|
if ((RegisterRead(Register::WIA1) == Company_ID) && (RegisterRead(Register::WIA2) == device_id)) {
|
||||||
// RESET not complete
|
// if reset succeeded then configure
|
||||||
if (hrt_elapsed_time(&_reset_timestamp) > 30_s) {
|
_state = STATE::CONFIGURE;
|
||||||
PX4_ERR("Reset failed, retrying");
|
ScheduleDelayed(100_ms);
|
||||||
Reset();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_DEBUG("Reset not complete, check again in 100 ms");
|
// RESET not complete
|
||||||
ScheduleDelayed(100_ms);
|
if (hrt_elapsed_time(&_reset_timestamp) > 30_s) {
|
||||||
}
|
PX4_ERR("Reset failed, retrying");
|
||||||
}
|
Reset();
|
||||||
|
|
||||||
break;
|
} else {
|
||||||
|
PX4_DEBUG("Reset not complete, check again in 100 ms");
|
||||||
|
ScheduleDelayed(100_ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case STATE::CONFIGURE:
|
case STATE::CONFIGURE:
|
||||||
if (Configure()) {
|
if (Configure()) {
|
||||||
|
|||||||
@@ -106,4 +106,6 @@ private:
|
|||||||
// Register | Set bits, Clear bits
|
// Register | Set bits, Clear bits
|
||||||
{ Register::CNTL2, CNTL2_BIT::MODE3_SET, CNTL2_BIT::MODE3_CLEAR },
|
{ Register::CNTL2, CNTL2_BIT::MODE3_SET, CNTL2_BIT::MODE3_CLEAR },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool _is_ak09918 {false};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0b0001100;
|
|||||||
|
|
||||||
static constexpr uint8_t Company_ID = 0x48;
|
static constexpr uint8_t Company_ID = 0x48;
|
||||||
static constexpr uint8_t Device_ID = 0x09;
|
static constexpr uint8_t Device_ID = 0x09;
|
||||||
|
static constexpr uint8_t Device_ID_AK09918 = 0x0C;
|
||||||
|
|
||||||
enum class Register : uint8_t {
|
enum class Register : uint8_t {
|
||||||
WIA1 = 0x00, // Company ID of AKM
|
WIA1 = 0x00, // Company ID of AKM
|
||||||
|
|||||||
Reference in New Issue
Block a user