drivers: minimize additional I2C retries

This commit is contained in:
Daniel Agar
2021-06-27 12:52:36 -04:00
parent 8a8171c7aa
commit cb610caf1e
18 changed files with 44 additions and 109 deletions
@@ -72,20 +72,18 @@ int LPS22HB_I2C::probe()
{
uint8_t id = 0;
_retries = 10;
if (read(WHO_AM_I, &id, 1)) {
DEVICE_DEBUG("read_reg fail");
return -EIO;
}
_retries = 2;
if (id != LPS22HB_ID_WHO_AM_I) {
DEVICE_DEBUG("ID byte mismatch (%02x != %02x)", LPS22HB_ID_WHO_AM_I, id);
return -EIO;
}
_retries = 1;
return PX4_OK;
}
+2 -4
View File
@@ -71,20 +71,18 @@ int LPS25H_I2C::probe()
{
uint8_t id;
_retries = 10;
if (read(ADDR_WHO_AM_I, &id, 1)) {
DEVICE_DEBUG("read_reg fail");
return -EIO;
}
_retries = 2;
if (id != ID_WHO_AM_I) {
DEVICE_DEBUG("ID byte mismatch (%02x != %02x)", ID_WHO_AM_I, id);
return -EIO;
}
_retries = 1;
return OK;
}
+3 -11
View File
@@ -85,18 +85,15 @@ int MPL3115A2::init()
int MPL3115A2::probe()
{
_retries = 10;
uint8_t whoami = 0;
if ((RegisterRead(MPL3115A2_REG_WHO_AM_I, &whoami) > 0) && (whoami == MPL3115A2_WHO_AM_I)) {
/*
* Disable retries; we may enable them selectively in some cases,
* but the device gets confused if we retry some of the commands.
*/
_retries = 0;
return PX4_OK;
}
_retries = 1;
return -EIO;
}
@@ -198,11 +195,6 @@ int MPL3115A2::measure()
// Send the command to read the ADC for P and T.
unsigned addr = (MPL3115A2_CTRL_REG1 << 8) | MPL3115A2_CTRL_TRIGGER;
/*
* Disable retries on this command; we can't know whether failure
* means the device did or did not see the command.
*/
_retries = 0;
int ret = RegisterWrite((addr >> 8) & 0xff, addr & 0xff);
if (ret == -EIO) {
+4 -14
View File
@@ -141,18 +141,14 @@ MS5611_I2C::ioctl(unsigned operation, unsigned &arg)
int
MS5611_I2C::probe()
{
_retries = 10;
if ((PX4_OK == _probe_address(MS5611_ADDRESS_1)) ||
(PX4_OK == _probe_address(MS5611_ADDRESS_2))) {
/*
* Disable retries; we may enable them selectively in some cases,
* but the device gets confused if we retry some of the commands.
*/
_retries = 0;
return PX4_OK;
}
_retries = 1;
return -EIO;
}
@@ -183,7 +179,7 @@ MS5611_I2C::_reset()
int result;
/* bump the retry count */
_retries = 10;
_retries = 3;
result = transfer(&cmd, 1, nullptr, 0);
_retries = old_retrycount;
@@ -193,12 +189,6 @@ MS5611_I2C::_reset()
int
MS5611_I2C::_measure(unsigned addr)
{
/*
* Disable retries on this command; we can't know whether failure
* means the device did or did not see the command.
*/
_retries = 0;
uint8_t cmd = addr;
return transfer(&cmd, 1, nullptr, 0);
}