1 """I2C Class for Pico u2if"""
2 from .pico_u2if import pico_u2if
6 """Custom I2C Class for Pico u2if"""
8 def __init__(self, scl, sda, *, frequency=100000):
10 if scl.id == 5 and sda.id == 4:
12 if scl.id == 15 and sda.id == 14:
15 raise ValueError("I2C not found on specified pins.")
17 pico_u2if.i2c_set_port(self._index)
18 pico_u2if.i2c_configure(frequency)
21 """Perform an I2C Device Scan"""
22 pico_u2if.i2c_set_port(self._index)
23 return pico_u2if.i2c_scan()
25 # pylint: disable=unused-argument
26 def writeto(self, address, buffer, *, start=0, end=None, stop=True):
27 """Write data from the buffer to an address"""
28 pico_u2if.i2c_set_port(self._index)
29 pico_u2if.i2c_writeto(address, buffer, start=start, end=end)
31 def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
32 """Read data from an address and into the buffer"""
33 pico_u2if.i2c_set_port(self._index)
34 pico_u2if.i2c_readfrom_into(address, buffer, start=start, end=end)
36 def writeto_then_readfrom(
48 """Write data from buffer_out to an address and then
49 read data from an address and into buffer_in
51 pico_u2if.i2c_set_port(self._index)
52 pico_u2if.i2c_writeto_then_readfrom(
62 # pylint: enable=unused-argument