X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/6db6ef855f798996075d2919ca924ec31983f7f1..refs/heads/revert-863-do-not-upload-bdist:/src/adafruit_blinka/microcontroller/rp2040/i2c.py diff --git a/src/adafruit_blinka/microcontroller/rp2040/i2c.py b/src/adafruit_blinka/microcontroller/rp2040/i2c.py index 16ff2e3..8daf249 100644 --- a/src/adafruit_blinka/microcontroller/rp2040/i2c.py +++ b/src/adafruit_blinka/microcontroller/rp2040/i2c.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT """I2C Class for RP2040""" from machine import I2C as _I2C from machine import Pin @@ -28,14 +31,13 @@ class I2C: """Perform an I2C Device Scan""" return self._i2c.scan() - # pylint: disable=unused-argument def writeto(self, address, buffer, *, stop=True): "Write data to the address from the buffer" - return self._i2c.writeto(address, buffer) + return self._i2c.writeto(address, buffer, stop) def readfrom_into(self, address, buffer, *, stop=True): """Read data from an address and into the buffer""" - return self._i2c.readfrom_into(address, buffer) + return self._i2c.readfrom_into(address, buffer, stop) def writeto_then_readfrom( self, @@ -47,19 +49,17 @@ class I2C: out_end=None, in_start=0, in_end=None, - stop=False + stop=False, ): """Write data from buffer_out to an address and then read data from an address and into buffer_in """ - self._i2c.writeto_then_readfrom( - address, - buffer_out, - buffer_in, - out_start=out_start, - out_end=out_end, - in_start=in_start, - in_end=in_end, - ) + if out_end: + self.writeto(address, buffer_out[out_start:out_end], stop=stop) + else: + self.writeto(address, buffer_out[out_start:], stop=stop) - # pylint: enable=unused-argument + if not in_end: + in_end = len(buffer_in) + read_buffer = memoryview(buffer_in)[in_start:in_end] + self.readfrom_into(address, read_buffer, stop=stop)