machine: make I2C usable in the simulator

This fixes/improves a few issues with I2C support:

  * Validate I2C pins, so only pins that are supported by the hardware
    can be used (similar to how it's done with PWM).
  * Add address to Tx API (without it, the simulator can't really
    simulate I2C).
  * Add frequency when configuring. Not currently used, but might be
    useful in the future and adding it now avoids possibly breaking
    changes.

This is a breaking change, but since the simulator doesn't support I2C
yet that seems fine to me. (It does in my local changes, but those need
to be cleaned up before I can push them).
This commit is contained in:
Ayke van Laethem
2025-07-07 13:40:44 +02:00
committed by Ron Evans
parent 35adbffa54
commit f845b469b1
9 changed files with 87 additions and 17 deletions
+3
View File
@@ -37,6 +37,9 @@ var (
errI2COverflow = errors.New("I2C receive buffer overflow")
errI2COverread = errors.New("I2C transmit buffer overflow")
errI2CNotImplemented = errors.New("I2C operation not yet implemented")
errI2CNoDevices = errors.New("i2c: bus has no devices") // simulator only
errI2CMultipleDevices = errors.New("i2c: bus has address conflict") // simulator only
errI2CWrongAddress = errors.New("i2c: bus has devices but none with this address") // simulator only
)
// I2CTargetEvent reflects events on the I2C bus