@@ -193,13 +193,12 @@ class CodecConfig : public codec_config_t {
193
193
*/
194
194
class AudioDriver {
195
195
public:
196
-
197
196
// / Starts the processing
198
197
virtual bool begin (CodecConfig codecCfg, DriverPins &pins) {
199
198
AD_LOGI (" AudioDriver::begin" );
200
199
p_pins = &pins;
201
200
pins.setSPIActiveForSD (codecCfg.sd_active );
202
- if (!setConfig (codecCfg)){
201
+ if (!setConfig (codecCfg)) {
203
202
AD_LOGE (" setConfig has failed" );
204
203
return false ;
205
204
}
@@ -215,17 +214,17 @@ class AudioDriver {
215
214
if (!init (codec_cfg)) {
216
215
AD_LOGE (" AudioDriver init failed" );
217
216
return false ;
218
- }
217
+ }
219
218
codec_mode_t codec_mode = codec_cfg.get_mode ();
220
219
if (!controlState (codec_mode)) {
221
220
AD_LOGE (" AudioDriver controlState failed" );
222
221
return false ;
223
- }
222
+ }
224
223
bool result = configInterface (codec_mode, codec_cfg.i2s );
225
224
if (!result) {
226
225
AD_LOGE (" AudioDriver configInterface failed" );
227
226
return false ;
228
- }
227
+ }
229
228
return result;
230
229
}
231
230
// / Ends the processing: shut down dac and adc
@@ -258,7 +257,7 @@ class AudioDriver {
258
257
if (p_pins == nullptr ) {
259
258
AD_LOGI (" pins are null" );
260
259
return false ;
261
- }
260
+ }
262
261
GpioPin pin = pins ().getPinID (PinFunction::PA);
263
262
if (pin == -1 ) {
264
263
AD_LOGI (" PinFunction::PA not defined" );
@@ -269,7 +268,7 @@ class AudioDriver {
269
268
return true ;
270
269
}
271
270
272
- operator bool () {return p_pins != nullptr ;}
271
+ operator bool () { return p_pins != nullptr ; }
273
272
274
273
protected:
275
274
CodecConfig codec_cfg;
@@ -282,7 +281,7 @@ class AudioDriver {
282
281
if (!i2c) {
283
282
return &Wire;
284
283
}
285
- TwoWire* result = i2c.value ().p_wire ;
284
+ TwoWire * result = i2c.value ().p_wire ;
286
285
return result != nullptr ? result : &Wire;
287
286
}
288
287
@@ -321,8 +320,8 @@ class AudioDriver {
321
320
class NoDriverClass : public AudioDriver {
322
321
public:
323
322
virtual bool begin (CodecConfig codecCfg, DriverPins &pins) {
324
- // codec_cfg = codecCfg;
325
- // p_pins = &pins;
323
+ // codec_cfg = codecCfg;
324
+ // p_pins = &pins;
326
325
return true ;
327
326
}
328
327
virtual bool end (void ) { return true ; }
@@ -331,7 +330,9 @@ class NoDriverClass : public AudioDriver {
331
330
virtual int getVolume () { return 100 ; }
332
331
virtual bool setInputVolume (int volume) { return false ; }
333
332
virtual bool isVolumeSupported () {
334
- { return false ; }
333
+ {
334
+ return false ;
335
+ }
335
336
}
336
337
virtual bool isInputVolumeSupported () { return false ; }
337
338
};
@@ -774,7 +775,7 @@ class AudioDriverES8311Class : public AudioDriver {
774
775
// determine address from data
775
776
if (i2c_address <= 0 ) i2c_address = getI2CAddress ();
776
777
777
- assert (getI2C ()!= nullptr );
778
+ assert (getI2C () != nullptr );
778
779
return es8311_codec_init (&codec_cfg, getI2C (), mclk_src, i2c_address) ==
779
780
RESULT_OK;
780
781
}
@@ -1379,29 +1380,43 @@ class AudioDriverPCM3168Class : public AudioDriver {
1379
1380
PCM3168::FMT fmt = PCM3168::FMT::I2SHighSpeedTDM24bit;
1380
1381
switch (iface.bits ) {
1381
1382
case BIT_LENGTH_16BITS:
1382
- if (iface.fmt != I2S_RIGHT) {
1383
+ if (iface.fmt != I2S_RIGHT) {
1383
1384
AD_LOGW (" Only I2S_RIGHT is supported for 16 bits" );
1384
1385
}
1385
1386
fmt = PCM3168::FMT::Right16bit;
1386
1387
break ;
1387
1388
case BIT_LENGTH_32BITS:
1388
1389
case BIT_LENGTH_24BITS:
1389
- switch (iface.fmt ) {
1390
- case I2S_NORMAL:
1391
- fmt = PCM3168::FMT::I2S24bit;
1392
- break ;
1393
- case I2S_LEFT:
1394
- fmt = PCM3168::FMT::Left24bit;
1395
- break ;
1396
- case I2S_RIGHT:
1397
- fmt = PCM3168::FMT::Right24bit;
1398
- break ;
1399
- case I2S_DSP:
1400
- fmt = PCM3168::FMT::LeftDSP24bit;
1401
- break ;
1402
- case I2S_TDM:
1403
- fmt = PCM3168::FMT::I2SHighSpeedTDM24bit;
1404
- break ;
1390
+ if (iface.singal_type == TDM) {
1391
+ switch (iface.fmt ) {
1392
+ case I2S_NORMAL:
1393
+ fmt = PCM3168::FMT::I2STDM24bit;
1394
+ break ;
1395
+ case I2S_LEFT:
1396
+ fmt = PCM3168::FMT::LeftTDM24bit;
1397
+ break ;
1398
+ default :
1399
+ AD_LOGE (" Unsupported fmt for tdm" );
1400
+ return false ;
1401
+ }
1402
+ } else {
1403
+ switch (iface.fmt ) {
1404
+ case I2S_NORMAL:
1405
+ fmt = PCM3168::FMT::I2S24bit;
1406
+ break ;
1407
+ case I2S_LEFT:
1408
+ fmt = PCM3168::FMT::Left24bit;
1409
+ break ;
1410
+ case I2S_RIGHT:
1411
+ fmt = PCM3168::FMT::Right24bit;
1412
+ break ;
1413
+ case I2S_DSP:
1414
+ fmt = PCM3168::FMT::LeftDSP24bit;
1415
+ break ;
1416
+ default :
1417
+ AD_LOGE (" Unsupported fmt" );
1418
+ return false ;
1419
+ }
1405
1420
}
1406
1421
break ;
1407
1422
default :
@@ -1426,7 +1441,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
1426
1441
codec_cfg = codecCfg;
1427
1442
1428
1443
// setup SPI for SD
1429
- // pins.setSPIActiveForSD(codecCfg.sd_active);
1444
+ // pins.setSPIActiveForSD(codecCfg.sd_active);
1430
1445
1431
1446
bool ok = true ;
1432
1447
@@ -1438,7 +1453,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
1438
1453
setVolume (DRIVER_DEFAULT_VOLUME);
1439
1454
1440
1455
// Start ES7243
1441
- if (codecCfg.input_device != ADC_INPUT_NONE){
1456
+ if (codecCfg.input_device != ADC_INPUT_NONE) {
1442
1457
AD_LOGI (" starting ES7243" );
1443
1458
adc.setPins (this ->pins ());
1444
1459
ok = ok && adc.setConfig (codecCfg);
@@ -1455,11 +1470,11 @@ class AudioDriverLyratMiniClass : public AudioDriver {
1455
1470
rc += adc.end ();
1456
1471
return rc == 2 ;
1457
1472
}
1458
- bool setMute (bool enable) override { return dac.setMute (enable); }
1459
- bool setVolume (int volume) override { return dac.setVolume (volume); }
1460
- int getVolume () override { return dac.getVolume (); }
1473
+ bool setMute (bool enable) override { return dac.setMute (enable); }
1474
+ bool setVolume (int volume) override { return dac.setVolume (volume); }
1475
+ int getVolume () override { return dac.getVolume (); }
1461
1476
bool setInputVolume (int volume) override { return adc.setVolume (volume); }
1462
- int getInputVolume () { return adc.getVolume (); }
1477
+ int getInputVolume () { return adc.getVolume (); }
1463
1478
bool isInputVolumeSupported () override { return true ; }
1464
1479
1465
1480
protected:
0 commit comments