|
34 | 34 | import threading
|
35 | 35 |
|
36 | 36 | from os import path
|
37 |
| -from busio import I2C |
| 37 | +from busio import I2C, SPI |
38 | 38 | from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C
|
| 39 | +from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI |
39 | 40 |
|
40 | 41 | __version__ = "0.0.0-auto.0"
|
41 | 42 | __repo__ = "https://github.com/adafruit/Adafruit_Python_Extended_Bus.git"
|
@@ -66,3 +67,39 @@ def init(self, bus_id, frequency):
|
66 | 67 | self._lock = threading.RLock()
|
67 | 68 |
|
68 | 69 | # pylint: enable=arguments-differ
|
| 70 | + |
| 71 | + |
| 72 | +# pylint: disable=too-few-public-methods |
| 73 | +class ExtendedSPI(SPI): |
| 74 | + """Extended SPI is a busio extension that allows creating a compatible |
| 75 | + SPI object using the Bus ID number. The bus ID is the numbers at the end |
| 76 | + of /dev/spidev#.# and you can find which SPI devices you have by typing |
| 77 | + `ls /dev/spi*`""" |
| 78 | + |
| 79 | + # pylint: disable=invalid-name, redefined-builtin |
| 80 | + class Pin: |
| 81 | + """Fake Pin class""" |
| 82 | + |
| 83 | + def __init__(self, id): |
| 84 | + self.id = id |
| 85 | + |
| 86 | + # pylint: enable=invalid-name, redefined-builtin |
| 87 | + |
| 88 | + # pylint: disable=super-init-not-called |
| 89 | + def __init__(self, bus_id, chip_select): |
| 90 | + self.deinit() |
| 91 | + |
| 92 | + # Check if the file /dev/i2c-{bus_id} exists and error if not |
| 93 | + if not path.exists("/dev/spidev{}.{}".format(bus_id, chip_select)): |
| 94 | + raise ValueError( |
| 95 | + "No device found for /dev/spidev{}.{}".format(bus_id, chip_select) |
| 96 | + ) |
| 97 | + |
| 98 | + self._spi = _SPI((bus_id, chip_select)) |
| 99 | + # Pins aren't used in Linux, so we just use fake pins |
| 100 | + self._pins = (self.Pin(0), self.Pin(0), self.Pin(0)) |
| 101 | + |
| 102 | + # pylint: enable=super-init-not-called |
| 103 | + |
| 104 | + |
| 105 | +# pylint: enable=too-few-public-methods |
0 commit comments