From 78d7b40914499489e81766c20c877cc47c74d36e Mon Sep 17 00:00:00 2001 From: Terrence Date: Sun, 13 Apr 2025 11:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=A1=B9=E7=9B=AE=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=B31.5.9=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=86=85=E5=AD=98=E4=BD=BF=E7=94=A8=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=BB=E4=BB=BB=E5=8A=A1=E6=A0=88=E5=A4=A7=E5=B0=8F=E8=87=B3?= =?UTF-8?q?8192=EF=BC=8C=E4=BC=98=E5=8C=96=E5=9B=BA=E4=BB=B6=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E6=B5=81=E7=A8=8B=EF=BC=8C=E9=87=8D=E6=9E=84=E4=B8=BB?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E4=B8=BAMainEventLoop=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B0=E7=89=88=E6=9C=AC=E6=A3=80=E6=9F=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=9B=B4=E6=96=B0=E9=9F=B3=E9=A2=91=E7=BC=96?= =?UTF-8?q?=E8=A7=A3=E7=A0=81=E5=99=A8=E7=9A=84DMA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- main/application.cc | 149 +++++++++--------- main/application.h | 7 +- main/assets/en-US/language.json | 3 +- main/assets/ja-JP/language.json | 3 +- main/assets/zh-CN/language.json | 3 +- main/assets/zh-TW/language.json | 3 +- main/audio_codecs/audio_codec.h | 3 + main/audio_codecs/box_audio_codec.cc | 4 +- main/audio_codecs/es8311_audio_codec.cc | 4 +- main/audio_codecs/es8388_audio_codec.cc | 4 +- main/audio_codecs/no_audio_codec.cc | 20 +-- main/boards/df-k10/k10_audio_codec.cc | 4 +- .../esp-box-lite/box_audio_codec_lite.cc | 4 +- .../m5stack-core-s3/cores3_audio_codec.cc | 4 +- .../sensecap-watcher/sensecap_audio_codec.cc | 4 +- main/idf_component.yml | 4 +- main/main.cc | 1 - main/ota.cc | 10 +- sdkconfig.defaults | 2 +- 20 files changed, 125 insertions(+), 113 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b93da0..a64d4e8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) -set(PROJECT_VER "1.5.8") +set(PROJECT_VER "1.5.9") # Add this line to disable the specific warning add_compile_options(-Wno-missing-field-initializers) diff --git a/main/application.cc b/main/application.cc index dda50fb..af3f9d9 100644 --- a/main/application.cc +++ b/main/application.cc @@ -48,6 +48,7 @@ Application::Application() { .skip_unhandled_events = true }; esp_timer_create(&clock_timer_args, &clock_timer_handle_); + esp_timer_start_periodic(clock_timer_handle_, 1000000); } Application::~Application() { @@ -81,58 +82,49 @@ void Application::CheckNewVersion() { if (ota_.HasNewVersion()) { Alert(Lang::Strings::OTA_UPGRADE, Lang::Strings::UPGRADING, "happy", Lang::Sounds::P3_UPGRADE); - // Wait for the chat state to be idle - do { - vTaskDelay(pdMS_TO_TICKS(3000)); - } while (GetDeviceState() != kDeviceStateIdle); - // Use main task to do the upgrade, not cancelable - Schedule([this, display]() { - SetDeviceState(kDeviceStateUpgrading); - - display->SetIcon(FONT_AWESOME_DOWNLOAD); - std::string message = std::string(Lang::Strings::NEW_VERSION) + ota_.GetFirmwareVersion(); - display->SetChatMessage("system", message.c_str()); + vTaskDelay(pdMS_TO_TICKS(3000)); - auto& board = Board::GetInstance(); - board.SetPowerSaveMode(false); + SetDeviceState(kDeviceStateUpgrading); + + display->SetIcon(FONT_AWESOME_DOWNLOAD); + std::string message = std::string(Lang::Strings::NEW_VERSION) + ota_.GetFirmwareVersion(); + display->SetChatMessage("system", message.c_str()); + + auto& board = Board::GetInstance(); + board.SetPowerSaveMode(false); #if CONFIG_USE_WAKE_WORD_DETECT - wake_word_detect_.StopDetection(); + wake_word_detect_.StopDetection(); #endif - // 预先关闭音频输出,避免升级过程有音频操作 - auto codec = board.GetAudioCodec(); - codec->EnableInput(false); - codec->EnableOutput(false); - { - std::lock_guard lock(mutex_); - audio_decode_queue_.clear(); - } - background_task_->WaitForCompletion(); - delete background_task_; - background_task_ = nullptr; - vTaskDelay(pdMS_TO_TICKS(1000)); + // 预先关闭音频输出,避免升级过程有音频操作 + auto codec = board.GetAudioCodec(); + codec->EnableInput(false); + codec->EnableOutput(false); + { + std::lock_guard lock(mutex_); + audio_decode_queue_.clear(); + } + background_task_->WaitForCompletion(); + delete background_task_; + background_task_ = nullptr; + vTaskDelay(pdMS_TO_TICKS(1000)); - ota_.StartUpgrade([display](int progress, size_t speed) { - char buffer[64]; - snprintf(buffer, sizeof(buffer), "%d%% %zuKB/s", progress, speed / 1024); - display->SetChatMessage("system", buffer); - }); - - // If upgrade success, the device will reboot and never reach here - display->SetStatus(Lang::Strings::UPGRADE_FAILED); - ESP_LOGI(TAG, "Firmware upgrade failed..."); - vTaskDelay(pdMS_TO_TICKS(3000)); - Reboot(); + ota_.StartUpgrade([display](int progress, size_t speed) { + char buffer[64]; + snprintf(buffer, sizeof(buffer), "%d%% %zuKB/s", progress, speed / 1024); + display->SetChatMessage("system", buffer); }); + // If upgrade success, the device will reboot and never reach here + display->SetStatus(Lang::Strings::UPGRADE_FAILED); + ESP_LOGI(TAG, "Firmware upgrade failed..."); + vTaskDelay(pdMS_TO_TICKS(3000)); + Reboot(); return; } // No new version, mark the current version as valid ota_.MarkCurrentVersionValid(); - std::string message = std::string(Lang::Strings::VERSION) + ota_.GetCurrentVersion(); - display->ShowNotification(message.c_str()); - if (ota_.HasActivationCode()) { // Activation code is valid SetDeviceState(kDeviceStateActivating); @@ -148,11 +140,8 @@ void Application::CheckNewVersion() { continue; } - SetDeviceState(kDeviceStateIdle); - display->SetChatMessage("system", ""); - ResetDecoder(); - PlaySound(Lang::Sounds::P3_SUCCESS); - // Exit the loop if upgrade or idle + xEventGroupSetBits(event_group_, CHECK_NEW_VERSION_DONE_EVENT); + // Exit the loop if done checking new version break; } } @@ -180,8 +169,6 @@ void Application::ShowActivationCode() { // This sentence uses 9KB of SRAM, so we need to wait for it to finish Alert(Lang::Strings::ACTIVATION, message.c_str(), "happy", Lang::Sounds::P3_ACTIVATION); - vTaskDelay(pdMS_TO_TICKS(1000)); - background_task_->WaitForCompletion(); for (const auto& digit : code) { auto it = std::find_if(digit_sounds.begin(), digit_sounds.end(), @@ -214,6 +201,15 @@ void Application::DismissAlert() { } void Application::PlaySound(const std::string_view& sound) { + // Wait for the previous sound to finish + { + std::unique_lock lock(mutex_); + audio_decode_cv_.wait(lock, [this]() { + return audio_decode_queue_.empty(); + }); + } + background_task_->WaitForCompletion(); + // The assets are encoded at 16000Hz, 60ms frame duration SetDecodeSampleRate(16000, 60); const char* data = sound.data(); @@ -295,6 +291,16 @@ void Application::StartListening() { } void Application::StopListening() { + const std::array valid_states = { + kDeviceStateListening, + kDeviceStateSpeaking, + kDeviceStateIdle, + }; + // If not valid, do nothing + if (std::find(valid_states.begin(), valid_states.end(), device_state_) == valid_states.end()) { + return; + } + Schedule([this]() { if (device_state_ == kDeviceStateListening) { protocol_->SendStopListening(); @@ -337,16 +343,13 @@ void Application::Start() { vTaskDelete(NULL); }, "audio_loop", 4096 * 2, this, 8, &audio_loop_task_handle_, realtime_chat_enabled_ ? 1 : 0); - /* Start the main loop */ - xTaskCreatePinnedToCore([](void* arg) { - Application* app = (Application*)arg; - app->MainLoop(); - vTaskDelete(NULL); - }, "main_loop", 4096 * 2, this, 4, &main_loop_task_handle_, 0); - /* Wait for the network to be ready */ board.StartNetwork(); + // Check for new firmware version or get the MQTT broker address + display->SetStatus(Lang::Strings::CHECKING_NEW_VERSION); + CheckNewVersion(); + // Initialize the protocol display->SetStatus(Lang::Strings::LOADING_PROTOCOL); #ifdef CONFIG_CONNECTION_TYPE_WEBSOCKET @@ -444,13 +447,6 @@ void Application::Start() { }); protocol_->Start(); - // Check for new firmware version or get the MQTT broker address - xTaskCreate([](void* arg) { - Application* app = (Application*)arg; - app->CheckNewVersion(); - vTaskDelete(NULL); - }, "check_new_version", 4096 * 2, this, 2, nullptr); - #if CONFIG_USE_AUDIO_PROCESSOR audio_processor_.Initialize(codec, realtime_chat_enabled_); audio_processor_.OnOutput([this](std::vector&& data) { @@ -509,15 +505,18 @@ void Application::Start() { wake_word_detect_.StartDetection(); #endif + // Wait for the new version check to finish + xEventGroupWaitBits(event_group_, CHECK_NEW_VERSION_DONE_EVENT, pdTRUE, pdFALSE, portMAX_DELAY); SetDeviceState(kDeviceStateIdle); - esp_timer_start_periodic(clock_timer_handle_, 1000000); - -#if 0 - while (true) { - SystemInfo::PrintRealTimeStats(pdMS_TO_TICKS(1000)); - vTaskDelay(pdMS_TO_TICKS(10000)); - } -#endif + std::string message = std::string(Lang::Strings::VERSION) + ota_.GetCurrentVersion(); + display->ShowNotification(message.c_str()); + display->SetChatMessage("system", ""); + // Play the success sound to indicate the device is ready + ResetDecoder(); + PlaySound(Lang::Sounds::P3_SUCCESS); + + // Enter the main event loop + MainEventLoop(); } void Application::OnClockTimer() { @@ -553,10 +552,10 @@ void Application::Schedule(std::function callback) { xEventGroupSetBits(event_group_, SCHEDULE_EVENT); } -// The Main Loop controls the chat state and websocket connection +// The Main Event Loop controls the chat state and websocket connection // If other tasks need to access the websocket or chat state, // they should use Schedule to call this function -void Application::MainLoop() { +void Application::MainEventLoop() { while (true) { auto bits = xEventGroupWaitBits(event_group_, SCHEDULE_EVENT, pdTRUE, pdFALSE, portMAX_DELAY); @@ -601,12 +600,14 @@ void Application::OnAudioOutput() { if (device_state_ == kDeviceStateListening) { audio_decode_queue_.clear(); + audio_decode_cv_.notify_all(); return; } auto opus = std::move(audio_decode_queue_.front()); audio_decode_queue_.pop_front(); lock.unlock(); + audio_decode_cv_.notify_all(); background_task_->Schedule([this, codec, opus = std::move(opus)]() mutable { if (aborted_) { @@ -630,10 +631,9 @@ void Application::OnAudioOutput() { } void Application::OnAudioInput() { - std::vector data; - #if CONFIG_USE_WAKE_WORD_DETECT if (wake_word_detect_.IsDetectionRunning()) { + std::vector data; ReadAudio(data, 16000, wake_word_detect_.GetFeedSize()); wake_word_detect_.Feed(data); return; @@ -641,12 +641,14 @@ void Application::OnAudioInput() { #endif #if CONFIG_USE_AUDIO_PROCESSOR if (audio_processor_.IsRunning()) { + std::vector data; ReadAudio(data, 16000, audio_processor_.GetFeedSize()); audio_processor_.Feed(data); return; } #else if (device_state_ == kDeviceStateListening) { + std::vector data; ReadAudio(data, 16000, 30 * 16000 / 1000); background_task_->Schedule([this, data = std::move(data)]() mutable { opus_encoder_->Encode(std::move(data), [this](std::vector&& opus) { @@ -792,6 +794,7 @@ void Application::ResetDecoder() { std::lock_guard lock(mutex_); opus_decoder_->ResetState(); audio_decode_queue_.clear(); + audio_decode_cv_.notify_all(); last_output_time_ = std::chrono::steady_clock::now(); auto codec = Board::GetInstance().GetAudioCodec(); diff --git a/main/application.h b/main/application.h index eb6c90a..e5d89ea 100644 --- a/main/application.h +++ b/main/application.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -28,6 +30,7 @@ #define SCHEDULE_EVENT (1 << 0) #define AUDIO_INPUT_READY_EVENT (1 << 1) #define AUDIO_OUTPUT_READY_EVENT (1 << 2) +#define CHECK_NEW_VERSION_DONE_EVENT (1 << 3) enum DeviceState { kDeviceStateUnknown, @@ -97,7 +100,6 @@ private: bool aborted_ = false; bool voice_detected_ = false; int clock_ticks_ = 0; - TaskHandle_t main_loop_task_handle_ = nullptr; TaskHandle_t check_new_version_task_handle_ = nullptr; // Audio encode / decode @@ -105,6 +107,7 @@ private: BackgroundTask* background_task_ = nullptr; std::chrono::steady_clock::time_point last_output_time_; std::list> audio_decode_queue_; + std::condition_variable audio_decode_cv_; std::unique_ptr opus_encoder_; std::unique_ptr opus_decoder_; @@ -113,7 +116,7 @@ private: OpusResampler reference_resampler_; OpusResampler output_resampler_; - void MainLoop(); + void MainEventLoop(); void OnAudioInput(); void OnAudioOutput(); void ReadAudio(std::vector& data, int sample_rate, int samples); diff --git a/main/assets/en-US/language.json b/main/assets/en-US/language.json index 6265ae5..e255d0d 100644 --- a/main/assets/en-US/language.json +++ b/main/assets/en-US/language.json @@ -7,7 +7,8 @@ "INFO": "Information", "ERROR": "Error", "VERSION": "Ver ", - "LOADING_PROTOCOL": "Loading Protocol...", + "LOADING_PROTOCOL": "Logging in...", + "CHECKING_NEW_VERSION": "Checking for new version...", "INITIALIZING": "Initializing...", "PIN_ERROR": "Please insert SIM card", "REG_ERROR": "Unable to access network, please check SIM card status", diff --git a/main/assets/ja-JP/language.json b/main/assets/ja-JP/language.json index 5a8776a..b69dbf1 100644 --- a/main/assets/ja-JP/language.json +++ b/main/assets/ja-JP/language.json @@ -7,12 +7,13 @@ "INFO": "情報", "ERROR": "エラー", "VERSION": "バージョン ", - "LOADING_PROTOCOL": "プロトコルを読み込み中...", + "LOADING_PROTOCOL": "サーバーにログイン中...", "INITIALIZING": "初期化中...", "PIN_ERROR": "SIMカードを挿入してください", "REG_ERROR": "ネットワークに接続できません。ネットワーク状態を確認してください", "DETECTING_MODULE": "モジュールを検出中...", "REGISTERING_NETWORK": "ネットワーク接続待機中...", + "CHECKING_NEW_VERSION": "新しいバージョンを確認中...", "STANDBY": "待機中", "CONNECT_TO": "接続先 ", diff --git a/main/assets/zh-CN/language.json b/main/assets/zh-CN/language.json index d9e75cd..d057be7 100644 --- a/main/assets/zh-CN/language.json +++ b/main/assets/zh-CN/language.json @@ -7,12 +7,13 @@ "INFO":"信息", "ERROR":"错误", "VERSION": "版本 ", - "LOADING_PROTOCOL":"加载协议...", + "LOADING_PROTOCOL":"登录服务器...", "INITIALIZING":"正在初始化...", "PIN_ERROR":"请插入 SIM 卡", "REG_ERROR":"无法接入网络,请检查流量卡状态", "DETECTING_MODULE":"检测模组...", "REGISTERING_NETWORK":"等待网络...", + "CHECKING_NEW_VERSION":"检查新版本...", "STANDBY":"待命", "CONNECT_TO":"连接 ", diff --git a/main/assets/zh-TW/language.json b/main/assets/zh-TW/language.json index 0668f22..45e9eb5 100644 --- a/main/assets/zh-TW/language.json +++ b/main/assets/zh-TW/language.json @@ -7,12 +7,13 @@ "INFO": "資訊", "ERROR": "錯誤", "VERSION": "版本 ", - "LOADING_PROTOCOL": "加載協議...", + "LOADING_PROTOCOL": "登入伺服器...", "INITIALIZING": "正在初始化...", "PIN_ERROR": "請插入 SIM 卡", "REG_ERROR": "無法接入網絡,請檢查網路狀態", "DETECTING_MODULE": "檢測模組...", "REGISTERING_NETWORK": "等待網絡...", + "CHECKING_NEW_VERSION": "檢查新版本...", "STANDBY": "待命", "CONNECT_TO": "連接 ", diff --git a/main/audio_codecs/audio_codec.h b/main/audio_codecs/audio_codec.h index c97daff..f252475 100644 --- a/main/audio_codecs/audio_codec.h +++ b/main/audio_codecs/audio_codec.h @@ -11,6 +11,9 @@ #include "board.h" +#define AUDIO_CODEC_DMA_DESC_NUM 6 +#define AUDIO_CODEC_DMA_FRAME_NUM 240 + class AudioCodec { public: AudioCodec(); diff --git a/main/audio_codecs/box_audio_codec.cc b/main/audio_codecs/box_audio_codec.cc index 57bc321..1a644fe 100644 --- a/main/audio_codecs/box_audio_codec.cc +++ b/main/audio_codecs/box_audio_codec.cc @@ -96,8 +96,8 @@ void BoxAudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_ i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/audio_codecs/es8311_audio_codec.cc b/main/audio_codecs/es8311_audio_codec.cc index 2b5e3b5..ff7560a 100644 --- a/main/audio_codecs/es8311_audio_codec.cc +++ b/main/audio_codecs/es8311_audio_codec.cc @@ -80,8 +80,8 @@ void Es8311AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/audio_codecs/es8388_audio_codec.cc b/main/audio_codecs/es8388_audio_codec.cc index 347ef11..f3c076c 100644 --- a/main/audio_codecs/es8388_audio_codec.cc +++ b/main/audio_codecs/es8388_audio_codec.cc @@ -85,8 +85,8 @@ void Es8388AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/audio_codecs/no_audio_codec.cc b/main/audio_codecs/no_audio_codec.cc index 8fbd5da..2a7d353 100644 --- a/main/audio_codecs/no_audio_codec.cc +++ b/main/audio_codecs/no_audio_codec.cc @@ -23,8 +23,8 @@ NoAudioCodecDuplex::NoAudioCodecDuplex(int input_sample_rate, int output_sample_ i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, @@ -82,8 +82,8 @@ ATK_NoAudioCodecDuplex::ATK_NoAudioCodecDuplex(int input_sample_rate, int output i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, @@ -141,8 +141,8 @@ NoAudioCodecSimplex::NoAudioCodecSimplex(int input_sample_rate, int output_sampl i2s_chan_config_t chan_cfg = { .id = (i2s_port_t)0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, @@ -210,8 +210,8 @@ NoAudioCodecSimplex::NoAudioCodecSimplex(int input_sample_rate, int output_sampl i2s_chan_config_t chan_cfg = { .id = (i2s_port_t)0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, @@ -278,8 +278,8 @@ NoAudioCodecSimplexPdm::NoAudioCodecSimplexPdm(int input_sample_rate, int output // Create a new channel for speaker i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)1, I2S_ROLE_MASTER); - tx_chan_cfg.dma_desc_num = 6; - tx_chan_cfg.dma_frame_num = 240; + tx_chan_cfg.dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM; + tx_chan_cfg.dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM; tx_chan_cfg.auto_clear_after_cb = true; tx_chan_cfg.auto_clear_before_cb = false; tx_chan_cfg.intr_priority = 0; diff --git a/main/boards/df-k10/k10_audio_codec.cc b/main/boards/df-k10/k10_audio_codec.cc index be86216..fce2b7f 100644 --- a/main/boards/df-k10/k10_audio_codec.cc +++ b/main/boards/df-k10/k10_audio_codec.cc @@ -74,8 +74,8 @@ void K10AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_ i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/boards/esp-box-lite/box_audio_codec_lite.cc b/main/boards/esp-box-lite/box_audio_codec_lite.cc index 25b8ed5..658f49a 100644 --- a/main/boards/esp-box-lite/box_audio_codec_lite.cc +++ b/main/boards/esp-box-lite/box_audio_codec_lite.cc @@ -97,8 +97,8 @@ void BoxAudioCodecLite::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, g i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/boards/m5stack-core-s3/cores3_audio_codec.cc b/main/boards/m5stack-core-s3/cores3_audio_codec.cc index 2e885c1..b89be7d 100644 --- a/main/boards/m5stack-core-s3/cores3_audio_codec.cc +++ b/main/boards/m5stack-core-s3/cores3_audio_codec.cc @@ -99,8 +99,8 @@ void CoreS3AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gp i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/boards/sensecap-watcher/sensecap_audio_codec.cc b/main/boards/sensecap-watcher/sensecap_audio_codec.cc index 9e06a94..ac474d7 100644 --- a/main/boards/sensecap-watcher/sensecap_audio_codec.cc +++ b/main/boards/sensecap-watcher/sensecap_audio_codec.cc @@ -98,8 +98,8 @@ void SensecapAudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, i2s_chan_config_t chan_cfg = { .id = I2S_NUM_0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = AUDIO_CODEC_DMA_DESC_NUM, + .dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, diff --git a/main/idf_component.yml b/main/idf_component.yml index 58b1281..751e9b1 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -8,8 +8,8 @@ dependencies: espressif/esp_io_expander_tca9554: "==2.0.0" espressif/esp_lcd_panel_io_additions: "^1.0.1" 78/esp_lcd_nv3023: "~1.0.0" - 78/esp-wifi-connect: "~2.3.1" - 78/esp-opus-encoder: "~2.3.0" + 78/esp-wifi-connect: "~2.3.2" + 78/esp-opus-encoder: "~2.3.1" 78/esp-ml307: "~1.8.1" 78/xiaozhi-fonts: "~1.3.2" espressif/led_strip: "^2.4.1" diff --git a/main/main.cc b/main/main.cc index 64b122a..cc03cbd 100755 --- a/main/main.cc +++ b/main/main.cc @@ -26,5 +26,4 @@ extern "C" void app_main(void) // Launch the application Application::GetInstance().Start(); - // The main thread will exit and release the stack memory } diff --git a/main/ota.cc b/main/ota.cc index 8d663c1..8544ff6 100644 --- a/main/ota.cc +++ b/main/ota.cc @@ -58,15 +58,15 @@ bool Ota::CheckVersion() { http->SetHeader("Accept-Language", Lang::CODE); http->SetHeader("Content-Type", "application/json"); - std::string post_data = board.GetJson(); - std::string method = post_data.length() > 0 ? "POST" : "GET"; - if (!http->Open(method, check_version_url_, post_data)) { + std::string data = board.GetJson(); + std::string method = data.length() > 0 ? "POST" : "GET"; + if (!http->Open(method, check_version_url_, data)) { ESP_LOGE(TAG, "Failed to open HTTP connection"); delete http; return false; } - auto response = http->GetBody(); + data = http->GetBody(); http->Close(); delete http; @@ -74,7 +74,7 @@ bool Ota::CheckVersion() { // Parse the JSON response and check if the version is newer // If it is, set has_new_version_ to true and store the new version and URL - cJSON *root = cJSON_Parse(response.c_str()); + cJSON *root = cJSON_Parse(data.c_str()); if (root == NULL) { ESP_LOGE(TAG, "Failed to parse JSON response"); return false; diff --git a/sdkconfig.defaults b/sdkconfig.defaults index e883ccc..575592c 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -17,7 +17,7 @@ CONFIG_ESP_TASK_WDT_TIMEOUT_S=10 CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y -CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 CONFIG_MBEDTLS_DYNAMIC_BUFFER=y CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=n CONFIG_ESP_WIFI_IRAM_OPT=n