@@ -190,9 +190,10 @@ class CodecConfig : public codec_config_t {
190
190
*/
191
191
class AudioDriver {
192
192
public:
193
+
193
194
// / Starts the processing
194
195
virtual bool begin (CodecConfig codecCfg, DriverPins &pins) {
195
- AD_LOGD (" AudioDriver::begin" );
196
+ AD_LOGI (" AudioDriver::begin" );
196
197
p_pins = &pins;
197
198
pins.setSPIActiveForSD (codecCfg.sd_active );
198
199
if (!setConfig (codecCfg)){
@@ -206,27 +207,22 @@ class AudioDriver {
206
207
}
207
208
// / changes the configuration
208
209
virtual bool setConfig (CodecConfig codecCfg) {
210
+ AD_LOGI (" AudioDriver::setConfig" );
209
211
codec_cfg = codecCfg;
210
212
if (!init (codec_cfg)) {
211
- AD_LOGE (" AudioDriver::begin:: init failed" );
213
+ AD_LOGE (" AudioDriver init failed" );
212
214
return false ;
213
- } else {
214
- AD_LOGD (" AudioDriver::begin::init succeeded" );
215
- }
215
+ }
216
216
codec_mode_t codec_mode = codec_cfg.get_mode ();
217
217
if (!controlState (codec_mode)) {
218
- AD_LOGE (" AudioDriver::begin:: controlState failed" );
218
+ AD_LOGE (" AudioDriver controlState failed" );
219
219
return false ;
220
- } else {
221
- AD_LOGD (" AudioDriver::begin::controlState succeeded" );
222
- }
220
+ }
223
221
bool result = configInterface (codec_mode, codec_cfg.i2s );
224
222
if (!result) {
225
- AD_LOGE (" AudioDriver::begin:: configInterface failed" );
223
+ AD_LOGE (" AudioDriver configInterface failed" );
226
224
return false ;
227
- } else {
228
- AD_LOGD (" AudioDriver::begin::configInterface succeeded" );
229
- }
225
+ }
230
226
return result;
231
227
}
232
228
// / Ends the processing: shut down dac and adc
@@ -250,28 +246,32 @@ class AudioDriver {
250
246
// / Determines if setInputVolume() is supported
251
247
virtual bool isInputVolumeSupported () { return false ; }
252
248
// / Provides the pin information
253
- DriverPins &pins () { return *p_pins; }
249
+ virtual DriverPins &pins () { return *p_pins; }
254
250
255
251
// / Sets the PA Power pin to active or inactive
256
252
bool setPAPower (bool enable) {
253
+ if (p_pins == nullptr ) {
254
+ AD_LOGI (" pins are null" );
255
+ return false ;
256
+ }
257
257
GpioPin pin = pins ().getPinID (PinFunction::PA);
258
258
if (pin == -1 ) {
259
+ AD_LOGI (" PinFunction::PA not defined" );
259
260
return false ;
260
261
}
261
262
AD_LOGI (" setPAPower pin %d -> %d" , pin, enable);
262
263
digitalWrite (pin, enable ? HIGH : LOW);
263
264
return true ;
264
265
}
265
266
266
- // / Gets the number of I2S Interfaces
267
- virtual int getI2SCount () { return 1 ; }
267
+ operator bool () {return p_pins != nullptr ;}
268
268
269
269
protected:
270
270
CodecConfig codec_cfg;
271
271
DriverPins *p_pins = nullptr ;
272
272
273
273
// / Determine the TwoWire object from the I2C config or use Wire
274
- TwoWire *getI2C () {
274
+ virtual TwoWire *getI2C () {
275
275
if (p_pins == nullptr ) return &Wire;
276
276
auto i2c = pins ().getI2CPins (PinFunction::CODEC);
277
277
if (!i2c) {
@@ -281,7 +281,7 @@ class AudioDriver {
281
281
return result != nullptr ? result : &Wire;
282
282
}
283
283
284
- int getI2CAddress () {
284
+ virtual int getI2CAddress () {
285
285
if (p_pins == nullptr ) return -1 ;
286
286
auto i2c = pins ().getI2CPins (PinFunction::CODEC);
287
287
if (i2c) {
@@ -316,8 +316,8 @@ class AudioDriver {
316
316
class NoDriverClass : public AudioDriver {
317
317
public:
318
318
virtual bool begin (CodecConfig codecCfg, DriverPins &pins) {
319
- codec_cfg = codecCfg;
320
- p_pins = &pins;
319
+ // codec_cfg = codecCfg;
320
+ // p_pins = &pins;
321
321
return true ;
322
322
}
323
323
virtual bool end (void ) { return true ; }
@@ -390,6 +390,7 @@ class AudioDriverAD1938Class : public AudioDriver {
390
390
return true ;
391
391
}
392
392
virtual bool setConfig (CodecConfig codecCfg) {
393
+ assert (p_pins != nullptr );
393
394
bool result = begin (codecCfg, *p_pins);
394
395
return result;
395
396
}
@@ -428,7 +429,6 @@ class AudioDriverAD1938Class : public AudioDriver {
428
429
429
430
protected:
430
431
AD1938 ad1938;
431
- DriverPins *p_pins = nullptr ;
432
432
int volume = 100 ;
433
433
int volumes[8 ] = {100 };
434
434
};
@@ -563,6 +563,7 @@ class AudioDriverCS42448Class : public AudioDriver {
563
563
cs42448.setMute (false );
564
564
}
565
565
} else {
566
+ assert (p_pins != nullptr );
566
567
result = begin (codecCfg, *p_pins);
567
568
}
568
569
return result;
@@ -594,7 +595,6 @@ class AudioDriverCS42448Class : public AudioDriver {
594
595
595
596
protected:
596
597
CS42448 cs42448;
597
- DriverPins *p_pins = nullptr ;
598
598
int volume = 100 ;
599
599
CodecConfig cfg;
600
600
};
@@ -1414,27 +1414,35 @@ class AudioDriverPCM3168Class : public AudioDriver {
1414
1414
class AudioDriverLyratMiniClass : public AudioDriver {
1415
1415
public:
1416
1416
bool begin (CodecConfig codecCfg, DriverPins &pins) {
1417
- int rc = 0 ;
1418
- if (codecCfg.output_device != DAC_OUTPUT_NONE)
1419
- rc += !dac.begin (codecCfg, pins);
1420
- if (codecCfg.input_device != ADC_INPUT_NONE)
1421
- rc += !adc.begin (codecCfg, pins);
1422
- return rc == 0 ;
1417
+ AD_LOGI (" AudioDriverLyratMiniClass::begin" );
1418
+ p_pins = &pins;
1419
+ codec_cfg = codecCfg;
1420
+ bool ok = true ;
1421
+ if (codecCfg.output_device != DAC_OUTPUT_NONE){
1422
+ AD_LOGI (" starting DAC" );
1423
+ ok = dac.begin (codecCfg, pins);
1424
+ }
1425
+ if (codecCfg.input_device != ADC_INPUT_NONE){
1426
+ AD_LOGI (" starting ADC" );
1427
+ ok = ok && adc.begin (codecCfg, pins);
1428
+ }
1429
+ if (!ok) {
1430
+ AD_LOGI (" AudioDriverLyratMiniClass::begin failed" );
1431
+ }
1432
+ return ok;
1423
1433
}
1424
1434
bool end (void ) {
1425
1435
int rc = 0 ;
1426
1436
rc += dac.end ();
1427
1437
rc += adc.end ();
1428
- return rc == 0 ;
1438
+ return rc == 2 ;
1429
1439
}
1430
1440
bool setMute (bool enable) { return dac.setMute (enable); }
1431
1441
bool setVolume (int volume) { return dac.setVolume (volume); }
1432
1442
int getVolume () { return dac.getVolume (); }
1433
1443
bool setInputVolume (int volume) { return adc.setVolume (volume); }
1434
1444
int getInputVolume () { return adc.getVolume (); }
1435
1445
bool isInputVolumeSupported () { return true ; }
1436
- // Separate ADC and DAC I2S
1437
- int getI2SCount () override { return 2 ; }
1438
1446
1439
1447
protected:
1440
1448
AudioDriverES8311Class dac;
0 commit comments