diff options
author | Kenneth Bell <[email protected]> | 2023-03-25 16:27:54 +0000 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-04-04 09:36:42 +0200 |
commit | ad3e9e1a776855a0844909054578d987593cd095 (patch) | |
tree | 5b0c7203c073d3625bbfc2fa0bd208dab50d0553 /src/machine/i2c.go | |
parent | e0385e48d09907c028f5f5926a2523c62757474a (diff) | |
download | tinygo-ad3e9e1a776855a0844909054578d987593cd095.tar.gz tinygo-ad3e9e1a776855a0844909054578d987593cd095.zip |
i2c: implement target mode for rp2040 and nrf
Diffstat (limited to 'src/machine/i2c.go')
-rw-r--r-- | src/machine/i2c.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/machine/i2c.go b/src/machine/i2c.go index 4e7a630b9..c8bd6d1b4 100644 --- a/src/machine/i2c.go +++ b/src/machine/i2c.go @@ -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 |