Skip to content

Commit 7d291d4

Browse files
committed
Remove code setting IC_DATA_CMD.RESTART bit
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)
1 parent 23a68bc commit 7d291d4

File tree

2 files changed

+0
-30
lines changed

2 files changed

+0
-30
lines changed

rp2040-hal/src/i2c/controller.rs

-15
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,13 @@ impl<T: Deref<Target = Block>, PINS> I2C<T, PINS, Controller> {
227227
)?;
228228

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

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

237236
self.i2c.ic_data_cmd().write(|w| {
238-
if first_byte {
239-
if !first_transaction {
240-
w.restart().enable();
241-
}
242-
first_byte = false;
243-
}
244-
245237
w.stop().bit(do_stop && last_byte);
246238
w.cmd().read()
247239
});
@@ -270,7 +262,6 @@ impl<T: Deref<Target = Block>, PINS> I2C<T, PINS, Controller> {
270262
)?;
271263

272264
let mut abort_reason = Ok(());
273-
let mut first_byte = true;
274265
'outer: while let Some(byte) = peekable.next() {
275266
if self.tx_fifo_full() {
276267
// wait for more room in the fifo
@@ -289,12 +280,6 @@ impl<T: Deref<Target = Block>, PINS> I2C<T, PINS, Controller> {
289280
// else enqueue
290281
let last = peekable.peek().is_none();
291282
self.i2c.ic_data_cmd().write(|w| {
292-
if first_byte {
293-
if !first_transaction {
294-
w.restart().enable();
295-
}
296-
first_byte = false;
297-
}
298283
w.stop().bit(do_stop && last);
299284
unsafe { w.dat().bits(byte) }
300285
});

rp2040-hal/src/i2c/controller/non_blocking.rs

-15
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ where
120120
)?;
121121

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

@@ -135,13 +134,6 @@ where
135134
.await;
136135

137136
self.i2c.ic_data_cmd().write(|w| {
138-
if first_byte {
139-
if !first_transaction {
140-
w.restart().enable();
141-
}
142-
first_byte = false;
143-
}
144-
145137
w.stop().bit(do_stop && last_byte);
146138
w.cmd().read()
147139
});
@@ -174,7 +166,6 @@ where
174166
)?;
175167

176168
let mut abort_reason = Ok(());
177-
let mut first_byte = true;
178169
while let Some(byte) = peekable.next() {
179170
if self.tx_fifo_full() {
180171
// wait for more room in the fifo
@@ -193,12 +184,6 @@ where
193184
// else enqueue
194185
let last = peekable.peek().is_none();
195186
self.i2c.ic_data_cmd().write(|w| {
196-
if first_byte {
197-
if !first_transaction {
198-
w.restart().enable();
199-
}
200-
first_byte = false;
201-
}
202187
w.stop().bit(do_stop && last);
203188
unsafe { w.dat().bits(byte) }
204189
});

0 commit comments

Comments
 (0)