SPIs

Functions

struct metal_spi *metal_spi_get_device(unsigned 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

__inline__ 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

__inline__ 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.

__inline__ 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

__inline__ 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:

enumerator METAL_SPI_SINGLE
enumerator METAL_SPI_DUAL
enumerator METAL_SPI_QUAD
enum [anonymous]

The Dual/Quad spi mode selection.

Values:

enumerator MULTI_WIRE_ALL
enumerator MULTI_WIRE_DATA_ONLY
enumerator MULTI_WIRE_ADDR_DATA

Public Members

enum metal_spi_config::[anonymous] 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.

unsigned int cmd_num

The spi command frame number (cycles = num * frame_len)

unsigned int addr_num

The spi address frame number.

unsigned int dummy_num

The spi dummy frame number.

enum metal_spi_config::[anonymous] multi_wire

The Dual/Quad spi mode selection.

struct metal_spi
#include <spi.h>

A handle for a SPI device.