Zephyr Project API 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
199#define SPI_LOCK_ON BIT(13)
200
212#define SPI_CS_ACTIVE_HIGH BIT(14)
213
215
216
226#define SPI_LINES_SINGLE (0U << 16)
227#define SPI_LINES_DUAL (1U << 16)
228#define SPI_LINES_QUAD (2U << 16)
229#define SPI_LINES_OCTAL (3U << 16)
230
231#define SPI_LINES_MASK (0x3U << 16)
232
234
239
248 union {
249 struct {
263 };
264 struct {
276 };
277 };
278 /* To keep track of which form of this struct is valid */
280};
281
319#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
320 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
321 DT_REG_ADDR_RAW(spi_dev), {})
322
332#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
333 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
334
336#define SPI_CS_CONTROL_MAX_DELAY(node_id) \
337 MAX(DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
338 DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0))
339
340
341#define SPI_CS_CONTROL_INIT_GPIO(node_id, ...) \
342 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
343 .delay = COND_CODE_1(IS_EMPTY(__VA_ARGS__), \
344 (DIV_ROUND_UP(SPI_CS_CONTROL_MAX_DELAY(node_id), 1000)), \
345 (__VA_ARGS__)),
346
347#define SPI_CS_CONTROL_INIT_NATIVE(node_id) \
348 .setup_ns = DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
349 .hold_ns = DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0),
350
351#define SPI_DEPRECATE_DELAY_WARN \
352 __WARN("Delay parameter in SPI DT macros is deprecated, use DT prop instead")
354
397#define SPI_CS_CONTROL_INIT(node_id, ...) \
398{ \
399 COND_CODE_0(IS_EMPTY(__VA_ARGS__), (SPI_DEPRECATE_DELAY_WARN), ()) \
400 COND_CODE_1(DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
401 (SPI_CS_CONTROL_INIT_GPIO(node_id, __VA_ARGS__)), \
402 (SPI_CS_CONTROL_INIT_NATIVE(node_id))) \
403 .cs_is_gpio = DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
404}
405
419#define SPI_CS_CONTROL_INIT_INST(inst) \
420 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst))
421
423
427#if defined(CONFIG_SPI_EXTENDED_MODES)
429#else
431#endif
432
477
479/* converts from the special DT zero value to half of the frequency, for drivers usage mostly */
480static inline uint16_t spi_get_word_delay(const struct spi_config *cfg)
481{
482 uint32_t freq = cfg->frequency;
483
484 if (cfg->word_delay != 0) {
485 return cfg->word_delay;
486 }
487
488 if (freq == 0) {
489 return 0;
490 }
491
492 uint64_t period_ns = NSEC_PER_SEC / freq;
493
494 period_ns = MIN(period_ns, UINT16_MAX);
495 period_ns /= 2;
496
497 return (uint16_t)period_ns;
498}
500
512#define SPI_CONFIG_DT(node_id, operation_, ...) \
513 { \
514 .frequency = DT_PROP(node_id, spi_max_frequency), \
515 .operation = (operation_) | \
516 DT_PROP(node_id, duplex) | \
517 DT_PROP(node_id, frame_format) | \
518 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
519 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
520 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)) | \
521 COND_CODE_1(DT_PROP(node_id, spi_lsb_first), SPI_TRANSFER_LSB, (0)) | \
522 COND_CODE_1(DT_PROP(node_id, spi_cs_high), SPI_CS_ACTIVE_HIGH, (0)), \
523 .slave = DT_REG_ADDR(node_id), \
524 .cs = SPI_CS_CONTROL_INIT(node_id, __VA_ARGS__), \
525 .word_delay = DT_PROP(node_id, spi_interframe_delay_ns),\
526 }
527
537#define SPI_CONFIG_DT_INST(inst, operation_, ...) \
538 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, __VA_ARGS__)
539
545 const struct device *bus;
548};
549
565#define SPI_DT_SPEC_GET(node_id, operation_, ...) \
566 { \
567 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
568 .config = SPI_CONFIG_DT(node_id, operation_, __VA_ARGS__), \
569 }
570
580#define SPI_DT_SPEC_INST_GET(inst, operation_, ...) \
581 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, __VA_ARGS__)
582
586#define SPI_MOSI_OVERRUN_UNKNOWN 0x100
587
600#define SPI_MOSI_OVERRUN_DT(node_id) \
601 DT_PROP_OR(node_id, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
602
614#define SPI_MOSI_OVERRUN_DT_INST(inst) \
615 DT_INST_PROP_OR(inst, overrun_character, SPI_MOSI_OVERRUN_UNKNOWN)
616
626struct spi_buf {
628 void *buf;
630 size_t len;
631};
632
646 const struct spi_buf *buffers;
648 size_t count;
649};
650
655#if defined(CONFIG_SPI_STATS)
657STATS_SECT_ENTRY32(rx_bytes)
658STATS_SECT_ENTRY32(tx_bytes)
659STATS_SECT_ENTRY32(transfer_error)
661
663STATS_NAME(spi, rx_bytes)
664STATS_NAME(spi, tx_bytes)
665STATS_NAME(spi, transfer_error)
666STATS_NAME_END(spi);
667
671struct spi_device_state {
672 struct device_state devstate;
673 struct stats_spi stats;
674};
675
679#define Z_SPI_GET_STATS(dev_) \
680 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
681
687#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
688 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
689
695#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
696 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
697
705#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
706 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
707
712#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
713 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
714 __attribute__((__section__(".z_devstate")));
715
722#define Z_SPI_INIT_FN(dev_id, init_fn) \
723 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
724 { \
725 struct spi_device_state *state = \
726 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
727 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
728 STATS_NAME_INIT_PARMS(spi)); \
729 stats_register(dev->name, &(state->stats.s_hdr)); \
730 return init_fn(dev); \
731 }
733
734#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, \
735 pm_device, data_ptr, cfg_ptr, \
736 level, prio, api_ptr, ...) \
737 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
738 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
739 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
740 DEVICE_DT_NAME(node_id), \
741 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
742 deinit_fn, Z_DEVICE_DT_FLAGS(node_id), \
743 pm_device, data_ptr, cfg_ptr, level, prio, \
744 api_ptr, \
745 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
746 __VA_ARGS__)
747
748static inline void spi_transceive_stats(const struct device *dev, int error,
749 const struct spi_buf_set *tx_bufs,
750 const struct spi_buf_set *rx_bufs)
751{
752 uint32_t tx_bytes;
753 uint32_t rx_bytes;
754
755 if (error) {
757 }
758
759 if (tx_bufs) {
760 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
761 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
762 }
763
764 if (rx_bufs) {
765 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
766 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
767 }
768}
770
771#else /*CONFIG_SPI_STATS*/
772
777
798#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, \
799 config, level, prio, api, ...) \
800 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
801 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
802 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
803 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \
804 level, prio, api, \
805 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
806 __VA_ARGS__)
807
809
810#define SPI_STATS_RX_BYTES_INC(dev_)
811#define SPI_STATS_TX_BYTES_INC(dev_)
812#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
813
814#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
815
816#endif /*CONFIG_SPI_STATS*/
817
837#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, \
838 api, ...) \
839 SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
840 level, prio, api, __VA_ARGS__)
841
850#define SPI_DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
851 SPI_DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
852
861#define SPI_DEVICE_DT_INST_DEFINE(inst, ...) \
862 SPI_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
863
868
874typedef int (*spi_api_io)(const struct device *dev,
875 const struct spi_config *config,
876 const struct spi_buf_set *tx_bufs,
877 const struct spi_buf_set *rx_bufs);
878
886typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
887
893typedef int (*spi_api_io_async)(const struct device *dev,
894 const struct spi_config *config,
895 const struct spi_buf_set *tx_bufs,
896 const struct spi_buf_set *rx_bufs,
898 void *userdata);
899
900#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
901
905typedef void (*spi_api_iodev_submit)(const struct device *dev,
906 struct rtio_iodev_sqe *iodev_sqe);
907#endif /* CONFIG_SPI_RTIO */
908
913typedef int (*spi_api_release)(const struct device *dev,
914 const struct spi_config *config);
915
916
920__subsystem struct spi_driver_api {
925#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
931#endif /* CONFIG_SPI_ASYNC */
932#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
938#endif /* CONFIG_SPI_RTIO */
943};
944
947
955static inline bool spi_cs_is_gpio(const struct spi_config *config)
956{
957 return config->cs.cs_is_gpio;
958}
959
967static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
968{
969 return spi_cs_is_gpio(&spec->config);
970}
971
980static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
981{
982 /* Validate bus is ready */
983 if (!device_is_ready(spec->bus)) {
984 return false;
985 }
986 /* Validate CS gpio port is ready, if it is used */
987 if (spi_cs_is_gpio_dt(spec) &&
988 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
989 return false;
990 }
991 return true;
992}
993
1001
1031__syscall int spi_transceive(const struct device *dev,
1032 const struct spi_config *config,
1033 const struct spi_buf_set *tx_bufs,
1034 const struct spi_buf_set *rx_bufs);
1035
1036static inline int z_impl_spi_transceive(const struct device *dev,
1037 const struct spi_config *config,
1038 const struct spi_buf_set *tx_bufs,
1039 const struct spi_buf_set *rx_bufs)
1040{
1041 int ret = DEVICE_API_GET(spi, dev)->transceive(dev, config, tx_bufs, rx_bufs);
1042
1043 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1044
1045 return ret;
1046}
1047
1063static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1064 const struct spi_buf_set *tx_bufs,
1065 const struct spi_buf_set *rx_bufs)
1066{
1067 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1068}
1069
1089static inline int spi_read(const struct device *dev,
1090 const struct spi_config *config,
1091 const struct spi_buf_set *rx_bufs)
1092{
1093 return spi_transceive(dev, config, NULL, rx_bufs);
1094}
1095
1108static inline int spi_read_dt(const struct spi_dt_spec *spec,
1109 const struct spi_buf_set *rx_bufs)
1110{
1111 return spi_read(spec->bus, &spec->config, rx_bufs);
1112}
1113
1132static inline int spi_write(const struct device *dev,
1133 const struct spi_config *config,
1134 const struct spi_buf_set *tx_bufs)
1135{
1136 return spi_transceive(dev, config, tx_bufs, NULL);
1137}
1138
1151static inline int spi_write_dt(const struct spi_dt_spec *spec,
1152 const struct spi_buf_set *tx_bufs)
1153{
1154 return spi_write(spec->bus, &spec->config, tx_bufs);
1155}
1156
1157
1158#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1170
1199static inline int spi_transceive_cb(const struct device *dev,
1200 const struct spi_config *config,
1201 const struct spi_buf_set *tx_bufs,
1202 const struct spi_buf_set *rx_bufs,
1203 spi_callback_t callback,
1204 void *userdata)
1205{
1206 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, callback,
1207 userdata);
1208}
1209
1210#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
1211
1213void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
1215
1245static inline int spi_transceive_signal(const struct device *dev,
1246 const struct spi_config *config,
1247 const struct spi_buf_set *tx_bufs,
1248 const struct spi_buf_set *rx_bufs,
1249 struct k_poll_signal *sig)
1250{
1251 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1252
1253 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1254}
1255
1281static inline int spi_read_signal(const struct device *dev,
1282 const struct spi_config *config,
1283 const struct spi_buf_set *rx_bufs,
1284 struct k_poll_signal *sig)
1285{
1286 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1287}
1288
1313static inline int spi_write_signal(const struct device *dev,
1314 const struct spi_config *config,
1315 const struct spi_buf_set *tx_bufs,
1316 struct k_poll_signal *sig)
1317{
1318 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1319}
1320
1321#endif /* CONFIG_POLL */
1322
1324#endif /* CONFIG_SPI_ASYNC */
1325
1326
1327#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1328
1343static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1344{
1345 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1346 const struct device *dev = dt_spec->bus;
1347
1348 DEVICE_API_GET(spi, dev)->iodev_submit(dev, iodev_sqe);
1349}
1350
1352extern const struct rtio_iodev_api spi_iodev_api;
1354
1365#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, ...) \
1366 const struct spi_dt_spec _spi_dt_spec_##name = \
1367 SPI_DT_SPEC_GET(node_id, operation_, __VA_ARGS__); \
1368 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1369
1380#define SPI_DT_INST_IODEV_DEFINE(name, inst, operation_, ...) \
1381 SPI_DT_IODEV_DEFINE(name, DT_DRV_INST(inst), operation_, __VA_ARGS__)
1382
1391static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1392{
1393 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1394
1395 return spi_is_ready_dt(spec);
1396}
1397
1398
1399#endif /* CONFIG_SPI_RTIO */
1400
1420__syscall int spi_release(const struct device *dev,
1421 const struct spi_config *config);
1422
1423static inline int z_impl_spi_release(const struct device *dev,
1424 const struct spi_config *config)
1425{
1426 return DEVICE_API_GET(spi, dev)->release(dev, config);
1427}
1428
1440static inline int spi_release_dt(const struct spi_dt_spec *spec)
1441{
1442 return spi_release(spec->bus, &spec->config);
1443}
1444
1445#ifdef __cplusplus
1446}
1447#endif
1448
1452
1453#include <zephyr/syscalls/spi.h>
1454
1458#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:1449
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:958
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:893
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:886
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:1151
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:980
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:430
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)
@def_driverbackendgroup{SPI,spi_interface}
Definition spi.h:874
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:1245
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:1089
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:1063
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:1199
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition spi.h:812
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:1108
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:1132
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1440
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit an SPI device with a request.
Definition spi.h:1343
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:1281
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:967
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:913
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:814
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:1313
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:955
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:905
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:1391
#define STATS_SECT_END
Ends a stats group struct definition.
Definition stats.h:169
#define STATS_NAME(sectname__, entry__)
Add an entry name to a statistics entry name map.
Definition stats.h:519
#define STATS_SECT_ENTRY32(var__)
Declares a 32-bit stat entry inside a group struct.
Definition stats.h:204
#define STATS_NAME_START(sectname__)
Begin a statistics entry name map.
Definition stats.h:510
#define STATS_NAME_END(sectname__)
End a statistics entry name map.
Definition stats.h:527
#define STATS_SECT_START(group__)
Begins a stats group struct definition.
Definition stats.h:181
#define MIN(a, b)
Obtain the minimum of two values.
Definition util.h:406
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
Real-Time IO device API for moving bytes with low effort.
Statistics.
__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
Poll signal object.
Definition kernel.h:6862
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:644
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition spi.h:646
size_t count
Number of buffers in the array pointed to: by buffers.
Definition spi.h:648
SPI buffer structure.
Definition spi.h:626
size_t len
Length of the buffer buf in bytes, or length of NOP.
Definition spi.h:630
void * buf
Valid pointer to a data buffer, or NULL for NOP indication.
Definition spi.h:628
SPI controller configuration structure.
Definition spi.h:440
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition spi.h:465
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition spi.h:470
spi_operation_t operation
Operation flags.
Definition spi.h:463
uint32_t frequency
Bus frequency in Hertz.
Definition spi.h:442
uint16_t word_delay
Delay between SPI words on SCK line in nanoseconds, if supported.
Definition spi.h:475
SPI Chip Select control structure.
Definition spi.h:247
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition spi.h:262
uint32_t hold_ns
CS enable lag time, i.e.
Definition spi.h:275
bool cs_is_gpio
Definition spi.h:279
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition spi.h:257
uint32_t setup_ns
CS enable lead time, i.e.
Definition spi.h:269
@driver_ops{SPI}
Definition spi.h:920
spi_api_io transceive
@driver_ops_mandatory Read/write the specified amount of data from the SPI driver.
Definition spi.h:924
spi_api_release release
@driver_ops_mandatory Release the SPI device locked on and/or the CS by the current config.
Definition spi.h:942
spi_api_io_async transceive_async
@driver_ops_optional Read/write the specified amount of data from the SPI driver asynchronously.
Definition spi.h:930
spi_api_iodev_submit iodev_submit
@driver_ops_optional Submit an SPI device with a request.
Definition spi.h:937
Complete SPI DT information.
Definition spi.h:543
const struct device * bus
SPI bus.
Definition spi.h:545
struct spi_config config
Slave specific configuration.
Definition spi.h:547