阶段1: 将 dzbj 项目的 LVGL 8.3.11 LCD 显示集成到 AI小智 主项目, 开机显示 ScreenHome 界面,同时优化配网模式下的内存使用, 确保 WiFi+BLE+LVGL 三者共存运行。 ## 新增功能 ### dzbj 显示模块集成 - 新增 main/dzbj/ 目录,移植 LCD 驱动(ST77916 QSPI)、触摸驱动(CST816S)、 LVGL 初始化和 SquareLine Studio UI 界面 - I2C 总线共享:dzbj 触摸控制器复用主项目的 I2C_NUM_1 总线 - GPIO 冲突解决:LED(GPIO21)、Touch1(GPIO1)、Touch4(GPIO7) 改为 NC, 电池 ADC 从 GPIO6 改为 GPIO3 - 添加 LVGL、esp_lcd_st77916、esp_lcd_touch_cst816s 等组件依赖 - managed_components 纳入版本管理 ### 配网模式轻量化启动 - BoxAudioCodec: 新增 output_only 模式,仅创建 I2S TX 通道(省 ~13KB DMA) 跳过 ES7210 ADC 初始化(省 ~2-4KB) - AudioCodec: 新增 StartOutputOnly() 方法,仅启用扬声器输出 - Application: 配网模式跳过 Opus 编码器、输入重采样器、协议初始化、 天气位置检测等网络业务 - 板级构造函数: 配网模式跳过电池检测、IMU传感器、PowerSaveTimer ### WifiBoard 配网流程修复 - NeedsProvisioning() 静态方法: 读取 NVS force_ap 和 SSID 列表, 用于提前判断配网模式 - force_ap 竞态修复: 构造函数不再清零 force_ap,改在 StartNetwork() 清零, 确保 NeedsProvisioning() 能正确读到 force_ap=1 - Application 缓存 provisioning_mode_ 成员变量,避免重复读 NVS ### BLE 配网重启修复 - 配网成功后用 esp_timer 延迟重启替代 xTaskCreate, 避免内存紧张时任务创建失败导致设备不重启 - 注释掉 WiFi 连接成功后的 MAC 地址发送步骤 ### sdkconfig 内存优化 - BT_ALLOCATION_FROM_SPIRAM_FIRST=y (BLE 动态分配优先 PSRAM) - SPIRAM_MALLOC_RESERVE_INTERNAL=32768 - NVS_ALLOCATE_CACHE_IN_SPIRAM=y - WiFi 静态缓冲区数量优化 (RX=10, TX=8) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
#include "audio_codec.h"
|
|
#include "board.h"
|
|
#include "settings.h"
|
|
|
|
#include <esp_log.h>
|
|
#include <cstring>
|
|
#include <driver/i2s_common.h>
|
|
|
|
#define TAG "AudioCodec"
|
|
|
|
AudioCodec::AudioCodec() {
|
|
}
|
|
|
|
AudioCodec::~AudioCodec() {
|
|
}
|
|
|
|
void AudioCodec::OutputData(std::vector<int16_t>& data) {
|
|
Write(data.data(), data.size());
|
|
}
|
|
|
|
bool AudioCodec::InputData(std::vector<int16_t>& data) {
|
|
int samples = Read(data.data(), data.size());
|
|
if (samples > 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void AudioCodec::Start() {
|
|
Settings settings("audio", false);
|
|
output_volume_ = settings.GetInt("output_volume", output_volume_);
|
|
if (output_volume_ <= 0) {
|
|
ESP_LOGW(TAG, "Output volume value (%d) is too small, setting to default (10)", output_volume_);
|
|
output_volume_ = 10;
|
|
}
|
|
|
|
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
|
|
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
|
|
|
|
EnableInput(true);
|
|
EnableOutput(true);
|
|
ESP_LOGI(TAG, "Audio codec started");
|
|
}
|
|
|
|
void AudioCodec::StartOutputOnly() {
|
|
Settings settings("audio", false);
|
|
output_volume_ = settings.GetInt("output_volume", output_volume_);
|
|
if (output_volume_ <= 0) {
|
|
ESP_LOGW(TAG, "Output volume value (%d) is too small, setting to default (10)", output_volume_);
|
|
output_volume_ = 10;
|
|
}
|
|
|
|
// 仅启用 TX 通道(扬声器输出),跳过 RX 通道(麦克风输入)
|
|
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle_));
|
|
// 跳过: i2s_channel_enable(rx_handle_) — 配网模式不需要麦克风
|
|
// 跳过: EnableInput(true) — 不打开 ES7210 麦克风
|
|
EnableOutput(true);
|
|
ESP_LOGI(TAG, "Audio codec started (output only, provisioning mode)");
|
|
}
|
|
|
|
void AudioCodec::SetOutputVolume(int volume) {
|
|
output_volume_ = volume;
|
|
ESP_LOGI(TAG, "Set output volume to %d", output_volume_);
|
|
|
|
Settings settings("audio", true);
|
|
settings.SetInt("output_volume", output_volume_);
|
|
}
|
|
|
|
void AudioCodec::SetOutputVolumeRuntime(int volume) {
|
|
output_volume_ = volume;
|
|
ESP_LOGI(TAG, "将运行时输出音量设置为:%d", output_volume_);
|
|
}
|
|
|
|
void AudioCodec::EnableInput(bool enable) {
|
|
if (enable == input_enabled_) {
|
|
return;
|
|
}
|
|
input_enabled_ = enable;
|
|
ESP_LOGI(TAG, "Set input enable to %s", enable ? "true" : "false");
|
|
}
|
|
|
|
void AudioCodec::EnableOutput(bool enable) {
|
|
if (enable == output_enabled_) {
|
|
return;
|
|
}
|
|
output_enabled_ = enable;
|
|
ESP_LOGI(TAG, "Set output enable to %s", enable ? "true" : "false");
|
|
}
|