Skip to content

Commit e1ef0a2

Browse files
committed
Merge branch 'main' into remote_ctrl
2 parents ae05029 + 99efb8d commit e1ef0a2

File tree

6 files changed

+222
-3
lines changed

6 files changed

+222
-3
lines changed

main/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ elseif(CONFIG_BOARD_TYPE_DOIT_AI_01_KIT)
159159
set(BOARD_TYPE "doit-ai-01-kit")
160160
elseif(CONFIG_BOARD_TYPE_DOIT_AI_01_KIT_LCD)
161161
set(BOARD_TYPE "doit-ai-01-kit-lcd")
162+
elseif(CONFIG_BOARD_TYPE_DOIT_AI_02_KIT_LCD)
163+
set(BOARD_TYPE "doit-ai-02-kit-lcd")
162164
elseif(CONFIG_BOARD_TYPE_DOIT_AI_SPEAKER)
163165
set(BOARD_TYPE "doit-ai-speaker")
164166
endif()
@@ -202,7 +204,7 @@ if(CONFIG_IDF_TARGET_ESP32)
202204
)
203205
endif()
204206

205-
if(CONFIG_USE_AUDIO_CODEC_ENCODE_OPUS OR CONFIG_USE_AUDIO_CODEC_DECODE_OPUS)
207+
if(CONFIG_USE_AUDIO_CODEC_ENCODE_OPUS OR CONFIG_USE_AUDIO_CODEC_DECODE_OPUS OR CONFIG_BOARD_TYPE_DOIT_AI_02_KIT_LCD)
206208
list(APPEND SOURCES "audio_codecs/vb6824_audio_codec.cc")
207209
list(REMOVE_ITEM SOURCES "audio_codecs/box_audio_codec.cc"
208210
"audio_codecs/no_audio_codec.cc"

main/Kconfig.projbuild

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ choice BOARD_TYPE
152152
bool "Doit-AI-01-Kit"
153153
config BOARD_TYPE_DOIT_AI_01_KIT_LCD
154154
bool "Doit-AI-01-Kit-lcd"
155+
config BOARD_TYPE_DOIT_AI_02_KIT_LCD
156+
bool "Doit-AI-02-Kit-lcd"
155157
config BOARD_TYPE_DOIT_AI_SPEAKER
156158
bool "Doit-AI-SPEAKER"
157159
endchoice
@@ -276,12 +278,12 @@ config USE_EMOTION_REMOTE
276278
可用于控制 doit_ai_two_eye 做出对应的表情
277279

278280
config USE_AUDIO_CODEC_ENCODE_OPUS
279-
depends on BOARD_TYPE_DOIT_AI_01_KIT || BOARD_TYPE_DOIT_AI_01_KIT_LCD
281+
depends on BOARD_TYPE_DOIT_AI_01_KIT || BOARD_TYPE_DOIT_AI_01_KIT_LCD || BOARD_TYPE_DOIT_AI_02_KIT_LCD
280282
bool "use audio codec encode opus"
281283
default y
282284

283285
config USE_AUDIO_CODEC_DECODE_OPUS
284-
depends on BOARD_TYPE_DOIT_AI_01_KIT || BOARD_TYPE_DOIT_AI_01_KIT_LCD
286+
depends on BOARD_TYPE_DOIT_AI_01_KIT || BOARD_TYPE_DOIT_AI_01_KIT_LCD || BOARD_TYPE_DOIT_AI_02_KIT_LCD
285287
bool "use audio codec decode opus"
286288
default n
287289

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3;sdkconfig.defaults;main/boards/doit-ai-02-kit-lcd/boards.defaults" -DIDF_TARGET=esp32c3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_BOARD_TYPE_DOIT_AI_02_KIT_LCD=y
2+
3+
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
4+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_8M.csv"
5+
CONFIG_PARTITION_TABLE_FILENAME="partitions_8M.csv"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef _BOARD_CONFIG_H_
2+
#define _BOARD_CONFIG_H_
3+
4+
#include <driver/gpio.h>
5+
6+
#define BOOT_BUTTON_GPIO GPIO_NUM_9
7+
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_8
8+
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_7
9+
10+
#define CODEC_TX_GPIO GPIO_NUM_20
11+
#define CODEC_RX_GPIO GPIO_NUM_10
12+
13+
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_5
14+
#define DISPLAY_MOSI_PIN GPIO_NUM_1
15+
#define DISPLAY_CLK_PIN GPIO_NUM_3
16+
#define DISPLAY_DC_PIN GPIO_NUM_0
17+
#define DISPLAY_RST_PIN GPIO_NUM_2
18+
#define DISPLAY_CS_PIN GPIO_NUM_12
19+
20+
#define DISPLAY_WIDTH 240
21+
#define DISPLAY_HEIGHT 240
22+
#define DISPLAY_MIRROR_X false
23+
#define DISPLAY_MIRROR_Y false
24+
#define DISPLAY_SWAP_XY false
25+
#define DISPLAY_INVERT_COLOR true
26+
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
27+
#define DISPLAY_OFFSET_X 0
28+
#define DISPLAY_OFFSET_Y 0
29+
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
30+
31+
#endif // _BOARD_CONFIG_H_
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
2+
#include "wifi_board.h"
3+
#include "audio_codecs/vb6824_audio_codec.h"
4+
#include "display/lcd_display.h"
5+
#include "application.h"
6+
#include "button.h"
7+
#include "config.h"
8+
#include "iot/thing_manager.h"
9+
10+
#include <wifi_station.h>
11+
#include <esp_log.h>
12+
#include <esp_lcd_panel_vendor.h>
13+
#include <driver/spi_common.h>
14+
15+
#include <wifi_station.h>
16+
#include <wifi_configuration_ap.h>
17+
#include <ssid_manager.h>
18+
19+
#include "font_awesome_symbols.h"
20+
#include "settings.h"
21+
#include "assets/lang_config.h"
22+
23+
#include "power_save_timer.h"
24+
25+
#include "esp_timer.h"
26+
27+
#define TAG "CustomBoard"
28+
29+
LV_FONT_DECLARE(font_puhui_16_4);
30+
LV_FONT_DECLARE(font_awesome_16_4);
31+
32+
class CustomBoard : public WifiBoard {
33+
private:
34+
Button boot_button_;
35+
Button volume_up_button_;
36+
Button volume_down_button_;
37+
VbAduioCodec audio_codec;
38+
LcdDisplay* display;
39+
40+
void InitializeButtons() {
41+
boot_button_.OnClick([this]() {
42+
auto &app = Application::GetInstance();
43+
app.ToggleChatState();
44+
});
45+
boot_button_.OnPressRepeaDone([this](uint16_t count) {
46+
if(count >= 3){
47+
ResetWifiConfiguration();
48+
}
49+
});
50+
51+
volume_up_button_.OnClick([this]() {
52+
auto codec = GetAudioCodec();
53+
auto volume = codec->output_volume() + 10;
54+
if (volume > 100) {
55+
volume = 100;
56+
}
57+
codec->SetOutputVolume(volume);
58+
GetDisplay()->ShowNotification(Lang::Strings::VOLUME + std::to_string(volume));
59+
});
60+
61+
volume_up_button_.OnLongPress([this]() {
62+
GetAudioCodec()->SetOutputVolume(100);
63+
GetDisplay()->ShowNotification(Lang::Strings::MAX_VOLUME);
64+
});
65+
66+
volume_down_button_.OnClick([this]() {
67+
auto codec = GetAudioCodec();
68+
auto volume = codec->output_volume() - 10;
69+
if (volume < 0) {
70+
volume = 0;
71+
}
72+
codec->SetOutputVolume(volume);
73+
GetDisplay()->ShowNotification(Lang::Strings::VOLUME + std::to_string(volume));
74+
});
75+
76+
volume_down_button_.OnLongPress([this]() {
77+
GetAudioCodec()->SetOutputVolume(0);
78+
GetDisplay()->ShowNotification(Lang::Strings::MUTED);
79+
});
80+
81+
}
82+
83+
// 物联网初始化,添加对 AI 可见设备
84+
void InitializeIot() {
85+
auto& thing_manager = iot::ThingManager::GetInstance();
86+
thing_manager.AddThing(iot::CreateThing("Speaker"));
87+
thing_manager.AddThing(iot::CreateThing("Screen"));
88+
}
89+
90+
void InitializeSpi() {
91+
spi_bus_config_t buscfg = {};
92+
buscfg.mosi_io_num = DISPLAY_MOSI_PIN;
93+
buscfg.miso_io_num = GPIO_NUM_NC;
94+
buscfg.sclk_io_num = DISPLAY_CLK_PIN;
95+
buscfg.quadwp_io_num = GPIO_NUM_NC;
96+
buscfg.quadhd_io_num = GPIO_NUM_NC;
97+
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
98+
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
99+
}
100+
101+
void InitializeLcdDisplay() {
102+
esp_lcd_panel_io_handle_t panel_io = nullptr;
103+
esp_lcd_panel_handle_t panel = nullptr;
104+
esp_lcd_panel_io_spi_config_t io_config = {};
105+
106+
io_config.cs_gpio_num = DISPLAY_CS_PIN;
107+
io_config.dc_gpio_num = DISPLAY_DC_PIN;
108+
io_config.spi_mode = 3;
109+
io_config.pclk_hz = 80 * 1000 * 1000;
110+
io_config.trans_queue_depth = 10;
111+
io_config.lcd_cmd_bits = 8;
112+
io_config.lcd_param_bits = 8;
113+
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &panel_io));
114+
115+
esp_lcd_panel_dev_config_t panel_config = {};
116+
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
117+
panel_config.rgb_ele_order = DISPLAY_RGB_ORDER;
118+
panel_config.bits_per_pixel = 16;
119+
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
120+
121+
esp_lcd_panel_reset(panel);
122+
vTaskDelay(100 / portTICK_PERIOD_MS);
123+
esp_lcd_panel_reset(panel);
124+
125+
esp_lcd_panel_init(panel);
126+
esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR);
127+
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
128+
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
129+
display = new SpiLcdDisplay(panel_io, panel,
130+
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
131+
{
132+
.text_font = &font_puhui_16_4,
133+
.icon_font = &font_awesome_16_4,
134+
.emoji_font = font_emoji_64_init(),
135+
});
136+
}
137+
138+
public:
139+
CustomBoard() :
140+
boot_button_(BOOT_BUTTON_GPIO, false),
141+
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
142+
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO),
143+
audio_codec(CODEC_TX_GPIO, CODEC_RX_GPIO){
144+
145+
InitializeButtons();
146+
InitializeSpi();
147+
InitializeLcdDisplay();
148+
GetBacklight()->RestoreBrightness();
149+
InitializeIot();
150+
audio_codec.OnWakeUp([this](const std::string& command) {
151+
if (command == std::string(vb6824_get_wakeup_word())){
152+
if(Application::GetInstance().GetDeviceState() != kDeviceStateListening){
153+
Application::GetInstance().WakeWordInvoke("你好小智");
154+
}
155+
}else if (command == "开始配网"){
156+
ResetWifiConfiguration();
157+
}
158+
});
159+
}
160+
161+
virtual AudioCodec* GetAudioCodec() override {
162+
return &audio_codec;
163+
}
164+
165+
virtual Display* GetDisplay() override {
166+
return display;
167+
}
168+
169+
virtual Backlight* GetBacklight() override {
170+
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
171+
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
172+
return &backlight;
173+
}
174+
return nullptr;
175+
}
176+
};
177+
178+
DECLARE_BOARD(CustomBoard);

0 commit comments

Comments
 (0)