Skip to content

Commit 4ef6ef3

Browse files
authored
增加四博智联AI陪伴盒子 (#309)
* 添加四博智联AI陪伴盒子适配,典型pdm麦克风设备 * doit_s3_aibox LED切换到GPIO LED * doit_s3_aibox 添加说明文件 * doit_s3_aibox 音量最大值设置到100
1 parent f141a6b commit 4ef6ef3

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-0
lines changed

main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_1_54TFT_ML307)
134134
set(BOARD_TYPE "xingzhi-cube-1.54tft-ml307")
135135
elseif(CONFIG_BOARD_TYPE_SENSECAP_WATCHER)
136136
set(BOARD_TYPE "sensecap-watcher")
137+
elseif(CONFIG_BOARD_TYPE_DOIT_S3_AIBOX)
138+
set(BOARD_TYPE "doit-s3-aibox")
137139
elseif(CONFIG_BOARD_TYPE_ESP32_CGC)
138140
set(BOARD_TYPE "esp32-cgc")
139141
endif()

main/Kconfig.projbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ choice BOARD_TYPE
158158
bool "无名科技星智1.54(ML307)"
159159
config BOARD_TYPE_SENSECAP_WATCHER
160160
bool "SenseCAP Watcher"
161+
config BOARD_TYPE_DOIT_S3_AIBOX
162+
bool "四博智联AI陪伴盒子"
161163
endchoice
162164

163165
choice DISPLAY_OLED_TYPE
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# 四博智联AI陪伴盒子
2+
3+
# 特性
4+
* 使用PDM麦克风
5+
* 使用共阳极LED
6+
7+
## 按键配置
8+
* BUTTON3:短按-打断/唤醒
9+
* BUTTON1:音量+
10+
* BUTTON2:音量-
11+
12+
## 编译配置命令
13+
14+
**配置编译目标为 ESP32S3:**
15+
16+
```bash
17+
idf.py set-target esp32s3
18+
```
19+
20+
**打开 menuconfig:**
21+
22+
```bash
23+
idf.py menuconfig
24+
```
25+
26+
**选择板子:**
27+
28+
```
29+
Xiaozhi Assistant -> Board Type -> 四博智联AI陪伴盒子
30+
```
31+
32+
**修改 psram 配置:**
33+
34+
```
35+
Component config -> ESP PSRAM -> SPI RAM config -> Mode (QUAD/OCT) -> Octal Mode PSRAM
36+
```
37+
38+
**编译:**
39+
40+
```bash
41+
idf.py build
42+
```

