mirror of https://github.com/ARMmbed/mbed-os.git
Addressed review comments
parent
a30da7e61e
commit
0ef5d92d92
|
|
@ -145,22 +145,20 @@ int I2C::recover(PinName sda, PinName scl)
|
||||||
DigitalInOut pin_sda(sda, PIN_INPUT, PullNone, 1);
|
DigitalInOut pin_sda(sda, PIN_INPUT, PullNone, 1);
|
||||||
DigitalInOut pin_scl(scl, PIN_INPUT, PullNone, 1);
|
DigitalInOut pin_scl(scl, PIN_INPUT, PullNone, 1);
|
||||||
|
|
||||||
// Read and verify if recovery is required
|
|
||||||
if (pin_scl == 1) {
|
|
||||||
if (pin_sda == 1) {
|
|
||||||
// Return successfuly as SDA and SCL is high
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Return as SCL is low and no access to become master.
|
// Return as SCL is low and no access to become master.
|
||||||
|
if (pin_scl == 0) {
|
||||||
return I2C_ERROR_BUS_BUSY;
|
return I2C_ERROR_BUS_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return successfully as SDA and SCL is high
|
||||||
|
if (pin_sda == 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Send clock pulses, for device to recover 9
|
// Send clock pulses, for device to recover 9
|
||||||
pin_scl.mode(PullNone);
|
pin_scl.mode(PullNone);
|
||||||
pin_scl.output();
|
pin_scl.output();
|
||||||
int count = 9;
|
for (int count = 0; count < 10; count++) {
|
||||||
while (count--) {
|
|
||||||
pin_scl.mode(PullNone);
|
pin_scl.mode(PullNone);
|
||||||
pin_scl = 0;
|
pin_scl = 0;
|
||||||
wait_us(5);
|
wait_us(5);
|
||||||
|
|
@ -184,6 +182,7 @@ int I2C::recover(PinName sda, PinName scl)
|
||||||
// Return as SCL is low and no access to become master.
|
// Return as SCL is low and no access to become master.
|
||||||
return I2C_ERROR_BUS_BUSY;
|
return I2C_ERROR_BUS_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue