From 1224b6acd41334bc6354ccfda686b2e759ea49c1 Mon Sep 17 00:00:00 2001 From: Gary Roumanis Date: Mon, 31 Oct 2022 20:59:56 -0700 Subject: [PATCH 1/3] Limit the number of writes to improve performance --- adafruit_sharpmemorydisplay.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/adafruit_sharpmemorydisplay.py b/adafruit_sharpmemorydisplay.py index 89050d4..5bb1225 100644 --- a/adafruit_sharpmemorydisplay.py +++ b/adafruit_sharpmemorydisplay.py @@ -28,9 +28,9 @@ """ # pylint: enable=line-too-long -from micropython import const import adafruit_framebuf from adafruit_bus_device.spi_device import SPIDevice +from micropython import const try: import numpy @@ -85,23 +85,26 @@ def show(self): with self.spi_device as spi: + _imageBuf = bytearray() # toggle the VCOM bit self._buf[0] = _SHARPMEM_BIT_WRITECMD if self._vcom: self._buf[0] |= _SHARPMEM_BIT_VCOM self._vcom = not self._vcom - spi.write(self._buf) + _imageBuf.extend(self._buf) slice_from = 0 line_len = self.width // 8 for line in range(self.height): self._buf[0] = reverse_bit(line + 1) - spi.write(self._buf) - spi.write(memoryview(self.buffer[slice_from : slice_from + line_len])) + _imageBuf.extend(self._buf) + _imageBuf.extend( + self.buffer[slice_from: slice_from + line_len]) slice_from += line_len self._buf[0] = 0 - spi.write(self._buf) - spi.write(self._buf) # we send one last 0 byte + _imageBuf.extend(self._buf) + _imageBuf.extend(self._buf) + spi.write(_imageBuf) def image(self, img): """Set buffer to value of Python Imaging Library image. The image should @@ -135,7 +138,7 @@ def image(self, img): self.buf[i] = 0 # Iterate through the pixels for x in range(width): # yes this double loop is slow, - for y in range(height): # but these displays are small! + for y in range(height): # but these displays are small! if img.mode == "RGB": self.pixel(x, y, pixels[(x, y)]) elif pixels[(x, y)]: From 1260ac0ae5f1c56ce89a702e452ac387ed95fd0c Mon Sep 17 00:00:00 2001 From: Gary Roumanis Date: Wed, 2 Nov 2022 20:41:40 -0700 Subject: [PATCH 2/3] rename --- adafruit_sharpmemorydisplay.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_sharpmemorydisplay.py b/adafruit_sharpmemorydisplay.py index 5bb1225..609f4a9 100644 --- a/adafruit_sharpmemorydisplay.py +++ b/adafruit_sharpmemorydisplay.py @@ -85,26 +85,26 @@ def show(self): with self.spi_device as spi: - _imageBuf = bytearray() + image_buffer = bytearray() # toggle the VCOM bit self._buf[0] = _SHARPMEM_BIT_WRITECMD if self._vcom: self._buf[0] |= _SHARPMEM_BIT_VCOM self._vcom = not self._vcom - _imageBuf.extend(self._buf) + image_buffer.extend(self._buf) slice_from = 0 line_len = self.width // 8 for line in range(self.height): self._buf[0] = reverse_bit(line + 1) - _imageBuf.extend(self._buf) - _imageBuf.extend( + image_buffer.extend(self._buf) + image_buffer.extend( self.buffer[slice_from: slice_from + line_len]) slice_from += line_len self._buf[0] = 0 - _imageBuf.extend(self._buf) - _imageBuf.extend(self._buf) - spi.write(_imageBuf) + image_buffer.extend(self._buf) + image_buffer.extend(self._buf) + spi.write(image_buffer) def image(self, img): """Set buffer to value of Python Imaging Library image. The image should From f2e02496675b0d30aab450dd1d58b686fd5b4f61 Mon Sep 17 00:00:00 2001 From: Gary Roumanis Date: Wed, 2 Nov 2022 20:48:14 -0700 Subject: [PATCH 3/3] black format --- adafruit_sharpmemorydisplay.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_sharpmemorydisplay.py b/adafruit_sharpmemorydisplay.py index 609f4a9..526095c 100644 --- a/adafruit_sharpmemorydisplay.py +++ b/adafruit_sharpmemorydisplay.py @@ -98,8 +98,7 @@ def show(self): for line in range(self.height): self._buf[0] = reverse_bit(line + 1) image_buffer.extend(self._buf) - image_buffer.extend( - self.buffer[slice_from: slice_from + line_len]) + image_buffer.extend(self.buffer[slice_from : slice_from + line_len]) slice_from += line_len self._buf[0] = 0 image_buffer.extend(self._buf)