Skip to content

Commit 09a0048

Browse files
committed
Add additinal logging
1 parent f1c8c23 commit 09a0048

File tree

6 files changed

+45
-23
lines changed

6 files changed

+45
-23
lines changed

examples/audiotools-sine/audiotools-sine.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ void setup(void) {
1212
// Open Serial
1313
Serial.begin(115200);
1414
AudioLogger::instance().begin(Serial, AudioLogger::Info);
15+
// logging for driver
16+
LOGLEVEL_AUDIODRIVER = AudioDriverInfo;
17+
1518

1619
// start I2S
1720
Serial.println("starting I2S...");

src/Driver.h

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ class CodecConfig : public codec_config_t {
3838
is_output = true;
3939

4040
if (is_input && is_output) {
41+
AUDIODRIVER_LOGD("CODEC_MODE_BOTH");
4142
return CODEC_MODE_BOTH;
4243
}
4344

44-
if (is_input)
45-
return CODEC_MODE_ENCODE;
46-
4745
if (is_output)
46+
AUDIODRIVER_LOGD("CODEC_MODE_DECODE");
4847
return CODEC_MODE_DECODE;
4948

49+
if (is_input)
50+
AUDIODRIVER_LOGD("CODEC_MODE_ENCODE");
51+
return CODEC_MODE_ENCODE;
52+
53+
AUDIODRIVER_LOGD("CODEC_MODE_NONE");
5054
return CODEC_MODE_NONE;
5155
}
5256
};
@@ -60,10 +64,19 @@ class AudioDriver {
6064
virtual bool begin(CodecConfig codecCfg, Pins &pins) {
6165
codec_cfg = codecCfg;
6266
p_pins = &pins;
63-
init(codec_cfg);
67+
if (!init(codec_cfg)){
68+
TRACEE();
69+
return false;
70+
}
6471
codec_mode_t codec_mode = codec_cfg.get_mode();
65-
controlState(codec_mode);
72+
if(!controlState(codec_mode)){
73+
TRACEE();
74+
return false;
75+
}
6676
bool result = configInterface(codec_mode, codec_cfg.i2s);
77+
if(!result){
78+
TRACEE();
79+
}
6780
setPAPower(true);
6881
return result;
6982
}
@@ -83,6 +96,7 @@ class AudioDriver {
8396
Pin pin = pins().getPin(PA);
8497
if (pin == -1)
8598
return false;
99+
AUDIODRIVER_LOGI("setPAPower pin %d -> %d", pin, enable);
86100
digitalWrite(pin, enable ? HIGH : LOW);
87101
return true;
88102
}
@@ -98,11 +112,14 @@ class AudioDriver {
98112
return false;
99113
};
100114

101-
int limitVolume(int volume) {
102-
if (volume > 100)
103-
volume = 100;
104-
if (volume < 0)
105-
volume = 0;
115+
/// make sure that value is in range
116+
/// @param volume
117+
/// @return
118+
int limitVolume(int volume, int min=0, int max=100) {
119+
if (volume > max)
120+
volume = max;
121+
if (volume < min)
122+
volume = min;
106123
return volume;
107124
}
108125
};
@@ -114,6 +131,7 @@ class AudioDriverES8388Class : public AudioDriver {
114131
public:
115132
bool setMute(bool mute) { return es8388_set_voice_mute(mute) == RESULT_OK; }
116133
bool setVolume(int volume) {
134+
AUDIODRIVER_LOGD("volume %d", volume);
117135
return es8388_set_voice_volume(limitVolume(volume)) == RESULT_OK;
118136
}
119137
int getVolume() {
@@ -125,6 +143,7 @@ class AudioDriverES8388Class : public AudioDriver {
125143
bool setInputVolume(int volume) {
126144
// map values from 0 - 100 to 0 to 10
127145
es_mic_gain_t gain = (es_mic_gain_t)(limitVolume(volume) / 10);
146+
AUDIODRIVER_LOGD("input volume: %d -> gain %d", volume, gain);
128147
return setMicrophoneGain(gain);
129148
}
130149

src/Driver/es8374/es8374.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ error_t es8374_i2s_config_clock(es_i2s_clock_t cfg)
491491
return res;
492492
}
493493

494-
error_t es8374_config_DAC_OUTPUT(es_dac_output_t output)
494+
error_t es8374_config_dac_output(es_dac_output_t output)
495495
{
496496
error_t res = RESULT_OK;
497497
uint8_t reg = 0;
@@ -678,7 +678,7 @@ static int es8374_init_reg(codec_mode_t ms_mode, i2s_format_t fmt, es_i2s_clock_
678678
res |= es8374_write_reg(0x71, 0x05); //for automute setting
679679
res |= es8374_write_reg(0x73, 0x70);
680680

681-
res |= es8374_config_DAC_OUTPUT(out_channel); //0x3c Enable DAC and Enable Lout/Rout/1/2
681+
res |= es8374_config_dac_output(out_channel); //0x3c Enable DAC and Enable Lout/Rout/1/2
682682
res |= es8374_config_adc_input(in_channel); //0x00 LINSEL & RINSEL, LIN1/RIN1 as ADC Input; DSSEL,use one DS Reg11; DSR, LINPUT1-RINPUT1
683683
res |= es8374_codec_set_voice_volume(0);
684684

src/Driver/es8374/es8374.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ error_t es8374_config_adc_input(es_adc_input_t input);
186186
* - RESULT_FAIL Parameter error
187187
* - RESULT_OK Success
188188
*/
189-
error_t es8374_config_DAC_OUTPUT(es_dac_output_t output);
189+
error_t es8374_config_dac_output(es_dac_output_t output);
190190

191191
/**
192192
* @brief Write ES8374 register

src/Driver/es8388/es8388.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ error_t es8388_write_reg(uint8_t reg_add, uint8_t data)
7373
*/
7474
static int es8388_set_adc_dac_volume(int mode, int volume, int dot)
7575
{
76-
AUDIODRIVER_LOGD("es8388_set_adc_dac_volume: %d", volume);
76+
AUDIODRIVER_LOGD("es8388_set_adc_dac_volume: %d.%d", volume,dot);
7777
int res = 0;
7878
if ( volume < -96 || volume > 0 ) {
7979
AUDIODRIVER_LOGW("Warning: volume < -96! or > 0!\n");
@@ -255,7 +255,7 @@ error_t es8388_init(codec_config_t *cfg, i2c_bus_handle_t handle)
255255
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL23, 0x00); //vroi=0
256256
res |= es8388_set_adc_dac_volume(_ES_MODULE_DAC, 0, 0); // 0db
257257
dac_power = 0;
258-
AUDIODRIVER_LOGI("_DAC_OUTPUT %d",cfg->dac_output);
258+
AUDIODRIVER_LOGI("dac_output: %d",cfg->dac_output);
259259
if (DAC_OUTPUT_LINE2 == cfg->dac_output) {
260260
dac_power = _DAC_OUTPUT_LOUT1 | _DAC_OUTPUT_ROUT1;
261261
} else if (DAC_OUTPUT_LINE1 == cfg->dac_output) {
@@ -524,7 +524,7 @@ error_t es8388_config_adc_input(es_adc_input_t input)
524524
*/
525525
error_t es8388_set_mic_gain(es_mic_gain_t gain)
526526
{
527-
AUDIODRIVER_LOGD(LOG_METHOD);
527+
AUDIODRIVER_LOGD("es8388_set_mic_gain: %d", gain);
528528
error_t res, gain_n;
529529
gain_n = (int)gain / 3;
530530
gain_n = (gain_n << 4) + gain_n;
@@ -534,7 +534,7 @@ error_t es8388_set_mic_gain(es_mic_gain_t gain)
534534

535535
int es8388_ctrl_state_active(codec_mode_t mode, bool ctrl_state_active)
536536
{
537-
AUDIODRIVER_LOGD(LOG_METHOD);
537+
AUDIODRIVER_LOGD("es8388_ctrl_state_active: %d, %d", mode, ctrl_state_active);
538538
int res = 0;
539539
int es_mode_t = 0;
540540
switch (mode) {

src/Pins.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,20 @@ struct PinsSPI {
8686
}
8787
// if no pins are defined, just call begin
8888
if (!pinsAvailable()) {
89-
LOGI("setting up SPI w/o pins");
89+
AUDIODRIVER_LOGI("setting up SPI w/o pins");
9090
p_spi->begin();
9191
} else {
9292
// begin spi and set up pins if supported
9393
#if defined(ARDUINO_ARCH_STM32)
94-
LOGI("setting up SPI miso:%d,mosi:%d, clk:%d, cs:%d", miso, mosi, clk,
94+
LAUDIODRIVER_LOGIOGI("setting up SPI miso:%d,mosi:%d, clk:%d, cs:%d", miso, mosi, clk,
9595
cs);
9696
p_spi->setMISO(miso);
9797
p_spi->setMOSI(mosi);
9898
p_spi->setSCLK(clk);
9999
p_spi->setSSEL(cs);
100100
p_spi->begin();
101101
#elif defined(ESP32)
102-
LOGI("setting up SPI miso:%d,mosi:%d, clk:%d, cs:%d", miso, mosi, clk,
102+
AUDIODRIVER_LOGI("setting up SPI miso:%d,mosi:%d, clk:%d, cs:%d", miso, mosi, clk,
103103
cs);
104104
p_spi->begin(clk, miso, mosi, cs);
105105
#elif defined(ARDUINO_ARCH_AVR)
@@ -147,15 +147,15 @@ struct PinsI2C {
147147
if (set_active) {
148148
// if no pins are defined, just call begin
149149
if (!pinsAvailable()) {
150-
LOGI("setting up I2C w/o pins");
150+
AUDIODRIVER_LOGI("setting up I2C w/o pins");
151151
p_wire->begin();
152152
} else {
153153
// begin with defined pins, if supported
154154
#if defined(ESP32) || defined(ARDUINO_ARCH_STM32)
155-
LOGI("setting up I2C scl: %d, sda: %d", scl, sda);
155+
AUDIODRIVER_LOGI("setting up I2C scl: %d, sda: %d", scl, sda);
156156
p_wire->begin(sda, scl);
157157
#elif defined(ARDUINO_ARCH_RP2040)
158-
LOGI("setting up I2C scl: %d, sda: %d", scl, sda);
158+
AUDIODRIVER_LOGI("setting up I2C scl: %d, sda: %d", scl, sda);
159159
p_wire->setSCL(scl);
160160
p_wire->setSDA(sda);
161161
p_wire->begin();

0 commit comments

Comments
 (0)