From: ladyada Date: Sun, 12 Aug 2018 05:12:59 +0000 (-0400) Subject: add start/end as per http://circuitpython.readthedocs.io/en/latest/shared-bindings... X-Git-Tag: 0.2^2 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/a0f81f1931c83c18b0b4647c0ad1b868e02c71e8?hp=-c add start/end as per http://circuitpython.readthedocs.io/en/latest/shared-bindings/busio/SPI.html --- a0f81f1931c83c18b0b4647c0ad1b868e02c71e8 diff --git a/src/adafruit_blinka/microcontroller/raspi_23/spi.py b/src/adafruit_blinka/microcontroller/raspi_23/spi.py index 27ead42..a4e1158 100755 --- a/src/adafruit_blinka/microcontroller/raspi_23/spi.py +++ b/src/adafruit_blinka/microcontroller/raspi_23/spi.py @@ -30,9 +30,11 @@ class SPI: self.mode = mode self.bits = bits - def write(self, buf): + def write(self, buf, start=0, end=None): if not buf: return + if end is None: + end = len(buf) try: self._spi.open(self._port, 0) try: @@ -42,15 +44,17 @@ class SPI: self._spi.max_speed_hz = self.baudrate self._spi.mode = self.mode self._spi.bits_per_word = self.bits - self._spi.writebytes([x for x in buf]) + self._spi.writebytes([x for x in buf[start:end]]) self._spi.close() except FileNotFoundError as not_found: print("Could not open SPI device - check if SPI is enabled in kernel!") raise - def readinto(self, buf): + def readinto(self, buf, start=0, end=None): if not buf: return + if end is None: + end = len(buf) try: self._spi.open(self._port, 0) try: @@ -60,9 +64,9 @@ class SPI: self._spi.max_speed_hz = self.baudrate self._spi.mode = self.mode self._spi.bits_per_word = self.bits - data = self._spi.readbytes(len(buf)) - for i in range(len(buf)): # 'readinto' the given buffer - buf[i] = data[i] + data = self._spi.readbytes(end-start) + for i in range(end-start): # 'readinto' the given buffer + buf[start+i] = data[i] self._spi.close() except FileNotFoundError as not_found: print("Could not open SPI device - check if SPI is enabled in kernel!") diff --git a/src/busio.py b/src/busio.py index 0d23b33..69cbca0 100755 --- a/src/busio.py +++ b/src/busio.py @@ -108,11 +108,11 @@ class SPI(Lockable): self._spi = None self._pinIds = None - def write(self, buf): - return self._spi.write(buf) + def write(self, buf, start=0, end=None): + return self._spi.write(buf, start, end) - def readinto(self, buf): - return self._spi.readinto(buf) + def readinto(self, buf, start=0, end=None, write_value=0): + return self._spi.readinto(buf, start, end) def write_readinto(self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None): return self._spi.write_readinto(buffer_out, buffer_in, out_start, out_end, in_start, in_end)