Fix touch screen not responding, but screen still not refreshed.

This commit is contained in:
GW_MC
2026-01-25 15:51:49 +08:00
parent 57f698425b
commit 259660a0bc
3 changed files with 117 additions and 44 deletions

View File

@@ -3,6 +3,9 @@
#include "esp_log.h"
#include "esp_lcd_touch_gt911.h"
#define BUSY_ACTIVE_LEVEL 0 // BUSY pin is active low
#define BUSY_INACTIVE_LEVEL 1
DisplayHandler::~DisplayHandler() {
if (_spi_mutex != nullptr) {
vSemaphoreDelete(_spi_mutex);
@@ -32,7 +35,10 @@ void DisplayHandler::init_devices(bool set_display_ready /*= true*/) {
void DisplayHandler::epd_write_cmd(uint8_t cmd) {
ESP_LOGI("DisplayHandler", "epd_write_cmd: waiting to send 0x%02X", cmd);
xSemaphoreTake(_spi_mutex, portMAX_DELAY);
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
ESP_LOGE("DisplayHandler", "SPI mutex timeout for cmd 0x%02X", cmd);
return;
}
_dangerous_epd_write_cmd_without_lock(cmd);
xSemaphoreGive(_spi_mutex);
ESP_LOGI("DisplayHandler", "epd_write_cmd: 0x%02X done", cmd);
@@ -40,7 +46,10 @@ void DisplayHandler::epd_write_cmd(uint8_t cmd) {
void DisplayHandler::epd_write_data(uint8_t data) {
ESP_LOGI("DisplayHandler", "epd_write_data: waiting to send 0x%02X", data);
xSemaphoreTake(_spi_mutex, portMAX_DELAY);
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
ESP_LOGE("DisplayHandler", "SPI mutex timeout for data 0x%02X", data);
return;
}
_dangerous_epd_write_data_without_lock(data);
xSemaphoreGive(_spi_mutex);
ESP_LOGI("DisplayHandler", "epd_write_data: 0x%02X done", data);
@@ -48,7 +57,10 @@ void DisplayHandler::epd_write_data(uint8_t data) {
void DisplayHandler::epd_write_cmd_with_data(uint8_t cmd, const uint8_t* data, size_t data_len) {
ESP_LOGI("DisplayHandler", "epd_write_cmd_with_data: waiting to send cmd 0x%02X with %u bytes of data", cmd, (unsigned)data_len);
xSemaphoreTake(_spi_mutex, portMAX_DELAY);
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
ESP_LOGE("DisplayHandler", "SPI mutex timeout for cmd with data 0x%02X", cmd);
return;
}
_dangerous_epd_write_cmd_without_lock(cmd);
for (size_t i = 0; i < data_len; ++i) {
_dangerous_epd_write_data_without_lock(data[i]);
@@ -108,7 +120,7 @@ void DisplayHandler::_epd_init(void) {
// Check BUSY pin
ESP_LOGI("DisplayHandler", "Waiting for EPD to be ready...");
while (gpio_get_level(PIN_BUSY) == 0) { // 0=BUSY, 1=FREE
while (gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL) { // BUSY is active LOW
vTaskDelay(pdMS_TO_TICKS(10));
}
ESP_LOGI("DisplayHandler", "EPD is ready.");