drivers/magnetometer: ist8310: more efficient probe()

This commit is contained in:
Jacob Dahl
2024-06-17 13:01:14 -08:00
committed by GitHub
parent 377e2d7523
commit 8a08418a1f

View File

@@ -85,19 +85,27 @@ void IST8310::print_status()
int IST8310::probe()
{
// Apparently, the IST8310's WHOAMI register is writeable. Presumably,
// this can get corrupted by bus noise. It is only reset if powered off
// for 30s or by a reset.
//
// Therefore, we do a reset before doing the WHOAMI.
RegisterWrite(Register::CNTL2, CNTL2_BIT::SRST);
uint8_t id = RegisterRead(Register::WAI);
px4_usleep(10000);
if (id != Device_ID) {
DEVICE_DEBUG("unexpected WAI 0x%02x", id);
const uint8_t WAI = RegisterRead(Register::WAI);
// Apparently, the IST8310's WHOAMI register is writeable. Presumably,
// this can get corrupted by bus noise. It is only reset if powered off
// for 30s or by a reset.
RegisterWrite(Register::CNTL2, CNTL2_BIT::SRST);
auto start_time = hrt_absolute_time();
while (hrt_elapsed_time(&start_time) < 50_ms) {
px4_usleep(10'000);
id = RegisterRead(Register::WAI);
if (id == Device_ID) {
return PX4_OK;
}
}
if (WAI != Device_ID) {
DEVICE_DEBUG("unexpected WAI 0x%02x", WAI);
return PX4_ERROR;
}