public class

SPI

extends Object
java.lang.Object
   ↳ com.digi.android.spi.SPI

Class Overview

This class allows the user to manage SPI devices. This interaction is performed via the corresponding native library that interfaces directly with the kernel.

Each object of this class is created for a determined SPI interface and SPI slave device.

To obtain an instance of the SPI interface you have to use the SPIManager.createSPI(int, int) method.

Summary

Public Methods
void close()
Attempts to close the SPI interface.
SPIConfig getConfig()
Gets the SPI configuration.
int getInterface()
Gets the SPI interface number.
int getSlaveDevice()
Gets the SPI slave device number.
boolean isInterfaceOpen()
Gets the status of the SPI interface.
void open(SPIConfig config)
Opens the SPI interface with the given configuration.
byte[] read(int numBytes)
Reads the specified number of bytes from the SPI slave device.
void setConfig(SPIConfig config)
Changes the configuration of the SPI.
byte[] transfer(byte[] txData)
Simultaneous write (of the given bytes) and read (of the same number of bytes) using the default clock frequency and word length parameters.
byte[] transfer(byte[] txData, int clockFrequency, int wordLength)
Simultaneous write (of the given bytes) and read (of the same number of bytes) using the given clock frequency and word length parameters (these parameters are only used for this transfer, but their default values remain the same).
void write(byte[] txData)
Writes the given bytes in the SPI slave device.
Protected Methods
void finalize()
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void close ()

Attempts to close the SPI interface.

Throws
IOException If there is an error closing the SPI interface.

public SPIConfig getConfig ()

Gets the SPI configuration.

Returns
SPIConfig The SPI configuration.

public int getInterface ()

Gets the SPI interface number.

Returns
int The SPI interface in use.

public int getSlaveDevice ()

Gets the SPI slave device number.

Returns
int The SPI slave device.

public boolean isInterfaceOpen ()

Gets the status of the SPI interface.

Returns
boolean true if interface is open, false if not.

public void open (SPIConfig config)

Opens the SPI interface with the given configuration.

Parameters
config SPIConfig: SPI configuration.
Throws
IOException If there is an error opening the SPI interface.
NoSuchInterfaceException If the configured SPI interface does not exist.
NullPointerException If config == null.

public byte[] read (int numBytes)

Reads the specified number of bytes from the SPI slave device.

Parameters
numBytes int: Amount of bytes to read.
Returns
byte[] The read bytes, null if error.
Throws
IllegalArgumentException If numBytes < 0.
IOException If the interface is closed or there is an error reading from the SPI slave device.

public void setConfig (SPIConfig config)

Changes the configuration of the SPI.

Parameters
config SPIConfig: New SPI configuration.
Throws
IOException If the interface is closed or there is an error changing the configuration.
NullPointerException If config == null.

public byte[] transfer (byte[] txData)

Simultaneous write (of the given bytes) and read (of the same number of bytes) using the default clock frequency and word length parameters.

Parameters
txData byte: Bytes to write.
Returns
byte[] The read bytes, null if error.
Throws
IOException If the interface is closed or there is an error transferring data.
NullPointerException If txData == null.

public byte[] transfer (byte[] txData, int clockFrequency, int wordLength)

Simultaneous write (of the given bytes) and read (of the same number of bytes) using the given clock frequency and word length parameters (these parameters are only used for this transfer, but their default values remain the same).

Parameters
txData byte: Bytes to write.
clockFrequency int: The clock frequency in Hz.
wordLength int: Number of bits per word.
Returns
byte[] The read bytes, null if error.
Throws
IllegalArgumentException If clockFrequency < 1 o if wordLength < 1.
IOException If the interface is closed or there is an error transferring data.
NullPointerException If txData == null.

public void write (byte[] txData)

Writes the given bytes in the SPI slave device.

Parameters
txData byte: Bytes to write.
Throws
IOException If the interface is closed or there is an error writing in the SPI slave device.
NullPointerException If txData == null.

Protected Methods

protected void finalize ()

Throws
Throwable