Skip to content

Commit e73ebb1

Browse files
committed
Lyrat Using AI_THINKER_ES8388_VOLUME_HACK=3
1 parent 68e44af commit e73ebb1

File tree

4 files changed

+67
-38
lines changed

4 files changed

+67
-38
lines changed

src/AudioBoard.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ static AudioBoard AudioKitEs8388V2{AudioDriverES8388, PinsAudioKitEs8388v2};
120120
/// @ingroup audio_driver
121121
static AudioBoard AudioKitAC101{AudioDriverAC101, PinsAudioKitAC101};
122122
/// @ingroup audio_driver
123-
static AudioBoard LyratV43{AudioDriverES8388, PinsLyrat43};
123+
static AudioBoard LyratV43{AudioDriverES8388H3, PinsLyrat43};
124124
/// @ingroup audio_driver
125-
static AudioBoard LyratV42{AudioDriverES8388, PinsLyrat42};
125+
static AudioBoard LyratV42{AudioDriverES8388H3, PinsLyrat42};
126126
/// @ingroup audio_driver
127127
static AudioBoard LyratMini{AudioDriverLyratMini, PinsLyratMini};
128128
/// @ingroup audio_driver

src/Driver.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class AudioDriver {
202202
setupI2CAddress();
203203

204204
p_pins->setSPIActiveForSD(codec_cfg.sd_active);
205-
if (!p_pins->begin()){
205+
if (!p_pins->begin()) {
206206
AD_LOGE("AudioBoard::pins::begin failed");
207207
return false;
208208
}
@@ -802,6 +802,10 @@ class AudioDriverES8374Class : public AudioDriver {
802802
*/
803803
class AudioDriverES8388Class : public AudioDriver {
804804
public:
805+
AudioDriverES8388Class(int volumeHack) {
806+
i2c_default_address = 0x10;
807+
volume_hack = volumeHack;
808+
}
805809
AudioDriverES8388Class() { i2c_default_address = 0x10; }
806810
bool setMute(bool mute) {
807811
line_active[0] = !mute;
@@ -879,11 +883,16 @@ class AudioDriverES8388Class : public AudioDriver {
879883

880884
bool isInputVolumeSupported() { return true; }
881885

886+
void setVolumeHack(int volume_hack) { this->volume_hack = volume_hack; }
887+
int getVolumeHack() { return volume_hack; }
888+
882889
protected:
883890
bool line_active[2] = {true};
891+
int volume_hack = AI_THINKER_ES8388_VOLUME_HACK;
884892

885893
bool init(codec_config_t codec_cfg) {
886-
return es8388_init(&codec_cfg, getI2C(), getI2CAddress()) == RESULT_OK;
894+
return es8388_init(&codec_cfg, getI2C(), getI2CAddress(), volume_hack) ==
895+
RESULT_OK;
887896
}
888897
bool deinit() { return es8388_deinit() == RESULT_OK; }
889898

@@ -968,7 +977,8 @@ class AudioDriverWM8960Class : public AudioDriver {
968977
/// Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
969978
bool setVolume(int volume) {
970979
volume_out = limitValue(volume, 0, 100);
971-
int vol_int = volume_out == 0.0 ? 0 : mapVolume(volume_out, 0, 100, 30, 0x7F);
980+
int vol_int =
981+
volume_out == 0.0 ? 0 : mapVolume(volume_out, 0, 100, 30, 0x7F);
972982
return mtb_wm8960_set_output_volume(vol_int);
973983
}
974984

@@ -1540,6 +1550,14 @@ static AudioDriverES8374Class AudioDriverES8374;
15401550
/// @ingroup audio_driver
15411551
static AudioDriverES8388Class AudioDriverES8388;
15421552
/// @ingroup audio_driver
1553+
static AudioDriverES8388Class AudioDriverES8388H0{0};
1554+
/// @ingroup audio_driver
1555+
static AudioDriverES8388Class AudioDriverES8388H1{1};
1556+
/// @ingroup audio_driver
1557+
static AudioDriverES8388Class AudioDriverES8388H2{2};
1558+
/// @ingroup audio_driver
1559+
static AudioDriverES8388Class AudioDriverES8388H3{3};
1560+
/// @ingroup audio_driver
15431561
static AudioDriverWM8960Class AudioDriverWM8960;
15441562
/// @ingroup audio_driver
15451563
static AudioDriverWM8978Class AudioDriverWM8978;

src/Driver/es8388/es8388.c

+43-31
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef enum {
4343
static i2c_bus_handle_t i2c_handle = NULL;
4444
static int dac_power = 0x3c;
4545
static int address = ES8388_ADDR;
46+
static int esp8388_volume_hack = AI_THINKER_ES8388_VOLUME_HACK;
4647

4748
#define ES_ASSERT(a, format, b, ...) \
4849
if ((a) != 0) { \
@@ -260,9 +261,10 @@ error_t es8388_deinit(void) {
260261
* - (-1) Error
261262
* - (0) Success
262263
*/
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) {
264265
AD_TRACED();
265266
i2c_handle = handle;
267+
esp8388_volume_hack = volumeHack;
266268
// set address
267269
if (addr>0) address = addr;
268270

@@ -389,17 +391,25 @@ error_t es8388_config_fmt(codec_mode_t mode, i2s_format_t fmt) {
389391
return res;
390392
}
391393

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+
}
401410

402-
error_t es8388_set_voice_volume(int volume) {
411+
412+
error_t es8388_set_voice_volume_1(int volume) {
403413
AD_LOGD("es8388_set_voice_volume (HACK 1): %d", volume);
404414
error_t res = RESULT_OK;
405415
if (volume < 0)
@@ -419,9 +429,8 @@ error_t es8388_set_voice_volume(int volume) {
419429
return res;
420430
}
421431

422-
#elif AI_THINKER_ES8388_VOLUME_HACK == 2
423432

424-
error_t es8388_set_voice_volume(int volume) {
433+
error_t es8388_set_voice_volume_2(int volume) {
425434
AD_LOGD("es8388_set_voice_volume (HACK 2): %d", volume);
426435
error_t res = RESULT_OK;
427436
if (volume < 0)
@@ -441,25 +450,28 @@ error_t es8388_set_voice_volume(int volume) {
441450
return res;
442451
}
443452

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+
}
445474

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
463475

464476
/**
465477
* Provides the volume

src/Driver/es8388/es8388.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ typedef enum {
107107
ESP8388_INPUT_MAX,
108108
} es8388_input_device_t;
109109

110-
111110
/**
112111
* @brief Initialize ES8388 codec chip
113112
*
@@ -117,7 +116,7 @@ typedef enum {
117116
* - RESULT_OK
118117
* - RESULT_FAIL
119118
*/
120-
error_t es8388_init(codec_config_t *cfg, i2c_bus_handle_t handle, int addr);
119+
error_t es8388_init(codec_config_t *cfg, i2c_bus_handle_t handle, int addr, int volumeHack);
121120

122121
/**
123122
* @brief Deinitialize ES8388 codec chip

0 commit comments

Comments
 (0)