SPIs

Functions

struct metal_spi *metal_spi_get_device(int device_num)

Get a handle for a SPI device.

Return
A handle to the SPI device, or NULL if the device does not exist
Parameters
  • device_num: The index of the desired SPI device

void metal_spi_init(struct metal_spi *spi, int baud_rate)

Initialize a SPI device with a certain baud rate.

Parameters
  • spi: The handle for the SPI device to initialize
  • baud_rate: The baud rate to set the SPI device to

int metal_spi_transfer(struct metal_spi *spi, struct metal_spi_config *config, size_t len, char *tx_buf, char *rx_buf)

Perform a SPI transfer.

Return
0 if the transfer succeeds
Parameters
  • spi: The handle for the SPI device to perform the transfer
  • config: The configuration for the SPI transfer.
  • len: The number of bytes to transfer
  • tx_buf: The buffer to send over the SPI bus. Must be len bytes long. If NULL, the SPI will transfer the value 0.
  • rx_buf: The buffer to receive data into. Must be len bytes long. If NULL, the SPI will ignore received bytes.

int metal_spi_get_baud_rate(struct metal_spi *spi)

Get the current baud rate of the SPI device.

Return
The baud rate in Hz
Parameters
  • spi: The handle for the SPI device

int metal_spi_set_baud_rate(struct metal_spi *spi, int baud_rate)

Set the current baud rate of the SPI device.

Return
0 if the baud rate is successfully changed
Parameters
  • spi: The handle for the SPI device
  • baud_rate: The desired baud rate of the SPI device

struct metal_spi_config
#include <spi.h>

The configuration for a SPI transfer.

Public Types

enum [anonymous]

The protocol for the SPI transfer.

Values:

METAL_SPI_SINGLE
METAL_SPI_DUAL
METAL_SPI_QUAD

Public Members

metal_spi_config::@0 metal_spi_config::protocol

The protocol for the SPI transfer.

unsigned int polarity

The polarity of the SPI transfer, equivalent to CPOL.

unsigned int phase

The phase of the SPI transfer, equivalent to CPHA.

unsigned int little_endian

The endianness of the SPI transfer.

unsigned int cs_active_high

The active state of the chip select line.

unsigned int csid

The chip select ID to activate for the SPI transfer.

struct metal_spi
#include <spi.h>

A handle for a SPI device.