Skip to content

Commit 21c3326

Browse files
committed
es7243 configure format
1 parent aafd946 commit 21c3326

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

src/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14231423
// setup SPI for SD
14241424
pins.setSPIActiveForSD(codecCfg.sd_active);
14251425

1426-
// Start ES7243
14271426
bool ok = true;
14281427

14291428
// Start ES8311
@@ -1433,6 +1432,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14331432
setPAPower(true);
14341433
setVolume(DRIVER_DEFAULT_VOLUME);
14351434

1435+
// Start ES7243
14361436
if (codecCfg.input_device != ADC_INPUT_NONE){
14371437
AD_LOGI("starting ES7243");
14381438
adc.setPins(this->pins());

src/Driver/es7243/es7243.c

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
static i2c_bus_handle_t i2c_handle = NULL;
3838
static int es7243_addr = 0x13; // 0x26>>1;
3939
static int mclk_gpio = 0;
40+
static int actual_volume = 0;
41+
static uint8_t audio_format = 0x0C;
4042

4143
void es7243_mclk_gpio(int gpio){
4244
mclk_gpio = gpio;
@@ -57,13 +59,12 @@ error_t es7243_adc_set_addr(int addr)
5759

5860
static error_t es7243_mclk_active(uint8_t mclk_gpio)
5961
{
60-
#ifndef ARDUINO_ARCH_NRF52840
61-
pinMode(mclk_gpio, OUTPUT);
62-
#endif /*
62+
/*
6363
Before initializing es7243, it is necessary to output
6464
mclk to es7243 to activate the I2C configuration.
6565
So give some clocks to active es7243.
6666
*/
67+
pinMode(mclk_gpio, OUTPUT);
6768
for (int i = 0; i < MCLK_PULSES_NUMBER; ++i) {
6869
digitalWrite(mclk_gpio, 0);
6970
delay(1);
@@ -78,12 +79,12 @@ error_t es7243_adc_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle)
7879
error_t ret = RESULT_OK;
7980
i2c_handle = handle;
8081
es7243_mclk_active(mclk_gpio);
81-
ret |= es7243_write_reg(0x00, 0x01);
82+
ret |= es7243_write_reg(0x00, 0x01); // slave mode, software mode
8283
ret |= es7243_write_reg(0x06, 0x00);
83-
ret |= es7243_write_reg(0x05, 0x1B);
84-
ret |= es7243_write_reg(0x01, 0x0C);
85-
ret |= es7243_write_reg(0x08, 0x43);
86-
ret |= es7243_write_reg(0x05, 0x13);
84+
ret |= es7243_write_reg(0x05, 0x1B); // Mute ADC
85+
ret |= es7243_write_reg(0x01, audio_format); // i2s -16bit
86+
ret |= es7243_write_reg(0x08, 0x43); // enable AIN, PGA GAIN = 27DB
87+
ret |= es7243_write_reg(0x05, 0x13); // un Mute ADC
8788
if (ret) {
8889
AD_LOGE( "Es7243 initialize failed!");
8990
return RESULT_FAIL;
@@ -93,17 +94,53 @@ error_t es7243_adc_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle)
9394

9495
error_t es7243_adc_deinit(void)
9596
{
96-
return RESULT_OK;
97+
return es7243_adc_set_voice_mute(true);
9798
}
9899

99100
error_t es7243_adc_ctrl_state_active(codec_mode_t mode, bool ctrl_state_active)
100101
{
101-
return RESULT_OK;
102+
return es7243_adc_set_voice_mute(!ctrl_state_active);
102103
}
103104

104105
error_t es7243_adc_config_i2s(codec_mode_t mode, I2SDefinition *iface)
105106
{
106-
return RESULT_OK;
107+
// master mode not supported
108+
if (iface->mode == MODE_MASTER){
109+
return RESULT_FAIL;
110+
}
111+
112+
// set bits
113+
switch(iface->bits){
114+
case 16:
115+
audio_format |= 0b011 < 2;
116+
break;
117+
case 24:
118+
audio_format |= 0b000 < 2;
119+
break;
120+
case 32:
121+
audio_format |= 0b100 < 2;
122+
break;
123+
default:
124+
return RESULT_FAIL;
125+
}
126+
127+
switch(iface->fmt){
128+
case I2S_RIGHT:
129+
case I2S_NORMAL:
130+
audio_format |= 0b00;
131+
break;
132+
case I2S_LEFT:
133+
audio_format |= 0b01;
134+
break;
135+
case I2S_DSP:
136+
audio_format |= 0b11;
137+
break;
138+
default:
139+
return RESULT_FAIL;
140+
}
141+
142+
error_t ret = es7243_write_reg(0x01, audio_format);
143+
return ret;
107144
}
108145

109146
error_t es7243_adc_set_voice_mute(bool mute)
@@ -126,6 +163,7 @@ error_t es7243_adc_set_voice_volume(int volume)
126163
if (volume < 0) {
127164
volume = 0;
128165
}
166+
actual_volume = volume;
129167
switch (volume) {
130168
case 0 ... 12:
131169
ret |= es7243_write_reg(0x08, 0x11); // 1db
@@ -159,5 +197,6 @@ error_t es7243_adc_set_voice_volume(int volume)
159197

160198
error_t es7243_adc_get_voice_volume(int *volume)
161199
{
200+
*volume = actual_volume;
162201
return RESULT_OK;
163202
}

0 commit comments

Comments
 (0)