diff --git a/main/boards/echoear/EchoEar.cc b/main/boards/echoear/EchoEar.cc index 51404b55..1ebbc8b2 100644 --- a/main/boards/echoear/EchoEar.cc +++ b/main/boards/echoear/EchoEar.cc @@ -20,6 +20,9 @@ #include "touch.h" #include "driver/temperature_sensor.h" +#include +#include +#include #define TAG "EchoEar" @@ -274,6 +277,9 @@ private: TouchPoint_t tp_; }; static SemaphoreHandle_t touch_isr_mux = NULL; +static bool touch_event_pending = false; +static int64_t touch_event_time = 0; + class EspS3Cat : public WifiBoard { private: i2c_master_bus_handle_t i2c_bus_; @@ -362,19 +368,39 @@ private: static void lvgl_port_touch_isr_cb(void* arg) { - static int64_t touch_start_time = 0; - static int64_t touch_last_time = 0; - touch_start_time = esp_timer_get_time() / 1000; - if (touch_start_time - touch_last_time >= 300) { - auto& board = (EspS3Cat&)Board::GetInstance(); - auto& app = Application::GetInstance(); + int64_t current_time = esp_timer_get_time() / 1000; + static int64_t last_touch_time = 0; + + if (current_time - last_touch_time >= 300) { + touch_event_pending = true; + touch_event_time = current_time; + last_touch_time = current_time; + + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + if (touch_isr_mux != NULL) { + xSemaphoreGiveFromISR(touch_isr_mux, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + } + } + + static void touch_event_task(void* arg) { + while (true) { + if (xSemaphoreTake(touch_isr_mux, portMAX_DELAY) == pdTRUE) { + if (touch_event_pending) { + touch_event_pending = false; + + auto& board = (EspS3Cat&)Board::GetInstance(); + auto& app = Application::GetInstance(); + if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) { board.ResetWifiConfiguration(); } - app.ToggleChatState(); - touch_last_time = touch_start_time; - } + app.ToggleChatState(); + } + } + } } void InitializeCharge() { @@ -384,6 +410,14 @@ private: void InitializeCst816sTouchPad() { cst816s_ = new Cst816s(i2c_bus_, 0x15); + + touch_isr_mux = xSemaphoreCreateBinary(); + if (touch_isr_mux == NULL) { + ESP_LOGE(TAG, "Failed to create touch semaphore"); + return; + } + + xTaskCreatePinnedToCore(touch_event_task, "touch_task", 4 * 1024, NULL, 5, NULL, 1); const gpio_config_t int_gpio_config = { .pin_bit_mask = (1ULL << TP_PIN_NUM_INT), diff --git a/main/idf_component.yml b/main/idf_component.yml index 1847ab22..b6d71235 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -25,7 +25,7 @@ dependencies: espressif/esp_lcd_touch_ft5x06: ~1.0.7 espressif/esp_lcd_touch_gt911: ^1 waveshare/esp_lcd_touch_cst9217: ^1.0.3 - esp_lcd_touch_cst816s: "^1" + espressif/esp_lcd_touch_cst816s: ^1.0.6 lvgl/lvgl: ~9.2.2 esp_lvgl_port: ~2.6.0 espressif/esp_io_expander_tca95xx_16bit: ^2.0.0 @@ -33,6 +33,7 @@ dependencies: espressif/adc_mic: ^0.2.0 espressif/esp_mmap_assets: '>=1.2' txp666/otto-emoji-gif-component: ~1.0.2 + espressif/adc_battery_estimation: ^0.2.0 # SenseCAP Watcher Board wvirgil123/esp_jpeg_simd: @@ -73,4 +74,3 @@ dependencies: ## Required IDF version idf: version: '>=5.4.0' - espressif/adc_battery_estimation: =*