forked from xiaozhi/xiaozhi-esp32
* 1. 支持 ESP32系列开发板: DevKitC / NodeMcu-32S / GoouuuESP32 / ESP32 DoIt / ESP-32S 2. 注意:非ESP32-C3 / 非ESP32-S3 * 补图片: M5Stack Atom Matrix + ES8311 + NS4150B * 修订 ESP32 系列开发板 面包板 成品图 * 修订: ESP32系列开发板 README.md * 修订: 移除对首页修改的这部分内容,跳转链接添加至《百科全书》的目录里。
81 lines
2.6 KiB
C++
81 lines
2.6 KiB
C++
#include "wifi_board.h"
|
|
#include "audio_codecs/no_audio_codec.h"
|
|
#include "system_reset.h"
|
|
#include "application.h"
|
|
#include "button.h"
|
|
#include "config.h"
|
|
#include "iot/thing_manager.h"
|
|
#include "led/single_led.h"
|
|
|
|
#include <wifi_station.h>
|
|
#include <esp_log.h>
|
|
#include <driver/i2c_master.h>
|
|
|
|
#define TAG "ESP32-MarsbearSupport"
|
|
|
|
|
|
class CompactWifiBoard : public WifiBoard {
|
|
private:
|
|
Button boot_button_;
|
|
Button touch_button_;
|
|
|
|
void InitializeButtons() {
|
|
|
|
// 配置 GPIO
|
|
gpio_config_t io_conf = {
|
|
.pin_bit_mask = 1ULL << BUILTIN_LED_GPIO, // 设置需要配置的 GPIO 引脚
|
|
.mode = GPIO_MODE_OUTPUT, // 设置为输出模式
|
|
.pull_up_en = GPIO_PULLUP_DISABLE, // 禁用上拉
|
|
.pull_down_en = GPIO_PULLDOWN_DISABLE, // 禁用下拉
|
|
.intr_type = GPIO_INTR_DISABLE // 禁用中断
|
|
};
|
|
gpio_config(&io_conf); // 应用配置
|
|
|
|
boot_button_.OnClick([this]() {
|
|
auto& app = Application::GetInstance();
|
|
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
|
ResetWifiConfiguration();
|
|
}
|
|
gpio_set_level(BUILTIN_LED_GPIO, 1);
|
|
app.ToggleChatState();
|
|
});
|
|
touch_button_.OnPressDown([this]() {
|
|
gpio_set_level(BUILTIN_LED_GPIO, 1);
|
|
Application::GetInstance().StartListening();
|
|
});
|
|
touch_button_.OnPressUp([this]() {
|
|
gpio_set_level(BUILTIN_LED_GPIO, 0);
|
|
Application::GetInstance().StopListening();
|
|
});
|
|
}
|
|
|
|
// 物联网初始化,添加对 AI 可见设备
|
|
void InitializeIot() {
|
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
|
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
|
}
|
|
|
|
public:
|
|
CompactWifiBoard() : boot_button_(BOOT_BUTTON_GPIO), touch_button_(TOUCH_BUTTON_GPIO)
|
|
{
|
|
InitializeButtons();
|
|
InitializeIot();
|
|
}
|
|
|
|
virtual AudioCodec* GetAudioCodec() override
|
|
{
|
|
#ifdef AUDIO_I2S_METHOD_SIMPLEX
|
|
static NoAudioCodecSimplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
|
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
|
|
#else
|
|
static NoAudioCodecDuplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
|
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
|
|
#endif
|
|
return &audio_codec;
|
|
}
|
|
|
|
};
|
|
|
|
DECLARE_BOARD(CompactWifiBoard);
|