Skip to content

Commit 0ef5d92

Browse files
author
deepikabhavnani
committed
Addressed review comments
1 parent a30da7e commit 0ef5d92

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

drivers/I2C.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,20 @@ int I2C::recover(PinName sda, PinName scl)
145145
DigitalInOut pin_sda(sda, PIN_INPUT, PullNone, 1);
146146
DigitalInOut pin_scl(scl, PIN_INPUT, PullNone, 1);
147147

148-
// Read and verify if recovery is required
149-
if (pin_scl == 1) {
150-
if (pin_sda == 1) {
151-
// Return successfuly as SDA and SCL is high
152-
return 0;
153-
}
154-
} else {
155-
// Return as SCL is low and no access to become master.
148+
// Return as SCL is low and no access to become master.
149+
if (pin_scl == 0) {
156150
return I2C_ERROR_BUS_BUSY;
157151
}
158152

153+
// Return successfully as SDA and SCL is high
154+
if (pin_sda == 1) {
155+
return 0;
156+
}
157+
159158
// Send clock pulses, for device to recover 9
160159
pin_scl.mode(PullNone);
161160
pin_scl.output();
162-
int count = 9;
163-
while (count--) {
161+
for (int count = 0; count < 10; count++) {
164162
pin_scl.mode(PullNone);
165163
pin_scl = 0;
166164
wait_us(5);
@@ -184,6 +182,7 @@ int I2C::recover(PinName sda, PinName scl)
184182
// Return as SCL is low and no access to become master.
185183
return I2C_ERROR_BUS_BUSY;
186184
}
185+
187186
return 0;
188187
}
189188

0 commit comments

Comments
 (0)