-
- All Superinterfaces:
AutoCloseable
,Describable
,Identity
,IO<Spi,SpiConfig,SpiProvider>
,IODataReader
,IODataWriter
,Lifecycle
,Readable
- All Known Implementing Classes:
SpiBase
public interface Spi extends IO<Spi,SpiConfig,SpiProvider>, AutoCloseable, IODataWriter, IODataReader
Spi interface.
- Version:
- $Id: $Id
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BAUD
ConstantDEFAULT_BAUD=1000000
static SpiMode
DEFAULT_MODE
ConstantDEFAULT_MODE
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
close.boolean
isOpen()
SPI Device Communication State is OPENstatic SpiConfigBuilder
newConfigBuilder(Context context)
newConfigBuilder.void
open()
open.default int
transfer(byte[] buffer)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(byte[] write, byte[] read)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(byte[] write, byte[] read, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(byte[] buffer, int length)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.int
transfer(byte[] write, int writeOffset, byte[] read, int readOffset, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(byte[] buffer, int offset, int length)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(ByteBuffer buffer, int offset, int length)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(ByteBuffer write, int writeOffset, ByteBuffer read, int readOffset, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transfer(ByteBuffer write, ByteBuffer read, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle.default int
transferByte(int handle, byte value)
This function reads a byte from the serial port associated with the handle.-
Methods inherited from interface com.pi4j.common.Identity
describe, description, getDescription, getId, getMetadata, getName, id, metadata, name
-
Methods inherited from interface com.pi4j.io.IODataReader
getInputStream, in, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, readByte, readByteBuffer, readByteBuffer, readCharArray, readCharArray, readCharArray, readCharArray, readCharBuffer, readCharBuffer, readCharBuffer, readCharBuffer, readNBytes, readNBytes, readString, readString, readString, readString
-
Methods inherited from interface com.pi4j.io.IODataWriter
getOutputStream, out, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write
-
Methods inherited from interface com.pi4j.common.Lifecycle
initialize, shutdown
-
-
-
-
Field Detail
-
DEFAULT_MODE
static final SpiMode DEFAULT_MODE
ConstantDEFAULT_MODE
-
DEFAULT_BAUD
static final int DEFAULT_BAUD
ConstantDEFAULT_BAUD=1000000
- See Also:
- Constant Field Values
-
-
Method Detail
-
newConfigBuilder
static SpiConfigBuilder newConfigBuilder(Context context)
newConfigBuilder.
- Parameters:
context
-Context
- Returns:
- a
SpiConfigBuilder
object.
-
isOpen
boolean isOpen()
SPI Device Communication State is OPEN- Returns:
- The SPI device communication state
-
open
void open()
open.
-
close
void close()
close.
- Specified by:
close
in interfaceAutoCloseable
-
transferByte
default int transferByte(int handle, byte value)
This function reads a byte from the serial port associated with the handle. If no data is ready PI_SER_READ_NO_DATA is returned.- Parameters:
handle
- the open serial device handle; (>=0, as returned by a call to serOpen)value
- a byte.- Returns:
- Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#serReadByte"
-
transfer
int transfer(byte[] write, int writeOffset, byte[] read, int readOffset, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the 'write' byte array from the given 'writeOffset' index to the specified length ('numberOfBytes'). Data read from the SPI device is then copied to the 'read' byte array at the given 'readOffset' using the same length ('numberOfBytes'). Both the 'write' and 'read' byte arrays must be at least the size of the defined 'numberOfBytes' + their corresponding offsets.- Parameters:
write
- the array of bytes to write to the SPI devicewriteOffset
- the starting offset position in the provided 'write' buffer to start writing to the SPI device from.read
- the array of bytes to store read data in from the SPI devicereadOffset
- the starting offset position in the provided 'read' buffer to place data bytes read from the SPI device.numberOfBytes
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(byte[] write, byte[] read, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the 'write' byte array from the zero index (first byte) to the specified length ('numberOfBytes'). Data read from the SPI device is then copied to the 'read' byte array starting at the zero index (first byte) using the same length ('numberOfBytes'). Both the 'write' and 'read' byte arrays must be at least the size of the defined 'numberOfBytes' + their corresponding offsets.- Parameters:
write
- the array of bytes to write to the SPI deviceread
- the array of bytes to store read data in from the SPI devicenumberOfBytes
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(byte[] write, byte[] read)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the entire contents of the 'write' byte array (from the zero index (first byte) to the array size). Data read from the SPI device is then copied to the 'read' byte array starting at the zero index (first byte) using the same length of the number of bytes in the 'write' array. The 'read' byte array must be at least the size of the defined 'write' byte array.- Parameters:
write
- the array of bytes to write to the SPI deviceread
- the array of bytes to store read data in from the SPI device- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(byte[] buffer, int offset, int length)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the 'buffer' byte array from the given 'offset' index to the specified 'length' (number of bytes). Data read back from the SPI device is then copied to the same 'buffer' byte array starting at the given 'offset' using the same 'length' (number of bytes). The 'buffer' byte array must be at least the size of the defined 'length' + 'offset'.- Parameters:
buffer
- the array of bytes to write to the SPI device and to store read data back from the SPI deviceoffset
- the starting offset position in the provided buffer to start writing to the SPI device from and the position used as the starting offset position to place data bytes read back from the SPI device.length
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(byte[] buffer, int length)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the 'buffer' byte array from the zero index (first byte) to the specified length (number of bytes). Data read from the SPI device is then copied back to the same 'buffer' byte array starting at the zero index (first byte) using the same length. The 'buffer' byte array must be at least the size of the defined 'length'.- Parameters:
buffer
- the array of bytes to write to the SPI device and to store read data back from the SPI devicelength
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(byte[] buffer)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the entire 'buffer' byte array contents. Data read back from the SPI device is then copied back to the same 'buffer' byte array starting at the zero index (first byte).- Parameters:
buffer
- the array of bytes to write to the SPI device and to store read data back from the SPI device- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(ByteBuffer write, int writeOffset, ByteBuffer read, int readOffset, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the 'write' byte buffer from the given 'writeOffset' index to the specified length ('numberOfBytes'). Data read from the SPI device is then copied to the 'read' byte buffer at the given 'readOffset' using the same length ('numberOfBytes'). Both the 'write' and 'read' byte buffers must at least have the available capacity of the defined 'numberOfBytes' + their corresponding offsets. NOTE: The buffer's internal position tracking is not used but rather only the explicit offset and length provided. If the requested length is greater than the buffers capacity (minus offset) then the specified length will be ignored and this function will only read the number of bytes up to the buffers' available space.- Parameters:
write
- the ByteBuffer to write to the SPI devicewriteOffset
- the starting offset position in the provided 'write' buffer to start writing to the SPI device from.read
- the ByteBuffer to store read data in from the SPI devicereadOffset
- the starting offset position in the provided 'read' buffer to place data bytes read from the SPI device.numberOfBytes
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(ByteBuffer write, ByteBuffer read, int numberOfBytes)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the 'write' byte buffer from the buffer's current position up to the specified length ('numberOfBytes'). Data read from the SPI device is then copied to the 'read' byte buffer starting at the buffer's current position using the same length ('numberOfBytes'). Both the 'write' and 'read' byte buffers must at least have the available capacity of the defined 'numberOfBytes' + their corresponding current positions. NOTE: The contents from the 'write' byte buffer is read from the current position index up to the length requested or up to the buffer's remaining limit; whichever is is lower . If the buffer's current position is already at the buffer's limit, then we will automatically flip the buffer to begin reading data from the zero position up to the buffer's limit * NOTE: The data bytes read from the SPI device are copied/ inserted into the 'read' byte buffer starting at the current position index up to the length requested or up to the buffer's remaining limit; whichever is is lower . If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.- Parameters:
write
- the ByteBuffer to write to the SPI deviceread
- the ByteBuffer to store read data in from the SPI devicenumberOfBytes
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
transfer
default int transfer(ByteBuffer buffer, int offset, int length)
This function transfers (writes/reads simultaneously) multiple bytes with the SPI device associated with the handle. Write data is taken from the byte buffer from the given 'offset' index to the specified length (number of bytes). Data read from the SPI device is then copied to the byte buffer at the given 'offset' using the same length (number of bytes). The byte buffer must at least have the available capacity of the defined 'length' + 'offset'. NOTE: The buffer's internal position tracking is not used but rather only the explicit offset and length provided. If the requested length is greater than the buffers capacity (minus offset) then the specified length will be ignored and this function will only read the number of bytes up to the buffers' available space.- Parameters:
buffer
- the byte buffer to write to the SPI device and to store read data back from the SPI deviceoffset
- the starting offset position in the provided buffer to start writing to the SPI device from and the position used as the starting offset position to place data bytes read back from the SPI device.length
- the number of bytes to transfer/exchange (read & read))- Returns:
- Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
- See Also:
- "http://abyz.me.uk/rpi/pigpio/cif.html#spiWrite"
-
-