3#include "AudioToolsConfig.h"
4#include "AudioTools/CoreAudio/AudioI2S/I2SStream.h"
9#ifndef PIN_AUDIO_KIT_SD_CARD_CS
10#define PIN_AUDIO_KIT_SD_CARD_CS 13
11#define PIN_AUDIO_KIT_SD_CARD_MISO 2
12#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
13#define PIN_AUDIO_KIT_SD_CARD_CLK 14
25 input_device_t input_device = ADC_INPUT_LINE1;
26 output_device_t output_device = DAC_OUTPUT_ALL;
28 bool sd_active =
true;
29 bool sdmmc_active =
false;
31 PinFunction i2s_function = PinFunction::UNDEFINED;
33 return input_device == alt.input_device &&
34 output_device == alt.output_device && *((
AudioInfo *)
this) == alt;
65 memcpy(&cfg, &cfg1,
sizeof(cfg1));
66 cfg.input_device = ADC_INPUT_LINE1;
67 cfg.output_device = DAC_OUTPUT_ALL;
89 if (p_board) p_board->end();
109 if (!is_active || p_board ==
nullptr) {
121 p_board->setConfig(codec_cfg);
125 virtual size_t write(
const uint8_t *data,
size_t len) {
126 LOGD(
"I2SStream::write: %d", len);
127 return i2s.
write(data, len);
131 virtual size_t readBytes(uint8_t *data,
size_t len)
override {
144 if (!is_active || p_board ==
nullptr)
return false;
145 return p_board->setVolume(vol * 100.0);
150 if (p_board ==
nullptr)
return 0.0f;
151 return static_cast<float>(p_board->getVolume()) / 100.0f;
158 if (p_board ==
nullptr)
return false;
159 return p_board->setMute(mute);
163 if (p_board ==
nullptr)
return false;
164 return p_board->setMute(mute, line);
169 if (p_board ==
nullptr)
return false;
170 return p_board->setPAPower(active);
175 if (!is_active || p_board ==
nullptr)
return false;
176 return p_board->setInputVolume(100.0 * vol);
180 AudioBoard &
board() {
return *p_board; }
190 if (p_board ==
nullptr)
return -1;
191 return p_board->getPins().getPinID(function);
196 if (p_board ==
nullptr)
return -1;
197 return p_board->getPins().getPinID(function, pos);
204 DriverPins &
getPins() {
return p_board->getPins(); }
211 p_board->getPins().getGPIO().digitalWrite(pin, value);
216 return p_board->getPins().getGPIO().digitalRead(pin);
222 CodecConfig codec_cfg;
223 AudioBoard *p_board =
nullptr;
224 bool is_active =
false;
230 if (!beginCodec(cfg)) {
235 is_active = i2s.begin(cfg);
239 if (is_active && tobeVol >= 0.0f) {
247 if (cfg.i2s_function == PinFunction::UNDEFINED){
249 auto i2s = p_board->getPins().getI2SPins(PinFunction::CODEC_ADC);
251 cfg.i2s_function = PinFunction::CODEC_ADC;
252 LOGI(
"using i2s_function: CODEC_ADC");
254 cfg.i2s_function = PinFunction::CODEC;
257 cfg.i2s_function = PinFunction::CODEC;
266 auto i2s = getI2SPins();
269 PinsI2S i2s_pins = i2s.value();
270 cfg.pin_bck = i2s_pins.bck;
271 cfg.pin_mck = i2s_pins.mclk;
272 cfg.pin_ws = i2s_pins.ws;
275 cfg.pin_data = i2s_pins.data_in;
278 cfg.pin_data = i2s_pins.data_out;
281 cfg.pin_data = i2s_pins.data_out;
282 cfg.pin_data_rx = i2s_pins.data_in;
288 audio_driver_local::Optional<PinsI2S> getI2SPins(){
290 audio_driver_local::Optional<PinsI2S> i2s;
292 return p_board->getPins().getI2SPins(cfg.i2s_function);
295 bool beginCodec(I2SCodecConfig info) {
299 codec_cfg.input_device = info.input_device;
300 codec_cfg.output_device = DAC_OUTPUT_NONE;
303 codec_cfg.output_device = info.output_device;
304 codec_cfg.input_device = ADC_INPUT_NONE;
307 codec_cfg.input_device = info.input_device;
308 codec_cfg.output_device = info.output_device;
311 codec_cfg.sd_active = info.sd_active;
312 codec_cfg.sdmmc_active = info.sdmmc_active;
313 LOGD(
"input: %d", info.input_device);
314 LOGD(
"output: %d", info.output_device);
315 codec_cfg.i2s.bits = toCodecBits(info.bits_per_sample);
316 codec_cfg.i2s.rate = toRate(info.sample_rate);
317 codec_cfg.i2s.fmt = toFormat(info.i2s_format);
318 codec_cfg.i2s.signal_type = (signal_t) info.signal_type;
320 codec_cfg.i2s.mode = info.is_master ? MODE_SLAVE : MODE_MASTER;
321 if (p_board ==
nullptr)
return false;
324 return p_board->begin(codec_cfg);
327 sample_bits_t toCodecBits(
int bits) {
330 LOGD(
"BIT_LENGTH_16BITS");
331 return BIT_LENGTH_16BITS;
333 LOGD(
"BIT_LENGTH_24BITS");
334 return BIT_LENGTH_24BITS;
336 LOGD(
"BIT_LENGTH_32BITS");
337 return BIT_LENGTH_32BITS;
339 LOGE(
"Unsupported bits: %d", bits);
340 return BIT_LENGTH_16BITS;
342 samplerate_t toRate(
int rate) {
367 if (rate <= 48000 || rate > 48000) {
371 LOGE(
"Invalid rate: %d using 44K", rate);
377 case I2S_PHILIPS_FORMAT:
381 case I2S_LEFT_JUSTIFIED_FORMAT:
385 case I2S_RIGHT_JUSTIFIED_FORMAT:
393 LOGE(
"unsupported mode");
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition AudioTypes.h:30