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
136
138#define SPI_TRANSFER_MSB (0U)
140#define SPI_TRANSFER_LSB BIT(4)
141
143#define SPI_WORD_SIZE_SHIFT (5U)
144#define SPI_WORD_SIZE_MASK (0x3FU << SPI_WORD_SIZE_SHIFT)
146
153#define SPI_WORD_SIZE_GET(operation) \
154 (((operation) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
155
162#define SPI_WORD_SET(word_size) \
163 ((word_size) << SPI_WORD_SIZE_SHIFT)
164
166
167
172
180#define SPI_HOLD_ON_CS BIT(12)
181
195#define SPI_LOCK_ON BIT(13)
196
208#define SPI_CS_ACTIVE_HIGH BIT(14)
209
211
212
222#define SPI_LINES_SINGLE (0U << 16)
223#define SPI_LINES_DUAL (1U << 16)
224#define SPI_LINES_QUAD (2U << 16)
225#define SPI_LINES_OCTAL (3U << 16)
226
227#define SPI_LINES_MASK (0x3U << 16)
228
230
235
244 union {
245 struct {
259 };
260 struct {
272 };
273 };
274 /* To keep track of which form of this struct is valid */
276};
277
315#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
316 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
317 DT_REG_ADDR_RAW(spi_dev), {})
318
328#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
329 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
330
332#define SPI_CS_CONTROL_MAX_DELAY(node_id) \
333 MAX(DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
334 DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0))
335
336
337#define SPI_CS_CONTROL_INIT_GPIO(node_id, ...) \
338 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
339 .delay = COND_CODE_1(IS_EMPTY(__VA_ARGS__), \
340 (DIV_ROUND_UP(SPI_CS_CONTROL_MAX_DELAY(node_id), 1000)), \
341 (__VA_ARGS__)),
342
343#define SPI_CS_CONTROL_INIT_NATIVE(node_id) \
344 .setup_ns = DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
345 .hold_ns = DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0),
346
347#define SPI_DEPRECATE_DELAY_WARN \
348 __WARN("Delay parameter in SPI DT macros is deprecated, use DT prop instead")
350
393#define SPI_CS_CONTROL_INIT(node_id, ...) \
394{ \
395 COND_CODE_0(IS_EMPTY(__VA_ARGS__), (SPI_DEPRECATE_DELAY_WARN), ()) \
396 COND_CODE_1(DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
397 (SPI_CS_CONTROL_INIT_GPIO(node_id, __VA_ARGS__)), \
398 (SPI_CS_CONTROL_INIT_NATIVE(node_id))) \
399 .cs_is_gpio = DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
400}
401
415#define SPI_CS_CONTROL_INIT_INST(inst) \
416 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst))
417
419
423#if defined(CONFIG_SPI_EXTENDED_MODES)
425#else
427#endif
428
473
475/* converts from the special DT zero value to half of the frequency, for drivers usage mostly */
476static inline uint16_t spi_get_word_delay(const struct spi_config *cfg)
477{
478 uint32_t freq = cfg->frequency;
479
480 if (cfg->word_delay != 0) {
481 return cfg->word_delay;
482 }
483
484 if (freq == 0) {
485 return 0;
486 }
487
488 uint64_t period_ns = NSEC_PER_SEC / freq;
489
490 period_ns = MIN(period_ns, UINT16_MAX);
491 period_ns /= 2;
492
493 return (uint16_t)period_ns;
494}
496
508#define SPI_CONFIG_DT(node_id, operation_, ...) \
509 { \
510 .frequency = DT_PROP(node_id, spi_max_frequency), \
511 .operation = (operation_) | \
512 DT_PROP(node_id, duplex) | \
513 DT_PROP(node_id, frame_format) | \
514 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
515 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
516 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)) | \
517 COND_CODE_1(DT_PROP(node_id, spi_lsb_first), SPI_TRANSFER_LSB, (0)) | \
518 COND_CODE_1(DT_PROP(node_id, spi_cs_high), SPI_CS_ACTIVE_HIGH, (0)), \
519 .slave = DT_REG_ADDR(node_id), \
520 .cs = SPI_CS_CONTROL_INIT(node_id, __VA_ARGS__), \
521 .word_delay = DT_PROP(node_id, spi_interframe_delay_ns),\
522 }
523
533#define SPI_CONFIG_DT_INST(inst, operation_, ...) \
534 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, __VA_ARGS__)
535
541 const struct device *bus;
544};
545
561#define SPI_DT_SPEC_GET(node_id, operation_, ...) \
562 { \
563 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
564 .config = SPI_CONFIG_DT(node_id, operation_, __VA_ARGS__), \
565 }
566
576#define SPI_DT_SPEC_INST_GET(inst, operation_, ...) \
577 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, __VA_ARGS__)
578
582#define SPI_MOSI_OVERRUN_UNKNOWN 0x100
583
596#define SPI_MOSI_OVERRUN_DT(node_id) \
597 DT_PROP_OR(node_id, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
598
610#define SPI_MOSI_OVERRUN_DT_INST(inst) \
611 DT_INST_PROP_OR(inst, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
612
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
1027__syscall int spi_transceive(const struct device *dev,
1028 const struct spi_config *config,
1029 const struct spi_buf_set *tx_bufs,
1030 const struct spi_buf_set *rx_bufs);
1031
1032static inline int z_impl_spi_transceive(const struct device *dev,
1033 const struct spi_config *config,
1034 const struct spi_buf_set *tx_bufs,
1035 const struct spi_buf_set *rx_bufs)
1036{
1037 int ret = DEVICE_API_GET(spi, dev)->transceive(dev, config, tx_bufs, rx_bufs);
1038
1039 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1040
1041 return ret;
1042}
1043
1059static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1060 const struct spi_buf_set *tx_bufs,
1061 const struct spi_buf_set *rx_bufs)
1062{
1063 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1064}
1065
1085static inline int spi_read(const struct device *dev,
1086 const struct spi_config *config,
1087 const struct spi_buf_set *rx_bufs)
1088{
1089 return spi_transceive(dev, config, NULL, rx_bufs);
1090}
1091
1104static inline int spi_read_dt(const struct spi_dt_spec *spec,
1105 const struct spi_buf_set *rx_bufs)
1106{
1107 return spi_read(spec->bus, &spec->config, rx_bufs);
1108}
1109
1128static inline int spi_write(const struct device *dev,
1129 const struct spi_config *config,
1130 const struct spi_buf_set *tx_bufs)
1131{
1132 return spi_transceive(dev, config, tx_bufs, NULL);
1133}
1134
1147static inline int spi_write_dt(const struct spi_dt_spec *spec,
1148 const struct spi_buf_set *tx_bufs)
1149{
1150 return spi_write(spec->bus, &spec->config, tx_bufs);
1151}
1152
1153
1154#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1166
1195static inline int spi_transceive_cb(const struct device *dev,
1196 const struct spi_config *config,
1197 const struct spi_buf_set *tx_bufs,
1198 const struct spi_buf_set *rx_bufs,
1199 spi_callback_t callback,
1200 void *userdata)
1201{
1202 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, callback,
1203 userdata);
1204}
1205
1206#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
1207
1209void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
1211
1241static inline int spi_transceive_signal(const struct device *dev,
1242 const struct spi_config *config,
1243 const struct spi_buf_set *tx_bufs,
1244 const struct spi_buf_set *rx_bufs,
1245 struct k_poll_signal *sig)
1246{
1247 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1248
1249 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1250}
1251
1277static inline int spi_read_signal(const struct device *dev,
1278 const struct spi_config *config,
1279 const struct spi_buf_set *rx_bufs,
1280 struct k_poll_signal *sig)
1281{
1282 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1283}
1284
1309static inline int spi_write_signal(const struct device *dev,
1310 const struct spi_config *config,
1311 const struct spi_buf_set *tx_bufs,
1312 struct k_poll_signal *sig)
1313{
1314 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1315}
1316
1317#endif /* CONFIG_POLL */
1318
1320#endif /* CONFIG_SPI_ASYNC */
1321
1322
1323#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1324
1339static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1340{
1341 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1342 const struct device *dev = dt_spec->bus;
1343
1344 DEVICE_API_GET(spi, dev)->iodev_submit(dev, iodev_sqe);
1345}
1346
1348extern const struct rtio_iodev_api spi_iodev_api;
1350
1361#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, ...) \
1362 const struct spi_dt_spec _spi_dt_spec_##name = \
1363 SPI_DT_SPEC_GET(node_id, operation_, __VA_ARGS__); \
1364 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1365
1376#define SPI_DT_INST_IODEV_DEFINE(name, inst, operation_, ...) \
1377 SPI_DT_IODEV_DEFINE(name, DT_DRV_INST(inst), operation_, __VA_ARGS__)
1378
1387static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1388{
1389 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1390
1391 return spi_is_ready_dt(spec);
1392}
1393
1394
1395#endif /* CONFIG_SPI_RTIO */
1396
1416__syscall int spi_release(const struct device *dev,
1417 const struct spi_config *config);
1418
1419static inline int z_impl_spi_release(const struct device *dev,
1420 const struct spi_config *config)
1421{
1422 return DEVICE_API_GET(spi, dev)->release(dev, config);
1423}
1424
1436static inline int spi_release_dt(const struct spi_dt_spec *spec)
1437{
1438 return spi_release(spec->bus, &spec->config);
1439}
1440
1441#ifdef __cplusplus
1442}
1443#endif
1444
1448
1449#include <zephyr/syscalls/spi.h>
1450
1454#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 an 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 an SPI bus specified in spi_dt_spec.
Definition spi.h:1147
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:426
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:1241
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:1085
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:1059
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:1195
#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 an SPI bus specified in spi_dt_spec.
Definition spi.h:1104
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:1128
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1436
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit an SPI device with a request.
Definition spi.h:1339
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:1277
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:1309
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:1387
#define MIN(a, b)
Obtain the minimum of two values.
Definition util.h:406
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:6646
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:436
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition spi.h:461
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition spi.h:466
spi_operation_t operation
Operation flags.
Definition spi.h:459
uint32_t frequency
Bus frequency in Hertz.
Definition spi.h:438
uint16_t word_delay
Delay between SPI words on SCK line in nanoseconds, if supported.
Definition spi.h:471
SPI Chip Select control structure.
Definition spi.h:243
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition spi.h:258
uint32_t hold_ns
CS enable lag time, i.e.
Definition spi.h:271
bool cs_is_gpio
Definition spi.h:275
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition spi.h:253
uint32_t setup_ns
CS enable lead time, i.e.
Definition spi.h:265
<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:539
const struct device * bus
SPI bus.
Definition spi.h:541
struct spi_config config
Slave specific configuration.
Definition spi.h:543