Skip to content

try to import bitbangio if busio SPI is not available #36

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 1 commit into from
Oct 20, 2019
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
10 changes: 8 additions & 2 deletions adafruit_dotstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,23 @@ def __init__(self, clock, data, n, *, brightness=1.0, auto_write=True,
pixel_order=BGR, baudrate=4000000):
self._spi = None
try:
self._spi = busio.SPI(clock, MOSI=data)
try:
self._spi = busio.SPI(clock, MOSI=data)
except (NotImplementedError, ValueError):
import bitbangio
self._spi = bitbangio.SPI(clock, MOSI=data)

while not self._spi.try_lock():
pass
self._spi.configure(baudrate=baudrate)

except (NotImplementedError, ValueError):
except (NotImplementedError, ValueError, ImportError):
self.dpin = digitalio.DigitalInOut(data)
self.cpin = digitalio.DigitalInOut(clock)
self.dpin.direction = digitalio.Direction.OUTPUT
self.cpin.direction = digitalio.Direction.OUTPUT
self.cpin.value = False

self._n = n
# Supply one extra clock cycle for each two pixels in the strip.
self.end_header_size = n // 16
Expand Down