5#if defined(RP2040_MBED)
8#define IS_I2S_IMPLEMENTED
23 friend class I2SStream;
27 I2SConfigStd defaultConfig(
RxTxMode mode) {
33 bool setAudioInfo(AudioInfo) {
return false; }
38 return begin(defaultConfig(mode));
42 bool begin(I2SConfigStd cfg) {
46 if (cfg.rx_tx_mode !=
TX_MODE) {
47 LOGE(
"Unsupported mode: only TX_MODE is supported");
50 if (!
I2S.setBCLK(cfg.pin_bck)) {
51 LOGE(
"Could not set bck pin: %d", cfg.pin_bck);
54 if (!
I2S.setDATA(cfg.pin_data)) {
55 LOGE(
"Could not set data pin: %d", cfg.pin_data);
58 if (cfg.bits_per_sample != 16) {
59 LOGE(
"Unsupported bits_per_sample: %d", (
int)cfg.bits_per_sample);
63 if (cfg.channels < 1 || cfg.channels > 2) {
64 LOGE(
"Unsupported channels: '%d' - only 2 is supported", (
int)cfg.channels);
68 int rate = cfg.sample_rate;
69 if (cfg.channels == 1) {
73 if (!
I2S.begin(rate)) {
74 LOGE(
"Could not start I2S");
84 I2SConfigStd config() {
return cfg; }
87 size_t writeBytes(
const void *
src,
size_t size_bytes) {
92 if (cfg.channels == 1) {
93 int samples = size_bytes / 2;
96 for (
int j = 0;
j < samples;
j++) {
97 buffer[
j * 2] =
p16[
j];
98 buffer[
j * 2 + 1] =
p16[
j];
100 result =
I2S.write((
const uint8_t *)buffer, size_bytes * 2) * 2;
101 }
else if (cfg.channels == 2) {
107 size_t readBytes(
void *
dest,
size_t size_bytes) {
113 int availableForWrite() {
115 if (cfg.channels == 1) {
117 result =
I2S.availableForWrite() / 2 * 2;
122 result =
I2S.availableForWrite() / 4 * 4;
130 int available() {
return 0; }
132 void flush() {
return I2S.flush(); }
138 void writeSample(
int16_t sample) {
139 int written =
I2S.write(sample);
142 LOGW(
"written: %d ", written);
143 written =
I2S.write(sample);
149 for (
int j = 0;
j < samples;
j++) {
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define TRACEE()
Definition AudioLoggerIDF.h:34
#define LOGE(...)
Definition AudioLoggerIDF.h:30
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition AudioTypes.h:26
@ TX_MODE
Definition AudioTypes.h:26
constexpr const _Ep * end(initializer_list< _Ep > __il) noexcept
Definition InitializerList.h:63
constexpr const _Ep * begin(initializer_list< _Ep > __il) noexcept
Definition InitializerList.h:55