#include <libsimpleio/libspi.h> void SPI_open(const char *name, int32_t mode, int32_t wordsize, int32_t speed, int32_t *fd, int32_t *error); void SPI_close(int32_t fd, int32_t *error); void SPI_transaction(int32_t spifd, int32_t csfd, void *cmd, int32_t cmdlen, int32_t delayus, void *resp, int32_t resplen, int32_t *error);Link with -lsimpleio.
SPI_open() opens an SPI slave device. The device name, /dev/spidevx.x, must be passed in the name parameter. The mode parameter specifies the SPI bus transfer mode, 0 to 3. The wordsize parameter specifies the SPI bus transfer unit size, usually 8, 16, or 32 bits. Some SPI controllers only allow 8-bit transfers. The speed parameter specifies the SPI bus transfer speed in bits per second. Upon success, a file descriptor for the SPI slave device is returned in *fd.
SPI_close() closes a previously opened SPI slave device.
SPI_transaction() performs a single SPI bus transaction, with optional transmit and receive phases. Either the address of a command message and its length must be passed in the cmd and cmdlen parameters, or NULL and 0 for a receive only transaction. The delayus parameter indicates the time in microseconds between the transmit and receive phases. It should be set long enough for the SPI slave device to execute the command and generate its response. Either the address of a receive buffer and its size must be passed in the resp and resplen parameters, or NULL and 0 for a transmit only transaction. The csfd parameter should be set to SPI_CS_AUTO to use the hardware controlled slave chip select signal or set to the open file descriptor for a GPIO pin to use for the software controlled slave chip select signal.