Skip to content

Commit 2fd4f82

Browse files
committed
Move DriverConstants
1 parent 6d15719 commit 2fd4f82

File tree

7 files changed

+62
-56
lines changed

7 files changed

+62
-56
lines changed

src/AudioBoard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AudioBoard {
5252
return driver->end();
5353
}
5454
bool setMute(bool enable) { return driver->setMute(enable); }
55+
bool setMute(bool enable, int line) { return driver->setMute(enable, line); }
5556
bool setVolume(int volume) { return driver->setVolume(volume); }
5657
int getVolume() { return driver->getVolume(); }
5758
DriverPins& getPins() { return *pins; }

src/Driver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,8 @@ class AudioDriverES8388Class : public AudioDriver {
791791
AD_LOGD("invalid line %d", line);
792792
return false;
793793
}
794-
line_active[line] = !mute;
795794
// mute is managed on line level, so deactivate global mute
796-
setMute(false);
795+
line_active[line] = !mute;
797796
if (line_active[0] && line_active[1]) {
798797
return es8388_config_output_device(DAC_OUTPUT_ALL) == RESULT_OK;
799798
} else if (!line_active[0] && !line_active[1]) {

src/Driver/DriverConstants.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,6 @@
33
# include "Arduino.h" // for delay
44
#endif
55

6-
typedef enum {
7-
_DAC_OUTPUT_MIN = -1,
8-
_DAC_OUTPUT_LOUT1 = 0x04,
9-
_DAC_OUTPUT_LOUT2 = 0x08,
10-
_DAC_OUTPUT_SPK = 0x09,
11-
_DAC_OUTPUT_ROUT1 = 0x10,
12-
_DAC_OUTPUT_ROUT2 = 0x20,
13-
_DAC_OUTPUT_ALL = 0x3c,
14-
_DAC_OUTPUT_MAX,
15-
} es_output_device_t;
16-
17-
typedef enum {
18-
_ADC_INPUT_MIN = -1,
19-
_ADC_INPUT_LINPUT1_RINPUT1 = 0x00,
20-
_ADC_INPUT_MIC1 = 0x05,
21-
_ADC_INPUT_MIC2 = 0x06,
22-
_ADC_INPUT_LINPUT2_RINPUT2 = 0x50,
23-
_ADC_INPUT_DIFFERENCE = 0xf0,
24-
_ADC_INPUT_MAX,
25-
} es_input_device_t;
26-
27-
28-
typedef enum {
29-
_D2SE_PGA_GAIN_MIN = -1,
30-
_D2SE_PGA_GAIN_DIS = 0,
31-
_D2SE_PGA_GAIN_EN = 1,
32-
_D2SE_PGA_GAIN_MAX = 2,
33-
} es_d2se_pga_t;
34-
356

367
typedef enum {
378
MCLK_DIV_MIN = -1,

src/Driver/es8374/es8374.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static int codec_init_flag = 0;
3737
static i2c_bus_handle_t i2c_handle;
3838
static int i2c_address_es8374 = ES8374_ADDR;
3939

40+
4041
static bool es8374_codec_initialized()
4142
{
4243
return codec_init_flag;
@@ -480,7 +481,7 @@ error_t es8374_i2s_config_clock(es_i2s_clock_t cfg)
480481
return res;
481482
}
482483

483-
error_t es8374_config_output_device(es_output_device_t output)
484+
error_t es8374_config_output_device()
484485
{
485486
error_t res = RESULT_OK;
486487
uint8_t reg = 0;
@@ -498,7 +499,9 @@ error_t es8374_config_output_device(es_output_device_t output)
498499
return res;
499500
}
500501

501-
error_t es8374_config_input_device(es_input_device_t input)
502+
503+
504+
error_t es8374_config_input_device()
502505
{
503506
error_t res = RESULT_OK;
504507
uint8_t reg = 0;
@@ -593,7 +596,7 @@ static int es8374_set_d2se_pga(es_d2se_pga_t gain)
593596
int res = 0;
594597
uint8_t reg = 0;
595598

596-
if (gain > _D2SE_PGA_GAIN_MIN && gain < _D2SE_PGA_GAIN_MAX) {
599+
if (gain > ES8374_PGA_GAIN_MIN && gain < ES8374_PGA_GAIN_MAX) {
597600
res = es8374_read_reg(0x21, &reg);
598601
reg &= 0xfb;
599602
reg |= gain << 2;
@@ -606,7 +609,7 @@ static int es8374_set_d2se_pga(es_d2se_pga_t gain)
606609
return res;
607610
}
608611

609-
static int es8374_init_reg(codec_mode_t ms_mode, i2s_format_t fmt, es_i2s_clock_t cfg, es_output_device_t out_channel, es_input_device_t in_channel)
612+
static int es8374_init_reg(codec_mode_t ms_mode, i2s_format_t fmt, es_i2s_clock_t cfg)
610613
{
611614
int res = 0;
612615
uint8_t reg;
@@ -667,8 +670,8 @@ static int es8374_init_reg(codec_mode_t ms_mode, i2s_format_t fmt, es_i2s_clock_
667670
res |= es8374_write_reg(0x71, 0x05); //for automute setting
668671
res |= es8374_write_reg(0x73, 0x70);
669672

670-
res |= es8374_config_output_device(out_channel); //0x3c Enable DAC and Enable Lout/Rout/1/2
671-
res |= es8374_config_input_device(in_channel); //0x00 LINSEL & RINSEL, LIN1/RIN1 as ADC Input; DSSEL,use one DS Reg11; DSR, LINPUT1-RINPUT1
673+
res |= es8374_config_output_device(); //0x3c Enable DAC and Enable Lout/Rout/1/2
674+
res |= es8374_config_input_device(); //0x00 LINSEL & RINSEL, LIN1/RIN1 as ADC Input; DSSEL,use one DS Reg11; DSR, LINPUT1-RINPUT1
672675
res |= es8374_codec_set_voice_volume(0);
673676

674677
res |= es8374_write_reg(0x37, 0x00); // dac set
@@ -694,10 +697,9 @@ error_t es8374_codec_init(codec_config_t *cfg, codec_mode_t codec_mode, void* i2
694697

695698
// TODO
696699
res |= es8374_stop(codec_mode);
697-
res |= es8374_init_reg(cfg->i2s.mode, (BIT_LENGTH_16BITS << 4) | cfg->i2s.fmt, clkdiv,
698-
cfg->output_device, cfg->input_device);
700+
res |= es8374_init_reg(cfg->i2s.mode, (BIT_LENGTH_16BITS << 4) | cfg->i2s.fmt, clkdiv);
699701
res |= es8374_set_mic_gain(MIC_GAIN_15DB);
700-
res |= es8374_set_d2se_pga(_D2SE_PGA_GAIN_EN);
702+
res |= es8374_set_d2se_pga(ES8374_PGA_GAIN_EN);
701703
res |= es8374_config_fmt(codec_mode, cfg->i2s.mode);
702704
res |= es8374_codec_config_i2s(codec_mode, &(cfg->i2s));
703705
codec_init_flag = 1;

src/Driver/es8374/es8374.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ error_t es8374_set_mic_gain(es_mic_gain_t gain);
175175
* - RESULT_FAIL Parameter error
176176
* - RESULT_OK Success
177177
*/
178-
error_t es8374_config_input_device(es_input_device_t input);
178+
error_t es8374_config_input_device();
179179

180180
/**
181181
* @brief Set ES8374 DAC output mode
@@ -186,7 +186,7 @@ error_t es8374_config_input_device(es_input_device_t input);
186186
* - RESULT_FAIL Parameter error
187187
* - RESULT_OK Success
188188
*/
189-
error_t es8374_config_output_device(es_output_device_t output);
189+
error_t es8374_config_output_device();
190190

191191
/**
192192
* @brief Write ES8374 register
@@ -232,6 +232,13 @@ error_t es8374_codec_config_i2s(codec_mode_t mode, I2SDefinition *iface);
232232
*/
233233
error_t es8374_codec_ctrl_state_active(codec_mode_t mode, bool ctrl_state_active);
234234

235+
typedef enum {
236+
ES8374_PGA_GAIN_MIN = -1,
237+
ES8374_PGA_GAIN_DIS = 0,
238+
ES8374_PGA_GAIN_EN = 1,
239+
ES8374_PGA_GAIN_MAX = 2,
240+
} es_d2se_pga_t;
241+
235242

236243
#ifdef __cplusplus
237244
}

src/Driver/es8388/es8388.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
*/
2626
#include "es8388.h"
2727

28+
typedef enum {
29+
ES8388__OUTPUT_MIN = -1,
30+
ES8388_OUTPUT_LOUT1 = 0x04,
31+
ES8388_OUTPUT_LOUT2 = 0x08,
32+
ES8388_OUTPUT_SPK = 0x09,
33+
ES8388_OUTPUT_ROUT1 = 0x10,
34+
ES8388_OUTPUT_ROUT2 = 0x20,
35+
ES8388_OUTPUT_ALL = 0x3c,
36+
ES8388_OUTPUT_MAX,
37+
} es_output_device_t;
38+
39+
2840
#include <string.h>
2941
// #include "audio_hal/board_pins_config.h"
3042

@@ -303,12 +315,12 @@ error_t es8388_init(codec_config_t *cfg, i2c_bus_handle_t handle) {
303315
dac_power = 0;
304316
AD_LOGI("output_device: %d", cfg->output_device);
305317
if (DAC_OUTPUT_LINE2 == cfg->output_device) {
306-
dac_power = _DAC_OUTPUT_LOUT1 | _DAC_OUTPUT_ROUT1;
318+
dac_power = ES8388_OUTPUT_LOUT1 | ES8388_OUTPUT_ROUT1;
307319
} else if (DAC_OUTPUT_LINE1 == cfg->output_device) {
308-
dac_power = _DAC_OUTPUT_LOUT2 | _DAC_OUTPUT_ROUT2;
309-
} else {
310-
dac_power = _DAC_OUTPUT_LOUT1 | _DAC_OUTPUT_LOUT2 | _DAC_OUTPUT_ROUT1 |
311-
_DAC_OUTPUT_ROUT2;
320+
dac_power = ES8388_OUTPUT_LOUT2 | ES8388_OUTPUT_ROUT2;
321+
} else if (DAC_OUTPUT_ALL){
322+
dac_power = ES8388_OUTPUT_LOUT1 | ES8388_OUTPUT_LOUT2 |
323+
ES8388_OUTPUT_ROUT1 | ES8388_OUTPUT_ROUT2;
312324
}
313325
res |= es_write_reg(ES8388_ADDR, ES8388_DACPOWER,
314326
dac_power); // 0x3c Enable DAC and Enable Lout/Rout/1/2
@@ -331,9 +343,9 @@ error_t es8388_init(codec_config_t *cfg, i2c_bus_handle_t handle) {
331343
res |= es8388_set_mic_gain(mic_gain);
332344
int tmp = 0;
333345
if (ADC_INPUT_LINE1 == cfg->input_device) {
334-
tmp = _ADC_INPUT_LINPUT1_RINPUT1;
346+
tmp = ESP8388_INPUT_LINPUT1_RINPUT1;
335347
} else if (ADC_INPUT_LINE2 == cfg->input_device) {
336-
tmp = _ADC_INPUT_LINPUT2_RINPUT2;
348+
tmp = ESP8388_INPUT_LINPUT2_RINPUT2;
337349
} else {
338350
tmp = ADC_INPUT_DIFFERENCE;
339351
}
@@ -351,7 +363,7 @@ error_t es8388_init(codec_config_t *cfg, i2c_bus_handle_t handle) {
351363
res |= es_write_reg(ES8388_ADDR, ES8388_ADCPOWER,
352364
0x09); // Power on ADC, Enable LIN&RIN, Power off
353365
// MICBIAS, set int1lp to low power mode
354-
// es8388_pa_power(cfg->_DAC_OUTPUT!=_DAC_OUTPUT_LINE2);
366+
// es8388_pa_power(cfg->_DAC_OUTPUT!=ES8388_OUTPUT_LINE2);
355367
// AD_LOGI("init,out:%02x, in:%02x", cfg->_DAC_OUTPUT, cfg->input_device);
356368
return res;
357369
}
@@ -548,16 +560,20 @@ error_t es8388_config_output_device(output_device_t output_device) {
548560
AD_LOGI("output_device: %d", output_device);
549561
switch (output_device) {
550562
case DAC_OUTPUT_LINE2:
551-
dac_power = _DAC_OUTPUT_LOUT1 | _DAC_OUTPUT_ROUT1;
563+
AD_LOGI("DAC_OUTPUT_LINE2");
564+
dac_power = ES8388_OUTPUT_LOUT1 | ES8388_OUTPUT_ROUT1;
552565
break;
553566
case DAC_OUTPUT_LINE1:
554-
dac_power = _DAC_OUTPUT_LOUT2 | _DAC_OUTPUT_ROUT2;
567+
AD_LOGI("DAC_OUTPUT_LINE1");
568+
dac_power = ES8388_OUTPUT_LOUT2 | ES8388_OUTPUT_ROUT2;
555569
break;
556570
case DAC_OUTPUT_ALL:
557-
dac_power = _DAC_OUTPUT_LOUT1 | _DAC_OUTPUT_LOUT2 | _DAC_OUTPUT_ROUT1 |
558-
_DAC_OUTPUT_ROUT2;
571+
AD_LOGI("DAC_OUTPUT_ALL");
572+
dac_power = ES8388_OUTPUT_LOUT1 | ES8388_OUTPUT_LOUT2 |
573+
ES8388_OUTPUT_ROUT1 | ES8388_OUTPUT_ROUT2;
559574
break;
560575
case DAC_OUTPUT_NONE:
576+
AD_LOGI("DAC_OUTPUT_NONE");
561577
dac_power = 0;
562578
break;
563579
}
@@ -575,7 +591,7 @@ error_t es8388_config_output_device(output_device_t output_device) {
575591
* - (-1) Parameter error
576592
* - (0) Success
577593
*/
578-
error_t es8388_config_input_device(es_input_device_t input) {
594+
error_t es8388_config_input_device(es8388_input_device_t input) {
579595
AD_LOGD(LOG_METHOD);
580596
error_t res;
581597
uint8_t reg = 0;

src/Driver/es8388/es8388.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ extern "C" {
9797
#define ES8388_DACCONTROL29 0x33
9898
#define ES8388_DACCONTROL30 0x34
9999

100+
typedef enum {
101+
ESP8388_INPUT_MIN = -1,
102+
ESP8388_INPUT_LINPUT1_RINPUT1 = 0x00,
103+
ESP8388_INPUT_MIC1 = 0x05,
104+
ESP8388_INPUT_MIC2 = 0x06,
105+
ESP8388_INPUT_LINPUT2_RINPUT2 = 0x50,
106+
ESP8388_INPUT_DIFFERENCE = 0xf0,
107+
ESP8388_INPUT_MAX,
108+
} es8388_input_device_t;
109+
100110

101111
/**
102112
* @brief Initialize ES8388 codec chip
@@ -237,7 +247,7 @@ error_t es8388_set_mic_gain(es_mic_gain_t gain);
237247
* - RESULT_FAIL Parameter error
238248
* - RESULT_OK Success
239249
*/
240-
error_t es8388_config_input_device(es_input_device_t input);
250+
error_t es8388_config_input_device(es8388_input_device_t input);
241251

242252
/**
243253
* @brief Set ES8388 dac output mode

0 commit comments

Comments
 (0)