1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 """I2C Class for NXP LPC4330"""
5 from greatfet import GreatFET
9 """Custom I2C Class for NXP LPC4330"""
11 # pylint: disable=unused-argument
12 def __init__(self, *, frequency=100000):
16 """Perform an I2C Device Scan"""
17 return [index for index, dev in enumerate(self._gf.i2c.scan()) if dev[0]]
19 def writeto(self, address, buffer, *, start=0, end=None, stop=True):
20 """Write data from the buffer to an address"""
23 self._gf.i2c.write(address, buffer[start:end])
25 def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
26 """Read data from an address and into the buffer"""
29 readin = self._gf.i2c.read(address, end - start)
30 for i in range(end - start):
31 buffer[i + start] = readin[i]
33 # pylint: enable=unused-argument
35 def writeto_then_readfrom(
47 """Write data from buffer_out to an address and then
48 read data from an address and into buffer_in
50 self.writeto(address, buffer_out, start=out_start, end=out_end, stop=stop)
51 self.readfrom_into(address, buffer_in, start=in_start, end=in_end, stop=stop)