pihwm  r1
A lightweight C library for Raspberry Pi hardware modules.
SPI

SPI library functions. More...

Functions

int spi_init (uint8_t channel)
 Initialises the spidev interface. More...
 
int spi_init_name (char *devname)
 Initialises the spidev interface for the sysfs entry specified by the devname parameter. More...
 
int spi_config (int fd, uint8_t mode, uint8_t bits, uint32_t speed, uint16_t delay)
 Configures the spidev interface. More...
 
int spi_config_default (int fd)
 Configures the spidev interface with default values. More...
 
int spi_transfer (int fd, uint8_t txbuf[], uint8_t rxbuf[], uint8_t len)
 Initiates SPI transfers. More...
 

Detailed Description

SPI library functions.

Function Documentation

◆ spi_config()

int spi_config ( int  fd,
uint8_t  mode,
uint8_t  bits,
uint32_t  speed,
uint16_t  delay 
)

Configures the spidev interface.

Parameters
fdFile descriptor to use, can be acquired via spi_init()
modeSPI mode
bitsNumber of bits
speedBus speed
delayAmount of delay
Returns
1 for success, -1 for failure

Definition at line 139 of file pi_spi.c.

◆ spi_config_default()

int spi_config_default ( int  fd)

Configures the spidev interface with default values.

Parameters
fdFile descriptor to use, can be acquired via spi_init()
Returns
1 for success, -1 for failure

Definition at line 178 of file pi_spi.c.

◆ spi_init()

int spi_init ( uint8_t  channel)

Initialises the spidev interface.

Parameters
channelSPI channel to use (0 or 1)
Returns
1 for success, -1 for failure

Definition at line 52 of file pi_spi.c.

◆ spi_init_name()

int spi_init_name ( char *  devname)

Initialises the spidev interface for the sysfs entry specified by the devname parameter.

Parameters
devnameThe sysfs entry for a particular SPI peripheral
Returns
The file descriptor for the relevant spidev interface, -1 for failure

Definition at line 112 of file pi_spi.c.

◆ spi_transfer()

int spi_transfer ( int  fd,
uint8_t  txbuf[],
uint8_t  rxbuf[],
uint8_t  len 
)

Initiates SPI transfers.

Parameters
fdFile descriptor to use, can be acquired via spi_init()
txbufTransmit buffer array
rxbufReceive buffer array
lenLength of transfer
Returns
1 for success, -1 for failure

Definition at line 198 of file pi_spi.c.