12#ifndef ZEPHYR_INCLUDE_DRIVERS_SPI_H_
13#define ZEPHYR_INCLUDE_DRIVERS_SPI_H_
34#define SPI_OP_MODE_MASTER 0
35#define SPI_OP_MODE_SLAVE BIT(0)
36#define SPI_OP_MODE_MASK 0x1
37#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
48#define SPI_MODE_CPOL BIT(1)
57#define SPI_MODE_CPHA BIT(2)
64#define SPI_MODE_LOOP BIT(3)
66#define SPI_MODE_MASK (0xE)
67#define SPI_MODE_GET(_mode_) \
68 ((_mode_) & SPI_MODE_MASK)
73#define SPI_TRANSFER_MSB (0)
74#define SPI_TRANSFER_LSB BIT(4)
79#define SPI_WORD_SIZE_SHIFT (5)
80#define SPI_WORD_SIZE_MASK (0x3F << SPI_WORD_SIZE_SHIFT)
81#define SPI_WORD_SIZE_GET(_operation_) \
82 (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
84#define SPI_WORD_SET(_word_size_) \
85 ((_word_size_) << SPI_WORD_SIZE_SHIFT)
93#define SPI_LINES_SINGLE (0 << 11)
94#define SPI_LINES_DUAL (1 << 11)
95#define SPI_LINES_QUAD (2 << 11)
96#define SPI_LINES_OCTAL (3 << 11)
98#define SPI_LINES_MASK (0x3 << 11)
104#define SPI_HOLD_ON_CS BIT(13)
110#define SPI_LOCK_ON BIT(14)
119#define SPI_CS_ACTIVE_HIGH BIT(15)
190#define SPI_CS_CONTROL_PTR_DT(node_id, delay_) \
191 (&(struct spi_cs_control) { \
192 .gpio_dev = DEVICE_DT_GET( \
193 DT_SPI_DEV_CS_GPIOS_CTLR(node_id)), \
195 .gpio_pin = DT_SPI_DEV_CS_GPIOS_PIN(node_id), \
196 .gpio_dt_flags = DT_SPI_DEV_CS_GPIOS_FLAGS(node_id), \
214#define SPI_CS_CONTROL_PTR_DT_INST(inst, delay_) \
215 SPI_CS_CONTROL_PTR_DT(DT_DRV_INST(inst), delay_)
272#define SPI_CONFIG_DT(node_id, operation_, delay_) \
274 .frequency = DT_PROP(node_id, spi_max_frequency), \
275 .operation = (operation_), \
276 .slave = DT_REG_ADDR(node_id), \
278 DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
279 (SPI_CS_CONTROL_PTR_DT(node_id, delay_)), \
296#define SPI_CONFIG_DT_INST(inst, operation_, delay_) \
297 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
331#define SPI_DT_SPEC_GET(node_id, operation_, delay_) \
333 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
334 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
350#define SPI_DT_SPEC_INST_GET(inst, operation_, delay_) \
351 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
414#ifdef CONFIG_SPI_ASYNC
465static inline int z_impl_spi_transceive(
const struct device *dev,
473 return api->
transceive(dev, config, tx_bufs, rx_bufs);
581#ifdef CONFIG_SPI_ASYNC
704static inline int z_impl_spi_release(
const struct device *dev,
710 return api->
release(dev, config);
737#include <syscalls/spi.h>
Public APIs for GPIO drivers.
static bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
Definition: device.h:686
uint8_t gpio_dt_flags_t
Provides a type to hold GPIO devicetree flags.
Definition: gpio.h:304
uint8_t gpio_pin_t
Provides a type to hold a GPIO pin index.
Definition: gpio.h:295
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.
Definition: spi.h:674
int spi_release(const struct device *dev, const struct spi_config *config)
Release the SPI device locked on by the current config.
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)
Definition: spi.h:393
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.
Definition: spi.h:574
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.
Definition: spi.h:514
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.
Definition: spi.h:491
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.
Definition: spi.h:608
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.
Definition: spi.h:533
static bool spi_is_ready(const struct spi_dt_spec *spec)
Validate that SPI bus is ready.
Definition: spi.h:428
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.
Definition: spi.h:555
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition: spi.h:724
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.
Definition: spi.h:404
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.
Definition: spi.h:383
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.
Definition: spi.h:643
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.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Definition: kernel.h:5405
SPI buffer array structure.
Definition: spi.h:373
const struct spi_buf * buffers
Definition: spi.h:374
size_t count
Definition: spi.h:375
SPI buffer structure.
Definition: spi.h:362
size_t len
Definition: spi.h:364
void * buf
Definition: spi.h:363
SPI controller configuration structure.
Definition: spi.h:244
uint16_t slave
Definition: spi.h:247
const struct spi_cs_control * cs
Definition: spi.h:249
uint32_t frequency
Definition: spi.h:245
uint16_t operation
Definition: spi.h:246
SPI Chip Select control structure.
Definition: spi.h:138
uint32_t delay
Definition: spi.h:140
gpio_pin_t gpio_pin
Definition: spi.h:141
gpio_dt_flags_t gpio_dt_flags
Definition: spi.h:142
const struct device * gpio_dev
Definition: spi.h:139
SPI driver API This is the mandatory API any SPI driver needs to expose.
Definition: spi.h:412
spi_api_io transceive
Definition: spi.h:413
spi_api_release release
Definition: spi.h:417
spi_api_io_async transceive_async
Definition: spi.h:415
Complete SPI DT information.
Definition: spi.h:306
const struct device * bus
Definition: spi.h:307
struct spi_config config
Definition: spi.h:308