Zephyr API Documentation  3.6.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#ifndef ZEPHYR_INCLUDE_DRIVERS_SPI_H_
13#define ZEPHYR_INCLUDE_DRIVERS_SPI_H_
14
24#include <zephyr/types.h>
25#include <stddef.h>
26#include <zephyr/device.h>
28#include <zephyr/drivers/gpio.h>
29#include <zephyr/kernel.h>
30#include <zephyr/sys/__assert.h>
31#include <zephyr/rtio/rtio.h>
32#include <zephyr/stats/stats.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
42#define SPI_OP_MODE_MASTER 0U
43#define SPI_OP_MODE_SLAVE BIT(0)
45#define SPI_OP_MODE_MASK 0x1U
48#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
61#define SPI_MODE_CPOL BIT(1)
62
70#define SPI_MODE_CPHA BIT(2)
71
77#define SPI_MODE_LOOP BIT(3)
79#define SPI_MODE_MASK (0xEU)
82#define SPI_MODE_GET(_mode_) \
83 ((_mode_) & SPI_MODE_MASK)
84
91#define SPI_TRANSFER_MSB (0U)
92#define SPI_TRANSFER_LSB BIT(4)
100#define SPI_WORD_SIZE_SHIFT (5U)
101#define SPI_WORD_SIZE_MASK (0x3FU << SPI_WORD_SIZE_SHIFT)
104#define SPI_WORD_SIZE_GET(_operation_) \
105 (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
107#define SPI_WORD_SET(_word_size_) \
108 ((_word_size_) << SPI_WORD_SIZE_SHIFT)
116#define SPI_HOLD_ON_CS BIT(12)
122#define SPI_LOCK_ON BIT(13)
123
131#define SPI_CS_ACTIVE_HIGH BIT(14)
143#define SPI_LINES_SINGLE (0U << 16)
144#define SPI_LINES_DUAL (1U << 16)
145#define SPI_LINES_QUAD (2U << 16)
146#define SPI_LINES_OCTAL (3U << 16)
148#define SPI_LINES_MASK (0x3U << 16)
173};
174
212#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
213 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
214 DT_REG_ADDR(spi_dev), {})
215
225#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
226 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
227
266#define SPI_CS_CONTROL_INIT(node_id, delay_) \
267 { \
268 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
269 .delay = (delay_), \
270 }
271
285#define SPI_CS_CONTROL_INIT_INST(inst, delay_) \
286 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_)
287
292#if defined(CONFIG_SPI_EXTENDED_MODES)
294#else
296#endif
297
332};
333
347#define SPI_CONFIG_DT(node_id, operation_, delay_) \
348 { \
349 .frequency = DT_PROP(node_id, spi_max_frequency), \
350 .operation = (operation_) | \
351 DT_PROP(node_id, duplex) | \
352 DT_PROP(node_id, frame_format) | \
353 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
354 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
355 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)), \
356 .slave = DT_REG_ADDR(node_id), \
357 .cs = SPI_CS_CONTROL_INIT(node_id, delay_), \
358 }
359
371#define SPI_CONFIG_DT_INST(inst, operation_, delay_) \
372 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
373
379 const struct device *bus;
382};
383
402#define SPI_DT_SPEC_GET(node_id, operation_, delay_) \
403 { \
404 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
405 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
406 }
407
419#define SPI_DT_SPEC_INST_GET(inst, operation_, delay_) \
420 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
421
425struct spi_buf {
427 void *buf;
432 size_t len;
433};
434
440 const struct spi_buf *buffers;
442 size_t count;
443};
444
445#if defined(CONFIG_SPI_STATS)
447STATS_SECT_ENTRY32(rx_bytes)
448STATS_SECT_ENTRY32(tx_bytes)
449STATS_SECT_ENTRY32(transfer_error)
451
453STATS_NAME(spi, rx_bytes)
454STATS_NAME(spi, tx_bytes)
455STATS_NAME(spi, transfer_error)
456STATS_NAME_END(spi);
457
461struct spi_device_state {
462 struct device_state devstate;
463 struct stats_spi stats;
464};
465
469#define Z_SPI_GET_STATS(dev_) \
470 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
471
477#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
478 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
479
485#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
486 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
487
495#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
496 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
497
501#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
502 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
503 __attribute__((__section__(".z_devstate")));
504
511#define Z_SPI_INIT_FN(dev_id, init_fn) \
512 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
513 { \
514 struct spi_device_state *state = \
515 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
516 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
517 STATS_NAME_INIT_PARMS(spi)); \
518 stats_register(dev->name, &(state->stats.s_hdr)); \
519 return init_fn(dev); \
520 }
521
541#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
542 data_ptr, cfg_ptr, level, prio, \
543 api_ptr, ...) \
544 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
545 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
546 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
547 DEVICE_DT_NAME(node_id), \
548 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
549 pm_device, \
550 data_ptr, cfg_ptr, level, prio, \
551 api_ptr, \
552 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
553 __VA_ARGS__)
554
555static inline void spi_transceive_stats(const struct device *dev, int error,
556 const struct spi_buf_set *tx_bufs,
557 const struct spi_buf_set *rx_bufs)
558{
559 uint32_t tx_bytes;
560 uint32_t rx_bytes;
561
562 if (error) {
564 }
565
566 if (tx_bufs) {
567 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
568 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
569 }
570
571 if (rx_bufs) {
572 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
573 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
574 }
575}
576
577#else /*CONFIG_SPI_STATS*/
578
579#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, \
580 data, config, level, prio, \
581 api, ...) \
582 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
583 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
584 DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \
585 level, prio, api, \
586 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
587 __VA_ARGS__)
588
589#define SPI_STATS_RX_BYTES_INC(dev_)
590#define SPI_STATS_TX_BYTES_INC(dev_)
591#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
592
593#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
594
595#endif /*CONFIG_SPI_STATS*/
596
602typedef int (*spi_api_io)(const struct device *dev,
603 const struct spi_config *config,
604 const struct spi_buf_set *tx_bufs,
605 const struct spi_buf_set *rx_bufs);
606
614typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
615
621typedef int (*spi_api_io_async)(const struct device *dev,
622 const struct spi_config *config,
623 const struct spi_buf_set *tx_bufs,
624 const struct spi_buf_set *rx_bufs,
626 void *userdata);
627
628#if defined(CONFIG_SPI_RTIO) || defined(DOXYGEN)
629
634typedef void (*spi_api_iodev_submit)(const struct device *dev,
635 struct rtio_iodev_sqe *iodev_sqe);
636#endif /* CONFIG_SPI_RTIO */
637
643typedef int (*spi_api_release)(const struct device *dev,
644 const struct spi_config *config);
645
646
651__subsystem struct spi_driver_api {
653#ifdef CONFIG_SPI_ASYNC
654 spi_api_io_async transceive_async;
655#endif /* CONFIG_SPI_ASYNC */
656#ifdef CONFIG_SPI_RTIO
657 spi_api_iodev_submit iodev_submit;
658#endif /* CONFIG_SPI_RTIO */
660};
661
669static inline bool spi_cs_is_gpio(const struct spi_config *config)
670{
671 return config->cs.gpio.port != NULL;
672}
673
681static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
682{
683 return spi_cs_is_gpio(&spec->config);
684}
685
694__deprecated
695static inline bool spi_is_ready(const struct spi_dt_spec *spec)
696{
697 /* Validate bus is ready */
698 if (!device_is_ready(spec->bus)) {
699 return false;
700 }
701 /* Validate CS gpio port is ready, if it is used */
702 if (spi_cs_is_gpio_dt(spec) &&
703 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
704 return false;
705 }
706 return true;
707}
708
717static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
718{
719 /* Validate bus is ready */
720 if (!device_is_ready(spec->bus)) {
721 return false;
722 }
723 /* Validate CS gpio port is ready, if it is used */
724 if (spi_cs_is_gpio_dt(spec) &&
725 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
726 return false;
727 }
728 return true;
729}
730
749__syscall int spi_transceive(const struct device *dev,
750 const struct spi_config *config,
751 const struct spi_buf_set *tx_bufs,
752 const struct spi_buf_set *rx_bufs);
753
754static inline int z_impl_spi_transceive(const struct device *dev,
755 const struct spi_config *config,
756 const struct spi_buf_set *tx_bufs,
757 const struct spi_buf_set *rx_bufs)
758{
759 const struct spi_driver_api *api =
760 (const struct spi_driver_api *)dev->api;
761 int ret;
762
763 ret = api->transceive(dev, config, tx_bufs, rx_bufs);
764 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
765
766 return ret;
767}
768
784static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
785 const struct spi_buf_set *tx_bufs,
786 const struct spi_buf_set *rx_bufs)
787{
788 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
789}
790
808static inline int spi_read(const struct device *dev,
809 const struct spi_config *config,
810 const struct spi_buf_set *rx_bufs)
811{
812 return spi_transceive(dev, config, NULL, rx_bufs);
813}
814
827static inline int spi_read_dt(const struct spi_dt_spec *spec,
828 const struct spi_buf_set *rx_bufs)
829{
830 return spi_read(spec->bus, &spec->config, rx_bufs);
831}
832
849static inline int spi_write(const struct device *dev,
850 const struct spi_config *config,
851 const struct spi_buf_set *tx_bufs)
852{
853 return spi_transceive(dev, config, tx_bufs, NULL);
854}
855
868static inline int spi_write_dt(const struct spi_dt_spec *spec,
869 const struct spi_buf_set *tx_bufs)
870{
871 return spi_write(spec->bus, &spec->config, tx_bufs);
872}
873
874#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
875
902static inline int spi_transceive_cb(const struct device *dev,
903 const struct spi_config *config,
904 const struct spi_buf_set *tx_bufs,
905 const struct spi_buf_set *rx_bufs,
906 spi_callback_t callback,
907 void *userdata)
908{
909 const struct spi_driver_api *api =
910 (const struct spi_driver_api *)dev->api;
911
912 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata);
913}
914
915#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
916
918void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
946static inline int spi_transceive_signal(const struct device *dev,
947 const struct spi_config *config,
948 const struct spi_buf_set *tx_bufs,
949 const struct spi_buf_set *rx_bufs,
950 struct k_poll_signal *sig)
951{
952 const struct spi_driver_api *api =
953 (const struct spi_driver_api *)dev->api;
954 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
955
956 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
957}
958
964__deprecated static inline int spi_transceive_async(const struct device *dev,
965 const struct spi_config *config,
966 const struct spi_buf_set *tx_bufs,
967 const struct spi_buf_set *rx_bufs,
968 struct k_poll_signal *sig)
969{
970 return spi_transceive_signal(dev, config, tx_bufs, rx_bufs, sig);
971}
972
997static inline int spi_read_signal(const struct device *dev,
998 const struct spi_config *config,
999 const struct spi_buf_set *rx_bufs,
1000 struct k_poll_signal *sig)
1001{
1002 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1003}
1004
1010__deprecated static inline int spi_read_async(const struct device *dev,
1011 const struct spi_config *config,
1012 const struct spi_buf_set *rx_bufs,
1013 struct k_poll_signal *sig)
1014{
1015 return spi_read_signal(dev, config, rx_bufs, sig);
1016}
1017
1041static inline int spi_write_signal(const struct device *dev,
1042 const struct spi_config *config,
1043 const struct spi_buf_set *tx_bufs,
1044 struct k_poll_signal *sig)
1045{
1046 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1047}
1048
1054__deprecated static inline int spi_write_async(const struct device *dev,
1055 const struct spi_config *config,
1056 const struct spi_buf_set *tx_bufs,
1057 struct k_poll_signal *sig)
1058{
1059 return spi_write_signal(dev, config, tx_bufs, sig);
1060}
1061
1062#endif /* CONFIG_POLL */
1063
1064#endif /* CONFIG_SPI_ASYNC */
1065
1066
1067#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1068
1076static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1077{
1078 const struct spi_dt_spec *dt_spec = iodev_sqe->sqe.iodev->data;
1079 const struct device *dev = dt_spec->bus;
1080 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
1081
1082 api->iodev_submit(dt_spec->bus, iodev_sqe);
1083}
1084
1085extern const struct rtio_iodev_api spi_iodev_api;
1086
1098#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, delay_) \
1099 const struct spi_dt_spec _spi_dt_spec_##name = \
1100 SPI_DT_SPEC_GET(node_id, operation_, delay_); \
1101 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1102
1111static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1112{
1113 struct spi_dt_spec *spec = spi_iodev->data;
1114
1115 return spi_is_ready_dt(spec);
1116}
1117
1130static inline int spi_rtio_copy(struct rtio *r,
1131 struct rtio_iodev *iodev,
1132 const struct spi_buf_set *tx_bufs,
1133 const struct spi_buf_set *rx_bufs,
1134 struct rtio_sqe **last_sqe)
1135{
1136 int ret = 0;
1137 size_t tx_count = tx_bufs ? tx_bufs->count : 0;
1138 size_t rx_count = rx_bufs ? rx_bufs->count : 0;
1139
1140 uint32_t tx = 0, tx_len = 0;
1141 uint32_t rx = 0, rx_len = 0;
1142 uint8_t *tx_buf, *rx_buf;
1143
1144 struct rtio_sqe *sqe = NULL;
1145
1146 if (tx < tx_count) {
1147 tx_buf = tx_bufs->buffers[tx].buf;
1148 tx_len = tx_bufs->buffers[tx].len;
1149 } else {
1150 tx_buf = NULL;
1151 tx_len = rx_bufs->buffers[rx].len;
1152 }
1153
1154 if (rx < rx_count) {
1155 rx_buf = rx_bufs->buffers[rx].buf;
1156 rx_len = rx_bufs->buffers[rx].len;
1157 } else {
1158 rx_buf = NULL;
1159 rx_len = tx_bufs->buffers[tx].len;
1160 }
1161
1162
1163 while ((tx < tx_count || rx < rx_count) && (tx_len > 0 || rx_len > 0)) {
1164 sqe = rtio_sqe_acquire(r);
1165
1166 if (sqe == NULL) {
1167 ret = -ENOMEM;
1169 goto out;
1170 }
1171
1172 ret++;
1173
1174 /* If tx/rx len are same, we can do a simple transceive */
1175 if (tx_len == rx_len) {
1176 if (tx_buf == NULL) {
1178 rx_buf, rx_len, NULL);
1179 } else if (rx_buf == NULL) {
1181 tx_buf, tx_len, NULL);
1182 } else {
1184 tx_buf, rx_buf, rx_len, NULL);
1185 }
1186 tx++;
1187 rx++;
1188 if (rx < rx_count) {
1189 rx_buf = rx_bufs->buffers[rx].buf;
1190 rx_len = rx_bufs->buffers[rx].len;
1191 } else {
1192 rx_buf = NULL;
1193 rx_len = 0;
1194 }
1195 if (tx < tx_count) {
1196 tx_buf = tx_bufs->buffers[tx].buf;
1197 tx_len = tx_bufs->buffers[tx].len;
1198 } else {
1199 tx_buf = NULL;
1200 tx_len = 0;
1201 }
1202 } else if (tx_len == 0) {
1204 (uint8_t *)rx_buf,
1205 (uint32_t)rx_len,
1206 NULL);
1207 rx++;
1208 if (rx < rx_count) {
1209 rx_buf = rx_bufs->buffers[rx].buf;
1210 rx_len = rx_bufs->buffers[rx].len;
1211 } else {
1212 rx_buf = NULL;
1213 rx_len = 0;
1214 }
1215 } else if (rx_len == 0) {
1217 (uint8_t *)tx_buf,
1218 (uint32_t)tx_len,
1219 NULL);
1220 tx++;
1221 if (tx < tx_count) {
1222 tx_buf = rx_bufs->buffers[rx].buf;
1223 tx_len = rx_bufs->buffers[rx].len;
1224 } else {
1225 tx_buf = NULL;
1226 tx_len = 0;
1227 }
1228 } else if (tx_len > rx_len) {
1230 (uint8_t *)tx_buf,
1231 (uint8_t *)rx_buf,
1232 (uint32_t)rx_len,
1233 NULL);
1234 tx_len -= rx_len;
1235 tx_buf += rx_len;
1236 rx++;
1237 if (rx < rx_count) {
1238 rx_buf = rx_bufs->buffers[rx].buf;
1239 rx_len = rx_bufs->buffers[rx].len;
1240 } else {
1241 rx_buf = NULL;
1242 rx_len = tx_len;
1243 }
1244 } else if (rx_len > tx_len) {
1246 (uint8_t *)tx_buf,
1247 (uint8_t *)rx_buf,
1248 (uint32_t)tx_len,
1249 NULL);
1250 rx_len -= tx_len;
1251 rx_buf += tx_len;
1252 tx++;
1253 if (tx < tx_count) {
1254 tx_buf = tx_bufs->buffers[tx].buf;
1255 tx_len = tx_bufs->buffers[tx].len;
1256 } else {
1257 tx_buf = NULL;
1258 tx_len = rx_len;
1259 }
1260 } else {
1261 __ASSERT_NO_MSG("Invalid spi_rtio_copy state");
1262 }
1263
1265 }
1266
1267 if (sqe != NULL) {
1268 sqe->flags = 0;
1269 *last_sqe = sqe;
1270 }
1271
1272out:
1273 return ret;
1274}
1275
1276#endif /* CONFIG_SPI_RTIO */
1277
1298__syscall int spi_release(const struct device *dev,
1299 const struct spi_config *config);
1300
1301static inline int z_impl_spi_release(const struct device *dev,
1302 const struct spi_config *config)
1303{
1304 const struct spi_driver_api *api =
1305 (const struct spi_driver_api *)dev->api;
1306
1307 return api->release(dev, config);
1308}
1309
1321static inline int spi_release_dt(const struct spi_dt_spec *spec)
1322{
1323 return spi_release(spec->bus, &spec->config);
1324}
1325
1326#ifdef __cplusplus
1327}
1328#endif
1329
1334#include <syscalls/spi.h>
1335
1336#endif /* ZEPHYR_INCLUDE_DRIVERS_SPI_H_ */
workaround assembler barfing for ST r
Definition: asm-macro-32-bit-gnu.h:24
Public APIs for GPIO drivers.
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:835
#define RTIO_SQE_TRANSACTION
The next request in the queue is part of a transaction.
Definition: rtio.h:108
#define RTIO_PRIO_NORM
Normal priority.
Definition: rtio.h:70
static void rtio_sqe_prep_transceive(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *tx_buf, uint8_t *rx_buf, uint32_t buf_len, void *userdata)
Prepare a transceive op submission.
Definition: rtio.h:608
static void rtio_sqe_prep_read(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a read op submission.
Definition: rtio.h:499
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition: rtio.h:904
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition: rtio.h:922
static void rtio_sqe_prep_write(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a write op submission.
Definition: rtio.h:539
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)
Definition: spi.h:621
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition: spi.h:295
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.
void(* spi_callback_t)(const struct device *dev, int result, void *data)
SPI callback for asynchronous transfer requests.
Definition: spi.h:614
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:868
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:717
static int spi_write_async(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, struct k_poll_signal *sig)
Alias for spi_write_signal for backwards compatibility.
Definition: spi.h:1054
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:946
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:808
static int spi_read_async(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig)
Alias for spi_read_signal for backwards compatibility.
Definition: spi.h:1010
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:784
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.
Definition: spi.h:902
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition: spi.h:591
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:827
static bool spi_is_ready(const struct spi_dt_spec *spec)
Validate that SPI bus is ready.
Definition: spi.h:695
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:849
static int spi_rtio_copy(struct rtio *r, struct rtio_iodev *iodev, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, struct rtio_sqe **last_sqe)
Copy the tx_bufs and rx_bufs into a set of RTIO requests.
Definition: spi.h:1130
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition: spi.h:1321
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition: spi.h:643
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit a SPI device with a request.
Definition: spi.h:1076
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:997
int(* spi_api_io)(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
Callback API for I/O See spi_transceive() for argument descriptions.
Definition: spi.h:602
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:681
static int spi_transceive_async(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig)
Alias for spi_transceive_signal for backwards compatibility.
Definition: spi.h:964
const struct rtio_iodev_api spi_iodev_api
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:593
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:1041
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition: spi.h:669
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:1111
#define ENOMEM
Not enough core.
Definition: errno.h:51
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
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device dynamic structure (in RAM) per driver instance.
Definition: device.h:370
Runtime device structure (in ROM) per driver instance.
Definition: device.h:399
void * data
Address of the device instance private data.
Definition: device.h:409
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405
Container for GPIO pin information specified in devicetree.
Definition: gpio.h:288
const struct device * port
GPIO device controlling the pin.
Definition: gpio.h:290
Definition: kernel.h:5624
API that an RTIO IO device should implement.
Definition: rtio.h:433
Compute the mempool block index for a given pointer.
Definition: rtio.h:423
struct rtio_sqe sqe
Definition: rtio.h:424
An IO device with a function table for submitting requests.
Definition: rtio.h:448
void * data
Definition: rtio.h:456
A submission queue event.
Definition: rtio.h:232
uint8_t * tx_buf
Definition: rtio.h:277
uint8_t * rx_buf
Definition: rtio.h:278
const struct rtio_iodev * iodev
Device to operation on.
Definition: rtio.h:243
uint16_t flags
Op Flags.
Definition: rtio.h:237
An RTIO context containing what can be viewed as a pair of queues.
Definition: rtio.h:327
SPI buffer array structure.
Definition: spi.h:438
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition: spi.h:440
size_t count
Length of the array pointed by buffers.
Definition: spi.h:442
SPI buffer structure.
Definition: spi.h:425
size_t len
Length of the buffer buf.
Definition: spi.h:432
void * buf
Valid pointer to a data buffer, or NULL otherwise.
Definition: spi.h:427
SPI controller configuration structure.
Definition: spi.h:301
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition: spi.h:326
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition: spi.h:331
spi_operation_t operation
Operation flags.
Definition: spi.h:324
uint32_t frequency
Bus frequency in Hertz.
Definition: spi.h:303
SPI Chip Select control structure.
Definition: spi.h:159
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition: spi.h:172
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition: spi.h:167
SPI driver API This is the mandatory API any SPI driver needs to expose.
Definition: spi.h:651
spi_api_io transceive
Definition: spi.h:652
spi_api_release release
Definition: spi.h:659
Complete SPI DT information.
Definition: spi.h:377
const struct device * bus
SPI bus.
Definition: spi.h:379
struct spi_config config
Slave specific configuration.
Definition: spi.h:381