oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
i2s.h
Go to the documentation of this file.
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_I2S_H
10#define OVE_I2S_H
11
30#include "ove/types.h"
31#include "ove_config.h"
32#include "ove/storage.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/* ── Enums ───────────────────────────────────────────────────────── */
39
43typedef enum {
48
49/* ── Callback ────────────────────────────────────────────────────── */
50
61typedef void (*ove_i2s_cb_t)(ove_i2s_t i2s, void *user_data);
62
63/* ── Configuration ───────────────────────────────────────────────── */
64
69 unsigned int instance;
70 uint32_t sample_rate;
71 uint8_t bit_depth;
72 uint8_t channels;
75};
76
77#ifdef CONFIG_OVE_I2S
78
79/* ── Lifecycle ───────────────────────────────────────────────────── */
80
92int ove_i2s_init(ove_i2s_t *i2s, ove_i2s_storage_t *storage, void *tx_dma_buf, void *rx_dma_buf,
93 const struct ove_i2s_cfg *cfg);
96
97#ifdef OVE_HEAP_I2S
105int ove_i2s_create(ove_i2s_t *i2s, const struct ove_i2s_cfg *cfg);
108#endif /* OVE_HEAP_I2S */
109
110/* ── Callbacks ───────────────────────────────────────────────────── */
111
122int ove_i2s_set_rx_callback(ove_i2s_t i2s, ove_i2s_cb_t cb, void *user_data);
123
135int ove_i2s_set_tx_callback(ove_i2s_t i2s, ove_i2s_cb_t cb, void *user_data);
136
137/* ── Stream control ──────────────────────────────────────────────── */
138
149
157
165
173
174/* ── Buffer access ───────────────────────────────────────────────── */
175
186
197
205
206/* ── ISR helpers (called by backend, not by application) ─────────── */
207
216
217#else /* !CONFIG_OVE_I2S */
218
219/* No _init/_deinit stubs: OVE_I2S_DEFINE_STATIC is itself gated by
220 * #ifdef CONFIG_OVE_I2S in storage.h. */
221static inline int ove_i2s_create(ove_i2s_t *i, const struct ove_i2s_cfg *c)
222{
223 (void)i;
224 (void)c;
226}
227static inline void ove_i2s_destroy(ove_i2s_t i)
228{
229 (void)i;
230}
231static inline int ove_i2s_set_rx_callback(ove_i2s_t i, ove_i2s_cb_t cb, void *ud)
232{
233 (void)i;
234 (void)cb;
235 (void)ud;
237}
238static inline int ove_i2s_set_tx_callback(ove_i2s_t i, ove_i2s_cb_t cb, void *ud)
239{
240 (void)i;
241 (void)cb;
242 (void)ud;
244}
245static inline int ove_i2s_start(ove_i2s_t i)
246{
247 (void)i;
249}
250static inline int ove_i2s_stop(ove_i2s_t i)
251{
252 (void)i;
254}
255static inline int ove_i2s_pause(ove_i2s_t i)
256{
257 (void)i;
259}
260static inline int ove_i2s_resume(ove_i2s_t i)
261{
262 (void)i;
264}
265static inline void *ove_i2s_rx_buf(ove_i2s_t i)
266{
267 (void)i;
268 return (void *)0;
269}
270static inline void *ove_i2s_tx_buf(ove_i2s_t i)
271{
272 (void)i;
273 return (void *)0;
274}
275static inline size_t ove_i2s_half_buf_size(ove_i2s_t i)
276{
277 (void)i;
278 return 0;
279}
280
281#endif /* CONFIG_OVE_I2S */
282
283#ifdef __cplusplus
284}
285#endif
286
289#endif /* OVE_I2S_H */
void ove_i2s_destroy(ove_i2s_t i2s)
Destroy an I2S handle previously created with ove_i2s_create.
int ove_i2s_create(ove_i2s_t *i2s, const struct ove_i2s_cfg *cfg)
Heap-mode counterpart of ove_i2s_init() — allocates storage and DMA buffers internally.
int ove_i2s_start(ove_i2s_t i2s)
Start I2S DMA streaming.
void ove_i2s_tx_half_cplt_isr(ove_i2s_t i2s)
ISR helper — invoke from backend TX half-complete interrupt.
void(* ove_i2s_cb_t)(ove_i2s_t i2s, void *user_data)
I2S half-buffer completion callback.
Definition i2s.h:61
int ove_i2s_set_tx_callback(ove_i2s_t i2s, ove_i2s_cb_t cb, void *user_data)
Set the TX half-buffer completion callback.
int ove_i2s_pause(ove_i2s_t i2s)
Pause I2S DMA streaming (can be resumed).
void ove_i2s_deinit(ove_i2s_t i2s)
Release an I2S handle previously created with ove_i2s_init.
void * ove_i2s_tx_buf(ove_i2s_t i2s)
Get pointer to the TX half-buffer safe to write.
void ove_i2s_rx_half_cplt_isr(ove_i2s_t i2s)
ISR helper — invoke from backend RX half-complete interrupt.
void * ove_i2s_rx_buf(ove_i2s_t i2s)
Get pointer to the most recently completed RX half-buffer.
void ove_i2s_rx_cplt_isr(ove_i2s_t i2s)
ISR helper — invoke from backend RX full-complete interrupt.
int ove_i2s_init(ove_i2s_t *i2s, ove_i2s_storage_t *storage, void *tx_dma_buf, void *rx_dma_buf, const struct ove_i2s_cfg *cfg)
Initialise I2S with caller-provided static storage and DMA buffers.
int ove_i2s_stop(ove_i2s_t i2s)
Stop I2S DMA streaming.
ove_i2s_dir_t
I2S stream direction.
Definition i2s.h:43
int ove_i2s_resume(ove_i2s_t i2s)
Resume I2S DMA streaming after pause.
size_t ove_i2s_half_buf_size(ove_i2s_t i2s)
Get the size of one half-buffer in bytes.
void ove_i2s_tx_cplt_isr(ove_i2s_t i2s)
ISR helper — invoke from backend TX full-complete interrupt.
int ove_i2s_set_rx_callback(ove_i2s_t i2s, ove_i2s_cb_t cb, void *user_data)
Set the RX half-buffer completion callback.
@ OVE_I2S_DIR_RX
Definition i2s.h:45
@ OVE_I2S_DIR_TX
Definition i2s.h:44
@ OVE_I2S_DIR_TXRX
Definition i2s.h:46
struct ove_i2s * ove_i2s_t
Opaque handle for an I2S / SAI bus controller.
Definition types.h:271
@ OVE_ERR_NOT_SUPPORTED
Definition types.h:98
I2S bus configuration descriptor.
Definition i2s.h:68
uint32_t sample_rate
Definition i2s.h:70
size_t dma_buf_samples
Definition i2s.h:74
unsigned int instance
Definition i2s.h:69
ove_i2s_dir_t direction
Definition i2s.h:73
uint8_t bit_depth
Definition i2s.h:71
uint8_t channels
Definition i2s.h:72