Skip to content

Commit 4af3f61

Browse files
sparquesdeadprogram
authored andcommitted
rewrite Reply() to fix sending long replies in I2C Target Mode
1 parent 89340f8 commit 4af3f61

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/machine/machine_rp2040_i2c.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,23 @@ func (i2c *I2C) Reply(buf []byte) error {
501501
}
502502

503503
for txPtr < len(buf) {
504-
if stat&rp.I2C0_IC_INTR_MASK_M_TX_EMPTY != 0 {
505-
i2c.Bus.IC_DATA_CMD.Set(uint32(buf[txPtr]))
504+
if i2c.Bus.GetIC_RAW_INTR_STAT_TX_EMPTY() != 0 {
505+
i2c.Bus.SetIC_DATA_CMD_DAT(uint32(buf[txPtr]))
506506
txPtr++
507+
// The DW_apb_i2c flushes/resets/empties the
508+
// TX_FIFO and RX_FIFO whenever there is a transmit abort
509+
// caused by any of the events tracked by the
510+
// IC_TX_ABRT_SOURCE register.
511+
// In other words, it's safe to block until TX FIFO is
512+
// EMPTY--it will empty from being transmitted or on error.
513+
for i2c.Bus.GetIC_RAW_INTR_STAT_TX_EMPTY() == 0 {
514+
}
507515
}
508516

509517
// This Tx abort is a normal case - we're sending more
510518
// data than controller wants to receive
511-
if stat&rp.I2C0_IC_INTR_MASK_M_TX_ABRT != 0 {
512-
i2c.Bus.IC_CLR_TX_ABRT.Get()
519+
if i2c.Bus.GetIC_RAW_INTR_STAT_TX_ABRT() != 0 {
520+
i2c.Bus.GetIC_CLR_TX_ABRT_CLR_TX_ABRT()
513521
return nil
514522
}
515523

0 commit comments

Comments
 (0)