def __init__(self, spi_cs, spi_bus = board.SPI()): from adafruit_bus_device.spi_device import SPIDevice as spidev _spi = spidev(spi_bus, spi_cs, baudrate=1000000) read_buffer = bytearray(1) # We don't know what state the flash is in, so make sure it's not up to anything, then reset. with _spi as spi: while True: # The write in progress bit should be low. spi.write(bytearray([SFLASH_CMD_READ_STATUS])) spi.readinto(read_buffer) if read_buffer[0] & 0x01 == 0: break while True: # The suspended write/erase bit should be low. spi.write(bytearray([SFLASH_CMD_READ_STATUS2])) spi.readinto(read_buffer) if read_buffer[0] & 0x80 == 0: break # reset and disable writes spi.write(bytearray([SFLASH_CMD_ENABLE_RESET])) spi.write(bytearray([SFLASH_CMD_RESET])) spi.write(bytearray([SFLASH_CMD_WRITE_DISABLE])) self._spi = _spi super().__init__()
def __init__(self, spi_bus, spi_cs, write_protect=False, wp_pin=None, baudrate=100000): from adafruit_bus_device.spi_device import SPIDevice as spidev _spi = spidev(spi_bus, spi_cs, baudrate=baudrate) read_buffer = bytearray(4) with _spi as spi: spi.write(bytearray([_SPI_OPCODE_RDID])) spi.readinto(read_buffer) prod_id = (read_buffer[3] << 8) + (read_buffer[2]) if (read_buffer[0] != _SPI_MANF_ID) and (prod_id != _SPI_PROD_ID): raise OSError("FRAM SPI device not found.") self._spi = _spi super().__init__(_MAX_SIZE_SPI, write_protect, wp_pin)
def __init__( self, spi_bus: SPI, spi_cs: DigitalInOut, write_protect: bool = False, wp_pin: Optional[DigitalInOut] = None, baudrate: int = 100000, max_size: int = _MAX_SIZE_SPI, ): from adafruit_bus_device.spi_device import ( # pylint: disable=import-outside-toplevel SPIDevice as spidev, ) _spi = spidev(spi_bus, spi_cs, baudrate=baudrate) read_buffer = bytearray(4) with _spi as spi: spi.write(bytearray([_SPI_OPCODE_RDID])) spi.readinto(read_buffer) prod_id = (read_buffer[3] << 8) + (read_buffer[2]) if (read_buffer[0] != _SPI_MANF_ID) and (prod_id != _SPI_PROD_ID): raise OSError("FRAM SPI device not found.") self._spi = _spi super().__init__(max_size, write_protect, wp_pin)