main/boards/doit-s3-aibox/config.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef _BOARD_CONFIG_H_
2+
#define _BOARD_CONFIG_H_
3+
4+
#include <driver/gpio.h>
5+
6+
#define AUDIO_INPUT_SAMPLE_RATE 16000
7+
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
8+
9+
#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_41
10+
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_40
11+
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_42
12+
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_18
13+
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_17
14+
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_16
15+
16+
/*
17+
IO9: BUTTON2
18+
IO10: BUTTON3 引出:KEY3
19+
IO15: BUTTON1
20+
*/
21+
#define BUILTIN_LED_GPIO GPIO_NUM_45
22+
#define BOOT_BUTTON_GPIO GPIO_NUM_10
23+
#define TOUCH_BUTTON_GPIO GPIO_NUM_NC
24+
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_15
25+
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_9
26+
#define RESET_NVS_BUTTON_GPIO GPIO_NUM_10
27+
#define RESET_FACTORY_BUTTON_GPIO GPIO_NUM_NC
28+
29+
#endif // _BOARD_CONFIG_H_
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"target": "esp32s3",
3+
"builds": [
4+
{
5+
"name": "doit-s3-aibox",
6+
"sdkconfig_append": [
7+
]
8+
}
9+
]
10+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#include "wifi_board.h"
2+
#include "audio_codecs/no_audio_codec.h"
3+
#include "system_reset.h"
4+
#include "application.h"
5+
#include "button.h"
6+
#include "config.h"
7+
#include "iot/thing_manager.h"
8+
#include "led/gpio_led.h"
9+
#include <wifi_station.h>
10+
#include <esp_log.h>
11+
#include <driver/i2c_master.h>
12+
#include <driver/gpio.h>
13+
14+
#define TAG "DoitS3AiBox"
15+
16+
class DoitS3AiBox : public WifiBoard {
17+
private:
18+
Button boot_button_;
19+
Button touch_button_;
20+
Button volume_up_button_;
21+
Button volume_down_button_;
22+
uint8_t click_times;
23+
uint32_t check_time;
24+
25+
void InitializeButtons() {
26+
click_times = 0;
27+
check_time = 0;
28+
boot_button_.OnClick([this]() {
29+
if(click_times==0) {
30+
check_time = esp_timer_get_time()/1000;
31+
}
32+
if(esp_timer_get_time()/1000-check_time<1000) {
33+
click_times++;
34+
check_time = esp_timer_get_time()/1000;
35+
} else {
36+
click_times = 0;
37+
check_time = 0;
38+
}
39+
auto& app = Application::GetInstance();
40+
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
41+
ResetWifiConfiguration();
42+
}
43+
app.ToggleChatState();
44+
});
45+
boot_button_.OnDoubleClick([this]() {
46+
click_times++;
47+
ESP_LOGI(TAG, "DoubleClick times %d", click_times);
48+
if(click_times==3) {
49+
click_times = 0;
50+
ResetWifiConfiguration();
51+
}
52+
});
53+
54+
boot_button_.OnLongPress([this]() {
55+
if(click_times>=3) {
56+
ResetWifiConfiguration();
57+
} else {
58+
click_times = 0;
59+
check_time = 0;
60+
}
61+
});
62+
63+
touch_button_.OnPressDown([this]() {
64+
click_times = 0;
65+
Application::GetInstance().StartListening();
66+
});
67+
touch_button_.OnPressUp([this]() {
68+
click_times = 0;
69+
Application::GetInstance().StopListening();
70+
});
71+
72+
volume_up_button_.OnClick([this]() {
73+
click_times = 0;
74+
auto codec = GetAudioCodec();
75+
auto volume = codec->output_volume() + 10;
76+
if (volume > 100) {
77+
volume = 100;
78+
}
79+
codec->SetOutputVolume(volume);
80+
});
81+
82+
volume_up_button_.OnLongPress([this]() {
83+
click_times = 0;
84+
GetAudioCodec()->SetOutputVolume(100);
85+
});
86+
87+
volume_down_button_.OnClick([this]() {
88+
click_times = 0;
89+
auto codec = GetAudioCodec();
90+
auto volume = codec->output_volume() - 10;
91+
if (volume < 0) {
92+
volume = 0;
93+
}
94+
codec->SetOutputVolume(volume);
95+
});
96+
97+
volume_down_button_.OnLongPress([this]() {
98+
click_times = 0;
99+
GetAudioCodec()->SetOutputVolume(0);
100+
});
101+
}
102+
103+
// 物联网初始化,添加对 AI 可见设备
104+
void InitializeIot() {
105+
auto& thing_manager = iot::ThingManager::GetInstance();
106+
thing_manager.AddThing(iot::CreateThing("Speaker"));
107+
}
108+
109+
110+
void InitializeGpio(gpio_num_t gpio_num_) {
111+
gpio_config_t config = {
112+
.pin_bit_mask = (1ULL << gpio_num_),
113+
.mode = GPIO_MODE_OUTPUT,
114+
.pull_up_en = GPIO_PULLUP_ENABLE,
115+
.pull_down_en = GPIO_PULLDOWN_DISABLE,
116+
.intr_type = GPIO_INTR_DISABLE,
117+
};
118+
ESP_ERROR_CHECK(gpio_config(&config));
119+
gpio_set_level(gpio_num_, 1);
120+
}
121+
122+
public:
123+
DoitS3AiBox() :
124+
boot_button_(BOOT_BUTTON_GPIO),
125+
touch_button_(TOUCH_BUTTON_GPIO),
126+
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
127+
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO){
128+
// 上拉io48 置高电平
129+
InitializeGpio(GPIO_NUM_48);
130+
InitializeButtons();
131+
InitializeIot();
132+
}
133+
134+
virtual Led* GetLed() override {
135+
static GpioLed led(BUILTIN_LED_GPIO, 1);
136+
return &led;
137+
}
138+
139+
virtual AudioCodec* GetAudioCodec() override {
140+
static NoAudioCodecSimplexPdm audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
141+
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
142+
return &audio_codec;
143+
}
144+
};
145+
146+
DECLARE_BOARD(DoitS3AiBox);

0 commit comments

Comments
 (0)