]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/ft232h/spi.py
Update spi.py
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / ft232h / spi.py
index fc7ad939b726d57362d7913f1cc2b15f7371d1fe..9ae57512233c1f6dce07f512e6194a7e753dc8c1 100644 (file)
@@ -32,7 +32,13 @@ class SPI:
     def write(self, buf, start=0, end=None):
         end = end if end else len(buf)
         port = self._spi.get_port(self.cs, self.freq, self.mode)
-        port.write(buf[start:end])
+        chunks, rest = divmod(end - start, self._spi.PAYLOAD_MAX_LENGTH)
+        for i in range(chunks):
+            chunk_start = start + i * self._spi.PAYLOAD_MAX_LENGTH
+            chunk_end = chunk_start + self._spi.PAYLOAD_MAX_LENGTH
+            port.write(buf[chunk_start:chunk_end])
+        if rest:
+            port.write(buf[-1*rest:])
 
     def readinto(self, buf, start=0, end=None, write_value=0):
         end = end if end else len(buf)
@@ -46,6 +52,6 @@ class SPI:
         in_end = in_end if in_end else len(buffer_in)
         port = self._spi.get_port(self.cs, self.freq, self.mode)
         result = port.exchange(buffer_out[out_start:out_end],
-                               in_end-in_start)
+                               in_end-in_start, duplex=True)
         for i, b in enumerate(result):
             buffer_in[in_start+i] = b