Zephyr API Documentation 4.3.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
425#if defined(CONFIG_SPI_EXTENDED_MODES)
427#else
429#endif
430
475
477/* converts from the special DT zero value to half of the frequency, for drivers usage mostly */
478static inline uint16_t spi_get_word_delay(const struct spi_config *cfg)
479{
480 uint32_t freq = cfg->frequency;
481
482 if (cfg->word_delay != 0) {
483 return cfg->word_delay;
484 }
485
486 if (freq == 0) {
487 return 0;
488 }
489
490 uint64_t period_ns = NSEC_PER_SEC / freq;
491
492 period_ns = MIN(period_ns, UINT16_MAX);
493 period_ns /= 2;
494
495 return (uint16_t)period_ns;
496}
498
510#define SPI_CONFIG_DT(node_id, operation_, ...) \
511 { \
512 .frequency = DT_PROP(node_id, spi_max_frequency), \
513 .operation = (operation_) | \
514 DT_PROP(node_id, duplex) | \
515 DT_PROP(node_id, frame_format) | \
516 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
517 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
518 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)) | \
519 COND_CODE_1(DT_PROP(node_id, spi_lsb_first), SPI_TRANSFER_LSB, (0)) | \
520 COND_CODE_1(DT_PROP(node_id, spi_cs_high), SPI_CS_ACTIVE_HIGH, (0)), \
521 .slave = DT_REG_ADDR(node_id), \
522 .cs = SPI_CS_CONTROL_INIT(node_id, __VA_ARGS__), \
523 .word_delay = DT_PROP(node_id, spi_interframe_delay_ns),\
524 }
525
535#define SPI_CONFIG_DT_INST(inst, operation_, ...) \
536 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, __VA_ARGS__)
537
543 const struct device *bus;
546};
547
563#define SPI_DT_SPEC_GET(node_id, operation_, ...) \
564 { \
565 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
566 .config = SPI_CONFIG_DT(node_id, operation_, __VA_ARGS__), \
567 }
568
578#define SPI_DT_SPEC_INST_GET(inst, operation_, ...) \
579 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, __VA_ARGS__)
580
584#define SPI_MOSI_OVERRUN_UNKNOWN 0x100
585
598#define SPI_MOSI_OVERRUN_DT(node_id) \
599 DT_PROP_OR(node_id, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
600
612#define SPI_MOSI_OVERRUN_DT_INST(inst) \
613 DT_INST_PROP_OR(inst, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
614
623struct spi_buf {
625 void *buf;
627 size_t len;
628};
629
643 const struct spi_buf *buffers;
645 size_t count;
646};
647
652#if defined(CONFIG_SPI_STATS)
654STATS_SECT_ENTRY32(rx_bytes)
655STATS_SECT_ENTRY32(tx_bytes)
656STATS_SECT_ENTRY32(transfer_error)
658
660STATS_NAME(spi, rx_bytes)
661STATS_NAME(spi, tx_bytes)
662STATS_NAME(spi, transfer_error)
663STATS_NAME_END(spi);
664
668struct spi_device_state {
669 struct device_state devstate;
670 struct stats_spi stats;
671};
672
676#define Z_SPI_GET_STATS(dev_) \
677 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
678
684#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
685 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
686
692#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
693 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
694
702#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
703 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
704
709#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
710 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
711 __attribute__((__section__(".z_devstate")));
712
719#define Z_SPI_INIT_FN(dev_id, init_fn) \
720 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
721 { \
722 struct spi_device_state *state = \
723 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
724 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
725 STATS_NAME_INIT_PARMS(spi)); \
726 stats_register(dev->name, &(state->stats.s_hdr)); \
727 return init_fn(dev); \
728 }
730
731#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, \
732 pm_device, data_ptr, cfg_ptr, \
733 level, prio, api_ptr, ...) \
734 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
735 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
736 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
737 DEVICE_DT_NAME(node_id), \
738 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
739 deinit_fn, Z_DEVICE_DT_FLAGS(node_id), \
740 pm_device, data_ptr, cfg_ptr, level, prio, \
741 api_ptr, \
742 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
743 __VA_ARGS__)
744
745static inline void spi_transceive_stats(const struct device *dev, int error,
746 const struct spi_buf_set *tx_bufs,
747 const struct spi_buf_set *rx_bufs)
748{
749 uint32_t tx_bytes;
750 uint32_t rx_bytes;
751
752 if (error) {
754 }
755
756 if (tx_bufs) {
757 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
758 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
759 }
760
761 if (rx_bufs) {
762 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
763 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
764 }
765}
767
768#else /*CONFIG_SPI_STATS*/
769
774
795#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, \
796 config, level, prio, api, ...) \
797 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
798 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
799 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
800 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \
801 level, prio, api, \
802 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
803 __VA_ARGS__)
804
806
807#define SPI_STATS_RX_BYTES_INC(dev_)
808#define SPI_STATS_TX_BYTES_INC(dev_)
809#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
810
811#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
812
813#endif /*CONFIG_SPI_STATS*/
814
834#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, \
835 api, ...) \
836 SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
837 level, prio, api, __VA_ARGS__)
838
847#define SPI_DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
848 SPI_DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
849
858#define SPI_DEVICE_DT_INST_DEFINE(inst, ...) \
859 SPI_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
860
865
872typedef int (*spi_api_io)(const struct device *dev,
873 const struct spi_config *config,
874 const struct spi_buf_set *tx_bufs,
875 const struct spi_buf_set *rx_bufs);
876
884typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
885
892typedef int (*spi_api_io_async)(const struct device *dev,
893 const struct spi_config *config,
894 const struct spi_buf_set *tx_bufs,
895 const struct spi_buf_set *rx_bufs,
897 void *userdata);
898
899#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
900
905typedef void (*spi_api_iodev_submit)(const struct device *dev,
906 struct rtio_iodev_sqe *iodev_sqe);
907#endif /* CONFIG_SPI_RTIO */
908
914typedef int (*spi_api_release)(const struct device *dev,
915 const struct spi_config *config);
916
917
921__subsystem struct spi_driver_api {
926#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
932#endif /* CONFIG_SPI_ASYNC */
933#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
939#endif /* CONFIG_SPI_RTIO */
944};
945
948
956static inline bool spi_cs_is_gpio(const struct spi_config *config)
957{
958 return config->cs.cs_is_gpio;
959}
960
968static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
969{
970 return spi_cs_is_gpio(&spec->config);
971}
972
981static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
982{
983 /* Validate bus is ready */
984 if (!device_is_ready(spec->bus)) {
985 return false;
986 }
987 /* Validate CS gpio port is ready, if it is used */
988 if (spi_cs_is_gpio_dt(spec) &&
989 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
990 return false;
991 }
992 return true;
993}
994
1002
1033__syscall int 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
1038static inline int z_impl_spi_transceive(const struct device *dev,
1039 const struct spi_config *config,
1040 const struct spi_buf_set *tx_bufs,
1041 const struct spi_buf_set *rx_bufs)
1042{
1043 const struct spi_driver_api *api =
1044 (const struct spi_driver_api *)dev->api;
1045 int ret;
1046
1047 ret = api->transceive(dev, config, tx_bufs, rx_bufs);
1048 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1049
1050 return ret;
1051}
1052
1068static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1069 const struct spi_buf_set *tx_bufs,
1070 const struct spi_buf_set *rx_bufs)
1071{
1072 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1073}
1074
1095static inline int spi_read(const struct device *dev,
1096 const struct spi_config *config,
1097 const struct spi_buf_set *rx_bufs)
1098{
1099 return spi_transceive(dev, config, NULL, rx_bufs);
1100}
1101
1114static inline int spi_read_dt(const struct spi_dt_spec *spec,
1115 const struct spi_buf_set *rx_bufs)
1116{
1117 return spi_read(spec->bus, &spec->config, rx_bufs);
1118}
1119
1139static inline int spi_write(const struct device *dev,
1140 const struct spi_config *config,
1141 const struct spi_buf_set *tx_bufs)
1142{
1143 return spi_transceive(dev, config, tx_bufs, NULL);
1144}
1145
1158static inline int spi_write_dt(const struct spi_dt_spec *spec,
1159 const struct spi_buf_set *tx_bufs)
1160{
1161 return spi_write(spec->bus, &spec->config, tx_bufs);
1162}
1163
1164
1165#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1177
1208static inline int spi_transceive_cb(const struct device *dev,
1209 const struct spi_config *config,
1210 const struct spi_buf_set *tx_bufs,
1211 const struct spi_buf_set *rx_bufs,
1212 spi_callback_t callback,
1213 void *userdata)
1214{
1215 const struct spi_driver_api *api =
1216 (const struct spi_driver_api *)dev->api;
1217
1218 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata);
1219}
1220
1221#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
1222
1224void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
1226
1258static inline int spi_transceive_signal(const struct device *dev,
1259 const struct spi_config *config,
1260 const struct spi_buf_set *tx_bufs,
1261 const struct spi_buf_set *rx_bufs,
1262 struct k_poll_signal *sig)
1263{
1264 const struct spi_driver_api *api =
1265 (const struct spi_driver_api *)dev->api;
1266 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1267
1268 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1269}
1270
1298static inline int spi_read_signal(const struct device *dev,
1299 const struct spi_config *config,
1300 const struct spi_buf_set *rx_bufs,
1301 struct k_poll_signal *sig)
1302{
1303 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1304}
1305
1332static inline int spi_write_signal(const struct device *dev,
1333 const struct spi_config *config,
1334 const struct spi_buf_set *tx_bufs,
1335 struct k_poll_signal *sig)
1336{
1337 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1338}
1339
1340#endif /* CONFIG_POLL */
1341
1343#endif /* CONFIG_SPI_ASYNC */
1344
1345
1346#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1347
1362static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1363{
1364 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1365 const struct device *dev = dt_spec->bus;
1366 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
1367
1368 api->iodev_submit(dt_spec->bus, iodev_sqe);
1369}
1370
1372extern const struct rtio_iodev_api spi_iodev_api;
1374
1385#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, ...) \
1386 const struct spi_dt_spec _spi_dt_spec_##name = \
1387 SPI_DT_SPEC_GET(node_id, operation_, __VA_ARGS__); \
1388 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1389
1400#define SPI_DT_INST_IODEV_DEFINE(name, inst, operation_, ...) \
1401 SPI_DT_IODEV_DEFINE(name, DT_DRV_INST(inst), operation_, __VA_ARGS__)
1402
1411static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1412{
1413 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1414
1415 return spi_is_ready_dt(spec);
1416}
1417
1418
1419#endif /* CONFIG_SPI_RTIO */
1420
1441__syscall int spi_release(const struct device *dev,
1442 const struct spi_config *config);
1443
1444static inline int z_impl_spi_release(const struct device *dev,
1445 const struct spi_config *config)
1446{
1447 const struct spi_driver_api *api =
1448 (const struct spi_driver_api *)dev->api;
1449
1450 return api->release(dev, config);
1451}
1452
1464static inline int spi_release_dt(const struct spi_dt_spec *spec)
1465{
1466 return spi_release(spec->bus, &spec->config);
1467}
1468
1469#ifdef __cplusplus
1470}
1471#endif
1472
1476
1477#include <zephyr/syscalls/spi.h>
1478
1482#endif /* ZEPHYR_INCLUDE_DRIVERS_SPI_H_ */
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:854
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:892
void(* spi_callback_t)(const struct device *dev, int result, void *data)
SPI callback for asynchronous transfer requests.
Definition spi.h:884
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:872
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:914
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:905
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:1158
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:981
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:428
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:1258
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:1095
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:1068
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:1208
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition spi.h:809
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:1114
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:1139
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1464
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit a SPI device with a request.
Definition spi.h:1362
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:1298
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:968
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:811
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:1332
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:956
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:1411
#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
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Definition kernel.h:6429
Compute the mempool block index for a given pointer.
Definition rtio.h:538
IO device submission queue entry.
Definition rtio.h:386
struct rtio_sqe sqe
Definition rtio.h:387
An IO device with a function table for submitting requests.
Definition rtio.h:553
void * data
Definition rtio.h:558
const struct rtio_iodev * iodev
Device to operation on.
Definition rtio.h:305
SPI scatter-gather buffer array structure.
Definition spi.h:641
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition spi.h:643
size_t count
Number of buffers in the array pointed to: by buffers.
Definition spi.h:645
SPI buffer structure.
Definition spi.h:623
size_t len
Length of the buffer buf in bytes, or length of NOP.
Definition spi.h:627
void * buf
Valid pointer to a data buffer, or NULL for NOP indication.
Definition spi.h:625
SPI controller configuration structure.
Definition spi.h:438
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition spi.h:463
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition spi.h:468
spi_operation_t operation
Operation flags.
Definition spi.h:461
uint32_t frequency
Bus frequency in Hertz.
Definition spi.h:440
uint16_t word_delay
Delay between SPI words on SCK line in nanoseconds, if supported.
Definition spi.h:473
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:921
spi_api_io transceive
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition spi.h:925
spi_api_release release
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition spi.h:943
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:931
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:938
Complete SPI DT information.
Definition spi.h:541
const struct device * bus
SPI bus.
Definition spi.h:543
struct spi_config config
Slave specific configuration.
Definition spi.h:545