@@ -43,6 +43,7 @@ typedef enum {
43
43
static i2c_bus_handle_t i2c_handle = NULL ;
44
44
static int dac_power = 0x3c ;
45
45
static int address = ES8388_ADDR ;
46
+ static int esp8388_volume_hack = AI_THINKER_ES8388_VOLUME_HACK ;
46
47
47
48
#define ES_ASSERT (a , format , b , ...) \
48
49
if ((a) != 0) { \
@@ -260,9 +261,10 @@ error_t es8388_deinit(void) {
260
261
* - (-1) Error
261
262
* - (0) Success
262
263
*/
263
- error_t es8388_init (codec_config_t * cfg , i2c_bus_handle_t handle , int addr ) {
264
+ error_t es8388_init (codec_config_t * cfg , i2c_bus_handle_t handle , int addr , int volumeHack ) {
264
265
AD_TRACED ();
265
266
i2c_handle = handle ;
267
+ esp8388_volume_hack = volumeHack ;
266
268
// set address
267
269
if (addr > 0 ) address = addr ;
268
270
@@ -389,17 +391,25 @@ error_t es8388_config_fmt(codec_mode_t mode, i2s_format_t fmt) {
389
391
return res ;
390
392
}
391
393
392
- /**
393
- * @brief Sets the output volume
394
- * @param volume: 0 ~ 100
395
- *
396
- * @return
397
- * - (-1) Error
398
- * - (0) Success
399
- */
400
- #if AI_THINKER_ES8388_VOLUME_HACK == 1
394
+ error_t es8388_set_voice_volume_0 (int volume ) {
395
+ AD_LOGD ("es8388_set_voice_volume: %d" , volume );
396
+ error_t res = RESULT_OK ;
397
+ if (volume < 0 )
398
+ volume = 0 ;
399
+ else if (volume > 100 )
400
+ volume = 100 ;
401
+ volume /= 3 ;
402
+ // ROUT1VOL LOUT1VOL 0 -> -45dB; 33 -> – 4.5dB
403
+ res = es_write_reg (address , ES8388_DACCONTROL24 , volume );
404
+ res |= es_write_reg (address , ES8388_DACCONTROL25 , volume );
405
+ // DAC LDACVOL RDACVOL default 0 = 0DB; Default value 192 = – -96 dB
406
+ res |= es_write_reg (address , ES8388_DACCONTROL26 , 0 );
407
+ res |= es_write_reg (address , ES8388_DACCONTROL27 , 0 );
408
+ return res ;
409
+ }
401
410
402
- error_t es8388_set_voice_volume (int volume ) {
411
+
412
+ error_t es8388_set_voice_volume_1 (int volume ) {
403
413
AD_LOGD ("es8388_set_voice_volume (HACK 1): %d" , volume );
404
414
error_t res = RESULT_OK ;
405
415
if (volume < 0 )
@@ -419,9 +429,8 @@ error_t es8388_set_voice_volume(int volume) {
419
429
return res ;
420
430
}
421
431
422
- #elif AI_THINKER_ES8388_VOLUME_HACK == 2
423
432
424
- error_t es8388_set_voice_volume (int volume ) {
433
+ error_t es8388_set_voice_volume_2 (int volume ) {
425
434
AD_LOGD ("es8388_set_voice_volume (HACK 2): %d" , volume );
426
435
error_t res = RESULT_OK ;
427
436
if (volume < 0 )
@@ -441,25 +450,28 @@ error_t es8388_set_voice_volume(int volume) {
441
450
return res ;
442
451
}
443
452
444
- #else
453
+ /**
454
+ * @brief Sets the output volume
455
+ * @param volume: 0 ~ 100
456
+ *
457
+ * @return
458
+ * - (-1) Error
459
+ * - (0) Success
460
+ */
461
+
462
+ error_t es8388_set_voice_volume (int volume ) {
463
+ switch (esp8388_volume_hack ) {
464
+ case 0 :
465
+ return es8388_set_voice_volume_0 (volume );
466
+ case 1 :
467
+ return es8388_set_voice_volume_1 (volume );
468
+ case 2 :
469
+ return es8388_set_voice_volume_2 (volume );
470
+ default :
471
+ return es8388_set_voice_volume_0 (volume );
472
+ }
473
+ }
445
474
446
- error_t es8388_set_voice_volume (int volume ) {
447
- AD_LOGD ("es8388_set_voice_volume: %d" , volume );
448
- error_t res = RESULT_OK ;
449
- if (volume < 0 )
450
- volume = 0 ;
451
- else if (volume > 100 )
452
- volume = 100 ;
453
- volume /= 3 ;
454
- // ROUT1VOL LOUT1VOL 0 -> -45dB; 33 -> – 4.5dB
455
- res = es_write_reg (address , ES8388_DACCONTROL24 , volume );
456
- res |= es_write_reg (address , ES8388_DACCONTROL25 , volume );
457
- // DAC LDACVOL RDACVOL default 0 = 0DB; Default value 192 = – -96 dB
458
- res |= es_write_reg (address , ES8388_DACCONTROL26 , 0 );
459
- res |= es_write_reg (address , ES8388_DACCONTROL27 , 0 );
460
- return res ;
461
- }
462
- #endif
463
475
464
476
/**
465
477
* Provides the volume
0 commit comments