oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
spi.h
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
9#ifndef OVE_SPI_H
10#define OVE_SPI_H
11
27#include "ove/types.h"
28#include "ove_config.h"
29#include "ove/storage.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/* ── Enums ───────────────────────────────────────────────────────── */
36
46
54
55/* ── Configuration ───────────────────────────────────────────────── */
56
67
75struct ove_spi_cs {
76 unsigned int gpio_port;
77 unsigned int gpio_pin;
79};
80
88 const void *tx;
89 void *rx;
90 size_t len;
91};
92
93#ifdef CONFIG_OVE_SPI
94
95/* ── Lifecycle ───────────────────────────────────────────────────── */
96
97int ove_spi_init(ove_spi_t *spi, ove_spi_storage_t *storage,
98 const struct ove_spi_cfg *cfg);
99void ove_spi_deinit(ove_spi_t spi);
100
101#ifdef OVE_HEAP_SPI
102int ove_spi_create(ove_spi_t *spi, const struct ove_spi_cfg *cfg);
103void ove_spi_destroy(ove_spi_t spi);
104#elif !defined(__ZIG_CIMPORT__)
105#define ove_spi_create(pspi, cfg) \
106 ({ static ove_spi_storage_t _ove_stor_; \
107 ove_spi_init((pspi), &_ove_stor_, (cfg)); })
108#define ove_spi_destroy(spi) ove_spi_deinit(spi)
109#endif
110
111/* ── Operations ──────────────────────────────────────────────────── */
112
128int ove_spi_transfer(ove_spi_t spi, const struct ove_spi_cs *cs,
129 const void *tx, void *rx, size_t len,
130 uint32_t timeout_ms);
131
142int ove_spi_write(ove_spi_t spi, const struct ove_spi_cs *cs,
143 const void *data, size_t len, uint32_t timeout_ms);
144
155int ove_spi_read(ove_spi_t spi, const struct ove_spi_cs *cs,
156 void *buf, size_t len, uint32_t timeout_ms);
157
172int ove_spi_transfer_seq(ove_spi_t spi, const struct ove_spi_cs *cs,
173 const struct ove_spi_xfer *xfers,
174 unsigned int num_xfers,
175 uint32_t timeout_ms);
176
177#else /* !CONFIG_OVE_SPI */
178
179static inline int ove_spi_create(ove_spi_t *s, const struct ove_spi_cfg *c) { (void)s; (void)c; return OVE_ERR_NOT_SUPPORTED; }
180static inline void ove_spi_destroy(ove_spi_t s) { (void)s; }
181static inline int ove_spi_transfer(ove_spi_t s, const struct ove_spi_cs *cs, const void *tx, void *rx, size_t l, uint32_t t) { (void)s; (void)cs; (void)tx; (void)rx; (void)l; (void)t; return OVE_ERR_NOT_SUPPORTED; }
182static inline int ove_spi_write(ove_spi_t s, const struct ove_spi_cs *cs, const void *d, size_t l, uint32_t t) { (void)s; (void)cs; (void)d; (void)l; (void)t; return OVE_ERR_NOT_SUPPORTED; }
183static inline int ove_spi_read(ove_spi_t s, const struct ove_spi_cs *cs, void *b, size_t l, uint32_t t) { (void)s; (void)cs; (void)b; (void)l; (void)t; return OVE_ERR_NOT_SUPPORTED; }
184static inline int ove_spi_transfer_seq(ove_spi_t s, const struct ove_spi_cs *cs, const struct ove_spi_xfer *x, unsigned int n, uint32_t t) { (void)s; (void)cs; (void)x; (void)n; (void)t; return OVE_ERR_NOT_SUPPORTED; }
185
186#endif /* CONFIG_OVE_SPI */
187
188#ifdef __cplusplus
189}
190#endif
191
194#endif /* OVE_SPI_H */
ove_spi_bit_order_t
SPI bit order.
Definition spi.h:50
ove_spi_mode_t
SPI clock polarity / phase mode.
Definition spi.h:40
@ OVE_SPI_MSB_FIRST
Definition spi.h:51
@ OVE_SPI_LSB_FIRST
Definition spi.h:52
@ OVE_SPI_MODE_3
Definition spi.h:44
@ OVE_SPI_MODE_0
Definition spi.h:41
@ OVE_SPI_MODE_2
Definition spi.h:43
@ OVE_SPI_MODE_1
Definition spi.h:42
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_spi * ove_spi_t
Opaque handle for an SPI bus controller.
Definition types.h:139
SPI bus configuration descriptor.
Definition spi.h:60
unsigned int instance
Definition spi.h:61
uint8_t word_size
Definition spi.h:65
ove_spi_mode_t mode
Definition spi.h:63
uint32_t clock_hz
Definition spi.h:62
ove_spi_bit_order_t bit_order
Definition spi.h:64
SPI chip-select descriptor.
Definition spi.h:75
unsigned int gpio_port
Definition spi.h:76
unsigned int gpio_pin
Definition spi.h:77
int active_low
Definition spi.h:78
SPI transfer segment for multi-segment transactions.
Definition spi.h:87
size_t len
Definition spi.h:90
void * rx
Definition spi.h:89
const void * tx
Definition spi.h:88