Package com.diozero.api
Class SpiDevice
java.lang.Object
com.diozero.api.SpiDevice
- All Implemented Interfaces:
DeviceInterface
,SpiDeviceInterface
,Closeable
,AutoCloseable
public class SpiDevice extends Object implements SpiDeviceInterface
Serial Peripheral Interface device
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SpiDevice.Builder
I2C device builder. -
Constructor Summary
Constructors Constructor Description SpiDevice(int chipSelect)
SpiDevice(int controller, int chipSelect)
SpiDevice(int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst)
-
Method Summary
Modifier and Type Method Description static SpiDevice.Builder
builder(int chipSelect)
Construct a new SPI device builder instance using the specified chip select valuevoid
close()
Close this deviceint
getChipSelect()
Get the SPI Chip Selectint
getController()
Get the SPI controllerString
getKey()
Get the unique device identifier for this deviceboolean
isOpen()
Check if this device is open or closedvoid
write(byte... txBuffer)
Write the entire contents ofdata
to the devicevoid
write(byte[] txBuffer, int txOffset, int length)
Writelength
bytes fromdata
starting atoffset
byte[]
writeAndRead(byte... out)
Write thedata
to the device then readdata.length
bytes from the device
-
Constructor Details
-
SpiDevice
- Throws:
RuntimeIOException
-
SpiDevice
- Throws:
RuntimeIOException
-
SpiDevice
public SpiDevice(int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst) throws RuntimeIOException- Throws:
RuntimeIOException
-
-
Method Details
-
builder
Construct a new SPI device builder instance using the specified chip select value- Parameters:
chipSelect
- SPI chip select- Returns:
- SPI device builder
-
getKey
Get the unique device identifier for this device- Specified by:
getKey
in interfaceDeviceInterface
- Returns:
- unique device identifier
-
isOpen
public boolean isOpen()Check if this device is open or closed- Specified by:
isOpen
in interfaceDeviceInterface
- Returns:
- true if this device is open
-
close
Close this device- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceDeviceInterface
- Throws:
RuntimeIOException
-
getController
public int getController()Get the SPI controller- Specified by:
getController
in interfaceSpiDeviceInterface
- Returns:
- the SPI controller
-
getChipSelect
public int getChipSelect()Get the SPI Chip Select- Specified by:
getChipSelect
in interfaceSpiDeviceInterface
- Returns:
- the SPI chip select
-
write
Write the entire contents ofdata
to the device- Specified by:
write
in interfaceSpiDeviceInterface
- Parameters:
txBuffer
- the data to write- Throws:
RuntimeIOException
- if an I/O error occurs
-
write
Writelength
bytes fromdata
starting atoffset
- Specified by:
write
in interfaceSpiDeviceInterface
- Parameters:
txBuffer
- the data to write.txOffset
- the start offset in the data.length
- the number of bytes to write.- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeAndRead
Write thedata
to the device then readdata.length
bytes from the device- Specified by:
writeAndRead
in interfaceSpiDeviceInterface
- Parameters:
out
- the data to write.- Returns:
- the data read from the device, same length as the data written.
- Throws:
RuntimeIOException
- if an I/O error occurs
-