Skip to content

Commit 4d861e6

Browse files
committed
change _BUFFER_SIZE logic
1 parent f4b72ad commit 4d861e6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

adafruit_rgb_display/rgb.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,26 @@
4141
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
4242

4343
# This is the size of the buffer to be used for fill operations, in 16-bit
44-
# units. #We use 256, which is 512 bytes — size of the DMA buffer on SAMD21.
45-
_BUFFER_SIZE = const(256)
46-
# If we're on CPython, we have more memory, so get a big ol chunk!
44+
# units.
4745
try:
46+
# If we're on CPython, try to set as large as possible
4847
import platform
4948
if "CPython" in platform.python_implementation():
50-
_BUFFER_SIZE = const(320*240) # blit the whole thing at once
49+
# check for FT232H special case
50+
import os
51+
if os.environ['BLINKA_FT232H']:
52+
# we are limited by pyftdi's max SPI payload
53+
from pyftdi.spi import SpiController
54+
_BUFFER_SIZE = SpiController.PAYLOAD_MAX_LENGTH // 2 # max bytes / bytes per pixel
55+
else:
56+
# set it to blit the whole thing
57+
_BUFFER_SIZE = 320 * 240
58+
else:
59+
# in case CircuitPython ever implements platform
60+
_BUFFER_SIZE = 256
5161
except ImportError:
52-
pass
62+
# Otherwise set smaller MCU friendly size
63+
_BUFFER_SIZE = 256
5364

5465
def color565(r, g=0, b=0):
5566
"""Convert red, green and blue values (0-255) into a 16-bit 565 encoding. As
@@ -200,6 +211,7 @@ def fill_rectangle(self, x, y, width, height, color):
200211
pixel = self._encode_pixel(color)
201212
if chunks:
202213
data = pixel * _BUFFER_SIZE
214+
print(pixel, len(data))
203215
for _ in range(chunks):
204216
self.write(None, data)
205217
self.write(None, pixel * rest)

0 commit comments

Comments
 (0)