mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-23 06:36:45 +08:00
drivers/magnetometer/ak09916: Add support to AK09915 (#23909)
The only difference between the ak09915 and ak09916 is the communication method Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f9c4c8b22c
commit
bc8f98c9ad
@@ -78,7 +78,7 @@ bool AK09916::Reset()
|
||||
void AK09916::print_status()
|
||||
{
|
||||
I2CSPIDriverBase::print_status();
|
||||
PX4_INFO("Variant: %s", _is_ak09918 ? "AK09918" : "AK09916");
|
||||
PX4_INFO("Variant: %s", device_name());
|
||||
|
||||
perf_print_counter(_reset_perf);
|
||||
perf_print_counter(_bad_register_perf);
|
||||
@@ -94,23 +94,28 @@ int AK09916::probe()
|
||||
const uint8_t WIA1 = RegisterRead(Register::WIA1);
|
||||
const uint8_t WIA2 = RegisterRead(Register::WIA2);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (WIA1 != Company_ID) {
|
||||
if ((WIA1 != Company_ID)) {
|
||||
PX4_DEBUG("unexpected WIA1 0x%02x", WIA1);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
if (WIA2 != Device_ID && WIA2 != Device_ID_AK09918) {
|
||||
switch (static_cast<AKTYPE>(WIA2)) {
|
||||
case AKTYPE::AK09916:
|
||||
_device = AKTYPE::AK09916;
|
||||
return PX4_OK;
|
||||
|
||||
case AKTYPE::AK09915:
|
||||
_device = AKTYPE::AK09915;
|
||||
return PX4_OK;
|
||||
|
||||
case AKTYPE::AK09918:
|
||||
_device = AKTYPE::AK09918;
|
||||
return PX4_OK;
|
||||
|
||||
default:
|
||||
PX4_DEBUG("unexpected WIA2 0x%02x", WIA2);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
return PX4_ERROR;
|
||||
@@ -132,9 +137,7 @@ void AK09916::RunImpl()
|
||||
break;
|
||||
|
||||
case STATE::WAIT_FOR_RESET: {
|
||||
uint8_t device_id = _is_ak09918 ? Device_ID_AK09918 : Device_ID;
|
||||
|
||||
if ((RegisterRead(Register::WIA1) == Company_ID) && (RegisterRead(Register::WIA2) == device_id)) {
|
||||
if ((RegisterRead(Register::WIA1) == Company_ID) && (static_cast<AKTYPE>(RegisterRead(Register::WIA2)) == _device)) {
|
||||
// if reset succeeded then configure
|
||||
_state = STATE::CONFIGURE;
|
||||
ScheduleDelayed(100_ms);
|
||||
|
||||
@@ -64,6 +64,30 @@ public:
|
||||
void print_status() override;
|
||||
|
||||
private:
|
||||
enum class AKTYPE : uint8_t {
|
||||
AK09916 = 0X09,
|
||||
AK09915 = 0X10,
|
||||
AK09918 = 0x0c,
|
||||
};
|
||||
|
||||
constexpr char const *device_name()
|
||||
{
|
||||
switch (_device) {
|
||||
case AKTYPE::AK09916:
|
||||
return "AK09916";
|
||||
|
||||
case AKTYPE::AK09915:
|
||||
return "AK09915";
|
||||
|
||||
case AKTYPE::AK09918:
|
||||
return "AK09918";
|
||||
|
||||
default:
|
||||
return "Unknown";
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
struct register_config_t {
|
||||
Register reg;
|
||||
uint8_t set_bits{0};
|
||||
@@ -107,5 +131,5 @@ private:
|
||||
{ Register::CNTL2, CNTL2_BIT::MODE3_SET, CNTL2_BIT::MODE3_CLEAR },
|
||||
};
|
||||
|
||||
bool _is_ak09918 {false};
|
||||
AKTYPE _device;
|
||||
};
|
||||
|
||||
@@ -59,8 +59,6 @@ static constexpr uint32_t I2C_SPEED = 400 * 1000; // 400 kHz I2C serial interfac
|
||||
static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0b0001100;
|
||||
|
||||
static constexpr uint8_t Company_ID = 0x48;
|
||||
static constexpr uint8_t Device_ID = 0x09;
|
||||
static constexpr uint8_t Device_ID_AK09918 = 0x0C;
|
||||
|
||||
enum class Register : uint8_t {
|
||||
WIA1 = 0x00, // Company ID of AKM
|
||||
|
||||
Reference in New Issue
Block a user