Zephyr API Documentation 4.2.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 .cs_is_gpio = DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
398 COND_CODE_1(DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
399 (SPI_CS_CONTROL_INIT_GPIO(node_id, __VA_ARGS__)), \
400 (SPI_CS_CONTROL_INIT_NATIVE(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
866typedef int (*spi_api_io)(const struct device *dev,
867 const struct spi_config *config,
868 const struct spi_buf_set *tx_bufs,
869 const struct spi_buf_set *rx_bufs);
870
878typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
879
885typedef int (*spi_api_io_async)(const struct device *dev,
886 const struct spi_config *config,
887 const struct spi_buf_set *tx_bufs,
888 const struct spi_buf_set *rx_bufs,
890 void *userdata);
891
892#if defined(CONFIG_SPI_RTIO) || defined(DOXYGEN)
893
898typedef void (*spi_api_iodev_submit)(const struct device *dev,
899 struct rtio_iodev_sqe *iodev_sqe);
900#endif /* CONFIG_SPI_RTIO */
901
907typedef int (*spi_api_release)(const struct device *dev,
908 const struct spi_config *config);
909
910
915__subsystem struct spi_driver_api {
917#ifdef CONFIG_SPI_ASYNC
918 spi_api_io_async transceive_async;
919#endif /* CONFIG_SPI_ASYNC */
920#ifdef CONFIG_SPI_RTIO
921 spi_api_iodev_submit iodev_submit;
922#endif /* CONFIG_SPI_RTIO */
924};
925
933static inline bool spi_cs_is_gpio(const struct spi_config *config)
934{
935 return config->cs.cs_is_gpio;
936}
937
945static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
946{
947 return spi_cs_is_gpio(&spec->config);
948}
949
958static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
959{
960 /* Validate bus is ready */
961 if (!device_is_ready(spec->bus)) {
962 return false;
963 }
964 /* Validate CS gpio port is ready, if it is used */
965 if (spi_cs_is_gpio_dt(spec) &&
966 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
967 return false;
968 }
969 return true;
970}
971
979
1010__syscall int spi_transceive(const struct device *dev,
1011 const struct spi_config *config,
1012 const struct spi_buf_set *tx_bufs,
1013 const struct spi_buf_set *rx_bufs);
1014
1015static inline int z_impl_spi_transceive(const struct device *dev,
1016 const struct spi_config *config,
1017 const struct spi_buf_set *tx_bufs,
1018 const struct spi_buf_set *rx_bufs)
1019{
1020 const struct spi_driver_api *api =
1021 (const struct spi_driver_api *)dev->api;
1022 int ret;
1023
1024 ret = api->transceive(dev, config, tx_bufs, rx_bufs);
1025 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1026
1027 return ret;
1028}
1029
1045static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1046 const struct spi_buf_set *tx_bufs,
1047 const struct spi_buf_set *rx_bufs)
1048{
1049 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1050}
1051
1072static inline int spi_read(const struct device *dev,
1073 const struct spi_config *config,
1074 const struct spi_buf_set *rx_bufs)
1075{
1076 return spi_transceive(dev, config, NULL, rx_bufs);
1077}
1078
1091static inline int spi_read_dt(const struct spi_dt_spec *spec,
1092 const struct spi_buf_set *rx_bufs)
1093{
1094 return spi_read(spec->bus, &spec->config, rx_bufs);
1095}
1096
1116static inline int spi_write(const struct device *dev,
1117 const struct spi_config *config,
1118 const struct spi_buf_set *tx_bufs)
1119{
1120 return spi_transceive(dev, config, tx_bufs, NULL);
1121}
1122
1135static inline int spi_write_dt(const struct spi_dt_spec *spec,
1136 const struct spi_buf_set *tx_bufs)
1137{
1138 return spi_write(spec->bus, &spec->config, tx_bufs);
1139}
1140
1141
1142#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1154
1187static inline int spi_transceive_cb(const struct device *dev,
1188 const struct spi_config *config,
1189 const struct spi_buf_set *tx_bufs,
1190 const struct spi_buf_set *rx_bufs,
1191 spi_callback_t callback,
1192 void *userdata)
1193{
1194 const struct spi_driver_api *api =
1195 (const struct spi_driver_api *)dev->api;
1196
1197 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata);
1198}
1199
1200#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
1201
1203void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
1205
1237static inline int spi_transceive_signal(const struct device *dev,
1238 const struct spi_config *config,
1239 const struct spi_buf_set *tx_bufs,
1240 const struct spi_buf_set *rx_bufs,
1241 struct k_poll_signal *sig)
1242{
1243 const struct spi_driver_api *api =
1244 (const struct spi_driver_api *)dev->api;
1245 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1246
1247 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1248}
1249
1277static inline int spi_read_signal(const struct device *dev,
1278 const struct spi_config *config,
1279 const struct spi_buf_set *rx_bufs,
1280 struct k_poll_signal *sig)
1281{
1282 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1283}
1284
1311static inline int spi_write_signal(const struct device *dev,
1312 const struct spi_config *config,
1313 const struct spi_buf_set *tx_bufs,
1314 struct k_poll_signal *sig)
1315{
1316 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1317}
1318
1319#endif /* CONFIG_POLL */
1320
1322#endif /* CONFIG_SPI_ASYNC */
1323
1324
1325#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1326
1341static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1342{
1343 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1344 const struct device *dev = dt_spec->bus;
1345 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
1346
1347 api->iodev_submit(dt_spec->bus, iodev_sqe);
1348}
1349
1351extern const struct rtio_iodev_api spi_iodev_api;
1353
1364#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, ...) \
1365 const struct spi_dt_spec _spi_dt_spec_##name = \
1366 SPI_DT_SPEC_GET(node_id, operation_, __VA_ARGS__); \
1367 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1368
1377static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1378{
1379 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1380
1381 return spi_is_ready_dt(spec);
1382}
1383
1384
1385#endif /* CONFIG_SPI_RTIO */
1386
1407__syscall int spi_release(const struct device *dev,
1408 const struct spi_config *config);
1409
1410static inline int z_impl_spi_release(const struct device *dev,
1411 const struct spi_config *config)
1412{
1413 const struct spi_driver_api *api =
1414 (const struct spi_driver_api *)dev->api;
1415
1416 return api->release(dev, config);
1417}
1418
1430static inline int spi_release_dt(const struct spi_dt_spec *spec)
1431{
1432 return spi_release(spec->bus, &spec->config);
1433}
1434
1435#ifdef __cplusplus
1436}
1437#endif
1438
1442
1443#include <zephyr/syscalls/spi.h>
1444
1448#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)
Definition spi.h:885
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:878
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:1135
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:958
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:428
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:866
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:1237
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:1072
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:1045
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:1187
#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:1091
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:1116
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1430
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit a SPI device with a request.
Definition spi.h:1341
static int spi_read_signal(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig)
Read the specified amount of data from the SPI driver.
Definition spi.h:1277
static bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
Check if SPI CS in spi_dt_spec is controlled using a GPIO.
Definition spi.h:945
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:907
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:1311
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:933
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:1377
#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:455
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
void * data
Address of the device instance private data.
Definition device.h:520
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Definition kernel.h:6167
API that an RTIO IO device should implement.
Definition rtio.h:525
Compute the mempool block index for a given pointer.
Definition rtio.h:515
struct rtio_sqe sqe
Definition rtio.h:516
An IO device with a function table for submitting requests.
Definition rtio.h:540
void * data
Definition rtio.h:545
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
SPI driver API This is the mandatory API any SPI driver needs to expose.
Definition spi.h:915
spi_api_io transceive
Definition spi.h:916
spi_api_release release
Definition spi.h:923
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