Enhance EInkDisplayHandler and LVGLHandler with deep sleep functionality and partial refresh improvements

This commit is contained in:
GW_MC
2026-01-27 19:12:37 +08:00
parent dc2a76e131
commit de2f166151
5 changed files with 343 additions and 80 deletions

View File

@@ -4,6 +4,7 @@
#include "esp_lcd_touch_gt911.h"
#include "common/semaphore_guard.h"
#include <vector>
#include <atomic>
// Refresh mode configuration
#define PARTIAL_REFRESH_THRESHOLD 10 // Full refresh every N partial refreshes
@@ -21,6 +22,28 @@ public:
int32_t y1;
int32_t x2;
int32_t y2;
// reset to empty area
void reset() {
x1 = y1 = x2 = y2 = 0;
}
// expand area to include another area
void expand_to_include(const RefreshArea& other) {
expand_to_include(other.x1, other.y1, other.x2, other.y2);
}
void expand_to_include(int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
const bool force_update = is_empty();
if (x1 < this->x1 || force_update) this->x1 = x1;
if (y1 < this->y1 || force_update) this->y1 = y1;
if (x2 > this->x2 || force_update) this->x2 = x2;
if (y2 > this->y2 || force_update) this->y2 = y2;
}
bool is_empty() const {
return (x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0);
}
uint32_t area() const {
if (is_empty()) return 0;
return (x2 - x1 + 1) * (y2 - y1 + 1);
}
};
class EInkDisplayHandler {
@@ -32,9 +55,10 @@ public:
esp_err_t refresh_display(void);
esp_err_t full_write(const uint8_t* framebuffer);
esp_err_t full_write(const uint8_t* framebuffer, const bool white_basemap = true);
esp_err_t partial_refresh(const uint8_t* framebuffer, const RefreshArea& area);
esp_err_t clear_display(void);
esp_err_t deep_sleep_display(void);
// Request a full refresh on next flush
void request_full_refresh(void);
@@ -53,7 +77,9 @@ protected:
private:
esp_err_t init_display_pins_(void);
esp_err_t epd_init_(void);
esp_err_t epd_init_(void); // full fast refresh init
esp_err_t epd_init_partial_(void); // partial refresh init (standalone)
esp_err_t epd_init_partial_internal_(uint32_t transaction_id); // partial refresh init (within existing transaction)
esp_err_t init_touch_(void);
esp_err_t dangerous_epd_write_cmd_without_lock_(const uint8_t cmd);
esp_err_t dangerous_epd_write_data_without_lock_(const uint8_t data);
@@ -67,6 +93,7 @@ private:
uint32_t partial_refresh_count_ = 0;
bool force_full_refresh_ = false;
std::atomic<bool> is_deep_sleep_ { false };
SemaphoreHandle_t spi_mutex_ = nullptr;
SemaphoreHandle_t spi_transaction_mutex_ = nullptr;