Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_SPI_H_
14#define ZEPHYR_INCLUDE_DRIVERS_SPI_H_
15
25
26#include <zephyr/types.h>
27#include <stddef.h>
28#include <zephyr/device.h>
30#include <zephyr/drivers/gpio.h>
31#include <zephyr/kernel.h>
32#include <zephyr/sys/__assert.h>
33#include <zephyr/rtio/rtio.h>
34#include <zephyr/stats/stats.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
44
52#define SPI_OP_MODE_MASTER 0U
53
62#define SPI_OP_MODE_SLAVE BIT(0)
63
65#define SPI_OP_MODE_MASK 0x1U
67
71#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
73
74
79
89#define SPI_MODE_CPOL BIT(1)
90
100#define SPI_MODE_CPHA BIT(2)
101
111#define SPI_MODE_LOOP BIT(3)
112
114#define SPI_MODE_MASK (0xEU)
116
120#define SPI_MODE_GET(_mode_) \
121 ((_mode_) & SPI_MODE_MASK)
122
124
125
137
139#define SPI_TRANSFER_MSB (0U)
141#define SPI_TRANSFER_LSB BIT(4)
142
144#define SPI_WORD_SIZE_SHIFT (5U)
145#define SPI_WORD_SIZE_MASK (0x3FU << SPI_WORD_SIZE_SHIFT)
147
154#define SPI_WORD_SIZE_GET(operation) \
155 (((operation) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
156
163#define SPI_WORD_SET(word_size) \
164 ((word_size) << SPI_WORD_SIZE_SHIFT)
165
167
168
173
181#define SPI_HOLD_ON_CS BIT(12)
182
196#define SPI_LOCK_ON BIT(13)
197
209#define SPI_CS_ACTIVE_HIGH BIT(14)
210
212
213
223#define SPI_LINES_SINGLE (0U << 16)
224#define SPI_LINES_DUAL (1U << 16)
225#define SPI_LINES_QUAD (2U << 16)
226#define SPI_LINES_OCTAL (3U << 16)
227
228#define SPI_LINES_MASK (0x3U << 16)
229
231
236
245 union {
246 struct {
260 };
261 struct {
273 };
274 };
275 /* To keep track of which form of this struct is valid */
277};
278
316#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
317 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
318 DT_REG_ADDR_RAW(spi_dev), {})
319
329#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
330 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
331
333#define SPI_CS_CONTROL_MAX_DELAY(node_id) \
334 MAX(DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
335 DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0))
336
337
338#define SPI_CS_CONTROL_INIT_GPIO(node_id, ...) \
339 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
340 .delay = COND_CODE_1(IS_EMPTY(__VA_ARGS__), \
341 (DIV_ROUND_UP(SPI_CS_CONTROL_MAX_DELAY(node_id), 1000)), \
342 (__VA_ARGS__)),
343
344#define SPI_CS_CONTROL_INIT_NATIVE(node_id) \
345 .setup_ns = DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
346 .hold_ns = DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0),
347
348#define SPI_DEPRECATE_DELAY_WARN \
349 __WARN("Delay parameter in SPI DT macros is deprecated, use DT prop instead")
351
394#define SPI_CS_CONTROL_INIT(node_id, ...) \
395{ \
396 COND_CODE_0(IS_EMPTY(__VA_ARGS__), (SPI_DEPRECATE_DELAY_WARN), ()) \
397 COND_CODE_1(DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
398 (SPI_CS_CONTROL_INIT_GPIO(node_id, __VA_ARGS__)), \
399 (SPI_CS_CONTROL_INIT_NATIVE(node_id))) \
400 .cs_is_gpio = DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
401}
402
416#define SPI_CS_CONTROL_INIT_INST(inst) \
417 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst))
418
420
424#if defined(CONFIG_SPI_EXTENDED_MODES)
426#else
428#endif
429
474
476/* converts from the special DT zero value to half of the frequency, for drivers usage mostly */
477static inline uint16_t spi_get_word_delay(const struct spi_config *cfg)
478{
479 uint32_t freq = cfg->frequency;
480
481 if (cfg->word_delay != 0) {
482 return cfg->word_delay;
483 }
484
485 if (freq == 0) {
486 return 0;
487 }
488
489 uint64_t period_ns = NSEC_PER_SEC / freq;
490
491 period_ns = MIN(period_ns, UINT16_MAX);
492 period_ns /= 2;
493
494 return (uint16_t)period_ns;
495}
497
509#define SPI_CONFIG_DT(node_id, operation_, ...) \
510 { \
511 .frequency = DT_PROP(node_id, spi_max_frequency), \
512 .operation = (operation_) | \
513 DT_PROP(node_id, duplex) | \
514 DT_PROP(node_id, frame_format) | \
515 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
516 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
517 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)) | \
518 COND_CODE_1(DT_PROP(node_id, spi_lsb_first), SPI_TRANSFER_LSB, (0)) | \
519 COND_CODE_1(DT_PROP(node_id, spi_cs_high), SPI_CS_ACTIVE_HIGH, (0)), \
520 .slave = DT_REG_ADDR(node_id), \
521 .cs = SPI_CS_CONTROL_INIT(node_id, __VA_ARGS__), \
522 .word_delay = DT_PROP(node_id, spi_interframe_delay_ns),\
523 }
524
534#define SPI_CONFIG_DT_INST(inst, operation_, ...) \
535 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, __VA_ARGS__)
536
542 const struct device *bus;
545};
546
562#define SPI_DT_SPEC_GET(node_id, operation_, ...) \
563 { \
564 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
565 .config = SPI_CONFIG_DT(node_id, operation_, __VA_ARGS__), \
566 }
567
577#define SPI_DT_SPEC_INST_GET(inst, operation_, ...) \
578 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, __VA_ARGS__)
579
583#define SPI_MOSI_OVERRUN_UNKNOWN 0x100
584
597#define SPI_MOSI_OVERRUN_DT(node_id) \
598 DT_PROP_OR(node_id, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
599
611#define SPI_MOSI_OVERRUN_DT_INST(inst) \
612 DT_INST_PROP_OR(inst, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
613
622struct spi_buf {
624 void *buf;
626 size_t len;
627};
628
642 const struct spi_buf *buffers;
644 size_t count;
645};
646
651#if defined(CONFIG_SPI_STATS)
653STATS_SECT_ENTRY32(rx_bytes)
654STATS_SECT_ENTRY32(tx_bytes)
655STATS_SECT_ENTRY32(transfer_error)
657
659STATS_NAME(spi, rx_bytes)
660STATS_NAME(spi, tx_bytes)
661STATS_NAME(spi, transfer_error)
662STATS_NAME_END(spi);
663
667struct spi_device_state {
668 struct device_state devstate;
669 struct stats_spi stats;
670};
671
675#define Z_SPI_GET_STATS(dev_) \
676 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
677
683#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
684 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
685
691#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
692 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
693
701#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
702 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
703
708#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
709 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
710 __attribute__((__section__(".z_devstate")));
711
718#define Z_SPI_INIT_FN(dev_id, init_fn) \
719 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
720 { \
721 struct spi_device_state *state = \
722 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
723 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
724 STATS_NAME_INIT_PARMS(spi)); \
725 stats_register(dev->name, &(state->stats.s_hdr)); \
726 return init_fn(dev); \
727 }
729
730#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, \
731 pm_device, data_ptr, cfg_ptr, \
732 level, prio, api_ptr, ...) \
733 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
734 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
735 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
736 DEVICE_DT_NAME(node_id), \
737 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
738 deinit_fn, Z_DEVICE_DT_FLAGS(node_id), \
739 pm_device, data_ptr, cfg_ptr, level, prio, \
740 api_ptr, \
741 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
742 __VA_ARGS__)
743
744static inline void spi_transceive_stats(const struct device *dev, int error,
745 const struct spi_buf_set *tx_bufs,
746 const struct spi_buf_set *rx_bufs)
747{
748 uint32_t tx_bytes;
749 uint32_t rx_bytes;
750
751 if (error) {
753 }
754
755 if (tx_bufs) {
756 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
757 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
758 }
759
760 if (rx_bufs) {
761 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
762 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
763 }
764}
766
767#else /*CONFIG_SPI_STATS*/
768
773
794#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, \
795 config, level, prio, api, ...) \
796 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
797 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
798 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
799 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \
800 level, prio, api, \
801 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
802 __VA_ARGS__)
803
805
806#define SPI_STATS_RX_BYTES_INC(dev_)
807#define SPI_STATS_TX_BYTES_INC(dev_)
808#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
809
810#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
811
812#endif /*CONFIG_SPI_STATS*/
813
833#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, \
834 api, ...) \
835 SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
836 level, prio, api, __VA_ARGS__)
837
846#define SPI_DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
847 SPI_DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
848
857#define SPI_DEVICE_DT_INST_DEFINE(inst, ...) \
858 SPI_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
859
864
870typedef int (*spi_api_io)(const struct device *dev,
871 const struct spi_config *config,
872 const struct spi_buf_set *tx_bufs,
873 const struct spi_buf_set *rx_bufs);
874
882typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
883
889typedef int (*spi_api_io_async)(const struct device *dev,
890 const struct spi_config *config,
891 const struct spi_buf_set *tx_bufs,
892 const struct spi_buf_set *rx_bufs,
894 void *userdata);
895
896#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
897
901typedef void (*spi_api_iodev_submit)(const struct device *dev,
902 struct rtio_iodev_sqe *iodev_sqe);
903#endif /* CONFIG_SPI_RTIO */
904
909typedef int (*spi_api_release)(const struct device *dev,
910 const struct spi_config *config);
911
912
916__subsystem struct spi_driver_api {
921#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
927#endif /* CONFIG_SPI_ASYNC */
928#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
934#endif /* CONFIG_SPI_RTIO */
939};
940
943
951static inline bool spi_cs_is_gpio(const struct spi_config *config)
952{
953 return config->cs.cs_is_gpio;
954}
955
963static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
964{
965 return spi_cs_is_gpio(&spec->config);
966}
967
976static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
977{
978 /* Validate bus is ready */
979 if (!device_is_ready(spec->bus)) {
980 return false;
981 }
982 /* Validate CS gpio port is ready, if it is used */
983 if (spi_cs_is_gpio_dt(spec) &&
984 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
985 return false;
986 }
987 return true;
988}
989
997
1028__syscall int spi_transceive(const struct device *dev,
1029 const struct spi_config *config,
1030 const struct spi_buf_set *tx_bufs,
1031 const struct spi_buf_set *rx_bufs);
1032
1033static inline int z_impl_spi_transceive(const struct device *dev,
1034 const struct spi_config *config,
1035 const struct spi_buf_set *tx_bufs,
1036 const struct spi_buf_set *rx_bufs)
1037{
1038 int ret = DEVICE_API_GET(spi, dev)->transceive(dev, config, tx_bufs, rx_bufs);
1039
1040 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1041
1042 return ret;
1043}
1044
1060static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1061 const struct spi_buf_set *tx_bufs,
1062 const struct spi_buf_set *rx_bufs)
1063{
1064 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1065}
1066
1087static inline int spi_read(const struct device *dev,
1088 const struct spi_config *config,
1089 const struct spi_buf_set *rx_bufs)
1090{
1091 return spi_transceive(dev, config, NULL, rx_bufs);
1092}
1093
1106static inline int spi_read_dt(const struct spi_dt_spec *spec,
1107 const struct spi_buf_set *rx_bufs)
1108{
1109 return spi_read(spec->bus, &spec->config, rx_bufs);
1110}
1111
1131static inline int spi_write(const struct device *dev,
1132 const struct spi_config *config,
1133 const struct spi_buf_set *tx_bufs)
1134{
1135 return spi_transceive(dev, config, tx_bufs, NULL);
1136}
1137
1150static inline int spi_write_dt(const struct spi_dt_spec *spec,
1151 const struct spi_buf_set *tx_bufs)
1152{
1153 return spi_write(spec->bus, &spec->config, tx_bufs);
1154}
1155
1156
1157#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1169
1200static inline int spi_transceive_cb(const struct device *dev,
1201 const struct spi_config *config,
1202 const struct spi_buf_set *tx_bufs,
1203 const struct spi_buf_set *rx_bufs,
1204 spi_callback_t callback,
1205 void *userdata)
1206{
1207 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, callback,
1208 userdata);
1209}
1210
1211#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
1212
1214void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
1216
1248static inline int spi_transceive_signal(const struct device *dev,
1249 const struct spi_config *config,
1250 const struct spi_buf_set *tx_bufs,
1251 const struct spi_buf_set *rx_bufs,
1252 struct k_poll_signal *sig)
1253{
1254 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1255
1256 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1257}
1258
1286static inline int spi_read_signal(const struct device *dev,
1287 const struct spi_config *config,
1288 const struct spi_buf_set *rx_bufs,
1289 struct k_poll_signal *sig)
1290{
1291 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1292}
1293
1320static inline int spi_write_signal(const struct device *dev,
1321 const struct spi_config *config,
1322 const struct spi_buf_set *tx_bufs,
1323 struct k_poll_signal *sig)
1324{
1325 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1326}
1327
1328#endif /* CONFIG_POLL */
1329
1331#endif /* CONFIG_SPI_ASYNC */
1332
1333
1334#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1335
1350static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1351{
1352 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1353 const struct device *dev = dt_spec->bus;
1354
1355 DEVICE_API_GET(spi, dev)->iodev_submit(dev, iodev_sqe);
1356}
1357
1359extern const struct rtio_iodev_api spi_iodev_api;
1361
1372#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, ...) \
1373 const struct spi_dt_spec _spi_dt_spec_##name = \
1374 SPI_DT_SPEC_GET(node_id, operation_, __VA_ARGS__); \
1375 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1376
1387#define SPI_DT_INST_IODEV_DEFINE(name, inst, operation_, ...) \
1388 SPI_DT_IODEV_DEFINE(name, DT_DRV_INST(inst), operation_, __VA_ARGS__)
1389
1398static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1399{
1400 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1401
1402 return spi_is_ready_dt(spec);
1403}
1404
1405
1406#endif /* CONFIG_SPI_RTIO */
1407
1428__syscall int spi_release(const struct device *dev,
1429 const struct spi_config *config);
1430
1431static inline int z_impl_spi_release(const struct device *dev,
1432 const struct spi_config *config)
1433{
1434 return DEVICE_API_GET(spi, dev)->release(dev, config);
1435}
1436
1448static inline int spi_release_dt(const struct spi_dt_spec *spec)
1449{
1450 return spi_release(spec->bus, &spec->config);
1451}
1452
1453#ifdef __cplusplus
1454}
1455#endif
1456
1460
1461#include <zephyr/syscalls/spi.h>
1462
1466#endif /* ZEPHYR_INCLUDE_DRIVERS_SPI_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
Main header file for GPIO driver API.
#define NSEC_PER_SEC
number of nanoseconds per second
Definition clock.h:113
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
static bool gpio_is_ready_dt(const struct gpio_dt_spec *spec)
Validate that GPIO port is ready.
Definition gpio.h:853
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)
Callback API for asynchronous I/O.
Definition spi.h:889
void(* spi_callback_t)(const struct device *dev, int result, void *data)
SPI callback for asynchronous transfer requests.
Definition spi.h:882
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.
Definition spi.h:870
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:909
void(* spi_api_iodev_submit)(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
Callback API for submitting work to a SPI device with RTIO.
Definition spi.h:901
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_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:1150
static bool spi_is_ready_dt(const struct spi_dt_spec *spec)
Validate that SPI bus (and CS gpio if defined) is ready.
Definition spi.h:976
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:427
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.
Definition spi.h:1248
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:1087
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:1060
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 asynchronously.
Definition spi.h:1200
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition spi.h:808
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:1106
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:1131
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1448
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit a SPI device with a request.
Definition spi.h:1350
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.
Definition spi.h:1286
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.
Definition spi.h:963
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.
#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
Definition spi.h:810
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.
Definition spi.h:1320
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:951
static bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
Validate that SPI bus (and CS gpio if defined) is ready.
Definition spi.h:1398
#define MIN(a, b)
Obtain the minimum of two values.
Definition util.h:448
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
Real-Time IO device API for moving bytes with low effort.
Statistics.
#define STATS_NAME_END(name__)
Definition stats.h:391
#define STATS_NAME(name__, entry__)
Definition stats.h:390
#define STATS_SECT_END
Ends a stats group struct definition.
Definition stats.h:89
#define STATS_SECT_ENTRY32(var__)
Definition stats.h:359
#define STATS_NAME_START(name__)
Definition stats.h:389
#define STATS_SECT_START(group__)
Definition stats.h:354
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
#define UINT16_MAX
Definition stdint.h:28
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:458
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Definition kernel.h:6606
API that an RTIO IO device should implement.
Definition iodev.h:33
IO device submission queue entry.
Definition sqe.h:394
struct rtio_sqe sqe
Definition sqe.h:395
An IO device with a function table for submitting requests.
Definition iodev.h:48
void * data
Definition iodev.h:53
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:313
SPI scatter-gather buffer array structure.
Definition spi.h:640
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition spi.h:642
size_t count
Number of buffers in the array pointed to: by buffers.
Definition spi.h:644
SPI buffer structure.
Definition spi.h:622
size_t len
Length of the buffer buf in bytes, or length of NOP.
Definition spi.h:626
void * buf
Valid pointer to a data buffer, or NULL for NOP indication.
Definition spi.h:624
SPI controller configuration structure.
Definition spi.h:437
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition spi.h:462
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition spi.h:467
spi_operation_t operation
Operation flags.
Definition spi.h:460
uint32_t frequency
Bus frequency in Hertz.
Definition spi.h:439
uint16_t word_delay
Delay between SPI words on SCK line in nanoseconds, if supported.
Definition spi.h:472
SPI Chip Select control structure.
Definition spi.h:244
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition spi.h:259
uint32_t hold_ns
CS enable lag time, i.e.
Definition spi.h:272
bool cs_is_gpio
Definition spi.h:276
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition spi.h:254
uint32_t setup_ns
CS enable lead time, i.e.
Definition spi.h:266
<span class="mlabel">Driver Operations</span> SPI driver operations
Definition spi.h:916
spi_api_io transceive
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition spi.h:920
spi_api_release release
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition spi.h:938
spi_api_io_async transceive_async
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition spi.h:926
spi_api_iodev_submit iodev_submit
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition spi.h:933
Complete SPI DT information.
Definition spi.h:540
const struct device * bus
SPI bus.
Definition spi.h:542
struct spi_config config
Slave specific configuration.
Definition spi.h:544