Class LinuxFsSpi

All Implemented Interfaces:
Describable, Identity, Lifecycle, Extension, IO<Spi, SpiConfig, SpiProvider>, IODataReader, IODataWriter, Spi, AutoCloseable, Readable

public class LinuxFsSpi extends SpiBase implements Spi
SPI implementation that uses JNA bindings to the Linux SPI device (i.e. /dev/spidev0.0). Only supports writing but it works to drive an SSD1306 OLED display.
Since:
10/3/24.
Author:
mpilone
See Also:
  • Constructor Details

  • Method Details

    • open

      public void open()
      Specified by:
      open in interface Spi
      Overrides:
      open in class SpiBase
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Spi
      Overrides:
      close in class SpiBase
    • transfer

      public int transfer(byte[] write, int writeOffset, byte[] read, int readOffset, int numberOfBytes)
      Specified by:
      transfer in interface Spi
    • read

      public int read()
      Specified by:
      read in interface IODataReader
    • read

      public int read(byte[] read, int offset, int length)
      Specified by:
      read in interface IODataReader
    • write

      public int write(byte b)
      Specified by:
      write in interface IODataWriter
    • write

      public int write(byte[] data, int offset, int length)
      write SPI_BUFFSIZ most often is set to 4096. See initialize() This implementation can write blocks greater than 4096 byte 'however', read and understand how this is accomplished. A write of data no greater than 4096 bytes is accomplished with a single SPI write operation. So CE line low, write bytes, CE line high A write greater than 4096 bytes will be segmented to multiple writes each 4096 bytes in length, the last write is the MOD value. So, CE line low, write first 4096 bytes CE line high. This pattern will repeat until the last bytes length MOD 4096 are written. This means multiple SPI transaction with you SPI device. If CE line toggling creates problems with your SPI device your application can use a vacant GPIO configured as an Output pin and your application keep the CE pin low during the duration of the call to spi,write.
      Specified by:
      write in interface IODataWriter
      Parameters:
      data - data array of bytes to be written
      offset - offset in data buffer to start at
      length - number of bytes to be written
      Returns: