Package com.diozero.api
Class SpiDevice
- java.lang.Object
-
- com.diozero.api.SpiDevice
-
- All Implemented Interfaces:
DeviceInterface
,SpiDeviceInterface
,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)
SpiDevice(SpiDeviceFactoryInterface deviceFactory, int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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 controllervoid
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 Detail
-
SpiDevice
public SpiDevice(int chipSelect) throws RuntimeIOException
- Throws:
RuntimeIOException
-
SpiDevice
public SpiDevice(int controller, int chipSelect) throws RuntimeIOException
- Throws:
RuntimeIOException
-
SpiDevice
public SpiDevice(int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst) throws RuntimeIOException
- Throws:
RuntimeIOException
-
SpiDevice
public SpiDevice(SpiDeviceFactoryInterface deviceFactory, int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst) throws RuntimeIOException
- Throws:
RuntimeIOException
-
-
Method Detail
-
builder
public static SpiDevice.Builder builder(int chipSelect)
Construct a new SPI device builder instance using the specified chip select value- Parameters:
chipSelect
- SPI chip select- Returns:
- SPI device builder
-
close
public void close() throws RuntimeIOException
Close this device- Specified by:
close
in interfaceAutoCloseable
- 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
public void write(byte... txBuffer) throws RuntimeIOException
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
public void write(byte[] txBuffer, int txOffset, int length) throws RuntimeIOException
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
public byte[] writeAndRead(byte... out) throws RuntimeIOException
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
-
-