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))
def __init__(self, clock, MOSI=None, MISO=None): self.deinit() if detector.board.any_embedded_linux: from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI else: from machine import SPI as _SPI from microcontroller.pin import spiPorts for portId, portSck, portMosi, portMiso in spiPorts: if ((clock == portSck) and # Clock is required! (MOSI == portMosi or MOSI == None) and # But can do with just output (MISO == portMiso or MISO == None)): # Or just input self._spi = _SPI(portId) self._pins = (portSck, portMosi, portMiso) break else: raise NotImplementedError( "No Hardware SPI on (SCLK, MOSI, MISO)={}\nValid SPI ports:{}". format((clock, MOSI, MISO), spiPorts))