diff --git a/main/application.cc b/main/application.cc index 2e05ffe..9b64a91 100644 --- a/main/application.cc +++ b/main/application.cc @@ -45,7 +45,8 @@ Application::Application() { }, .arg = this, .dispatch_method = ESP_TIMER_TASK, - .name = "clock_timer" + .name = "clock_timer", + .skip_unhandled_events = true }; esp_timer_create(&clock_timer_args, &clock_timer_handle_); } diff --git a/main/boards/common/i2c_device.cc b/main/boards/common/i2c_device.cc index 5a9667a..835997d 100644 --- a/main/boards/common/i2c_device.cc +++ b/main/boards/common/i2c_device.cc @@ -9,7 +9,7 @@ I2cDevice::I2cDevice(i2c_master_bus_handle_t i2c_bus, uint8_t addr) { i2c_device_config_t i2c_device_cfg = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = addr, - .scl_speed_hz = 100000, + .scl_speed_hz = 400 * 1000, .scl_wait_us = 0, .flags = { .disable_ack_check = 0, diff --git a/main/boards/m5stack-core-s3/m5stack_core_s3.cc b/main/boards/m5stack-core-s3/m5stack_core_s3.cc index ae4da1d..fc886e5 100644 --- a/main/boards/m5stack-core-s3/m5stack_core_s3.cc +++ b/main/boards/m5stack-core-s3/m5stack_core_s3.cc @@ -113,7 +113,7 @@ public: tp_.y = ((read_buffer_[3] & 0x0F) << 8) | read_buffer_[4]; } - const TouchPoint_t& GetTouchPoint() { + inline const TouchPoint_t& GetTouchPoint() { return tp_; } @@ -203,15 +203,13 @@ private: vTaskDelay(pdMS_TO_TICKS(50)); } - static void touchpad_timer_callback(void* arg) { - auto& board = (M5StackCoreS3Board&)Board::GetInstance(); - auto touchpad = board.GetTouchpad(); + void PollTouchpad() { static bool was_touched = false; static int64_t touch_start_time = 0; const int64_t TOUCH_THRESHOLD_MS = 500; // 触摸时长阈值,超过500ms视为长按 - touchpad->UpdateTouchPoint(); - auto touch_point = touchpad->GetTouchPoint(); + ft6336_->UpdateTouchPoint(); + auto& touch_point = ft6336_->GetTouchPoint(); // 检测触摸开始 if (touch_point.num > 0 && !was_touched) { @@ -228,7 +226,7 @@ private: auto& app = Application::GetInstance(); if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) { - board.ResetWifiConfiguration(); + ResetWifiConfiguration(); } app.ToggleChatState(); } @@ -241,8 +239,11 @@ private: // 创建定时器,20ms 间隔 esp_timer_create_args_t timer_args = { - .callback = touchpad_timer_callback, - .arg = NULL, + .callback = [](void* arg) { + M5StackCoreS3Board* board = (M5StackCoreS3Board*)arg; + board->PollTouchpad(); + }, + .arg = this, .dispatch_method = ESP_TIMER_TASK, .name = "touchpad_timer", .skip_unhandled_events = true, @@ -374,10 +375,6 @@ public: static CustomBacklight backlight(pmic_); return &backlight; } - - Ft6336* GetTouchpad() { - return ft6336_; - } }; DECLARE_BOARD(M5StackCoreS3Board);