Skip to content

Commit

Permalink
rewrite Reply() to fix sending long replies in I2C Target Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sparques authored and deadprogram committed Jul 20, 2024
1 parent 89340f8 commit 4af3f61
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/machine/machine_rp2040_i2c.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,23 @@ func (i2c *I2C) Reply(buf []byte) error {
}

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

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

Expand Down

0 comments on commit 4af3f61

Please sign in to comment.