Skip to content

Commit ac7e370

Browse files
ysoldakdeadprogram
authored andcommitted
rp2040: i2c minor fixes
1 parent 77ec9b6 commit ac7e370

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/machine/machine_rp2040_i2c.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package machine
66
import (
77
"device/rp"
88
"errors"
9-
"strconv"
9+
"internal/itoa"
1010
)
1111

1212
// I2C on the RP2040.
@@ -289,7 +289,6 @@ func (i2c *I2C) tx(addr uint8, tx []byte, nostop bool, timeout uint64) (err erro
289289
for !i2c.interrupted(rp.I2C0_IC_RAW_INTR_STAT_TX_EMPTY) {
290290
if ticks() > deadline {
291291
i2c.restartOnNext = nostop
292-
println(1)
293292
return errI2CWriteTimeout // If there was a timeout, don't attempt to do anything else.
294293
}
295294
}
@@ -308,7 +307,6 @@ func (i2c *I2C) tx(addr uint8, tx []byte, nostop bool, timeout uint64) (err erro
308307
// to take care of the abort.
309308
for !i2c.interrupted(rp.I2C0_IC_RAW_INTR_STAT_STOP_DET) {
310309
if ticks() > deadline {
311-
println(2)
312310
i2c.restartOnNext = nostop
313311
return errI2CWriteTimeout
314312
}
@@ -330,7 +328,7 @@ func (i2c *I2C) tx(addr uint8, tx []byte, nostop bool, timeout uint64) (err erro
330328
fallthrough
331329
default:
332330
// panic("unknown i2c abortReason:" + strconv.Itoa(abortReason)
333-
err = makeI2CBuffError(byteCtr)
331+
err = makeI2CAbortError(abortReason)
334332
}
335333
}
336334

@@ -396,7 +394,7 @@ func (i2c *I2C) rx(addr uint8, rx []byte, nostop bool, timeout uint64) (err erro
396394
err = ErrI2CGeneric
397395
default:
398396
// undefined abort sequence
399-
err = makeI2CBuffError(byteCtr)
397+
err = makeI2CAbortError(abortReason)
400398
}
401399
}
402400

@@ -438,15 +436,15 @@ func (i2c *I2C) interrupted(mask uint32) bool {
438436
return reg&mask == mask
439437
}
440438

441-
type i2cBuffError int
439+
type i2cAbortError uint32
442440

443-
func (b i2cBuffError) Error() string {
444-
return "i2c err after addr ack at data " + strconv.Itoa(int(b))
441+
func (b i2cAbortError) Error() string {
442+
return "i2c abort, reason " + itoa.Uitoa(uint(b))
445443
}
446444

447445
//go:inline
448-
func makeI2CBuffError(idx int) error {
449-
return i2cBuffError(idx)
446+
func makeI2CAbortError(reason uint32) error {
447+
return i2cAbortError(reason)
450448
}
451449

452450
//go:inline

0 commit comments

Comments
 (0)