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

Add deinit code to I2C and SPI #17

Merged
merged 1 commit into from
Feb 1, 2021
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: 16 additions & 0 deletions adafruit_bitbangio.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def __init__(self, scl, sda, *, frequency=400000, timeout=1):
self._delay = 1 / frequency / 2
self._timeout = timeout

def deinit(self):
"""Free any hardware used by the object."""
self._sda.deinit()
self._scl.deinit()

def scan(self):
"""Perform an I2C Device Scan"""
found = []
Expand Down Expand Up @@ -276,6 +281,9 @@ def __init__(self, clock, MOSI=None, MISO=None):
while self.try_lock():
pass

self._mosi = None
self._miso = None

self.configure()
self.unlock()

Expand All @@ -291,6 +299,14 @@ def __init__(self, clock, MOSI=None, MISO=None):
self._miso = DigitalInOut(MISO)
self._miso.switch_to_input()

def deinit(self):
"""Free any hardware used by the object."""
self._sclk.deinit()
if self._miso:
self._miso.deinit()
if self._mosi:
self._mosi.deinit()

def configure(self, *, baudrate=100000, polarity=0, phase=0, bits=8):
"""Configures the SPI bus. Only valid when locked."""
if self._check_lock():
Expand Down