Skip to content

Commit

Permalink
Remove code setting IC_DATA_CMD.RESTART bit
Browse files Browse the repository at this point in the history
According to the datasheet, a restart is automatically triggered "if
the transfer direction is changing from the previous command". The
RESTART bit is only needed to trigger an unconditional RESTART sequence.

According to the contract of I2c::transaction, "Data from
adjacent operations of the same type are sent after each other without
an SP or SR" and "Between adjacent operations of a different type an SR
and SAD+R/W is sent". This looks like it is exactly what the hardware
provides out of the box.

(See: https://docs.rs/embedded-hal/1.0.0/ebedded_hal/i2c/trait.I2c.html#tymethod.transaction)
  • Loading branch information
jannic committed Aug 25, 2024
1 parent 84e1bf0 commit 16fc26c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 30 deletions.
15 changes: 0 additions & 15 deletions rp2040-hal/src/i2c/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,13 @@ impl<T: Deref<Target = Block>, PINS> I2C<T, PINS, Controller> {
)?;

let lastindex = buffer.len() - 1;
let mut first_byte = true;
for (i, byte) in buffer.iter_mut().enumerate() {
let last_byte = i == lastindex;

// wait until there is space in the FIFO to write the next byte
while self.i2c.ic_status().read().tfnf().bit_is_clear() {}

self.i2c.ic_data_cmd().write(|w| {
if first_byte {
if !first_transaction {
w.restart().enable();
}
first_byte = false;
}

w.stop().bit(do_stop && last_byte);
w.cmd().read()
});
Expand Down Expand Up @@ -270,7 +262,6 @@ impl<T: Deref<Target = Block>, PINS> I2C<T, PINS, Controller> {
)?;

let mut abort_reason = Ok(());
let mut first_byte = true;
'outer: while let Some(byte) = peekable.next() {
if self.tx_fifo_full() {
// wait for more room in the fifo
Expand All @@ -289,12 +280,6 @@ impl<T: Deref<Target = Block>, PINS> I2C<T, PINS, Controller> {
// else enqueue
let last = peekable.peek().is_none();
self.i2c.ic_data_cmd().write(|w| {
if first_byte {
if !first_transaction {
w.restart().enable();
}
first_byte = false;
}
w.stop().bit(do_stop && last);
unsafe { w.dat().bits(byte) }
});
Expand Down
15 changes: 0 additions & 15 deletions rp2040-hal/src/i2c/controller/non_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ where
)?;

let lastindex = buffer.len() - 1;
let mut first_byte = true;
for (i, byte) in buffer.iter_mut().enumerate() {
let last_byte = i == lastindex;

Expand All @@ -135,13 +134,6 @@ where
.await;

self.i2c.ic_data_cmd().write(|w| {
if first_byte {
if !first_transaction {
w.restart().enable();
}
first_byte = false;
}

w.stop().bit(do_stop && last_byte);
w.cmd().read()
});
Expand Down Expand Up @@ -174,7 +166,6 @@ where
)?;

let mut abort_reason = Ok(());
let mut first_byte = true;
while let Some(byte) = peekable.next() {
if self.tx_fifo_full() {
// wait for more room in the fifo
Expand All @@ -193,12 +184,6 @@ where
// else enqueue
let last = peekable.peek().is_none();
self.i2c.ic_data_cmd().write(|w| {
if first_byte {
if !first_transaction {
w.restart().enable();
}
first_byte = false;
}
w.stop().bit(do_stop && last);
unsafe { w.dat().bits(byte) }
});
Expand Down

0 comments on commit 16fc26c

Please sign in to comment.