Skip to content

Commit fb32ff2

Browse files
committed
Switch to bus device dependency
1 parent f47bea6 commit fb32ff2

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Dependencies
2020
This driver depends on:
2121

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

2425
Please ensure all dependencies are available on the CircuitPython filesystem.
2526
This is easily achieved by downloading

adafruit_sharpmemorydisplay.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from micropython import const
3232
import adafruit_framebuf
33+
from adafruit_bus_device.spi_device import SPIDevice
3334

3435
__version__ = "0.0.0-auto.0"
3536
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SharpMemoryDisplay.git"
@@ -57,11 +58,10 @@ class SharpMemoryDisplay(adafruit_framebuf.FrameBuffer):
5758
# pylint: disable=too-many-instance-attributes,abstract-method
5859

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

@@ -75,31 +75,25 @@ def __init__(self, spi, scs_pin, width, height, *, baudrate=2000000):
7575

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

81-
# CS pin is inverted so we have to do this all by hand
82-
while not self._spi.try_lock():
83-
pass
84-
self._spi.configure(baudrate=self._baudrate)
85-
self._scs_pin.value = True
86-
87-
# toggle the VCOM bit
88-
self._buf[0] = _SHARPMEM_BIT_WRITECMD
89-
if self._vcom:
90-
self._buf[0] |= _SHARPMEM_BIT_VCOM
91-
self._vcom = not self._vcom
92-
self._spi.write(self._buf)
93-
94-
slice_from = 0
95-
line_len = self.width // 8
96-
for line in range(self.height):
97-
self._buf[0] = reverse_bit(line + 1)
98-
self._spi.write(self._buf)
99-
self._spi.write(memoryview(self.buffer[slice_from : slice_from + line_len]))
100-
slice_from += line_len
101-
self._buf[0] = 0
102-
self._spi.write(self._buf)
103-
self._spi.write(self._buf) # we send one last 0 byte
104-
self._scs_pin.value = False
105-
self._spi.unlock()
81+
with self.spi_device as spi:
82+
83+
# toggle the VCOM bit
84+
self._buf[0] = _SHARPMEM_BIT_WRITECMD
85+
if self._vcom:
86+
self._buf[0] |= _SHARPMEM_BIT_VCOM
87+
self._vcom = not self._vcom
88+
spi.write(self._buf)
89+
90+
slice_from = 0
91+
line_len = self.width // 8
92+
for line in range(self.height):
93+
self._buf[0] = reverse_bit(line + 1)
94+
spi.write(self._buf)
95+
spi.write(memoryview(self.buffer[slice_from : slice_from + line_len]))
96+
slice_from += line_len
97+
self._buf[0] = 0
98+
spi.write(self._buf)
99+
spi.write(self._buf) # we send one last 0 byte

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
Adafruit-Blinka
66
adafruit-circuitpython-framebuf
7+
adafruit-circuitpython-busdevice

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
# Author details
3535
author="Adafruit Industries",
3636
author_email="circuitpython@adafruit.com",
37-
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-framebuf"],
37+
install_requires=[
38+
"Adafruit-Blinka",
39+
"adafruit-circuitpython-framebuf",
40+
"adafruit-circuitpython-busdevice",
41+
],
3842
# Choose your license
3943
license="MIT",
4044
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)