Class SPI
Defined in File spi.hh
Class Documentation
-
class SPI
SPI class.
Represents SPI bus on the linux device.
Public Functions
-
explicit SPI(const char *fileName)
Construct a new SPI object.
Opens bus file automatically. Explicit call with setConfig() is required for proper functional.
- Parameters:
fileName – File name to open.
-
SPI(const char *fileName, const SpiConfig &config)
Construct a new SPI object.
Open SPI bus file and set bus configuration.
- Parameters:
fileName – File name to open.
config – Bus configuration handle.
-
std::int32_t read(std::uint8_t *rxBuffer, std::uint8_t rxBufferLength)
Read bytes from the device.
- Parameters:
rxBuffer – Buffer to store read bytes from the device.
rxBufferLength – Size of the buffer.
- Returns:
Negative number on failure.
-
std::int32_t write(std::uint8_t *txBuffer, std::uint8_t txBufferLength)
Write number of bytes to the device.
- Parameters:
txBuffer – Buffer with data to be written to the device.
txBufferLength – Size of the buffer.
- Returns:
Negative number on failure.
-
std::int32_t xfer(std::uint8_t *txBuffer, std::uint8_t txBufferLength, std::uint8_t *rxBuffer, std::uint8_t rxBufferLength)
Write and the reads number of bytes from the device.
- Parameters:
txBuffer – Buffer with bytes to be written to the device.
txBufferLength – Size of buffer to be written to the device.
rxBuffer – Buffer to store read bytes.
rxBufferLength – Size of the return buffer.
- Returns:
Negative number on failure.
-
bool setSpeed(std::uint32_t speedHz)
Set SPI bus speed.
Value is only saved to the SPI configuration structure if transaction is successful.
- Parameters:
speedHz – Value of the speed in Hz.
- Returns:
True if transaction was successful and value has been saved to the bus configuration structure.
-
bool setMode(std::uint8_t mode)
Set SPI bus mode.
Value is only saved to the SPI configuration structure if transaction is successful.
- Parameters:
mode – SPI bus mode. One of the SPI_MODE_{0, 1, 2}
- Returns:
True if transaction was successful and value has been saved to the bus configuration structure.
-
bool setBitsPerWord(std::uint8_t bits)
Set SPI bus bits per word value.
Value is only saved to the SPI configuration structure if transaction is successful.
- Parameters:
bits – Bits per word value.
- Returns:
True if transaction was successful and value has been saved to the bus configuration structure.
-
bool setConfig(const SpiConfig &spiConfig)
Wrapper function for setting SPI bus parameters all at once.
Calls internally setMode(), setSpeed(), setBitsPerWord().
- Parameters:
spiConfig – SPI bus configuration structure.
- Returns:
True if transaction was successful and value has been saved to the bus configuration structure.
-
explicit SPI(const char *fileName)