X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/77b1e4d350a440c155bb8b4c06299fef1bd91e50..28aee6f47c1fc531d5f5e6ac83f2f53153c2fb3c:/src/adafruit_blinka/microcontroller/generic_linux/spi.py diff --git a/src/adafruit_blinka/microcontroller/generic_linux/spi.py b/src/adafruit_blinka/microcontroller/generic_linux/spi.py index 20607cd..6cce037 100755 --- a/src/adafruit_blinka/microcontroller/generic_linux/spi.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/spi.py @@ -1,5 +1,8 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT """Generic Linux SPI class using PureIO's SPI class""" -import Adafruit_PureIO.spi as spi +from Adafruit_PureIO import spi from adafruit_blinka.agnostic import detector @@ -70,7 +73,7 @@ class SPI: def write(self, buf, start=0, end=None): """Write data from the buffer to SPI""" - if not buf: + if buf is None or len(buf) < 1: return if end is None: end = len(buf) @@ -88,7 +91,7 @@ class SPI: def readinto(self, buf, start=0, end=None, write_value=0): """Read data from SPI and into the buffer""" - if not buf: + if buf is None or len(buf) < 1: return if end is None: end = len(buf) @@ -113,7 +116,9 @@ class SPI: """Perform a half-duplex write from buffer_out and then read data into buffer_in """ - if not buffer_out or not buffer_in: + if buffer_out is None or buffer_in is None: + return + if len(buffer_out) < 1 or len(buffer_in) < 1: return if out_end is None: out_end = len(buffer_out) @@ -129,7 +134,7 @@ class SPI: self._spi.bits_per_word = self.bits data = self._spi.transfer(list(buffer_out[out_start : out_end + 1])) for i in range((in_end - in_start)): - buffer_in[i + in_start] = data[i + 1] + buffer_in[i + in_start] = data[i] # self._spi.close() except FileNotFoundError: print("Could not open SPI device - check if SPI is enabled in kernel!")