1 """I2C Class for RP2040"""
2 from machine import I2C as _I2C
3 from machine import Pin
4 from microcontroller.pin import i2cPorts
8 """Custom I2C Class for RP2040"""
10 def __init__(self, scl, sda, *, frequency=100000):
11 for portId, portScl, portSda in i2cPorts:
13 if scl == portScl and sda == portSda:
15 portId, sda=Pin(sda.id), scl=Pin(scl.id), freq=frequency
22 "No Hardware I2C on (scl,sda)={}\nValid I2C ports: {}".format(
28 """Perform an I2C Device Scan"""
29 return self._i2c.scan()
31 # pylint: disable=unused-argument
32 def writeto(self, address, buffer, *, stop=True):
33 "Write data to the address from the buffer"
34 return self._i2c.writeto(address, buffer)
36 def readfrom_into(self, address, buffer, *, stop=True):
37 """Read data from an address and into the buffer"""
38 return self._i2c.readfrom_into(address, buffer)
40 def writeto_then_readfrom(
52 """Write data from buffer_out to an address and then
53 read data from an address and into buffer_in
55 self._i2c.writeto_then_readfrom(
65 # pylint: enable=unused-argument