]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/ft232h/spi.py
chunkify ft232h spi write
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / ft232h / spi.py
index fc7ad939b726d57362d7913f1cc2b15f7371d1fe..6a2d18f9334f0b9156d0d85410a3bfbd6a9af8eb 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)