Skip to content

Commit 4787eb4

Browse files
Almost-LoverY78
andauthored
The atk-dnesp32s3-box is compatible with ES8311 devices and non-ES8311 devices (#477)
* The atk-dnesp32s3-box is compatible with ES8311 devices and non-ES8311 devices * Update atk_dnesp32s3_box.cc format code --------- Co-authored-by: Xiaoxia <[email protected]>
1 parent a3a833b commit 4787eb4

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

main/boards/atk-dnesp32s3-box/atk_dnesp32s3_box.cc

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "wifi_board.h"
22
#include "audio_codec.h"
3-
#include "audio_codecs/no_audio_codec.h"
3+
#include "es8311_audio_codec.h"
4+
#include "no_audio_codec.h"
45
#include "display/lcd_display.h"
56
#include "application.h"
67
#include "button.h"
@@ -24,9 +25,14 @@
2425
LV_FONT_DECLARE(font_puhui_20_4);
2526
LV_FONT_DECLARE(font_awesome_20_4);
2627

27-
class XL9555 : public I2cDevice {
28+
class XL9555_IN : public I2cDevice {
2829
public:
29-
XL9555(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
30+
XL9555_IN(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
31+
WriteReg(0x06, 0x3B);
32+
WriteReg(0x07, 0xFE);
33+
}
34+
35+
void xl9555_cfg(void) {
3036
WriteReg(0x06, 0x1B);
3137
WriteReg(0x07, 0xFE);
3238
}
@@ -48,6 +54,19 @@ class XL9555 : public I2cDevice {
4854
WriteReg(0x03, data);
4955
}
5056
}
57+
58+
int GetPingState(uint16_t pin) {
59+
uint8_t data;
60+
if (pin <= 0x0080) {
61+
data = ReadReg(0x00);
62+
return (data & (uint8_t)(pin & 0xFF)) ? 1 : 0;
63+
} else {
64+
data = ReadReg(0x01);
65+
return (data & (uint8_t)((pin >> 8) & 0xFF )) ? 1 : 0;
66+
}
67+
68+
return 0;
69+
}
5170
};
5271

5372
class atk_dnesp32s3_box : public WifiBoard {
@@ -56,7 +75,8 @@ class atk_dnesp32s3_box : public WifiBoard {
5675
i2c_master_dev_handle_t xl9555_handle_;
5776
Button boot_button_;
5877
LcdDisplay* display_;
59-
XL9555* xl9555_;
78+
XL9555_IN* xl9555_in_;
79+
bool es8311_detected_ = false;
6080

6181
void InitializeI2c() {
6282
// Initialize I2C peripheral
@@ -75,7 +95,15 @@ class atk_dnesp32s3_box : public WifiBoard {
7595
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
7696

7797
// Initialize XL9555
78-
xl9555_ = new XL9555(i2c_bus_, 0x20);
98+
xl9555_in_ = new XL9555_IN(i2c_bus_, 0x20);
99+
100+
if (xl9555_in_->GetPingState(0x0020) == 1) {
101+
es8311_detected_ = true; /* 音频设备标志位,SPK_CTRL_IO为高电平时,该标志位置1,且判定为ES8311 */
102+
} else {
103+
es8311_detected_ = false; /* 音频设备标志位,SPK_CTRL_IO为低电平时,该标志位置0,且判定为NS4168 */
104+
}
105+
106+
xl9555_in_->xl9555_cfg();
79107
}
80108

81109
void InitializeATK_ST7789_80_Display() {
@@ -186,16 +214,41 @@ class atk_dnesp32s3_box : public WifiBoard {
186214
atk_dnesp32s3_box() : boot_button_(BOOT_BUTTON_GPIO) {
187215
InitializeI2c();
188216
InitializeATK_ST7789_80_Display();
189-
xl9555_->SetOutputState(5, 1);
190-
xl9555_->SetOutputState(7, 1);
217+
xl9555_in_->SetOutputState(5, 1);
218+
xl9555_in_->SetOutputState(7, 1);
191219
InitializeButtons();
192220
InitializeIot();
193221
}
194222

195223
virtual AudioCodec* GetAudioCodec() override {
196-
static ATK_NoAudioCodecDuplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
197-
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
198-
return &audio_codec;
224+
/* 根据探测结果初始化编解码器 */
225+
if (es8311_detected_) {
226+
/* 使用ES8311 驱动 */
227+
static Es8311AudioCodec audio_codec(
228+
i2c_bus_,
229+
I2C_NUM_0,
230+
AUDIO_INPUT_SAMPLE_RATE,
231+
AUDIO_OUTPUT_SAMPLE_RATE,
232+
GPIO_NUM_NC,
233+
AUDIO_I2S_GPIO_BCLK,
234+
AUDIO_I2S_GPIO_WS,
235+
AUDIO_I2S_GPIO_DOUT,
236+
AUDIO_I2S_GPIO_DIN,
237+
GPIO_NUM_NC,
238+
AUDIO_CODEC_ES8311_ADDR,
239+
false);
240+
return &audio_codec;
241+
} else {
242+
static ATK_NoAudioCodecDuplex audio_codec(
243+
AUDIO_INPUT_SAMPLE_RATE,
244+
AUDIO_OUTPUT_SAMPLE_RATE,
245+
AUDIO_I2S_GPIO_BCLK,
246+
AUDIO_I2S_GPIO_WS,
247+
AUDIO_I2S_GPIO_DOUT,
248+
AUDIO_I2S_GPIO_DIN);
249+
return &audio_codec;
250+
}
251+
return NULL;
199252
}
200253

201254
virtual Display* GetDisplay() override {

main/boards/atk-dnesp32s3-box/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_21
1111
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_47
1212
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_14
13+
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
1314

1415
#define BUILTIN_LED_GPIO GPIO_NUM_4
1516
#define BOOT_BUTTON_GPIO GPIO_NUM_0

0 commit comments

Comments
 (0)