2 #include "AudioBoard.h"
3 #include "AudioConfig.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;
31 return input_device == alt.input_device &&
32 output_device == alt.output_device && *((
AudioInfo *)
this) == alt;
63 memcpy(&cfg, &cfg1,
sizeof(cfg1));
64 cfg.input_device = ADC_INPUT_LINE1;
65 cfg.output_device = DAC_OUTPUT_ALL;
86 if (p_board) p_board->end();
106 if (!is_active || p_board ==
nullptr) {
118 p_board->setConfig(codec_cfg);
122 virtual size_t write(
const uint8_t *data,
size_t len) {
123 LOGD(
"I2SStream::write: %d", len);
124 return i2s.
write(data, len);
128 virtual size_t readBytes(uint8_t *data,
size_t len)
override {
141 if (!is_active || p_board ==
nullptr)
return false;
142 return p_board->setVolume(vol * 100.0);
147 if (p_board ==
nullptr)
return 0.0f;
148 return static_cast<float>(p_board->getVolume()) / 100.0f;
155 if (p_board ==
nullptr)
return false;
156 return p_board->setMute(mute);
160 if (p_board ==
nullptr)
return false;
161 return p_board->setMute(mute, line);
166 if (p_board ==
nullptr)
return false;
167 return p_board->setPAPower(active);
171 AudioBoard &
board() {
return *p_board; }
181 if (p_board ==
nullptr)
return -1;
182 return p_board->getPins().getPinID(
function);
187 if (p_board ==
nullptr)
return -1;
188 return p_board->getPins().getPinID(
function, pos);
195 DriverPins &
getPins() {
return p_board->getPins(); }
203 CodecConfig codec_cfg;
204 AudioBoard *p_board =
nullptr;
205 bool is_active =
false;
209 if (!beginCodec(cfg)) {
214 is_active = i2s.begin(cfg);
218 if (is_active && tobeVol >= 0.0f) {
228 auto i2s = p_board->getPins().getI2SPins();
231 PinsI2S i2s_pins = i2s.value();
232 cfg.pin_bck = i2s_pins.bck;
233 cfg.pin_mck = i2s_pins.mclk;
234 cfg.pin_ws = i2s_pins.ws;
237 cfg.pin_data = i2s_pins.data_in;
240 cfg.pin_data = i2s_pins.data_out;
243 cfg.pin_data = i2s_pins.data_out;
244 cfg.pin_data_rx = i2s_pins.data_in;
253 codec_cfg.input_device = info.input_device;
254 codec_cfg.output_device = DAC_OUTPUT_NONE;
257 codec_cfg.output_device = info.output_device;
258 codec_cfg.input_device = ADC_INPUT_NONE;
261 codec_cfg.input_device = info.input_device;
262 codec_cfg.output_device = info.output_device;
265 codec_cfg.sd_active = info.sd_active;
266 LOGD(
"input: %d", info.input_device);
267 LOGD(
"output: %d", info.output_device);
270 codec_cfg.i2s.fmt = toFormat(info.i2s_format);
272 codec_cfg.i2s.mode = info.is_master ? MODE_SLAVE : MODE_MASTER;
273 if (p_board ==
nullptr)
return false;
276 return p_board->begin(codec_cfg);
279 sample_bits_t toCodecBits(
int bits) {
282 LOGD(
"BIT_LENGTH_16BITS");
283 return BIT_LENGTH_16BITS;
285 LOGD(
"BIT_LENGTH_24BITS");
286 return BIT_LENGTH_24BITS;
288 LOGD(
"BIT_LENGTH_32BITS");
289 return BIT_LENGTH_32BITS;
291 LOGE(
"Unsupported bits: %d", bits);
292 return BIT_LENGTH_16BITS;
294 samplerate_t toRate(
int rate) {
319 if (rate <= 48000 || rate > 48000) {
323 LOGE(
"Invalid rate: %d using 44K", rate);
329 case I2S_PHILIPS_FORMAT:
333 case I2S_LEFT_JUSTIFIED_FORMAT:
337 case I2S_RIGHT_JUSTIFIED_FORMAT:
345 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:26