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
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
1028__syscall int spi_transceive(const struct device *dev,
1029 const struct spi_config *config,
1030 const struct spi_buf_set *tx_bufs,
1031 const struct spi_buf_set *rx_bufs);
1032
1033static inline int z_impl_spi_transceive(const struct device *dev,
1034 const struct spi_config *config,
1035 const struct spi_buf_set *tx_bufs,
1036 const struct spi_buf_set *rx_bufs)
1037{
1038 int ret = DEVICE_API_GET(spi, dev)->transceive(dev, config, tx_bufs, rx_bufs);
1039
1040 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1041
1042 return ret;
1043}
1044
1060static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1061 const struct spi_buf_set *tx_bufs,
1062 const struct spi_buf_set *rx_bufs)
1063{
1064 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1065}
1066
1087static inline int spi_read(const struct device *dev,
1088 const struct spi_config *config,
1089 const struct spi_buf_set *rx_bufs)
1090{
1091 return spi_transceive(dev, config, NULL, rx_bufs);
1092}
1093
1106static inline int spi_read_dt(const struct spi_dt_spec *spec,
1107 const struct spi_buf_set *rx_bufs)
1108{
1109 return spi_read(spec->bus, &spec->config, rx_bufs);
1110}
1111
1131static inline int spi_write(const struct device *dev,
1132 const struct spi_config *config,
1133 const struct spi_buf_set *tx_bufs)
1134{
1135 return spi_transceive(dev, config, tx_bufs, NULL);
1136}
1137
1150static inline int spi_write_dt(const struct spi_dt_spec *spec,
1151 const struct spi_buf_set *tx_bufs)
1152{
1153 return spi_write(spec->bus, &spec->config, tx_bufs);
1154}
1155
1156
1157#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1169
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
1246static inline int spi_transceive_signal(const struct device *dev,
1247 const struct spi_config *config,
1248 const struct spi_buf_set *tx_bufs,
1249 const struct spi_buf_set *rx_bufs,
1250 struct k_poll_signal *sig)
1251{
1252 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1253
1254 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1255}
1256
1283static inline int spi_read_signal(const struct device *dev,
1284 const struct spi_config *config,
1285 const struct spi_buf_set *rx_bufs,
1286 struct k_poll_signal *sig)
1287{
1288 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1289}
1290
1316static inline int spi_write_signal(const struct device *dev,
1317 const struct spi_config *config,
1318 const struct spi_buf_set *tx_bufs,
1319 struct k_poll_signal *sig)
1320{
1321 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1322}
1323
1324#endif /* CONFIG_POLL */
1325
1327#endif /* CONFIG_SPI_ASYNC */
1328
1329
1330#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1331
1346static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1347{
1348 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1349 const struct device *dev = dt_spec->bus;
1350
1351 DEVICE_API_GET(spi, dev)->iodev_submit(dev, iodev_sqe);
1352}
1353
1355extern const struct rtio_iodev_api spi_iodev_api;
1357
1368#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, ...) \
1369 const struct spi_dt_spec _spi_dt_spec_##name = \
1370 SPI_DT_SPEC_GET(node_id, operation_, __VA_ARGS__); \
1371 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1372
1383#define SPI_DT_INST_IODEV_DEFINE(name, inst, operation_, ...) \
1384 SPI_DT_IODEV_DEFINE(name, DT_DRV_INST(inst), operation_, __VA_ARGS__)
1385
1394static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1395{
1396 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1397
1398 return spi_is_ready_dt(spec);
1399}
1400
1401
1402#endif /* CONFIG_SPI_RTIO */
1403
1424__syscall int spi_release(const struct device *dev,
1425 const struct spi_config *config);
1426
1427static inline int z_impl_spi_release(const struct device *dev,
1428 const struct spi_config *config)
1429{
1430 return DEVICE_API_GET(spi, dev)->release(dev, config);
1431}
1432
1444static inline int spi_release_dt(const struct spi_dt_spec *spec)
1445{
1446 return spi_release(spec->bus, &spec->config);
1447}
1448
1449#ifdef __cplusplus
1450}
1451#endif
1452
1456
1457#include <zephyr/syscalls/spi.h>
1458
1462#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
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:882
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:1150
static bool spi_is_ready_dt(const struct spi_dt_spec *spec)
Validate that SPI bus (and CS gpio if defined) is ready.
Definition spi.h:976
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:426
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:870
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:1246
static int spi_read(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs)
Read the specified amount of data from the SPI driver.
Definition spi.h:1087
static int spi_transceive_dt(const struct spi_dt_spec *spec, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
Read/write data from an SPI bus specified in spi_dt_spec.
Definition spi.h:1060
static int spi_transceive_cb(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, spi_callback_t callback, void *userdata)
Read/write the specified amount of data from the SPI driver asynchronously.
Definition spi.h:1199
#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:1106
static int spi_write(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs)
Write the specified amount of data from the SPI driver.
Definition spi.h:1131
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1444
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit an SPI device with a request.
Definition spi.h:1346
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:1283
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_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:909
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:1316
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:951
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
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:1394
#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.
#define STATS_NAME_END(name__)
Definition stats.h:391
#define STATS_NAME(name__, entry__)
Definition stats.h:390
#define STATS_SECT_END
Ends a stats group struct definition.
Definition stats.h:89
#define STATS_SECT_ENTRY32(var__)
Definition stats.h:359
#define STATS_NAME_START(name__)
Definition stats.h:389
#define STATS_SECT_START(group__)
Definition stats.h:354
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
#define UINT16_MAX
Definition stdint.h:28
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:458
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Definition kernel.h:6606
API that an RTIO IO device should implement.
Definition iodev.h:33
IO device submission queue entry.
Definition sqe.h:394
struct rtio_sqe sqe
Definition sqe.h:395
An IO device with a function table for submitting requests.
Definition iodev.h:48
void * data
Definition iodev.h:53
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:313
SPI scatter-gather buffer array structure.
Definition spi.h:640
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition spi.h:642
size_t count
Number of buffers in the array pointed to: by buffers.
Definition spi.h:644
SPI buffer structure.
Definition spi.h:622
size_t len
Length of the buffer buf in bytes, or length of NOP.
Definition spi.h:626
void * buf
Valid pointer to a data buffer, or NULL for NOP indication.
Definition spi.h:624
SPI controller configuration structure.
Definition spi.h: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
@driver_ops{SPI}
Definition spi.h:916
spi_api_io transceive
@driver_ops_mandatory Read/write the specified amount of data from the SPI driver.
Definition spi.h:920
spi_api_release release
@driver_ops_mandatory Release the SPI device locked on and/or the CS by the current config.
Definition spi.h:938
spi_api_io_async transceive_async
@driver_ops_optional Read/write the specified amount of data from the SPI driver asynchronously.
Definition spi.h:926
spi_api_iodev_submit iodev_submit
@driver_ops_optional Submit an SPI device with a request.
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