Skip to content

Commit

Permalink
Merge pull request #3 from makermelissa/master
Browse files Browse the repository at this point in the history
Added Extended SPI class
  • Loading branch information
makermelissa committed Aug 5, 2020
2 parents 88d085c + e83da21 commit 9cc6085
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion adafruit_extended_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
import threading

from os import path
from busio import I2C
from busio import I2C, SPI
from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_Python_Extended_Bus.git"
Expand Down Expand Up @@ -66,3 +67,39 @@ def init(self, bus_id, frequency):
self._lock = threading.RLock()

# pylint: enable=arguments-differ


# pylint: disable=too-few-public-methods
class ExtendedSPI(SPI):
"""Extended SPI is a busio extension that allows creating a compatible
SPI object using the Bus ID number. The bus ID is the numbers at the end
of /dev/spidev#.# and you can find which SPI devices you have by typing
`ls /dev/spi*`"""

# pylint: disable=invalid-name, redefined-builtin
class Pin:
"""Fake Pin class"""

def __init__(self, id):
self.id = id

# pylint: enable=invalid-name, redefined-builtin

# pylint: disable=super-init-not-called
def __init__(self, bus_id, chip_select):
self.deinit()

# Check if the file /dev/i2c-{bus_id} exists and error if not
if not path.exists("/dev/spidev{}.{}".format(bus_id, chip_select)):
raise ValueError(
"No device found for /dev/spidev{}.{}".format(bus_id, chip_select)
)

self._spi = _SPI((bus_id, chip_select))
# Pins aren't used in Linux, so we just use fake pins
self._pins = (self.Pin(0), self.Pin(0), self.Pin(0))

# pylint: enable=super-init-not-called


# pylint: enable=too-few-public-methods

0 comments on commit 9cc6085

Please sign in to comment.