Skip to content

Commit 8a7e369

Browse files
committed
feat: update codec
1 parent 212d8bc commit 8a7e369

File tree

4 files changed

+150
-104
lines changed

4 files changed

+150
-104
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# BSP: ESP-SparkBot
22

3-
[![Component Registry](https://components.espressif.com/components/espressif/esp32_s3_eye/badge.svg)](https://components.espressif.com/components/espressif/esp32_s3_eye)
3+
[![Component Registry](https://components.espressif.com/components/espressif2022/esp_sparkbot/badge.svg)](https://components.espressif.com/components/espressif2022/esp_sparkbot)
44

5-
### Overview
5+
## **项目简介**
66

7-
The ESP32-S3-EYE board consists of two parts: the main board (ESP32-S3-EYE-MB) that integrates the ESP32-S3-WROOM-1 module, camera, uSD card slot, digital microphone, USB port, and function buttons; and the sub board (ESP32-S3-EYE-SUB) that contains an LCD display. The main board and sub board are connected through pin headers.
7+
ESP-SparkBot 是⼀款基于 **ESP32-S3**,集成语⾳交互、图像识别、遥控操作和多媒体功能于⼀体的智能设备。它不仅可以通过语⾳助⼿实现**⼤模型对话**、天⽓查询、⾳乐播放 等互动,还支持使⽤**⼩度⼿机 APP** 完成蓝牙配⽹、⾳⾊切换、⾳乐播放及其他智能服务。同时,ESP-SparkBot **内置加速度传感器**,⽀持摇⾊⼦和 2048 游戏等娱乐交互功能。硬件⽅⾯,其磁吸式设计⽀持模块扩展,可轻松转换为遥控⼩⻋,实现**摄像头实时传输****⼿机操控**。此外,设备⽀持本地 AI 处理,可以运⾏**⼈脸识别和动作检测**功能。还可以通过投屏模块实现⾼清视频播放和游戏运⾏,展⽰强⼤的性能和多功能性。
88

9-
* [Hardware Reference](https://www.espressif.com/en/products/devkits/esp-eye/overview.)
9+
## 硬件设计
1010

11-
![](https://raw.githubusercontent.com/espressif/esp-who/master/docs/_static/get-started/ESP32-S3-EYE_MB-annotated-photo.png)
11+
硬件已开源在**立创平台**[ESP-SparkBot](https://oshwhub.com/esp-college/esp-sparkbot)
1212

1313
**The development board has the following features:**
14-
* ESP32-S3 module with built-in 8 MB flash and 8 MB octal RAM
14+
* ESP32-S3 module with built-in 16 MB flash and 8 MB octal RAM
1515
* 1.3-inch 240x240 LCD color screen
16-
* Onboard uSD card slot
1716
* Digital microphone
1817
* Accelerometer
1918
* OV2640 camera
@@ -29,7 +28,6 @@ The ESP32-S3-EYE board consists of two parts: the main board (ESP32-S3-EYE-MB) t
2928
| AUDIO |:heavy_check_mark:|[espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev)| ^1,<1.2 |
3029
|AUDIO_SPEAKER| :x: | | |
3130
| AUDIO_MIC |:heavy_check_mark:| | |
32-
| SDCARD |:heavy_check_mark:| idf | >=4.4.5 |
33-
| IMU |:heavy_check_mark:| [qma6100p](https://components.espressif.com/components/qma6100p) | 1.* |
31+
| IMU |:heavy_check_mark:| [bmi270](https://components.espressif.com/components/espressif2022/bmi270) | 1.* |
3432
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.2 |
3533
<!-- Autogenerated end: Dependencies -->

esp_sparkbot_bsp.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,105 @@ void bsp_touch_button_create(touch_button_callback_t button_callback)
425425

426426
touch_element_start();
427427
ESP_LOGI(TAG, "Touch element library start");
428+
}
429+
430+
esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
431+
{
432+
const audio_codec_data_if_t *i2s_data_if = bsp_audio_get_codec_itf();
433+
if (i2s_data_if == NULL) {
434+
/* Initilize I2C */
435+
ESP_ERROR_CHECK(bsp_i2c_init());
436+
/* Configure I2S peripheral and Power Amplifier */
437+
ESP_ERROR_CHECK(bsp_audio_init(NULL));
438+
i2s_data_if = bsp_audio_get_codec_itf();
439+
}
440+
assert(i2s_data_if);
441+
442+
const audio_codec_gpio_if_t *gpio_if = audio_codec_new_gpio();
443+
444+
audio_codec_i2c_cfg_t i2c_cfg = {
445+
.port = BSP_I2C_NUM,
446+
.addr = ES8311_CODEC_DEFAULT_ADDR,
447+
};
448+
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
449+
assert(i2c_ctrl_if);
450+
451+
esp_codec_dev_hw_gain_t gain = {
452+
.pa_voltage = 5.0,
453+
.codec_dac_voltage = 3.3,
454+
};
455+
456+
es8311_codec_cfg_t es8311_cfg = {
457+
.ctrl_if = i2c_ctrl_if,
458+
.gpio_if = gpio_if,
459+
.codec_mode = ESP_CODEC_DEV_TYPE_OUT,
460+
.pa_pin = BSP_POWER_AMP_IO,
461+
.pa_reverted = false,
462+
.master_mode = false,
463+
.use_mclk = true,
464+
.digital_mic = false,
465+
.invert_mclk = false,
466+
.invert_sclk = false,
467+
.hw_gain = gain,
468+
};
469+
const audio_codec_if_t *es8311_dev = es8311_codec_new(&es8311_cfg);
470+
assert(es8311_dev);
471+
472+
esp_codec_dev_cfg_t codec_dev_cfg = {
473+
.dev_type = ESP_CODEC_DEV_TYPE_IN_OUT,
474+
.codec_if = es8311_dev,
475+
.data_if = i2s_data_if,
476+
};
477+
return esp_codec_dev_new(&codec_dev_cfg);
478+
}
479+
480+
esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
481+
{
482+
const audio_codec_data_if_t *i2s_data_if = bsp_audio_get_codec_itf();
483+
if (i2s_data_if == NULL) {
484+
/* Initilize I2C */
485+
ESP_ERROR_CHECK(bsp_i2c_init());
486+
/* Configure I2S peripheral and Power Amplifier */
487+
ESP_ERROR_CHECK(bsp_audio_init(NULL));
488+
i2s_data_if = bsp_audio_get_codec_itf();
489+
}
490+
assert(i2s_data_if);
491+
492+
const audio_codec_gpio_if_t *gpio_if = audio_codec_new_gpio();
493+
494+
audio_codec_i2c_cfg_t i2c_cfg = {
495+
.port = BSP_I2C_NUM,
496+
.addr = ES8311_CODEC_DEFAULT_ADDR,
497+
};
498+
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
499+
assert(i2c_ctrl_if);
500+
501+
esp_codec_dev_hw_gain_t gain = {
502+
.pa_voltage = 5.0,
503+
.codec_dac_voltage = 3.3,
504+
};
505+
506+
es8311_codec_cfg_t es8311_cfg = {
507+
.ctrl_if = i2c_ctrl_if,
508+
.gpio_if = gpio_if,
509+
.codec_mode = ESP_CODEC_DEV_WORK_MODE_BOTH,
510+
.pa_pin = BSP_POWER_AMP_IO,
511+
.pa_reverted = false,
512+
.master_mode = false,
513+
.use_mclk = true,
514+
.digital_mic = false,
515+
.invert_mclk = false,
516+
.invert_sclk = false,
517+
.hw_gain = gain,
518+
};
519+
520+
const audio_codec_if_t *es8311_dev = es8311_codec_new(&es8311_cfg);
521+
assert(es8311_dev);
522+
523+
esp_codec_dev_cfg_t codec_es8311_dev_cfg = {
524+
.dev_type = ESP_CODEC_DEV_TYPE_IN,
525+
.codec_if = es8311_dev,
526+
.data_if = i2s_data_if,
527+
};
528+
return esp_codec_dev_new(&codec_es8311_dev_cfg);
428529
}

esp_sparkbot_bsp_idf5.c

Lines changed: 26 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ static i2s_chan_handle_t i2s_tx_chan = NULL;
1515
static i2s_chan_handle_t i2s_rx_chan = NULL;
1616
static const audio_codec_data_if_t *i2s_data_if = NULL; /* Codec data interface */
1717

18+
/* Can be used for i2s_std_gpio_config_t and/or i2s_std_config_t initialization */
19+
#define BSP_I2S_GPIO_CFG \
20+
{ \
21+
.mclk = BSP_I2S_MCLK, \
22+
.bclk = BSP_I2S_SCLK, \
23+
.ws = BSP_I2S_LCLK, \
24+
.dout = BSP_I2S_DOUT, \
25+
.din = BSP_I2S_DSIN, \
26+
.invert_flags = { \
27+
.mclk_inv = false, \
28+
.bclk_inv = false, \
29+
.ws_inv = false, \
30+
}, \
31+
}
32+
33+
/* This configuration is used by default in bsp_audio_init() */
34+
#define BSP_I2S_DUPLEX_MONO_CFG(_sample_rate) \
35+
{ \
36+
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(_sample_rate), \
37+
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO), \
38+
.gpio_cfg = BSP_I2S_GPIO_CFG, \
39+
}
40+
1841
esp_err_t bsp_adc_initialize(void)
1942
{
2043
/* ADC was initialized before */
@@ -50,7 +73,7 @@ esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config)
5073
ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &i2s_tx_chan, &i2s_rx_chan));
5174

5275
/* Setup I2S channels */
53-
const i2s_std_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG(22050);
76+
const i2s_std_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG(16000);
5477
const i2s_std_config_t *p_i2s_cfg = &std_cfg_default;
5578
if (i2s_config != NULL) {
5679
p_i2s_cfg = i2s_config;
@@ -75,99 +98,7 @@ esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config)
7598
return ESP_OK;
7699
}
77100

78-
esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
79-
{
80-
if (i2s_data_if == NULL) {
81-
/* Initilize I2C */
82-
ESP_ERROR_CHECK(bsp_i2c_init());
83-
/* Configure I2S peripheral and Power Amplifier */
84-
ESP_ERROR_CHECK(bsp_extra_audio_init(NULL));
85-
}
86-
assert(i2s_data_if);
87-
88-
const audio_codec_gpio_if_t *gpio_if = audio_codec_new_gpio();
89-
90-
audio_codec_i2c_cfg_t i2c_cfg = {
91-
.port = BSP_I2C_NUM,
92-
.addr = ES8311_CODEC_DEFAULT_ADDR,
93-
};
94-
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
95-
assert(i2c_ctrl_if);
96-
97-
esp_codec_dev_hw_gain_t gain = {
98-
.pa_voltage = 5.0,
99-
.codec_dac_voltage = 3.3,
100-
};
101-
102-
es8311_codec_cfg_t es8311_cfg = {
103-
.ctrl_if = i2c_ctrl_if,
104-
.gpio_if = gpio_if,
105-
.codec_mode = ESP_CODEC_DEV_TYPE_OUT,
106-
.pa_pin = BSP_POWER_AMP_IO,
107-
.pa_reverted = false,
108-
.master_mode = false,
109-
.use_mclk = true,
110-
.digital_mic = false,
111-
.invert_mclk = false,
112-
.invert_sclk = false,
113-
.hw_gain = gain,
114-
};
115-
const audio_codec_if_t *es8311_dev = es8311_codec_new(&es8311_cfg);
116-
assert(es8311_dev);
117-
118-
esp_codec_dev_cfg_t codec_dev_cfg = {
119-
.dev_type = ESP_CODEC_DEV_TYPE_IN_OUT,
120-
.codec_if = es8311_dev,
121-
.data_if = i2s_data_if,
122-
};
123-
return esp_codec_dev_new(&codec_dev_cfg);
124-
}
125-
126-
esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
101+
const audio_codec_data_if_t *bsp_audio_get_codec_itf(void)
127102
{
128-
if (i2s_data_if == NULL) {
129-
/* Initilize I2C */
130-
ESP_ERROR_CHECK(bsp_i2c_init());
131-
/* Configure I2S peripheral and Power Amplifier */
132-
ESP_ERROR_CHECK(bsp_extra_audio_init(NULL));
133-
}
134-
assert(i2s_data_if);
135-
136-
const audio_codec_gpio_if_t *gpio_if = audio_codec_new_gpio();
137-
138-
audio_codec_i2c_cfg_t i2c_cfg = {
139-
.port = BSP_I2C_NUM,
140-
.addr = ES8311_CODEC_DEFAULT_ADDR,
141-
};
142-
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
143-
assert(i2c_ctrl_if);
144-
145-
esp_codec_dev_hw_gain_t gain = {
146-
.pa_voltage = 5.0,
147-
.codec_dac_voltage = 3.3,
148-
};
149-
150-
es8311_codec_cfg_t es8311_cfg = {
151-
.ctrl_if = i2c_ctrl_if,
152-
.gpio_if = gpio_if,
153-
.codec_mode = ESP_CODEC_DEV_WORK_MODE_BOTH,
154-
.pa_pin = BSP_POWER_AMP_IO,
155-
.pa_reverted = false,
156-
.master_mode = false,
157-
.use_mclk = true,
158-
.digital_mic = false,
159-
.invert_mclk = false,
160-
.invert_sclk = false,
161-
.hw_gain = gain,
162-
};
163-
164-
const audio_codec_if_t *es8311_dev = es8311_codec_new(&es8311_cfg);
165-
assert(es8311_dev);
166-
167-
esp_codec_dev_cfg_t codec_es8311_dev_cfg = {
168-
.dev_type = ESP_CODEC_DEV_TYPE_IN,
169-
.codec_if = es8311_dev,
170-
.data_if = i2s_data_if,
171-
};
172-
return esp_codec_dev_new(&codec_es8311_dev_cfg);
103+
return i2s_data_if;
173104
}

include/bsp/esp_sparkbot_bsp.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
#define BSP_I2C_SCL (GPIO_NUM_5)
5555
#define BSP_I2C_SDA (GPIO_NUM_4)
5656

57+
/* Audio */
58+
#define BSP_I2S_SCLK (GPIO_NUM_39)
59+
#define BSP_I2S_MCLK (GPIO_NUM_45)
60+
#define BSP_I2S_LCLK (GPIO_NUM_41)
61+
#define BSP_I2S_DOUT (GPIO_NUM_42) // To Codec ES8311
62+
#define BSP_I2S_DSIN (GPIO_NUM_40) // From Codec ES8311
63+
#define BSP_POWER_AMP_IO (GPIO_NUM_NC)
64+
5765
/* Display */
5866
#define BSP_LCD_SPI_MOSI (GPIO_NUM_47)
5967
#define BSP_LCD_SPI_CLK (GPIO_NUM_21)
@@ -196,6 +204,14 @@ i2c_bus_handle_t bsp_i2c_get_handle(void);
196204
*/
197205
esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config);
198206

207+
/**
208+
* @brief Get codec I2S interface (initialized in bsp_audio_init)
209+
*
210+
* @return
211+
* - Pointer to codec I2S interface handle or NULL when error occurred
212+
*/
213+
const audio_codec_data_if_t *bsp_audio_get_codec_itf(void);
214+
199215
/**
200216
* @brief Initialize speaker codec device
201217
*

0 commit comments

Comments
 (0)