Skip to content

Commit 0ee1753

Browse files
Clean up I2C write_then_read implementation
- Fix end_w/end_r falsy check: use 'is not None' to handle end=0 correctly - Differentiate error message for write_then_read vs regular write - Remove commented-out debug print statements
1 parent 7688c33 commit 0ee1753

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ def _i2c_write_then_read(
270270
if self._i2c_index is None:
271271
raise RuntimeError("I2C bus not initialized.")
272272

273-
end_w = end_w if end_w else len(buffer_w)
274-
end_r = end_r if end_r else len(buffer_r)
273+
end_w = end_w if end_w is not None else len(buffer_w)
274+
end_r = end_r if end_r is not None else len(buffer_r)
275275

276276
write_then_read_cmd = (
277277
self.I2C0_WRITE_THEN_READ
@@ -290,7 +290,7 @@ def _i2c_write_then_read(
290290
True,
291291
)
292292
if resp[1] != self.RESP_OK:
293-
raise RuntimeError("I2C write error")
293+
raise RuntimeError("I2C write_then_read error")
294294
# move into buffer
295295
for i in range(read_size):
296296
buffer_r[start_r + i] = resp[i + 2]
@@ -333,11 +333,9 @@ def i2c_writeto_then_readfrom(
333333
)
334334
return
335335
except RuntimeError:
336-
# print("DEBUG: SENDING I2C WRITE THEN READ FAILED. SETTING FLAG.")
336+
# Firmware may not support write_then_read; fall back
337+
# to separate write + read for this and future calls.
337338
self.FLAG_I2C_NO_WRITE_THEN_READ_AVAILABLE = True
338-
# print(
339-
# "DEBUG: NO I2C WRITE THEN READ AVAILABLE FLAG SET. SENDING SEPARATELY."
340-
# )
341339
self._i2c_write(address, out_buffer, out_start, out_end, False)
342340
self._i2c_read(address, in_buffer, in_start, in_end)
343341

0 commit comments

Comments
 (0)