Skip to content

Commit 8b5e71b

Browse files
authored
Merge pull request #9 from deshipu/fix-small-buffer
Use a 512 bytes buffer for the fill operations
2 parents 523d1f4 + 6f1347a commit 8b5e71b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_rgb_display/rgb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from micropython import const
12
import time
23
try:
34
import struct
@@ -7,6 +8,11 @@
78
import adafruit_bus_device.spi_device as spi_device
89

910

11+
# This is the size of the buffer to be used for fill operations, in 16-bit
12+
# units. We use 256, which is 512 bytes — size of the DMA buffer on SAMD21.
13+
_BUFFER_SIZE = const(256)
14+
15+
1016
def color565(r, g, b):
1117
return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3
1218

@@ -80,10 +86,10 @@ def fill_rectangle(self, x, y, width, height, color):
8086
w = min(self.width - x, max(1, width))
8187
h = min(self.height - y, max(1, height))
8288
self._block(x, y, x + w - 1, y + h - 1, b'')
83-
chunks, rest = divmod(w * h, 512)
89+
chunks, rest = divmod(w * h, _BUFFER_SIZE)
8490
pixel = self._encode_pixel(color)
8591
if chunks:
86-
data = pixel * 512
92+
data = pixel * _BUFFER_SIZE
8793
for count in range(chunks):
8894
self._write(None, data)
8995
self._write(None, pixel * rest)

0 commit comments

Comments
 (0)