i2c: implement target mode for rp2040 and nrf

This commit is contained in:
Kenneth Bell
2023-03-25 16:27:54 +00:00
committed by Ron Evans
parent e0385e48d0
commit ad3e9e1a77
9 changed files with 479 additions and 27 deletions
+31
View File
@@ -23,6 +23,37 @@ var (
errI2CSignalStopTimeout = errors.New("I2C timeout on signal stop")
errI2CAckExpected = errors.New("I2C error: expected ACK not NACK")
errI2CBusError = errors.New("I2C bus error")
errI2COverflow = errors.New("I2C receive buffer overflow")
errI2COverread = errors.New("I2C transmit buffer overflow")
)
// I2CTargetEvent reflects events on the I2C bus
type I2CTargetEvent uint8
const (
// I2CReceive indicates target has received a message from the controller.
I2CReceive I2CTargetEvent = iota
// I2CRequest indicates the controller is expecting a message from the target.
I2CRequest
// I2CFinish indicates the controller has ended the transaction.
//
// I2C controllers can chain multiple receive/request messages without
// relinquishing the bus by doing 'restarts'. I2CFinish indicates the
// bus has been relinquished by an I2C 'stop'.
I2CFinish
)
// I2CMode determines if an I2C peripheral is in Controller or Target mode.
type I2CMode int
const (
// I2CModeController represents an I2C peripheral in controller mode.
I2CModeController I2CMode = iota
// I2CModeTarget represents an I2C peripheral in target mode.
I2CModeTarget
)
// WriteRegister transmits first the register and then the data to the