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_CONTROLLER 0U
53
62#define SPI_OP_MODE_PERIPHERAL BIT(0)
63
68#define SPI_OP_MODE_MASTER SPI_OP_MODE_CONTROLLER __DEPRECATED_MACRO
69
74#define SPI_OP_MODE_SLAVE SPI_OP_MODE_PERIPHERAL __DEPRECATED_MACRO
75
77#define SPI_OP_MODE_MASK 0x1U
79
83#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
85
86
91
101#define SPI_MODE_CPOL BIT(1)
102
112#define SPI_MODE_CPHA BIT(2)
113
123#define SPI_MODE_LOOP BIT(3)
124
126#define SPI_MODE_MASK (0xEU)
128
132#define SPI_MODE_GET(_mode_) \
133 ((_mode_) & SPI_MODE_MASK)
134
136
148
150#define SPI_TRANSFER_MSB (0U)
152#define SPI_TRANSFER_LSB BIT(4)
153
155#define SPI_WORD_SIZE_SHIFT (5U)
156#define SPI_WORD_SIZE_MASK (0x3FU << SPI_WORD_SIZE_SHIFT)
158
165#define SPI_WORD_SIZE_GET(operation) \
166 (((operation) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
167
174#define SPI_WORD_SET(word_size) \
175 ((word_size) << SPI_WORD_SIZE_SHIFT)
176
178
179
184
192#define SPI_HOLD_ON_CS BIT(12)
193
211#define SPI_LOCK_ON BIT(13)
212
224#define SPI_CS_ACTIVE_HIGH BIT(14)
225
227
228
239#define SPI_LINES_SINGLE (0U << 16)
240#define SPI_LINES_DUAL (1U << 16)
241#define SPI_LINES_QUAD (2U << 16)
242#define SPI_LINES_OCTAL (3U << 16)
243
244#define SPI_LINES_MASK (0x3U << 16)
245
247
252
261 union {
262 struct {
276 };
277 struct {
289 };
290 };
291 /* To keep track of which form of this struct is valid */
293};
294
332#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
333 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
334 DT_REG_ADDR_RAW(spi_dev), {})
335
345#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
346 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
347
349#define SPI_CS_CONTROL_MAX_DELAY(node_id) \
350 MAX(DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
351 DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0))
352
353
354#define SPI_CS_CONTROL_INIT_GPIO(node_id) \
355 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
356 .delay = DIV_ROUND_UP(SPI_CS_CONTROL_MAX_DELAY(node_id), 1000),
357
358#define SPI_CS_CONTROL_INIT_NATIVE(node_id) \
359 .setup_ns = DT_PROP_OR(node_id, spi_cs_setup_delay_ns, 0), \
360 .hold_ns = DT_PROP_OR(node_id, spi_cs_hold_delay_ns, 0),
362
407#define SPI_CS_CONTROL_INIT(node_id) \
408{ \
409 COND_CODE_1(DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
410 (SPI_CS_CONTROL_INIT_GPIO(node_id)), \
411 (SPI_CS_CONTROL_INIT_NATIVE(node_id))) \
412 .cs_is_gpio = DT_SPI_DEV_HAS_CS_GPIOS(node_id), \
413}
414
428#define SPI_CS_CONTROL_INIT_INST(inst) \
429 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst))
430
432
436#if defined(CONFIG_SPI_EXTENDED_MODES)
438#else
440#endif
441
494
496/* converts from the special DT zero value to half of the frequency, for drivers usage mostly */
497static inline uint16_t spi_get_word_delay(const struct spi_config *cfg)
498{
499 uint32_t freq = cfg->frequency;
500
501 if (cfg->word_delay != 0) {
502 return cfg->word_delay;
503 }
504
505 if (freq == 0) {
506 return 0;
507 }
508
509 uint64_t period_ns = NSEC_PER_SEC / freq;
510
511 period_ns = MIN(period_ns, UINT16_MAX);
512 period_ns /= 2;
513
514 return (uint16_t)period_ns;
515}
517
529#define SPI_CONFIG_DT(node_id, operation_) \
530 { \
531 .frequency = DT_PROP(node_id, spi_max_frequency), \
532 .operation = (operation_) | \
533 DT_PROP(node_id, duplex) | \
534 DT_PROP(node_id, frame_format) | \
535 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
536 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
537 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)) | \
538 COND_CODE_1(DT_PROP(node_id, spi_lsb_first), SPI_TRANSFER_LSB, (0)) | \
539 COND_CODE_1(DT_PROP(node_id, spi_cs_high), SPI_CS_ACTIVE_HIGH, (0)), \
540 .peripheral = DT_REG_ADDR(node_id), \
541 .cs = SPI_CS_CONTROL_INIT(node_id), \
542 .word_delay = DT_PROP(node_id, spi_interframe_delay_ns),\
543 }
544
554#define SPI_CONFIG_DT_INST(inst, operation_) \
555 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_)
556
562 const struct device *bus;
565};
566
582#define SPI_DT_SPEC_GET(node_id, operation_) \
583 { \
584 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
585 .config = SPI_CONFIG_DT(node_id, operation_), \
586 }
587
597#define SPI_DT_SPEC_INST_GET(inst, operation_) \
598 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_)
599
603#define SPI_SDO_OVERRUN_UNKNOWN 0x100
604
609#define SPI_MOSI_OVERRUN_UNKNOWN SPI_SDO_OVERRUN_UNKNOWN __DEPRECATED_MACRO
610
623#define SPI_SDO_OVERRUN_DT(node_id) \
624 DT_PROP_OR(node_id, overrun_character, SPI_SDO_OVERRUN_UNKNOWN)
625
630#define SPI_MOSI_OVERRUN_DT(node_id) SPI_SDO_OVERRUN_DT(node_id) __DEPRECATED_MACRO
631
643#define SPI_SDO_OVERRUN_DT_INST(inst) \
644 DT_INST_PROP_OR(inst, overrun_character, SPI_SDO_OVERRUN_UNKNOWN)
645
650#define SPI_MOSI_OVERRUN_DT_INST(inst) SPI_SDO_OVERRUN_DT_INST(inst) __DEPRECATED_MACRO
651
661struct spi_buf {
663 void *buf;
665 size_t len;
666};
667
681 const struct spi_buf *buffers;
683 size_t count;
684};
685
690#if defined(CONFIG_SPI_STATS)
692STATS_SECT_ENTRY32(rx_bytes)
693STATS_SECT_ENTRY32(tx_bytes)
694STATS_SECT_ENTRY32(transfer_error)
696
698STATS_NAME(spi, rx_bytes)
699STATS_NAME(spi, tx_bytes)
700STATS_NAME(spi, transfer_error)
701STATS_NAME_END(spi);
702
706struct spi_device_state {
707 struct device_state devstate;
708 struct stats_spi stats;
709};
710
714#define Z_SPI_GET_STATS(dev_) \
715 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
716
722#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
723 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
724
730#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
731 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
732
740#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
741 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
742
747#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
748 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
749 __attribute__((__section__(".z_devstate")));
750
757#define Z_SPI_INIT_FN(dev_id, init_fn) \
758 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
759 { \
760 struct spi_device_state *state = \
761 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
762 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
763 STATS_NAME_INIT_PARMS(spi)); \
764 stats_register(dev->name, &(state->stats.s_hdr)); \
765 return init_fn(dev); \
766 }
768
769#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, \
770 pm_device, data_ptr, cfg_ptr, \
771 level, prio, api_ptr, ...) \
772 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
773 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
774 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
775 DEVICE_DT_NAME(node_id), \
776 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
777 deinit_fn, Z_DEVICE_DT_FLAGS(node_id), \
778 pm_device, data_ptr, cfg_ptr, level, prio, \
779 api_ptr, \
780 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
781 __VA_ARGS__)
782
783static inline void spi_transceive_stats(const struct device *dev, int error,
784 const struct spi_buf_set *tx_bufs,
785 const struct spi_buf_set *rx_bufs)
786{
787 uint32_t tx_bytes;
788 uint32_t rx_bytes;
789
790 if (error) {
792 }
793
794 if (tx_bufs) {
795 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
796 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
797 }
798
799 if (rx_bufs) {
800 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
801 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
802 }
803}
805
806#else /*CONFIG_SPI_STATS*/
807
812
833#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, \
834 config, level, prio, api, ...) \
835 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
836 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
837 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
838 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \
839 level, prio, api, \
840 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
841 __VA_ARGS__)
842
844
845#define SPI_STATS_RX_BYTES_INC(dev_)
846#define SPI_STATS_TX_BYTES_INC(dev_)
847#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
848
849#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
850
851#endif /*CONFIG_SPI_STATS*/
852
872#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, \
873 api, ...) \
874 SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
875 level, prio, api, __VA_ARGS__)
876
885#define SPI_DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
886 SPI_DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
887
896#define SPI_DEVICE_DT_INST_DEFINE(inst, ...) \
897 SPI_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
898
903
909typedef int (*spi_api_io)(const struct device *dev,
910 const struct spi_config *config,
911 const struct spi_buf_set *tx_bufs,
912 const struct spi_buf_set *rx_bufs);
913
921typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
922
928typedef int (*spi_api_io_async)(const struct device *dev,
929 const struct spi_config *config,
930 const struct spi_buf_set *tx_bufs,
931 const struct spi_buf_set *rx_bufs,
933 void *userdata);
934
935#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
936
940typedef void (*spi_api_iodev_submit)(const struct device *dev,
941 struct rtio_iodev_sqe *iodev_sqe);
942#endif /* CONFIG_SPI_RTIO */
943
948typedef int (*spi_api_release)(const struct device *dev,
949 const struct spi_config *config);
950
951
955__subsystem struct spi_driver_api {
960#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
966#endif /* CONFIG_SPI_ASYNC */
967#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
973#endif /* CONFIG_SPI_RTIO */
978};
979
982
990static inline bool spi_cs_is_gpio(const struct spi_config *config)
991{
992 return config->cs.cs_is_gpio;
993}
994
1002static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
1003{
1004 return spi_cs_is_gpio(&spec->config);
1005}
1006
1015static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
1016{
1017 /* Validate bus is ready */
1018 if (!device_is_ready(spec->bus)) {
1019 return false;
1020 }
1021 /* Validate CS gpio port is ready, if it is used */
1022 if (spi_cs_is_gpio_dt(spec) &&
1023 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
1024 return false;
1025 }
1026 return true;
1027}
1028
1036
1066__syscall int spi_transceive(const struct device *dev,
1067 const struct spi_config *config,
1068 const struct spi_buf_set *tx_bufs,
1069 const struct spi_buf_set *rx_bufs);
1070
1071static inline int z_impl_spi_transceive(const struct device *dev,
1072 const struct spi_config *config,
1073 const struct spi_buf_set *tx_bufs,
1074 const struct spi_buf_set *rx_bufs)
1075{
1076 int ret = DEVICE_API_GET(spi, dev)->transceive(dev, config, tx_bufs, rx_bufs);
1077
1078 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
1079
1080 return ret;
1081}
1082
1098static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
1099 const struct spi_buf_set *tx_bufs,
1100 const struct spi_buf_set *rx_bufs)
1101{
1102 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
1103}
1104
1124static inline int spi_read(const struct device *dev,
1125 const struct spi_config *config,
1126 const struct spi_buf_set *rx_bufs)
1127{
1128 return spi_transceive(dev, config, NULL, rx_bufs);
1129}
1130
1143static inline int spi_read_dt(const struct spi_dt_spec *spec,
1144 const struct spi_buf_set *rx_bufs)
1145{
1146 return spi_read(spec->bus, &spec->config, rx_bufs);
1147}
1148
1167static inline int spi_write(const struct device *dev,
1168 const struct spi_config *config,
1169 const struct spi_buf_set *tx_bufs)
1170{
1171 return spi_transceive(dev, config, tx_bufs, NULL);
1172}
1173
1186static inline int spi_write_dt(const struct spi_dt_spec *spec,
1187 const struct spi_buf_set *tx_bufs)
1188{
1189 return spi_write(spec->bus, &spec->config, tx_bufs);
1190}
1191
1192
1193#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
1205
1234static inline int spi_transceive_cb(const struct device *dev,
1235 const struct spi_config *config,
1236 const struct spi_buf_set *tx_bufs,
1237 const struct spi_buf_set *rx_bufs,
1238 spi_callback_t callback,
1239 void *userdata)
1240{
1241 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, callback,
1242 userdata);
1243}
1244
1245#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
1246
1248void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
1250
1280static inline int spi_transceive_signal(const struct device *dev,
1281 const struct spi_config *config,
1282 const struct spi_buf_set *tx_bufs,
1283 const struct spi_buf_set *rx_bufs,
1284 struct k_poll_signal *sig)
1285{
1286 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
1287
1288 return DEVICE_API_GET(spi, dev)->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
1289}
1290
1316static inline int spi_read_signal(const struct device *dev,
1317 const struct spi_config *config,
1318 const struct spi_buf_set *rx_bufs,
1319 struct k_poll_signal *sig)
1320{
1321 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
1322}
1323
1348static inline int spi_write_signal(const struct device *dev,
1349 const struct spi_config *config,
1350 const struct spi_buf_set *tx_bufs,
1351 struct k_poll_signal *sig)
1352{
1353 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1354}
1355
1356#endif /* CONFIG_POLL */
1357
1359#endif /* CONFIG_SPI_ASYNC */
1360
1361
1362#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1363
1378static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1379{
1380 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data;
1381 const struct device *dev = dt_spec->bus;
1382
1383 DEVICE_API_GET(spi, dev)->iodev_submit(dev, iodev_sqe);
1384}
1385
1387extern const struct rtio_iodev_api spi_iodev_api;
1389
1400#define SPI_DT_IODEV_DEFINE(name, node_id, operation_) \
1401 const struct spi_dt_spec _spi_dt_spec_##name = \
1402 SPI_DT_SPEC_GET(node_id, operation_); \
1403 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1404
1415#define SPI_DT_INST_IODEV_DEFINE(name, inst, operation_) \
1416 SPI_DT_IODEV_DEFINE(name, DT_DRV_INST(inst), operation_)
1417
1426static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1427{
1428 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data;
1429
1430 return spi_is_ready_dt(spec);
1431}
1432
1433
1434#endif /* CONFIG_SPI_RTIO */
1435
1455__syscall int spi_release(const struct device *dev,
1456 const struct spi_config *config);
1457
1458static inline int z_impl_spi_release(const struct device *dev,
1459 const struct spi_config *config)
1460{
1461 return DEVICE_API_GET(spi, dev)->release(dev, config);
1462}
1463
1475static inline int spi_release_dt(const struct spi_dt_spec *spec)
1476{
1477 return spi_release(spec->bus, &spec->config);
1478}
1479
1480#ifdef __cplusplus
1481}
1482#endif
1483
1487
1488#include <zephyr/syscalls/spi.h>
1489
1493#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:1461
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:982
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:928
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:921
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:1186
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:1015
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:439
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:909
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:1280
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:1124
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:1098
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:1234
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition spi.h:847
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:1143
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:1167
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1475
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit an SPI device with a request.
Definition spi.h:1378
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:1316
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:1002
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:948
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:849
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:1348
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:990
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:940
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:1426
#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:470
Runtime device structure (in ROM) per driver instance.
Definition device.h:525
void * data
Address of the device instance private data.
Definition device.h:535
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Poll signal object.
Definition kernel.h:6790
API that an RTIO IO device should implement.
Definition iodev.h:34
IO device submission queue entry.
Definition sqe.h:403
struct rtio_sqe sqe
Submission this entry carries.
Definition sqe.h:404
An IO device with a function table for submitting requests.
Definition iodev.h:49
void * data
Data associated with this iodev.
Definition iodev.h:54
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:319
SPI scatter-gather buffer array structure.
Definition spi.h:679
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition spi.h:681
size_t count
Number of buffers in the array pointed to: by buffers.
Definition spi.h:683
SPI buffer structure.
Definition spi.h:661
size_t len
Length of the buffer buf in bytes, or length of NOP.
Definition spi.h:665
void * buf
Valid pointer to a data buffer, or NULL for NOP indication.
Definition spi.h:663
SPI controller configuration structure.
Definition spi.h:449
uint16_t slave
Peripheral number.
Definition spi.h:481
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition spi.h:487
spi_operation_t operation
Operation flags.
Definition spi.h:472
uint32_t frequency
Bus frequency in Hertz.
Definition spi.h:451
uint16_t peripheral
Peripheral number.
Definition spi.h:476
uint16_t word_delay
Delay between SPI words on SCK line in nanoseconds, if supported.
Definition spi.h:492
SPI Chip Select control structure.
Definition spi.h:260
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition spi.h:275
uint32_t hold_ns
CS enable lag time, i.e.
Definition spi.h:288
bool cs_is_gpio
Definition spi.h:292
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition spi.h:270
uint32_t setup_ns
CS enable lead time, i.e.
Definition spi.h:282
@driver_ops{SPI}
Definition spi.h:955
spi_api_io transceive
@driver_ops_mandatory Read/write the specified amount of data from the SPI driver.
Definition spi.h:959
spi_api_release release
@driver_ops_mandatory Release the SPI device locked on and/or the CS by the current config.
Definition spi.h:977
spi_api_io_async transceive_async
@driver_ops_optional Read/write the specified amount of data from the SPI driver asynchronously.
Definition spi.h:965
spi_api_iodev_submit iodev_submit
@driver_ops_optional Submit an SPI device with a request.
Definition spi.h:972
Complete SPI DT information.
Definition spi.h:560
const struct device * bus
SPI bus.
Definition spi.h:562
struct spi_config config
Peripheral specific configuration.
Definition spi.h:564