Skip to content

Commit 47250da

Browse files
authored
Merge pull request #22 from grouma/main
Limit the number of writes to improve performance
2 parents b981155 + f2e0249 commit 47250da

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

adafruit_sharpmemorydisplay.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"""
2929
# pylint: enable=line-too-long
3030

31-
from micropython import const
3231
import adafruit_framebuf
3332
from adafruit_bus_device.spi_device import SPIDevice
33+
from micropython import const
3434

3535
try:
3636
import numpy
@@ -85,23 +85,25 @@ def show(self):
8585

8686
with self.spi_device as spi:
8787

88+
image_buffer = bytearray()
8889
# toggle the VCOM bit
8990
self._buf[0] = _SHARPMEM_BIT_WRITECMD
9091
if self._vcom:
9192
self._buf[0] |= _SHARPMEM_BIT_VCOM
9293
self._vcom = not self._vcom
93-
spi.write(self._buf)
94+
image_buffer.extend(self._buf)
9495

9596
slice_from = 0
9697
line_len = self.width // 8
9798
for line in range(self.height):
9899
self._buf[0] = reverse_bit(line + 1)
99-
spi.write(self._buf)
100-
spi.write(memoryview(self.buffer[slice_from : slice_from + line_len]))
100+
image_buffer.extend(self._buf)
101+
image_buffer.extend(self.buffer[slice_from : slice_from + line_len])
101102
slice_from += line_len
102103
self._buf[0] = 0
103-
spi.write(self._buf)
104-
spi.write(self._buf) # we send one last 0 byte
104+
image_buffer.extend(self._buf)
105+
image_buffer.extend(self._buf)
106+
spi.write(image_buffer)
105107

106108
def image(self, img):
107109
"""Set buffer to value of Python Imaging Library image. The image should
@@ -135,7 +137,7 @@ def image(self, img):
135137
self.buf[i] = 0
136138
# Iterate through the pixels
137139
for x in range(width): # yes this double loop is slow,
138-
for y in range(height): # but these displays are small!
140+
for y in range(height): # but these displays are small!
139141
if img.mode == "RGB":
140142
self.pixel(x, y, pixels[(x, y)])
141143
elif pixels[(x, y)]:

0 commit comments

Comments
 (0)