Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Switch to adafruit_bus_device dependency #21

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
Apr 25, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Dependencies
This driver depends on:

* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_

Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
Expand Down
58 changes: 26 additions & 32 deletions adafruit_sharpmemorydisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from micropython import const
import adafruit_framebuf
from adafruit_bus_device.spi_device import SPIDevice

try:
import numpy
Expand Down Expand Up @@ -62,11 +63,10 @@ class SharpMemoryDisplay(adafruit_framebuf.FrameBuffer):
# pylint: disable=too-many-instance-attributes,abstract-method

def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000):
self._scs_pin = scs_pin
scs_pin.switch_to_output(value=True)
self._baudrate = baudrate
# The SCS pin is active HIGH so we can't use bus_device. exciting!
self._spi = spi
self.spi_device = SPIDevice(
spi, scs_pin, cs_active_value=True, baudrate=baudrate
)
# prealloc for when we write the display
self._buf = bytearray(1)

Expand All @@ -80,34 +80,28 @@ def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000):

def show(self):
"""write out the frame buffer via SPI, we use MSB SPI only so some
bit-swapping is rquired. The display also uses inverted CS for some
reason so we con't use bus_device"""

# CS pin is inverted so we have to do this all by hand
while not self._spi.try_lock():
pass
self._spi.configure(baudrate=self._baudrate)
self._scs_pin.value = True

# toggle the VCOM bit
self._buf[0] = _SHARPMEM_BIT_WRITECMD
if self._vcom:
self._buf[0] |= _SHARPMEM_BIT_VCOM
self._vcom = not self._vcom
self._spi.write(self._buf)

slice_from = 0
line_len = self.width // 8
for line in range(self.height):
self._buf[0] = reverse_bit(line + 1)
self._spi.write(self._buf)
self._spi.write(memoryview(self.buffer[slice_from : slice_from + line_len]))
slice_from += line_len
self._buf[0] = 0
self._spi.write(self._buf)
self._spi.write(self._buf) # we send one last 0 byte
self._scs_pin.value = False
self._spi.unlock()
bit-swapping is required.
"""

with self.spi_device as spi:

# 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)

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]))
slice_from += line_len
self._buf[0] = 0
spi.write(self._buf)
spi.write(self._buf) # we send one last 0 byte

def image(self, img):
"""Set buffer to value of Python Imaging Library image. The image should
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

Adafruit-Blinka
adafruit-circuitpython-framebuf
adafruit-circuitpython-busdevice
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
# Author details
author="Adafruit Industries",
author_email="[email protected]",
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-framebuf"],
install_requires=[
"Adafruit-Blinka",
"adafruit-circuitpython-framebuf",
"adafruit-circuitpython-busdevice",
],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down