class I2C:
- def __init__(self):
+ def __init__(self, *, frequency=400000):
# change GPIO controller to I2C
from pyftdi.i2c import I2cController
self._i2c = I2cController()
- self._i2c.configure('ftdi:///1')
+ self._i2c.configure('ftdi:///1', frequency=frequency)
Pin.ft232h_gpio = self._i2c.get_gpio()
+ def scan(self):
+ return [addr for addr in range(0x79) if self._i2c.poll(addr)]
+
def writeto(self, address, buffer, *, start=0, end=None, stop=True):
end = end if end else len(buffer)
port = self._i2c.get_port(address)
port = self._i2c.get_port(address)
result = port.exchange(buffer_out[out_start:out_end],
in_end-in_start,
- relax=True).tobytes()
+ relax=True)
for i, b in enumerate(result):
buffer_in[in_start+i] = b