Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
spi.h File Reference

Public API for SPI drivers and applications. More...

#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
#include <drivers/gpio.h>
#include <syscalls/spi.h>

Go to the source code of this file.

Data Structures

struct  spi_cs_control
 SPI Chip Select control structure. More...
 
struct  spi_config
 SPI controller configuration structure. More...
 
struct  spi_dt_spec
 Complete SPI DT information. More...
 
struct  spi_buf
 SPI buffer structure. More...
 
struct  spi_buf_set
 SPI buffer array structure. More...
 
struct  spi_driver_api
 SPI driver API This is the mandatory API any SPI driver needs to expose. More...
 

Macros

#define SPI_OP_MODE_MASTER   0
 SPI operational mode. More...
 
#define SPI_OP_MODE_SLAVE   BIT(0)
 
#define SPI_OP_MODE_MASK   0x1
 
#define SPI_OP_MODE_GET(_operation_)   ((_operation_) & SPI_OP_MODE_MASK)
 
#define SPI_MODE_CPOL   BIT(1)
 SPI Polarity & Phase Modes. More...
 
#define SPI_MODE_CPHA   BIT(2)
 
#define SPI_MODE_LOOP   BIT(3)
 
#define SPI_MODE_MASK   (0xE)
 
#define SPI_MODE_GET(_mode_)    ((_mode_) & SPI_MODE_MASK)
 
#define SPI_TRANSFER_MSB   (0)
 SPI Transfer modes (host controller dependent) More...
 
#define SPI_TRANSFER_LSB   BIT(4)
 
#define SPI_WORD_SIZE_SHIFT   (5)
 SPI word size. More...
 
#define SPI_WORD_SIZE_MASK   (0x3F << SPI_WORD_SIZE_SHIFT)
 
#define SPI_WORD_SIZE_GET(_operation_)    (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
 
#define SPI_WORD_SET(_word_size_)    ((_word_size_) << SPI_WORD_SIZE_SHIFT)
 
#define SPI_LINES_SINGLE   (0 << 11)
 SPI MISO lines. More...
 
#define SPI_LINES_DUAL   (1 << 11)
 
#define SPI_LINES_QUAD   (2 << 11)
 
#define SPI_LINES_OCTAL   (3 << 11)
 
#define SPI_LINES_MASK   (0x3 << 11)
 
#define SPI_HOLD_ON_CS   BIT(13)
 Specific SPI devices control bits. More...
 
#define SPI_LOCK_ON   BIT(14)
 
#define SPI_CS_ACTIVE_HIGH   BIT(15)
 
#define SPI_CS_CONTROL_PTR_DT(node_id, delay_)
 Initialize and get a pointer to a spi_cs_control from a devicetree node identifier. More...
 
#define SPI_CS_CONTROL_PTR_DT_INST(inst, delay_)    SPI_CS_CONTROL_PTR_DT(DT_DRV_INST(inst), delay_)
 Get a pointer to a spi_cs_control from a devicetree node. More...
 
#define SPI_CONFIG_DT(node_id, operation_, delay_)
 Structure initializer for spi_config from devicetree. More...
 
#define SPI_CONFIG_DT_INST(inst, operation_, delay_)    SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
 Structure initializer for spi_config from devicetree instance. More...
 
#define SPI_DT_SPEC_GET(node_id, operation_, delay_)
 Structure initializer for spi_dt_spec from devicetree. More...
 
#define SPI_DT_SPEC_INST_GET(inst, operation_, delay_)    SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
 Structure initializer for spi_dt_spec from devicetree instance. More...
 

Typedefs

typedef int(* spi_api_io) (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
 Callback API for I/O See spi_transceive() for argument descriptions. More...
 
typedef int(* spi_api_io_async) (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, struct k_poll_signal *async)
 
typedef int(* spi_api_release) (const struct device *dev, const struct spi_config *config)
 Callback API for unlocking SPI device. See spi_release() for argument descriptions. More...
 

Functions

static bool spi_is_ready (const struct spi_dt_spec *spec)
 Validate that SPI bus is ready. More...
 
int spi_transceive (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
 Read/write the specified amount of data from the SPI driver. More...
 
static int spi_transceive_dt (const struct spi_dt_spec *spec, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
 Read/write data from an SPI bus specified in spi_dt_spec. More...
 
static int spi_read (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs)
 Read the specified amount of data from the SPI driver. More...
 
static int spi_read_dt (const struct spi_dt_spec *spec, const struct spi_buf_set *rx_bufs)
 Read data from a SPI bus specified in spi_dt_spec. More...
 
static int spi_write (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs)
 Write the specified amount of data from the SPI driver. More...
 
static int spi_write_dt (const struct spi_dt_spec *spec, const struct spi_buf_set *tx_bufs)
 Write data to a SPI bus specified in spi_dt_spec. More...
 
static int spi_transceive_async (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, struct k_poll_signal *async)
 Read/write the specified amount of data from the SPI driver. More...
 
static int spi_read_async (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs, struct k_poll_signal *async)
 Read the specified amount of data from the SPI driver. More...
 
static int spi_write_async (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, struct k_poll_signal *async)
 Write the specified amount of data from the SPI driver. More...
 
int spi_release (const struct device *dev, const struct spi_config *config)
 Release the SPI device locked on by the current config. More...
 
static int spi_release_dt (const struct spi_dt_spec *spec)
 Release the SPI device specified in spi_dt_spec. More...
 

Detailed Description

Public API for SPI drivers and applications.