From ac589b93c48b727403f9425632ddb709299c75af Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 5 Aug 2020 12:35:28 -0700 Subject: [PATCH 1/2] Added Extended SPI class --- adafruit_extended_bus.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/adafruit_extended_bus.py b/adafruit_extended_bus.py index aff0267..360190a 100644 --- a/adafruit_extended_bus.py +++ b/adafruit_extended_bus.py @@ -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" @@ -66,3 +67,34 @@ 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 From e83da21ea001f38e5d6a0ece13c1a485bcfccb0c Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 5 Aug 2020 12:38:54 -0700 Subject: [PATCH 2/2] black formatted again --- adafruit_extended_bus.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/adafruit_extended_bus.py b/adafruit_extended_bus.py index 360190a..5eca8cd 100644 --- a/adafruit_extended_bus.py +++ b/adafruit_extended_bus.py @@ -68,6 +68,7 @@ def init(self, bus_id, frequency): # pylint: enable=arguments-differ + # pylint: disable=too-few-public-methods class ExtendedSPI(SPI): """Extended SPI is a busio extension that allows creating a compatible @@ -78,8 +79,10 @@ class ExtendedSPI(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 @@ -97,4 +100,6 @@ def __init__(self, bus_id, chip_select): self._pins = (self.Pin(0), self.Pin(0), self.Pin(0)) # pylint: enable=super-init-not-called + + # pylint: enable=too-few-public-methods