]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
data into buffer_in
authorbrentru <robots199@me.com>
Tue, 24 Jul 2018 22:30:44 +0000 (18:30 -0400)
committerbrentru <robots199@me.com>
Tue, 24 Jul 2018 22:30:44 +0000 (18:30 -0400)
src/adafruit_blinka/microcontroller/raspi_23/spi.py

index 1b6bdc06711d20358a005243fd84b3548ee00116..27ead42ebc5eb9ca2f11e58031f0be3b4f43e816 100755 (executable)
@@ -68,11 +68,13 @@ class SPI:
             print("Could not open SPI device - check if SPI is enabled in kernel!")
             raise
 
-    def write_readinto(self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None):
+    def write_readinto(self, buffer_out, buffer_in, out_start=0,
+                       out_end=None, in_start=0, in_end=None):
         if not buffer_out or not buffer_in:
             return
-        if out_end is None or in_end is None:
-            out_end = len(buffer_out)
+        if out_end is None:
+            out_end = len(buffer_out)        
+        if in_end is None:
             in_end = len(buffer_in)
         if out_end - out_start != in_end - in_start:
             raise RuntimeError('Buffer slices must be of equal length.')
@@ -85,10 +87,10 @@ class SPI:
             self._spi.max_speed_hz = self.baudrate
             self._spi.mode = self.mode
             self._spi.bits_per_word = self.bits
-            data = self._spi.xfer(list(buffer_out[out_start:out_end]))
-            for i in range(len(buffer_in[in_start:in_end])): # 'readinto' the given buffer
-                buffer_in[i] = data[i]
+            data = self._spi.xfer(list(buffer_out[out_start:out_end+1]))
+            for i in range((in_end - in_start)):
+                buffer_in[i+in_start] = data[i]
             self._spi.close()
         except FileNotFoundError as not_found:
             print("Could not open SPI device - check if SPI is enabled in kernel!")
-            raise
\ No newline at end of file
+            raise