4#if defined(RP2040_MBED)
7#define IS_I2S_IMPLEMENTED
22 friend class I2SStream;
26 I2SConfigStd defaultConfig(
RxTxMode mode) {
32 bool setAudioInfo(AudioInfo) {
return false; }
37 return begin(defaultConfig(mode));
41 bool begin(I2SConfigStd cfg) {
45 if (cfg.rx_tx_mode !=
TX_MODE) {
46 LOGE(
"Unsupported mode: only TX_MODE is supported");
49 if (!
I2S.setBCLK(cfg.pin_bck)) {
50 LOGE(
"Could not set bck pin: %d", cfg.pin_bck);
53 if (!
I2S.setDATA(cfg.pin_data)) {
54 LOGE(
"Could not set data pin: %d", cfg.pin_data);
57 if (cfg.bits_per_sample != 16) {
58 LOGE(
"Unsupported bits_per_sample: %d", (
int)cfg.bits_per_sample);
62 if (cfg.channels < 1 || cfg.channels > 2) {
63 LOGE(
"Unsupported channels: '%d' - only 2 is supported", (
int)cfg.channels);
67 int rate = cfg.sample_rate;
68 if (cfg.channels == 1) {
72 if (!
I2S.begin(rate)) {
73 LOGE(
"Could not start I2S");
83 I2SConfigStd config() {
return cfg; }
86 size_t writeBytes(
const void *
src,
size_t size_bytes) {
91 if (cfg.channels == 1) {
92 int samples = size_bytes / 2;
95 for (
int j = 0;
j < samples;
j++) {
96 buffer[
j * 2] =
p16[
j];
97 buffer[
j * 2 + 1] =
p16[
j];
99 result =
I2S.write((
const uint8_t *)buffer, size_bytes * 2) * 2;
100 }
else if (cfg.channels == 2) {
106 size_t readBytes(
void *
dest,
size_t size_bytes) {
112 int availableForWrite() {
114 if (cfg.channels == 1) {
116 result =
I2S.availableForWrite() / 2 * 2;
121 result =
I2S.availableForWrite() / 4 * 4;
129 int available() {
return 0; }
131 void flush() {
return I2S.flush(); }
138 int written =
I2S.write(sample);
141 LOGW(
"written: %d ", written);
142 written =
I2S.write(sample);
148 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:30
@ TX_MODE
Definition AudioTypes.h:30
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