Skip to content

Limit the number of writes to improve performance #22

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 3 commits into from
Nov 10, 2022
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
16 changes: 9 additions & 7 deletions adafruit_sharpmemorydisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,23 +85,25 @@ def show(self):

with self.spi_device as spi:

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
spi.write(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)
spi.write(self._buf)
spi.write(memoryview(self.buffer[slice_from : slice_from + line_len]))
image_buffer.extend(self._buf)
image_buffer.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
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
Expand Down Expand Up @@ -135,7 +137,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!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a manual? My guess this whitespace change is what's making black angry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically formatted by VS Code. I'm not sure what black is in reference to. I can revert this change if you wish but it's probably good cleanup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's just that the CI will continue to complain. If you want to be extra sure, you can run pre-commit yourself, and let it decide what how to format everything. Pre-commit is what the CI uses, so that's the surest way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black is a formatter, and our CI tool pre-commit uses it to standardize the formatting of our code.

if img.mode == "RGB":
self.pixel(x, y, pixels[(x, y)])
elif pixels[(x, y)]:
Expand Down