1 """I2C Class for NXP LPC4330"""
 
   2 from greatfet import GreatFET
 
   6     """Custom I2C Class for NXP LPC4330"""
 
   8     # pylint: disable=unused-argument
 
   9     def __init__(self, *, frequency=100000):
 
  13         """Perform an I2C Device Scan"""
 
  14         return [index for index, dev in enumerate(self._gf.i2c.scan()) if dev[0]]
 
  16     def writeto(self, address, buffer, *, start=0, end=None, stop=True):
 
  17         """Write data from the buffer to an address"""
 
  20         self._gf.i2c.write(address, buffer[start:end])
 
  22     def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
 
  23         """Read data from an address and into the buffer"""
 
  26         readin = self._gf.i2c.read(address, end - start)
 
  27         for i in range(end - start):
 
  28             buffer[i + start] = readin[i]
 
  30     # pylint: enable=unused-argument
 
  32     def writeto_then_readfrom(
 
  44         """Write data from buffer_out to an address and then
 
  45         read data from an address and into buffer_in
 
  47         self.writeto(address, buffer_out, start=out_start, end=out_end, stop=stop)
 
  48         self.readfrom_into(address, buffer_in, start=in_start, end=in_end, stop=stop)