2 #include "AudioBoard.h"
3 #include "AudioConfig.h"
4 #include "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;
85 if (p_board) p_board->end();
105 if (!is_active || p_board ==
nullptr) {
117 p_board->setConfig(codec_cfg);
121 virtual size_t write(
const uint8_t *data,
size_t len) {
122 LOGD(
"I2SStream::write: %d", len);
123 return i2s.
write(data, len);
127 virtual size_t readBytes(uint8_t *data,
size_t len)
override {
140 if (!is_active || p_board ==
nullptr)
return false;
141 return p_board->setVolume(vol * 100.0);
146 if (p_board ==
nullptr)
return 0.0f;
147 return static_cast<float>(p_board->getVolume()) / 100.0f;
154 if (p_board ==
nullptr)
return false;
155 return p_board->setMute(mute);
159 if (p_board ==
nullptr)
return false;
160 return p_board->setMute(mute, line);
165 if (p_board ==
nullptr)
return false;
166 return p_board->setPAPower(active);
170 AudioBoard &
board() {
return *p_board; }
180 if (p_board ==
nullptr)
return -1;
181 return p_board->getPins().getPinID(
function);
186 if (p_board ==
nullptr)
return -1;
187 return p_board->getPins().getPinID(
function, pos);
194 DriverPins &
getPins() {
return p_board->getPins(); }
202 CodecConfig codec_cfg;
203 AudioBoard *p_board =
nullptr;
204 bool is_active =
false;
208 if (!beginCodec(cfg)) {
213 is_active = i2s.begin(cfg);
216 if (is_active &&
volume() >= 0.0f) {
226 auto i2s = p_board->getPins().getI2SPins();
229 PinsI2S i2s_pins = i2s.value();
230 cfg.pin_bck = i2s_pins.bck;
231 cfg.pin_mck = i2s_pins.mclk;
232 cfg.pin_ws = i2s_pins.ws;
235 cfg.pin_data = i2s_pins.data_in;
238 cfg.pin_data = i2s_pins.data_out;
241 cfg.pin_data = i2s_pins.data_out;
242 cfg.pin_data_rx = i2s_pins.data_in;
251 codec_cfg.input_device = info.input_device;
252 codec_cfg.output_device = DAC_OUTPUT_NONE;
255 codec_cfg.output_device = info.output_device;
256 codec_cfg.input_device = ADC_INPUT_NONE;
259 codec_cfg.input_device = info.input_device;
260 codec_cfg.output_device = info.output_device;
263 codec_cfg.sd_active = info.sd_active;
264 LOGD(
"input: %d", info.input_device);
265 LOGD(
"output: %d", info.output_device);
268 codec_cfg.i2s.fmt = toFormat(info.i2s_format);
270 codec_cfg.i2s.mode = info.is_master ? MODE_SLAVE : MODE_MASTER;
271 if (p_board ==
nullptr)
return false;
274 return p_board->begin(codec_cfg);
277 sample_bits_t toCodecBits(
int bits) {
280 LOGD(
"BIT_LENGTH_16BITS");
281 return BIT_LENGTH_16BITS;
283 LOGD(
"BIT_LENGTH_24BITS");
284 return BIT_LENGTH_24BITS;
286 LOGD(
"BIT_LENGTH_32BITS");
287 return BIT_LENGTH_32BITS;
289 LOGE(
"Unsupported bits: %d", bits);
290 return BIT_LENGTH_16BITS;
292 samplerate_t toRate(
int rate) {
317 if (rate <= 48000 || rate > 48000) {
321 LOGE(
"Invalid rate: %d using 44K", rate);
327 case I2S_PHILIPS_FORMAT:
331 case I2S_LEFT_JUSTIFIED_FORMAT:
335 case I2S_RIGHT_JUSTIFIED_FORMAT:
343 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