Zephyr Project API 4.0.0
A Scalable Open Source RTOS
|
SPI Interface. More...
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_CS_GPIOS_DT_SPEC_GET(spi_dev) |
Get a struct gpio_dt_spec for a SPI device's chip select pin. | |
#define | SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst)) |
Get a struct gpio_dt_spec for a SPI device's chip select pin. | |
#define | SPI_CS_CONTROL_INIT(node_id, delay_) |
Initialize and get a pointer to a spi_cs_control from a devicetree node identifier. | |
#define | SPI_CS_CONTROL_INIT_INST(inst, delay_) SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_) |
Get a pointer to a spi_cs_control from a devicetree node. | |
#define | SPI_CONFIG_DT(node_id, operation_, delay_) |
Structure initializer for spi_config from devicetree. | |
#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. | |
#define | SPI_DT_SPEC_GET(node_id, operation_, delay_) |
Structure initializer for spi_dt_spec from devicetree. | |
#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. | |
#define | SPI_MOSI_OVERRUN_UNKNOWN 0x100 |
Value that will never compare true with any valid overrun character. | |
#define | SPI_MOSI_OVERRUN_DT(node_id) DT_PROP_OR(node_id, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN) |
The value sent on MOSI when all TX bytes are sent, but RX continues. | |
#define | SPI_MOSI_OVERRUN_DT_INST(inst) DT_INST_PROP_OR(inst, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN) |
The value sent on MOSI when all TX bytes are sent, but RX continues. | |
#define | SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, ...) |
#define | SPI_STATS_RX_BYTES_INC(dev_) |
#define | SPI_STATS_TX_BYTES_INC(dev_) |
#define | SPI_STATS_TRANSFER_ERROR_INC(dev_) |
#define | spi_transceive_stats(dev, error, tx_bufs, rx_bufs) |
#define | SPI_DT_IODEV_DEFINE(name, node_id, operation_, delay_) |
Define an iodev for a given dt node on the bus. | |
Typedefs | |
typedef uint16_t | spi_operation_t |
Opaque type to hold the SPI operation flags. | |
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. | |
typedef void(* | spi_callback_t) (const struct device *dev, int result, void *data) |
SPI callback for asynchronous transfer requests. | |
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, spi_callback_t cb, void *userdata) |
typedef int(* | spi_api_release) (const struct device *dev, const struct spi_config *config) |
Callback API for unlocking SPI device. | |
Functions | |
static bool | spi_cs_is_gpio (const struct spi_config *config) |
Check if SPI CS is controlled using a GPIO. | |
static bool | spi_cs_is_gpio_dt (const struct spi_dt_spec *spec) |
Check if SPI CS in spi_dt_spec is controlled using a GPIO. | |
static bool | spi_is_ready_dt (const struct spi_dt_spec *spec) |
Validate that SPI bus (and CS gpio if defined) is ready. | |
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. | |
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 . | |
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. | |
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 . | |
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. | |
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 . | |
static int | spi_transceive_cb (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, spi_callback_t callback, void *userdata) |
Read/write the specified amount of data from the SPI driver. | |
static int | spi_transceive_signal (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 *sig) |
Read/write the specified amount of data from the SPI driver. | |
static int | spi_read_signal (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig) |
Read the specified amount of data from the SPI driver. | |
static int | spi_write_signal (const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, struct k_poll_signal *sig) |
Write the specified amount of data from the SPI driver. | |
static void | spi_iodev_submit (struct rtio_iodev_sqe *iodev_sqe) |
Submit a SPI device with a request. | |
static bool | spi_is_ready_iodev (const struct rtio_iodev *spi_iodev) |
Validate that SPI bus (and CS gpio if defined) is ready. | |
int | spi_release (const struct device *dev, const struct spi_config *config) |
Release the SPI device locked on and/or the CS by the current config. | |
static int | spi_release_dt (const struct spi_dt_spec *spec) |
Release the SPI device specified in spi_dt_spec . | |
Variables | |
const struct rtio_iodev_api | spi_iodev_api |
SPI operational mode | |
#define | SPI_OP_MODE_MASTER 0U |
Master mode. | |
#define | SPI_OP_MODE_SLAVE BIT(0) |
Slave mode. | |
#define | SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK) |
Get SPI operational mode. | |
SPI Polarity & Phase Modes | |
#define | SPI_MODE_CPOL BIT(1) |
Clock Polarity: if set, clock idle state will be 1 and active state will be 0. | |
#define | SPI_MODE_CPHA BIT(2) |
Clock Phase: this dictates when is the data captured, and depends clock's polarity. | |
#define | SPI_MODE_LOOP BIT(3) |
Whatever data is transmitted is looped-back to the receiving buffer of the controller. | |
#define | SPI_MODE_GET(_mode_) ((_mode_) & SPI_MODE_MASK) |
Get SPI polarity and phase mode bits. | |
SPI Transfer modes (host controller dependent) | |
#define | SPI_TRANSFER_MSB (0U) |
Most significant bit first. | |
#define | SPI_TRANSFER_LSB BIT(4) |
Least significant bit first. | |
SPI word size | |
#define | SPI_WORD_SIZE_GET(_operation_) (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT) |
Get SPI word size (data frame size) in bits. | |
#define | SPI_WORD_SET(_word_size_) ((_word_size_) << SPI_WORD_SIZE_SHIFT) |
Set SPI word size (data frame size) in bits. | |
Specific SPI devices control bits | |
#define | SPI_HOLD_ON_CS BIT(12) |
Requests - if possible - to keep CS asserted after the transaction. | |
#define | SPI_LOCK_ON BIT(13) |
Keep the device locked after the transaction for the current config. | |
#define | SPI_CS_ACTIVE_HIGH BIT(14) |
Active high logic on CS. | |
SPI MISO lines | |
Some controllers support dual, quad or octal MISO lines connected to slaves. Default is single, which is the case most of the time. Without CONFIG_SPI_EXTENDED_MODES being enabled, single is the only supported one. | |
#define | SPI_LINES_SINGLE (0U << 16) |
Single line. | |
#define | SPI_LINES_DUAL (1U << 16) |
Dual lines. | |
#define | SPI_LINES_QUAD (2U << 16) |
Quad lines. | |
#define | SPI_LINES_OCTAL (3U << 16) |
Octal lines. | |
#define | SPI_LINES_MASK (0x3U << 16) |
Mask for MISO lines in spi_operation_t. | |
SPI duplex mode | |
Some controllers support half duplex transfer, which results in 3-wire usage. By default, full duplex will prevail. | |
#define | SPI_FULL_DUPLEX (0U << 11) |
#define | SPI_HALF_DUPLEX (1U << 11) |
SPI Frame Format | |
2 frame formats are exposed: Motorola and TI. The main difference is the behavior of the CS line. In Motorola it stays active the whole transfer. In TI, it's active only one serial clock period prior to actually make the transfer, it is thus inactive during the transfer, which ends when the clocks ends as well. By default, as it is the most commonly used, the Motorola frame format will prevail. | |
#define | SPI_FRAME_FORMAT_MOTOROLA (0U << 15) |
#define | SPI_FRAME_FORMAT_TI (1U << 15) |
SPI Interface.
#define SPI_CONFIG_DT | ( | node_id, | |
operation_, | |||
delay_ | |||
) |
#include <include/zephyr/drivers/spi.h>
Structure initializer for spi_config from devicetree.
This helper macro expands to a static initializer for a struct spi_config
by reading the relevant frequency
, slave
, and cs
data from the devicetree.
node_id | Devicetree node identifier for the SPI device whose struct spi_config to create an initializer for |
operation_ | the desired operation field in the struct spi_config |
delay_ | the desired delay field in the struct spi_config's spi_cs_control, if there is one |
#define SPI_CONFIG_DT_INST | ( | inst, | |
operation_, | |||
delay_ | |||
) | SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_) |
#include <include/zephyr/drivers/spi.h>
Structure initializer for spi_config from devicetree instance.
This is equivalent to SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
.
inst | Devicetree instance number |
operation_ | the desired operation field in the struct spi_config |
delay_ | the desired delay field in the struct spi_config's spi_cs_control, if there is one |
#define SPI_CS_ACTIVE_HIGH BIT(14) |
#include <include/zephyr/drivers/spi.h>
Active high logic on CS.
Usually, and by default, CS logic is active low. However, some devices may require the reverse logic: active high. This bit will request the controller to use that logic. Note that not all controllers are able to handle that natively. In this case deferring the CS control to a gpio line through struct spi_cs_control would be the solution.
#define SPI_CS_CONTROL_INIT | ( | node_id, | |
delay_ | |||
) |
#include <include/zephyr/drivers/spi.h>
Initialize and get a pointer to a spi_cs_control
from a devicetree node identifier.
This helper is useful for initializing a device on a SPI bus. It initializes a struct spi_cs_control and returns a pointer to it. Here, node_id
is a node identifier for a SPI device, not a SPI controller.
Example devicetree fragment:
Example usage:
This example is equivalent to:
node_id | Devicetree node identifier for a device on a SPI bus |
delay_ | The delay field to set in the spi_cs_control |
spi_cs_control
structure #define SPI_CS_CONTROL_INIT_INST | ( | inst, | |
delay_ | |||
) | SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_) |
#include <include/zephyr/drivers/spi.h>
Get a pointer to a spi_cs_control
from a devicetree node.
This is equivalent to SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay)
.
Therefore, DT_DRV_COMPAT
must already be defined before using this macro.
inst | Devicetree node instance number |
delay_ | The delay field to set in the spi_cs_control |
spi_cs_control
structure #define SPI_CS_GPIOS_DT_SPEC_GET | ( | spi_dev | ) |
#include <include/zephyr/drivers/spi.h>
Get a struct gpio_dt_spec
for a SPI device's chip select pin.
Example devicetree fragment:
Example usage:
spi_dev | a SPI device node identifier |
#define SPI_CS_GPIOS_DT_SPEC_INST_GET | ( | inst | ) | SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst)) |
#include <include/zephyr/drivers/spi.h>
Get a struct gpio_dt_spec
for a SPI device's chip select pin.
This is equivalent to SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
.
inst | Devicetree instance number |
#define SPI_DEVICE_DT_DEFINE | ( | node_id, | |
init_fn, | |||
pm, | |||
data, | |||
config, | |||
level, | |||
prio, | |||
api, | |||
... | |||
) |
#include <include/zephyr/drivers/spi.h>
#define SPI_DT_IODEV_DEFINE | ( | name, | |
node_id, | |||
operation_, | |||
delay_ | |||
) |
#include <include/zephyr/drivers/spi.h>
Define an iodev for a given dt node on the bus.
These do not need to be shared globally but doing so will save a small amount of memory.
name | Symbolic name to use for defining the iodev |
node_id | Devicetree node identifier |
operation_ | SPI operational mode |
delay_ | Chip select delay in microseconds |
#define SPI_DT_SPEC_GET | ( | node_id, | |
operation_, | |||
delay_ | |||
) |
#include <include/zephyr/drivers/spi.h>
Structure initializer for spi_dt_spec from devicetree.
This helper macro expands to a static initializer for a struct spi_dt_spec
by reading the relevant bus, frequency, slave, and cs data from the devicetree.
Important: multiple fields are automatically constructed by this macro which must be checked before use. spi_is_ready_dt performs the required device_is_ready checks.
node_id | Devicetree node identifier for the SPI device whose struct spi_dt_spec to create an initializer for |
operation_ | the desired operation field in the struct spi_config |
delay_ | the desired delay field in the struct spi_config's spi_cs_control, if there is one |
#define SPI_DT_SPEC_INST_GET | ( | inst, | |
operation_, | |||
delay_ | |||
) | SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_) |
#include <include/zephyr/drivers/spi.h>
Structure initializer for spi_dt_spec from devicetree instance.
This is equivalent to SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
.
inst | Devicetree instance number |
operation_ | the desired operation field in the struct spi_config |
delay_ | the desired delay field in the struct spi_config's spi_cs_control, if there is one |
#define SPI_FRAME_FORMAT_MOTOROLA (0U << 15) |
#include <include/zephyr/dt-bindings/spi/spi.h>
#define SPI_FRAME_FORMAT_TI (1U << 15) |
#include <include/zephyr/dt-bindings/spi/spi.h>
#define SPI_FULL_DUPLEX (0U << 11) |
#include <include/zephyr/dt-bindings/spi/spi.h>
#define SPI_HALF_DUPLEX (1U << 11) |
#include <include/zephyr/dt-bindings/spi/spi.h>
#define SPI_HOLD_ON_CS BIT(12) |
#include <include/zephyr/drivers/spi.h>
Requests - if possible - to keep CS asserted after the transaction.
#define SPI_LINES_DUAL (1U << 16) |
#include <include/zephyr/drivers/spi.h>
Dual lines.
#define SPI_LINES_MASK (0x3U << 16) |
#include <include/zephyr/drivers/spi.h>
Mask for MISO lines in spi_operation_t.
#define SPI_LINES_OCTAL (3U << 16) |
#include <include/zephyr/drivers/spi.h>
Octal lines.
#define SPI_LINES_QUAD (2U << 16) |
#include <include/zephyr/drivers/spi.h>
Quad lines.
#define SPI_LINES_SINGLE (0U << 16) |
#include <include/zephyr/drivers/spi.h>
Single line.
#define SPI_LOCK_ON BIT(13) |
#include <include/zephyr/drivers/spi.h>
Keep the device locked after the transaction for the current config.
Use this with extreme caution (see spi_release() below) as it will prevent other callers to access the SPI device until spi_release() is properly called.
#define SPI_MODE_CPHA BIT(2) |
#include <include/zephyr/drivers/spi.h>
Clock Phase: this dictates when is the data captured, and depends clock's polarity.
When SPI_MODE_CPOL is set and this bit as well, capture will occur on low to high transition and high to low if this bit is not set (default). This is fully reversed if CPOL is not set.
#define SPI_MODE_CPOL BIT(1) |
#include <include/zephyr/drivers/spi.h>
Clock Polarity: if set, clock idle state will be 1 and active state will be 0.
If untouched, the inverse will be true which is the default.
#define SPI_MODE_GET | ( | _mode_ | ) | ((_mode_) & SPI_MODE_MASK) |
#include <include/zephyr/drivers/spi.h>
Get SPI polarity and phase mode bits.
#define SPI_MODE_LOOP BIT(3) |
#include <include/zephyr/drivers/spi.h>
Whatever data is transmitted is looped-back to the receiving buffer of the controller.
This is fully controller dependent as some may not support this, and can be used for testing purposes only.
#define SPI_MOSI_OVERRUN_DT | ( | node_id | ) | DT_PROP_OR(node_id, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN) |
#include <include/zephyr/drivers/spi.h>
The value sent on MOSI when all TX bytes are sent, but RX continues.
For drivers where the MOSI line state when receiving is important, this value can be queried at compile-time to determine whether allocating a constant array is necessary.
node_id | Devicetree node identifier for the SPI device to query |
SPI_MOSI_OVERRUN_UNKNOWN | if controller does not export the value |
byte | default MOSI value otherwise |
#define SPI_MOSI_OVERRUN_DT_INST | ( | inst | ) | DT_INST_PROP_OR(inst, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN) |
#include <include/zephyr/drivers/spi.h>
The value sent on MOSI when all TX bytes are sent, but RX continues.
This is equivalent to SPI_MOSI_OVERRUN_DT(DT_DRV_INST(inst))
.
inst | Devicetree instance number |
SPI_MOSI_OVERRUN_UNKNOWN | if controller does not export the value |
byte | default MOSI value otherwise |
#define SPI_MOSI_OVERRUN_UNKNOWN 0x100 |
#include <include/zephyr/drivers/spi.h>
Value that will never compare true with any valid overrun character.
#define SPI_OP_MODE_GET | ( | _operation_ | ) | ((_operation_) & SPI_OP_MODE_MASK) |
#include <include/zephyr/drivers/spi.h>
Get SPI operational mode.
#define SPI_OP_MODE_MASTER 0U |
#include <include/zephyr/drivers/spi.h>
Master mode.
#define SPI_OP_MODE_SLAVE BIT(0) |
#include <include/zephyr/drivers/spi.h>
Slave mode.
#define SPI_STATS_RX_BYTES_INC | ( | dev_ | ) |
#include <include/zephyr/drivers/spi.h>
#define SPI_STATS_TRANSFER_ERROR_INC | ( | dev_ | ) |
#include <include/zephyr/drivers/spi.h>
#define SPI_STATS_TX_BYTES_INC | ( | dev_ | ) |
#include <include/zephyr/drivers/spi.h>
#define spi_transceive_stats | ( | dev, | |
error, | |||
tx_bufs, | |||
rx_bufs | |||
) |
#include <include/zephyr/drivers/spi.h>
#define SPI_TRANSFER_LSB BIT(4) |
#include <include/zephyr/drivers/spi.h>
Least significant bit first.
#define SPI_TRANSFER_MSB (0U) |
#include <include/zephyr/drivers/spi.h>
Most significant bit first.
#define SPI_WORD_SET | ( | _word_size_ | ) | ((_word_size_) << SPI_WORD_SIZE_SHIFT) |
#include <include/zephyr/drivers/spi.h>
Set SPI word size (data frame size) in bits.
#define SPI_WORD_SIZE_GET | ( | _operation_ | ) | (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT) |
#include <include/zephyr/drivers/spi.h>
Get SPI word size (data frame size) in bits.
spi_api_io |
#include <include/zephyr/drivers/spi.h>
Callback API for I/O See spi_transceive() for argument descriptions.
Callback API for asynchronous I/O See spi_transceive_signal() for argument descriptions.
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, spi_callback_t cb, void *userdata) |
#include <include/zephyr/drivers/spi.h>
spi_api_release |
#include <include/zephyr/drivers/spi.h>
Callback API for unlocking SPI device.
See spi_release() for argument descriptions
typedef void(* spi_callback_t) (const struct device *dev, int result, void *data) |
#include <include/zephyr/drivers/spi.h>
SPI callback for asynchronous transfer requests.
dev | SPI device which is notifying of transfer completion or error |
result | Result code of the transfer request. 0 is success, -errno for failure. |
data | Transfer requester supplied data which is passed along to the callback. |
#include <include/zephyr/drivers/spi.h>
Opaque type to hold the SPI operation flags.
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Check if SPI CS is controlled using a GPIO.
config | SPI configuration. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Check if SPI CS in spi_dt_spec is controlled using a GPIO.
spec | SPI specification from devicetree. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Submit a SPI device with a request.
iodev_sqe | Prepared submissions queue entry connected to an iodev defined by SPI_IODEV_DEFINE. Must live as long as the request is in flight. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Validate that SPI bus (and CS gpio if defined) is ready.
spec | SPI specification from devicetree |
true | if the SPI bus is ready for use. |
false | if the SPI bus (or the CS gpio defined) is not ready for use. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Validate that SPI bus (and CS gpio if defined) is ready.
spi_iodev | SPI iodev defined with SPI_DT_IODEV_DEFINE |
true | if the SPI bus is ready for use. |
false | if the SPI bus (or the CS gpio defined) is not ready for use. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Read the specified amount of data from the SPI driver.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
rx_bufs | Buffer array where data to be read will be written to. |
frames | Positive number of frames received in slave mode. |
0 | If successful. |
-errno | Negative errno code on failure. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Read data from a SPI bus specified in spi_dt_spec
.
This is equivalent to:
spi_read(spec->bus, &spec->config, rx_bufs);
spec | SPI specification from devicetree |
rx_bufs | Buffer array where data to be read will be written to. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Read the specified amount of data from the SPI driver.
CONFIG_SPI_ASYNCand
CONFIG_POLLare selected.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
rx_bufs | Buffer array where data to be read will be written to. |
sig | A pointer to a valid and ready to be signaled struct k_poll_signal. (Note: if NULL this function will not notify the end of the transaction, and whether it went successfully or not). |
frames | Positive number of frames received in slave mode. |
0 | If successful |
-errno | Negative errno code on failure. |
int spi_release | ( | const struct device * | dev, |
const struct spi_config * | config | ||
) |
#include <include/zephyr/drivers/spi.h>
Release the SPI device locked on and/or the CS by the current config.
Note: This synchronous function is used to release either the lock on the SPI device and/or the CS line that was kept if, and if only, given config parameter was the last one to be used (in any of the above functions) and if it has the SPI_LOCK_ON bit set and/or the SPI_HOLD_ON_CS bit set into its operation bits field. This can be used if the caller needs to keep its hand on the SPI device for consecutive transactions and/or if it needs the device to stay selected. Usually both bits will be used along each other, so the the device is locked and stays on until another operation is necessary or until it gets released with the present function.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. |
0 | If successful. |
-errno | Negative errno code on failure. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Release the SPI device specified in spi_dt_spec
.
This is equivalent to:
spi_release(spec->bus, &spec->config);
spec | SPI specification from devicetree |
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 | ||
) |
#include <include/zephyr/drivers/spi.h>
Read/write the specified amount of data from the SPI driver.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
tx_bufs | Buffer array where data to be sent originates from, or NULL if none. |
rx_bufs | Buffer array where data to be read will be written to, or NULL if none. |
frames | Positive number of frames received in slave mode. |
0 | If successful in master mode. |
-errno | Negative errno code on failure. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Read/write the specified amount of data from the SPI driver.
CONFIG_SPI_ASYNCis selected.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
tx_bufs | Buffer array where data to be sent originates from, or NULL if none. |
rx_bufs | Buffer array where data to be read will be written to, or NULL if none. |
callback | Function pointer to completion callback. (Note: if NULL this function will not notify the end of the transaction, and whether it went successfully or not). |
userdata | Userdata passed to callback |
frames | Positive number of frames received in slave mode. |
0 | If successful in master mode. |
-errno | Negative errno code on failure. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Read/write data from an SPI bus specified in spi_dt_spec
.
This is equivalent to:
spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
spec | SPI specification from devicetree |
tx_bufs | Buffer array where data to be sent originates from, or NULL if none. |
rx_bufs | Buffer array where data to be read will be written to, or NULL if none. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Read/write the specified amount of data from the SPI driver.
CONFIG_SPI_ASYNCand
CONFIG_POLLare selected.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
tx_bufs | Buffer array where data to be sent originates from, or NULL if none. |
rx_bufs | Buffer array where data to be read will be written to, or NULL if none. |
sig | A pointer to a valid and ready to be signaled struct k_poll_signal. (Note: if NULL this function will not notify the end of the transaction, and whether it went successfully or not). |
frames | Positive number of frames received in slave mode. |
0 | If successful in master mode. |
-errno | Negative errno code on failure. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Write the specified amount of data from the SPI driver.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
tx_bufs | Buffer array where data to be sent originates from. |
0 | If successful. |
-errno | Negative errno code on failure. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Write data to a SPI bus specified in spi_dt_spec
.
This is equivalent to:
spi_write(spec->bus, &spec->config, tx_bufs);
spec | SPI specification from devicetree |
tx_bufs | Buffer array where data to be sent originates from. |
|
inlinestatic |
#include <include/zephyr/drivers/spi.h>
Write the specified amount of data from the SPI driver.
CONFIG_SPI_ASYNCand
CONFIG_POLLare selected.
dev | Pointer to the device structure for the driver instance |
config | Pointer to a valid spi_config structure instance. Pointer-comparison may be used to detect changes from previous operations. |
tx_bufs | Buffer array where data to be sent originates from. |
sig | A pointer to a valid and ready to be signaled struct k_poll_signal. (Note: if NULL this function will not notify the end of the transaction, and whether it went successfully or not). |
0 | If successful. |
-errno | Negative errno code on failure. |
|
extern |
#include <include/zephyr/drivers/spi.h>