Skip to content

Commit

Permalink
Merge pull request #17 from makermelissa/master
Browse files Browse the repository at this point in the history
Add deinit code to I2C and SPI
  • Loading branch information
makermelissa authored Feb 1, 2021
2 parents dd90855 + 82a8574 commit 156a95c
Showing 1 changed file with 16 additions and 0 deletions.
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

0 comments on commit 156a95c

Please sign in to comment.