nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
audio_i2s.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021, PACKETCRAFT, INC.
3 *
4 * SPDX-License-Identifier: LicenseRef-PCFT
5 */
6
7#ifndef _AUDIO_I2S_H_
8#define _AUDIO_I2S_H_
9
10#include <zephyr/kernel.h>
11#include <stdint.h>
12
13/*
14 * Calculate the number of bytes of one frame, as per now, this frame can either
15 * be 10 or 7.5 ms. Since we can't have floats in a define we use 15/2 instead
16 */
17
18#if ((CONFIG_AUDIO_FRAME_DURATION_US == 7500) && CONFIG_SW_CODEC_LC3)
19
20#define FRAME_SIZE_BYTES \
21 ((CONFIG_I2S_LRCK_FREQ_HZ / 1000 * 15 / 2) * CONFIG_I2S_CH_NUM * \
22 CONFIG_AUDIO_BIT_DEPTH_OCTETS)
23#else
24#define FRAME_SIZE_BYTES \
25 ((CONFIG_I2S_LRCK_FREQ_HZ / 1000 * 10) * CONFIG_I2S_CH_NUM * CONFIG_AUDIO_BIT_DEPTH_OCTETS)
26#endif /* ((CONFIG_AUDIO_FRAME_DURATION_US == 7500) && CONFIG_SW_CODEC_LC3) */
27
28#define BLOCK_SIZE_BYTES (FRAME_SIZE_BYTES / CONFIG_FIFO_FRAME_SPLIT_NUM)
29
30/*
31 * Calculate the number of samples in a block, divided by the number of samples
32 * that will fit within a 32-bit word
33 */
34#define I2S_SAMPLES_NUM \
35 (BLOCK_SIZE_BYTES / (CONFIG_AUDIO_BIT_DEPTH_OCTETS) / (32 / CONFIG_AUDIO_BIT_DEPTH_BITS))
36
44typedef void (*i2s_blk_comp_callback_t)(uint32_t frame_start_ts, uint32_t *rx_buf_released,
45 uint32_t const *tx_buf_released);
46
53void audio_i2s_set_next_buf(const uint8_t *tx_buf, uint32_t *rx_buf);
54
61void audio_i2s_start(const uint8_t *tx_buf, uint32_t *rx_buf);
62
66void audio_i2s_stop(void);
67
74
78void audio_i2s_init(void);
79
80#endif /* _AUDIO_I2S_H_ */
void audio_i2s_blk_comp_cb_register(i2s_blk_comp_callback_t blk_comp_callback)
Register callback function for I2S block complete event.
void audio_i2s_init(void)
Initialize I2S module.
void audio_i2s_set_next_buf(const uint8_t *tx_buf, uint32_t *rx_buf)
Supply the buffers to be used in the next part of the I2S transfer.
void audio_i2s_start(const uint8_t *tx_buf, uint32_t *rx_buf)
Start the continuous I2S transfer.
void audio_i2s_stop(void)
Stop the continuous I2S transfer.
void(* i2s_blk_comp_callback_t)(uint32_t frame_start_ts, uint32_t *rx_buf_released, uint32_t const *tx_buf_released)
I2S block complete event callback type.
Definition: audio_i2s.h:44