Skip to content

Use a 512 bytes buffer for the fill operations #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions adafruit_rgb_display/rgb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from micropython import const
import time
try:
import struct
Expand All @@ -7,6 +8,11 @@
import adafruit_bus_device.spi_device as spi_device


# This is the size of the buffer to be used for fill operations, in 16-bit
# units. We use 256, which is 512 bytes — size of the DMA buffer on SAMD21.
_BUFFER_SIZE = const(256)


def color565(r, g, b):
return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3

Expand Down Expand Up @@ -80,10 +86,10 @@ def fill_rectangle(self, x, y, width, height, color):
w = min(self.width - x, max(1, width))
h = min(self.height - y, max(1, height))
self._block(x, y, x + w - 1, y + h - 1, b'')
chunks, rest = divmod(w * h, 512)
chunks, rest = divmod(w * h, _BUFFER_SIZE)
pixel = self._encode_pixel(color)
if chunks:
data = pixel * 512
data = pixel * _BUFFER_SIZE
for count in range(chunks):
self._write(None, data)
self._write(None, pixel * rest)
Expand Down