1 """I2C Classes for RP2040s with u2if firmware"""
2 from .rp2040_u2if import rp2040_u2if
6 """I2C Base Class for RP2040 u2if"""
8 def __init__(self, index, *, frequency=100000):
10 rp2040_u2if.i2c_set_port(self._index)
11 rp2040_u2if.i2c_configure(frequency)
14 """Perform an I2C Device Scan"""
15 rp2040_u2if.i2c_set_port(self._index)
16 return rp2040_u2if.i2c_scan()
18 # pylint: disable=unused-argument
19 def writeto(self, address, buffer, *, start=0, end=None, stop=True):
20 """Write data from the buffer to an address"""
21 rp2040_u2if.i2c_set_port(self._index)
22 rp2040_u2if.i2c_writeto(address, buffer, start=start, end=end)
24 def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
25 """Read data from an address and into the buffer"""
26 rp2040_u2if.i2c_set_port(self._index)
27 rp2040_u2if.i2c_readfrom_into(address, buffer, start=start, end=end)
29 def writeto_then_readfrom(
41 """Write data from buffer_out to an address and then
42 read data from an address and into buffer_in
44 rp2040_u2if.i2c_set_port(self._index)
45 rp2040_u2if.i2c_writeto_then_readfrom(
55 # pylint: enable=unused-argument
58 """I2C Class for Pico u2if"""
60 def __init__(self, scl, sda, *, frequency=100000):
62 if scl.id == 5 and sda.id == 4:
64 if scl.id == 15 and sda.id == 14:
67 raise ValueError("I2C not found on specified pins.")
70 super().__init__(index, frequency=frequency)
72 class I2C_Feather(I2C):
73 """I2C Class for Feather u2if"""
75 def __init__(self, scl, sda, *, frequency=100000):
77 if scl.id == 3 and sda.id == 2:
80 raise ValueError("I2C not found on specified pins.")
83 super().__init__(index, frequency=frequency)