Skip to content
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

Made chip_select default to None #17

Merged
merged 3 commits into from
May 14, 2018
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
12 changes: 8 additions & 4 deletions adafruit_bus_device/spi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,29 @@ class SPIDevice:
with device as spi:
spi.write(bytes_read)
"""
def __init__(self, spi, chip_select, *, baudrate=100000, polarity=0, phase=0, extra_clocks=0):
def __init__(self, spi, chip_select=None, *,
baudrate=100000, polarity=0, phase=0, extra_clocks=0):
self.spi = spi
self.baudrate = baudrate
self.polarity = polarity
self.phase = phase
self.extra_clocks = extra_clocks
self.chip_select = chip_select
self.chip_select.switch_to_output(value=True)
if self.chip_select:
self.chip_select.switch_to_output(value=True)

def __enter__(self):
while not self.spi.try_lock():
pass
self.spi.configure(baudrate=self.baudrate, polarity=self.polarity,
phase=self.phase)
self.chip_select.value = False
if self.chip_select:
self.chip_select.value = False
return self.spi

def __exit__(self, *exc):
self.chip_select.value = True
if self.chip_select:
self.chip_select.value = True
if self.extra_clocks > 0:
buf = bytearray(1)
buf[0] = 0xff
Expand Down