From ad68c9d696c2dc89d0d2a3ee07cb485e836bbee9 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 2 Oct 2021 09:43:05 +0200 Subject: [PATCH] Fix i2c write read (#146) * i2c write_read: don't continue with read if write aborted * i2c write_read: use correct length of read buffer --- rp2040-hal/src/i2c.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rp2040-hal/src/i2c.rs b/rp2040-hal/src/i2c.rs index eadbd59..d6a3a99 100644 --- a/rp2040-hal/src/i2c.rs +++ b/rp2040-hal/src/i2c.rs @@ -383,9 +383,14 @@ macro_rules! hal { } } + if abort { + return Err(Error::Abort(abort_reason)); + } + + let buffer_len = buffer.len(); for (i, byte) in buffer.iter_mut().enumerate() { let first = i == 0; - let last = i == bytes.len() - 1; + let last = i == buffer_len - 1; // wait until there is space in the FIFO to write the next byte while self.tx_fifo_full() {}