From afd7260cf29f3c955c66a6dad31e49bbbd934458 Mon Sep 17 00:00:00 2001 From: Forairaaaaa Date: Thu, 7 May 2026 09:38:14 +0800 Subject: [PATCH] update firmware v1.2.6 --- firmware/CMakeLists.txt | 2 +- firmware/main/hal/board/hal_bridge.h | 1 + firmware/main/hal/board/stackchan.cc | 33 ++++++++++++++++---- firmware/main/hal/board/stackchan_display.cc | 14 +++++++-- firmware/main/hal/hal.cpp | 14 +++++---- firmware/main/hal/hal_head_touch.cpp | 4 ++- firmware/main/hal/hal_imu.cpp | 3 +- firmware/main/hal/hal_rtc.cpp | 7 +++-- firmware/main/hal/hal_ws_avatar.cpp | 2 +- firmware/patches/xiaozhi-esp32.patch | 26 +++++++++++++++ 10 files changed, 85 insertions(+), 21 deletions(-) diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index ed7e18b..2d397bc 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -2,7 +2,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) -set(PROJECT_VER "1.2.4") +set(PROJECT_VER "1.2.6") add_definitions(-DFIRMWARE_VERSION=\"${PROJECT_VER}\") # Add this line to disable the specific warning diff --git a/firmware/main/hal/board/hal_bridge.h b/firmware/main/hal/board/hal_bridge.h index 0189066..3c92b3b 100644 --- a/firmware/main/hal/board/hal_bridge.h +++ b/firmware/main/hal/board/hal_bridge.h @@ -41,6 +41,7 @@ lv_disp_t* display_get_lvgl_display(); void xiaozhi_board_init(); void start_xiaozhi_app(); bool is_xiaozhi_ready(); +bool is_xiaozhi_idle(); i2c_master_bus_handle_t board_get_i2c_bus(); StackChanCamera* board_get_camera(); diff --git a/firmware/main/hal/board/stackchan.cc b/firmware/main/hal/board/stackchan.cc index ecaac8f..a043dde 100644 --- a/firmware/main/hal/board/stackchan.cc +++ b/firmware/main/hal/board/stackchan.cc @@ -183,12 +183,29 @@ public: delete[] read_buffer_; } - void UpdateTouchPoint() + bool UpdateTouchPoint() { - ReadRegs(0x02, read_buffer_, 6); - tp_.num = read_buffer_[0] & 0x0F; - tp_.x = ((read_buffer_[1] & 0x0F) << 8) | read_buffer_[2]; - tp_.y = ((read_buffer_[3] & 0x0F) << 8) | read_buffer_[4]; + auto err = TryReadRegs(0x02, read_buffer_, 6); + if (err != ESP_OK) { + tp_.num = 0; + tp_.x = -1; + tp_.y = -1; + + consecutive_failures_++; + int64_t now_us = esp_timer_get_time(); + if (last_error_log_us_ == 0 || (now_us - last_error_log_us_) >= 1000 * 1000) { + ESP_LOGW(TAG, "FT6336 read failed (%s), skipped %lu sample(s)", esp_err_to_name(err), + static_cast(consecutive_failures_)); + last_error_log_us_ = now_us; + } + return false; + } + + consecutive_failures_ = 0; + tp_.num = read_buffer_[0] & 0x0F; + tp_.x = ((read_buffer_[1] & 0x0F) << 8) | read_buffer_[2]; + tp_.y = ((read_buffer_[3] & 0x0F) << 8) | read_buffer_[4]; + return true; } inline const TouchPoint_t& GetTouchPoint() @@ -199,6 +216,8 @@ public: private: uint8_t* read_buffer_ = nullptr; TouchPoint_t tp_; + int64_t last_error_log_us_ = 0; + uint32_t consecutive_failures_ = 0; }; class M5StackCoreS3Board : public WifiBoard { @@ -283,7 +302,9 @@ private: void PollTouchpad() { - ft6336_->UpdateTouchPoint(); + if (!ft6336_->UpdateTouchPoint()) { + return; + } auto& touch_point = ft6336_->GetTouchPoint(); // Update hal touch point diff --git a/firmware/main/hal/board/stackchan_display.cc b/firmware/main/hal/board/stackchan_display.cc index 13b3f55..a6a5cc8 100644 --- a/firmware/main/hal/board/stackchan_display.cc +++ b/firmware/main/hal/board/stackchan_display.cc @@ -119,7 +119,8 @@ StackChanAvatarDisplay::StackChanAvatarDisplay(esp_lcd_panel_io_handle_t panel_i ESP_LOGI(TAG, "Initialize LVGL port"); lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG(); - port_cfg.task_priority = 20; + // port_cfg.task_priority = 20; + port_cfg.task_priority = 3; #if CONFIG_SOC_CPU_CORES_NUM > 1 port_cfg.task_affinity = 1; #endif @@ -435,10 +436,15 @@ void StackChanAvatarDisplay::SetTheme(Theme* theme) #include static bool _is_xiaozhi_ready = false; +static bool _is_xiaozhi_idle = false; bool hal_bridge::is_xiaozhi_ready() { return _is_xiaozhi_ready; } +bool hal_bridge::is_xiaozhi_idle() +{ + return _is_xiaozhi_idle; +} void StackChanAvatarDisplay::SetStatus(const char* status) { @@ -486,7 +492,7 @@ void StackChanAvatarDisplay::SetStatus(const char* status) } else if (strcmp(status, Lang::Strings::SPEAKING) == 0) { if (speaking_modifier_id_ < 0) { - speaking_modifier_id_ = stackchan.addModifier(std::make_unique()); + speaking_modifier_id_ = stackchan.addModifier(std::make_unique(0, 180, false)); } GetHAL().setRgbColor(0, 0, 0, 50); @@ -502,6 +508,8 @@ void StackChanAvatarDisplay::SetStatus(const char* status) idle_motion_modifier_id_ = stackchan.addModifier(std::make_unique()); idle_expression_modifier_id_ = stackchan.addModifier(std::make_unique()); } + + _is_xiaozhi_idle = true; } else { // Stop idle motion ESP_LOGW(TAG, "Stop idle motion"); @@ -517,6 +525,8 @@ void StackChanAvatarDisplay::SetStatus(const char* status) // motion.pitchServo().moveWithSpeed(200, 350); // motion.yawServo().moveWithSpeed(0, 350); // } + + _is_xiaozhi_idle = false; } // Clear sleep state diff --git a/firmware/main/hal/hal.cpp b/firmware/main/hal/hal.cpp index 632175c..6d4408e 100644 --- a/firmware/main/hal/hal.cpp +++ b/firmware/main/hal/hal.cpp @@ -144,20 +144,22 @@ void Hal::xiaozhi_board_init() static void _stackchan_update_task(void* param) { - bool is_xiaozhi_ready = false; - bool is_setup_done = false; + bool is_setup_done = false; while (1) { - vTaskDelay(pdMS_TO_TICKS(10)); + vTaskDelay(pdMS_TO_TICKS(20)); tools::update_reminders(); LvglLockGuard lock; + if (!hal_bridge::is_xiaozhi_idle()) { + vTaskDelay(pdMS_TO_TICKS(100)); + } + GetStackChan().update(); - if (!is_xiaozhi_ready) { - is_xiaozhi_ready = hal_bridge::is_xiaozhi_ready(); + if (!hal_bridge::is_xiaozhi_ready()) { continue; } @@ -195,7 +197,7 @@ void Hal::startXiaozhi() }); // Start stackchan update task - xTaskCreatePinnedToCore(_stackchan_update_task, "stackchan", 4096, NULL, 5, NULL, 1); + xTaskCreatePinnedToCore(_stackchan_update_task, "stackchan", 4096, NULL, 3, NULL, 1); hal_bridge::start_xiaozhi_app(); } diff --git a/firmware/main/hal/hal_head_touch.cpp b/firmware/main/hal/hal_head_touch.cpp index eeef44e..3847d9e 100644 --- a/firmware/main/hal/hal_head_touch.cpp +++ b/firmware/main/hal/hal_head_touch.cpp @@ -158,5 +158,7 @@ void Hal::head_touch_init() si12t_init(&si12t_cfg, &si12t); si12t_setup(si12t, SI12T_TYPE_LOW, SI12T_SENSITIVITY_LEVEL_3); - xTaskCreateWithCaps(_head_touch_update_task, "headtouch", 1024 * 6, si12t, 5, NULL, MALLOC_CAP_SPIRAM); + // xTaskCreateWithCaps(_head_touch_update_task, "headtouch", 1024 * 6, si12t, 2, NULL, MALLOC_CAP_SPIRAM); + xTaskCreatePinnedToCoreWithCaps(_head_touch_update_task, "headtouch", 1024 * 6, si12t, 2, NULL, 1, + MALLOC_CAP_SPIRAM); } diff --git a/firmware/main/hal/hal_imu.cpp b/firmware/main/hal/hal_imu.cpp index 7fda0d8..24fdf60 100644 --- a/firmware/main/hal/hal_imu.cpp +++ b/firmware/main/hal/hal_imu.cpp @@ -53,5 +53,6 @@ void Hal::imu_init() } mclog::tagInfo(_tag, "BMI270 init ok"); - xTaskCreateWithCaps(_imu_task, "imu", 4096, NULL, 5, NULL, MALLOC_CAP_SPIRAM); + // xTaskCreateWithCaps(_imu_task, "imu", 4096, NULL, 2, NULL, MALLOC_CAP_SPIRAM); + xTaskCreatePinnedToCoreWithCaps(_imu_task, "imu", 4096, NULL, 2, NULL, 1, MALLOC_CAP_SPIRAM); } diff --git a/firmware/main/hal/hal_rtc.cpp b/firmware/main/hal/hal_rtc.cpp index f4e685d..63effc1 100644 --- a/firmware/main/hal/hal_rtc.cpp +++ b/firmware/main/hal/hal_rtc.cpp @@ -11,6 +11,7 @@ #include #include #include +#include static const std::string_view _tag = "HAL-RTC"; @@ -103,10 +104,10 @@ void Hal::syncSystemTimeToRtc() time.seconds = tm_curr.tm_sec; if (_pcf8563->setDateTime(&date, &time)) { - mclog::tagInfo(_tag, "system synced to rtc (UTC): {:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}", date.year, - date.month, date.date, time.hours, time.minutes, time.seconds); + ESP_LOGI(_tag.data(), "system synced to rtc (UTC): %04d-%02d-%02d %02d:%02d:%02d", date.year, date.month, + date.date, time.hours, time.minutes, time.seconds); } else { - mclog::tagError(_tag, "failed to write rtc"); + ESP_LOGE(_tag.data(), "failed to write rtc"); } } diff --git a/firmware/main/hal/hal_ws_avatar.cpp b/firmware/main/hal/hal_ws_avatar.cpp index 441e8cd..0fc43ec 100644 --- a/firmware/main/hal/hal_ws_avatar.cpp +++ b/firmware/main/hal/hal_ws_avatar.cpp @@ -126,7 +126,7 @@ public: _websocket->OnDisconnected([this]() { ESP_LOGI(_tag.c_str(), "Disconnected!"); - GetHAL().onWsLog.emit(CommonLogLevel::Error, "Server disconnected"); + // GetHAL().onWsLog.emit(CommonLogLevel::Error, "Server disconnected"); }); _websocket->OnData([this](const char* data, size_t len, bool binary) { diff --git a/firmware/patches/xiaozhi-esp32.patch b/firmware/patches/xiaozhi-esp32.patch index bf76bf7..a580fbc 100644 --- a/firmware/patches/xiaozhi-esp32.patch +++ b/firmware/patches/xiaozhi-esp32.patch @@ -245,3 +245,29 @@ index 3692e0c..7bfbc5c 100644 // Strategy instance std::unique_ptr strategy_; +diff --git a/main/boards/common/i2c_device.cc b/main/boards/common/i2c_device.cc +index 835997d..ea50d51 100644 +--- a/main/boards/common/i2c_device.cc ++++ b/main/boards/common/i2c_device.cc +@@ -32,4 +32,8 @@ uint8_t I2cDevice::ReadReg(uint8_t reg) { + + void I2cDevice::ReadRegs(uint8_t reg, uint8_t* buffer, size_t length) { + ESP_ERROR_CHECK(i2c_master_transmit_receive(i2c_device_, ®, 1, buffer, length, 100)); ++} ++ ++esp_err_t I2cDevice::TryReadRegs(uint8_t reg, uint8_t* buffer, size_t length, int timeout_ms) { ++ return i2c_master_transmit_receive(i2c_device_, ®, 1, buffer, length, timeout_ms); + } +\ No newline at end of file +diff --git a/main/boards/common/i2c_device.h b/main/boards/common/i2c_device.h +index 7bc917b..874b137 100644 +--- a/main/boards/common/i2c_device.h ++++ b/main/boards/common/i2c_device.h +@@ -13,6 +13,7 @@ protected: + void WriteReg(uint8_t reg, uint8_t value); + uint8_t ReadReg(uint8_t reg); + void ReadRegs(uint8_t reg, uint8_t* buffer, size_t length); ++ esp_err_t TryReadRegs(uint8_t reg, uint8_t* buffer, size_t length, int timeout_ms = 100); + }; + + #endif // I2C_DEVICE_H