mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-02 09:40:06 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 230e7bdbc6 | |||
| 9ae942c67a | |||
| 6f2feac880 | |||
| 4f9948d1de |
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019-2020 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2019-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -87,21 +87,26 @@ void AK09916::print_status()
|
||||
|
||||
int AK09916::probe()
|
||||
{
|
||||
const uint8_t WIA1 = RegisterRead(Register::WIA1);
|
||||
for (int retry = 0; retry < 3; retry++) {
|
||||
const uint8_t WIA1 = RegisterRead(Register::WIA1);
|
||||
const uint8_t WIA2 = RegisterRead(Register::WIA2);
|
||||
|
||||
if (WIA1 != Company_ID) {
|
||||
DEVICE_DEBUG("unexpected WIA1 0x%02x", WIA1);
|
||||
return PX4_ERROR;
|
||||
if ((WIA1 == Company_ID) && (WIA2 == Device_ID)) {
|
||||
return PX4_OK;
|
||||
|
||||
} else if (WIA1 != Company_ID) {
|
||||
DEVICE_DEBUG("unexpected WIA1 0x%02x", WIA1);
|
||||
|
||||
} else if (WIA2 != Device_ID) {
|
||||
DEVICE_DEBUG("unexpected WIA2 0x%02x", WIA2);
|
||||
}
|
||||
|
||||
if (retry > 0) {
|
||||
_retries = 1;
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t WIA2 = RegisterRead(Register::WIA2);
|
||||
|
||||
if (WIA2 != Device_ID) {
|
||||
DEVICE_DEBUG("unexpected WIA2 0x%02x", WIA2);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
return PX4_OK;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
void AK09916::RunImpl()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2020-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -87,14 +87,22 @@ void AK8963::print_status()
|
||||
|
||||
int AK8963::probe()
|
||||
{
|
||||
const uint8_t WIA = RegisterRead(Register::WIA);
|
||||
for (int retry = 0; retry < 3; retry++) {
|
||||
const uint8_t WIA = RegisterRead(Register::WIA);
|
||||
|
||||
if (WIA != Device_ID) {
|
||||
DEVICE_DEBUG("unexpected WIA 0x%02x", WIA);
|
||||
return PX4_ERROR;
|
||||
if (WIA == Device_ID) {
|
||||
return PX4_OK;
|
||||
|
||||
} else {
|
||||
DEVICE_DEBUG("unexpected WIA 0x%02x", WIA);
|
||||
}
|
||||
|
||||
if (retry > 0) {
|
||||
_retries = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return PX4_OK;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
void AK8963::RunImpl()
|
||||
|
||||
@@ -86,7 +86,7 @@ void BMM150::print_status()
|
||||
int BMM150::probe()
|
||||
{
|
||||
// 3 retries
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int retry = 0; retry < 3; retry++) {
|
||||
const uint8_t POWER_CONTROL = RegisterRead(Register::POWER_CONTROL);
|
||||
const uint8_t CHIP_ID = RegisterRead(Register::CHIP_ID);
|
||||
|
||||
@@ -99,6 +99,10 @@ int BMM150::probe()
|
||||
// in suspend Chip ID read (register 0x40) returns “0x00” (I²C) or high-Z (SPI).
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
if (retry > 0) {
|
||||
_retries = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return PX4_ERROR;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2020-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -85,14 +85,22 @@ void IST8310::print_status()
|
||||
|
||||
int IST8310::probe()
|
||||
{
|
||||
const uint8_t WAI = RegisterRead(Register::WAI);
|
||||
for (int retry = 0; retry < 3; retry++) {
|
||||
const uint8_t WAI = RegisterRead(Register::WAI);
|
||||
|
||||
if (WAI != Device_ID) {
|
||||
DEVICE_DEBUG("unexpected WAI 0x%02x", WAI);
|
||||
return PX4_ERROR;
|
||||
if (WAI == Device_ID) {
|
||||
return PX4_OK;
|
||||
|
||||
} else {
|
||||
DEVICE_DEBUG("unexpected WAI 0x%02x", WAI);
|
||||
}
|
||||
|
||||
if (retry > 0) {
|
||||
_retries = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return PX4_OK;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
void IST8310::RunImpl()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2020-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -85,9 +85,7 @@ void QMC5883L::print_status()
|
||||
|
||||
int QMC5883L::probe()
|
||||
{
|
||||
_retries = 1;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int retry = 0; retry < 3; retry++) {
|
||||
// first read 0x0 once
|
||||
const uint8_t cmd = 0;
|
||||
uint8_t buffer{};
|
||||
@@ -99,6 +97,10 @@ int QMC5883L::probe()
|
||||
return PX4_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (retry > 0) {
|
||||
_retries = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return PX4_ERROR;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2021 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2021-2022 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -85,9 +85,7 @@ void VCM1193L::print_status()
|
||||
|
||||
int VCM1193L::probe()
|
||||
{
|
||||
_retries = 1;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int retry = 0; retry < 3; retry++) {
|
||||
// first read 0x0 once
|
||||
const uint8_t cmd = 0;
|
||||
uint8_t buffer{};
|
||||
@@ -99,6 +97,10 @@ int VCM1193L::probe()
|
||||
return PX4_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (retry > 0) {
|
||||
_retries = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return PX4_ERROR;
|
||||
|
||||
@@ -216,6 +216,29 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const
|
||||
int ret_transfer = I2C_TRANSFER(_dev, &msgv[0], msgs);
|
||||
|
||||
if (ret_transfer != 0) {
|
||||
|
||||
switch (ret_transfer) {
|
||||
case -EAGAIN:
|
||||
PX4_WARN("I2C bus: %d, Addr: %X, Arbitration Lost", get_device_bus(), get_device_address());
|
||||
break;
|
||||
|
||||
case -EIO:
|
||||
PX4_WARN("I2C bus: %d, Addr: %X, Overrun/Underrun", get_device_bus(), get_device_address());
|
||||
break;
|
||||
|
||||
case -EADDRNOTAVAIL:
|
||||
//PX4_WARN("I2C bus: %d, Addr: %X, Address NACK", get_device_bus(), get_device_address());
|
||||
break;
|
||||
|
||||
case -ECOMM:
|
||||
PX4_WARN("I2C bus: %d, Addr: %X, Data NACK", get_device_bus(), get_device_address());
|
||||
break;
|
||||
|
||||
case -EBUSY:
|
||||
PX4_WARN("I2C bus: %d, Addr: %X, Bus busy", get_device_bus(), get_device_address());
|
||||
break;
|
||||
}
|
||||
|
||||
DEVICE_DEBUG("I2C transfer failed, result %d", ret_transfer);
|
||||
ret = PX4_ERROR;
|
||||
|
||||
@@ -225,9 +248,10 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const
|
||||
break;
|
||||
}
|
||||
|
||||
/* if we have already retried once, or we are going to give up, then reset the bus */
|
||||
if ((retry_count >= 1) || (retry_count >= _retries)) {
|
||||
// if we have already retried once, and we aren't going to give up, then reset the bus
|
||||
if ((retry_count >= 1) && (retry_count < _retries)) {
|
||||
#if defined(CONFIG_I2C_RESET)
|
||||
PX4_WARN("I2C bus: %d, Addr: %X, I2C_RESET %d/%d", get_device_bus(), get_device_address(), retry_count, _retries);
|
||||
I2C_RESET(_dev);
|
||||
#endif // CONFIG_I2C_RESET
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user