Compare commits
50 Commits
7cdd5c8e53
...
feature/mt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de2f166151 | ||
|
|
dc2a76e131 | ||
|
|
5f491dff6e | ||
|
|
6fbbfcde4f | ||
|
|
30dfdd630a | ||
|
|
abe840b65d | ||
|
|
f3dfc4f43f | ||
|
|
5865f6d383 | ||
|
|
259660a0bc | ||
|
|
57f698425b | ||
|
|
580d6a0a5b | ||
|
|
68f2c821fa | ||
|
|
d0a1e8c80f | ||
|
|
9487efff0e | ||
|
|
143a28de90 | ||
|
|
d091625cea | ||
|
|
d01167fd77 | ||
|
|
694ead2b42 | ||
|
|
39c4cfd85f | ||
|
|
89cc04951f | ||
|
|
dd1702e3e9 | ||
|
|
dfd8959f58 | ||
|
|
162b3710eb | ||
|
|
86e102adc7 | ||
|
|
ccae9e89da | ||
|
|
0c26d91565 | ||
|
|
6ad55c7efc | ||
|
|
d248557614 | ||
|
|
4f7418c77a | ||
|
|
4fa8dc608f | ||
|
|
44fb9aa632 | ||
|
|
14f4b8fdc0 | ||
|
|
fae9d30e3a | ||
|
|
e163392532 | ||
|
|
8f9f89cb32 | ||
|
|
4d19dd7294 | ||
|
|
654a0bc0f7 | ||
|
|
a1404a196e | ||
|
|
41516374f0 | ||
|
|
4cda7d2de3 | ||
|
|
a801caaae6 | ||
|
|
89e8014798 | ||
|
|
1d12dc5160 | ||
|
|
0b26e0c7c9 | ||
|
|
89daff2267 | ||
|
|
18ac21e257 | ||
|
|
821fb0d9d7 | ||
|
|
01c36669cf | ||
|
|
d339a1f4c3 | ||
|
|
e458256193 |
199
main/display/display.cpp.old
Normal file
199
main/display/display.cpp.old
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
#include "display/display.h"
|
||||||
|
#include "common/constants.h"
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
if (_spi != nullptr) {
|
||||||
|
spi_bus_remove_device(_spi);
|
||||||
|
}
|
||||||
|
if (_tp_handle != nullptr) {
|
||||||
|
esp_lcd_touch_del(_tp_handle);
|
||||||
|
}
|
||||||
|
if (_tp_io_handle != nullptr) {
|
||||||
|
esp_lcd_panel_io_del(_tp_io_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayHandler::init_devices(bool set_display_ready /*= true*/) {
|
||||||
|
ESP_LOGI("DisplayHandler", "Initializing display and touch...");
|
||||||
|
_epd_init();
|
||||||
|
_touch_init();
|
||||||
|
ESP_LOGI("DisplayHandler", "Display and touch initialized.");
|
||||||
|
if (set_display_ready) {
|
||||||
|
ESP_LOGI("DisplayHandler", "Setting display ready bit.");
|
||||||
|
xEventGroupSetBits(_system_event_group, DISPLAY_READY_BIT | TOUCH_CALIBRATED_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DisplayHandler::epd_write_cmd(uint8_t cmd) {
|
||||||
|
ESP_LOGI("DisplayHandler", "epd_write_cmd: waiting to send 0x%02X", cmd);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayHandler::epd_write_data(uint8_t data) {
|
||||||
|
ESP_LOGI("DisplayHandler", "epd_write_data: waiting to send 0x%02X", data);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
xSemaphoreGive(_spi_mutex);
|
||||||
|
ESP_LOGI("DisplayHandler", "epd_write_cmd_with_data: cmd 0x%02X with %u bytes of data done", cmd, (unsigned)data_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Private methods
|
||||||
|
//
|
||||||
|
|
||||||
|
void DisplayHandler::_dangerous_epd_write_cmd_without_lock(uint8_t cmd) {
|
||||||
|
ESP_LOGI("DisplayHandler", "_dangerous_epd_write_cmd_without_lock: sending 0x%02X", cmd);
|
||||||
|
gpio_set_level(PIN_DC, 0); // Command mode
|
||||||
|
spi_transaction_t t {};
|
||||||
|
t.length = 8;t.tx_buffer = &cmd;
|
||||||
|
esp_err_t err = spi_device_polling_transmit(_spi, &t);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE("DisplayHandler", "Failed to send data 0x%02X", cmd);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI("DisplayHandler", "_dangerous_epd_write_cmd_without_lock: 0x%02X sent", cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayHandler::_dangerous_epd_write_data_without_lock(uint8_t data) {
|
||||||
|
ESP_LOGI("DisplayHandler", "_dangerous_epd_write_data_without_lock: sending 0x%02X", data);
|
||||||
|
gpio_set_level(PIN_DC, 1); // Data mode
|
||||||
|
spi_transaction_t t = { };
|
||||||
|
t.length = 8; t.tx_buffer = &data;
|
||||||
|
esp_err_t err = spi_device_polling_transmit(_spi, &t);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE("DisplayHandler", "Failed to send data 0x%02X", data);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI("DisplayHandler", "_dangerous_epd_write_data_without_lock: 0x%02X sent", data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// required to be called by inheriting class after SPI device is created
|
||||||
|
void DisplayHandler::_epd_init(void) {
|
||||||
|
ESP_LOGI("DisplayHandler", "Initializing EPD...");
|
||||||
|
// 1. Hardware Reset
|
||||||
|
gpio_set_level(PIN_RST, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
gpio_set_level(PIN_RST, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
|
||||||
|
// 2. Initialization Sequence
|
||||||
|
const uint8_t panel_setting_data[] = { 0x1F };
|
||||||
|
epd_write_cmd_with_data(0x00, panel_setting_data, 1); // Panel Setting
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
const uint8_t vcom_data[] = { 0x10, 0x07 };
|
||||||
|
epd_write_cmd_with_data(0x50, vcom_data, 2); // VCOM
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
epd_write_cmd(0x04); // Power ON
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100)); // Wait for power on
|
||||||
|
|
||||||
|
// Check BUSY pin with detailed logging
|
||||||
|
ESP_LOGI("DisplayHandler", "Waiting for EPD to be ready after power on...");
|
||||||
|
ESP_LOGI("DisplayHandler", "BUSY pin level after power on: %d (0=BUSY, 1=FREE)", gpio_get_level(PIN_BUSY));
|
||||||
|
|
||||||
|
int busy_timeout = 0;
|
||||||
|
while (gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL) { // BUSY is active LOW
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
busy_timeout++;
|
||||||
|
if (busy_timeout > 500) { // 5 second timeout
|
||||||
|
ESP_LOGE("DisplayHandler", "EPD power on timeout! BUSY pin stuck at 0");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (busy_timeout % 50 == 0) { // Log every 500ms
|
||||||
|
ESP_LOGW("DisplayHandler", "Still waiting for EPD power on, timeout: %d/500", busy_timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI("DisplayHandler", "EPD power on complete after %d * 10ms, BUSY pin: %d", busy_timeout, gpio_get_level(PIN_BUSY));
|
||||||
|
const uint8_t booster_data[] = { 0x27, 0x27, 0x18, 0x17 };
|
||||||
|
epd_write_cmd_with_data(0x06, booster_data, 4); // Booster Soft Start
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
|
||||||
|
// Enhanced display drive commands
|
||||||
|
const uint8_t e0_data[] = { 0x02 };
|
||||||
|
epd_write_cmd_with_data(0xE0, e0_data, 1);
|
||||||
|
const uint8_t e5_data[] = { 0x5A };
|
||||||
|
epd_write_cmd_with_data(0xE5, e5_data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayHandler::_touch_init(void) {
|
||||||
|
ESP_LOGI("DisplayHandler", "Initializing touch...");
|
||||||
|
|
||||||
|
// 1. Initialize I2C Bus
|
||||||
|
i2c_config_t conf = {};
|
||||||
|
conf.mode = I2C_MODE_MASTER;
|
||||||
|
conf.sda_io_num = PIN_TOUCH_SDA;
|
||||||
|
conf.scl_io_num = PIN_TOUCH_SCL;
|
||||||
|
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
||||||
|
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
||||||
|
conf.master.clk_speed = 400000;
|
||||||
|
|
||||||
|
i2c_param_config(I2C_NUM_0, &conf);
|
||||||
|
i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
|
||||||
|
ESP_LOGI("DisplayHandler", "I2C driver installed");
|
||||||
|
|
||||||
|
// 2. Initialize GT911
|
||||||
|
ESP_LOGI("DisplayHandler", "Initializing GT911 touch controller...");
|
||||||
|
esp_lcd_panel_io_i2c_config_t tp_io_config = {};
|
||||||
|
// temporarily disable -Wmissing-field-initializers, as ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG macro does not set all fields
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||||
|
esp_lcd_panel_io_i2c_config_t default_tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
tp_io_config.dev_addr = default_tp_io_config.dev_addr;
|
||||||
|
tp_io_config.control_phase_bytes = default_tp_io_config.control_phase_bytes;
|
||||||
|
tp_io_config.dc_bit_offset = default_tp_io_config.dc_bit_offset;
|
||||||
|
tp_io_config.lcd_cmd_bits = default_tp_io_config.lcd_cmd_bits;
|
||||||
|
tp_io_config.flags = default_tp_io_config.flags;
|
||||||
|
esp_lcd_new_panel_io_i2c(I2C_NUM_0, &tp_io_config, &_tp_io_handle);
|
||||||
|
|
||||||
|
// GT911-specific config with I2C address (0x5D = INT low during reset)
|
||||||
|
static esp_lcd_touch_io_gt911_config_t gt911_config = {
|
||||||
|
.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS // 0x5D
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_lcd_touch_config_t tp_cfg = {};
|
||||||
|
tp_cfg.x_max = 800;
|
||||||
|
tp_cfg.y_max = 480;
|
||||||
|
tp_cfg.rst_gpio_num = PIN_TOUCH_RST;
|
||||||
|
tp_cfg.int_gpio_num = PIN_TOUCH_IRQ;
|
||||||
|
tp_cfg.driver_data = >911_config; // Pass GT911-specific config for automatic reset
|
||||||
|
|
||||||
|
esp_err_t touch_ret = esp_lcd_touch_new_i2c_gt911(_tp_io_handle, &tp_cfg, &_tp_handle);
|
||||||
|
if (touch_ret == ESP_OK && _tp_handle != nullptr) {
|
||||||
|
ESP_LOGI("DisplayHandler", "GT911 touch controller initialized successfully");
|
||||||
|
} else {
|
||||||
|
ESP_LOGE("DisplayHandler", "GT911 touch controller initialization failed: %s", esp_err_to_name(touch_ret));
|
||||||
|
_tp_handle = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
main/display/display.h.old
Normal file
42
main/display/display.h.old
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "esp_lcd_touch_gt911.h"
|
||||||
|
#include "display/constants.h"
|
||||||
|
#include <driver/i2c.h>
|
||||||
|
|
||||||
|
class DisplayHandler {
|
||||||
|
public:
|
||||||
|
DisplayHandler(
|
||||||
|
EventGroupHandle_t system_event_group
|
||||||
|
) : _system_event_group(system_event_group) { }
|
||||||
|
virtual ~DisplayHandler();
|
||||||
|
|
||||||
|
// required to be called by inheriting class after SPI device is created
|
||||||
|
// set set_display_ready to false if further initialization is needed before marking display ready
|
||||||
|
virtual void init_devices(bool set_display_ready = true);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Allow derived classes to access touch handle
|
||||||
|
esp_lcd_touch_handle_t get_touch_handle() const { return _tp_handle; }
|
||||||
|
|
||||||
|
void epd_write_cmd(uint8_t cmd);
|
||||||
|
void epd_write_data(uint8_t data);
|
||||||
|
|
||||||
|
void epd_write_cmd_with_data(uint8_t cmd, const uint8_t* data, size_t data_len);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SemaphoreHandle_t _spi_mutex = xSemaphoreCreateMutex();
|
||||||
|
spi_device_handle_t _spi = nullptr;
|
||||||
|
EventGroupHandle_t _system_event_group = nullptr;
|
||||||
|
esp_lcd_panel_io_handle_t _tp_io_handle = nullptr;
|
||||||
|
esp_lcd_touch_handle_t _tp_handle = nullptr;
|
||||||
|
|
||||||
|
void _dangerous_epd_write_cmd_without_lock(uint8_t cmd);
|
||||||
|
void _dangerous_epd_write_data_without_lock(uint8_t data);
|
||||||
|
|
||||||
|
void _epd_init(void);
|
||||||
|
void _touch_init(void);
|
||||||
|
};
|
||||||
@@ -11,53 +11,48 @@
|
|||||||
#define DISPLAY_BUFFER_SIZE (EINK_HEIGHT* EINK_WIDTH) / 8 // 1 bit per pixels
|
#define DISPLAY_BUFFER_SIZE (EINK_HEIGHT* EINK_WIDTH) / 8 // 1 bit per pixels
|
||||||
#define MINIMUM_PIN_SETUP_DELAY_MS 10
|
#define MINIMUM_PIN_SETUP_DELAY_MS 10
|
||||||
#define MINIMUM_POWER_ON_DELAY_MS 100
|
#define MINIMUM_POWER_ON_DELAY_MS 100
|
||||||
#define PARTIAL_REFRESH_THRESHOLD 5 // Full refresh every N partial refreshes
|
#define BUSY_ACTIVE_LEVEL 0 // BUSY pin is active low
|
||||||
|
#define BUSY_INACTIVE_LEVEL 1
|
||||||
|
#define DMA_TRANSFER_CHUNK_SIZE 4096 // 4KB chunk size for DMA transfers
|
||||||
|
|
||||||
static uint8_t* DRAW_BUFFER; // 1 bit per pixel
|
static uint8_t white_data[DISPLAY_BUFFER_SIZE]; // all white data
|
||||||
static uint8_t* OLD_DRAW_BUFFER; // 1 bit per pixel
|
static uint8_t black_data[DISPLAY_BUFFER_SIZE]; // all black data
|
||||||
static uint8_t* black_data;
|
|
||||||
static uint8_t* white_data;
|
|
||||||
|
|
||||||
EInkDisplayHandler::EInkDisplayHandler() {
|
EInkDisplayHandler::EInkDisplayHandler() {
|
||||||
black_data = static_cast<uint8_t*>(heap_caps_malloc(DISPLAY_BUFFER_SIZE, MALLOC_CAP_SPIRAM));
|
memset(white_data, 0xFF, sizeof(white_data));
|
||||||
white_data = static_cast<uint8_t*>(heap_caps_malloc(DISPLAY_BUFFER_SIZE, MALLOC_CAP_SPIRAM));
|
memset(black_data, 0x00, sizeof(black_data));
|
||||||
DRAW_BUFFER = static_cast<uint8_t*>(heap_caps_malloc(DISPLAY_BUFFER_SIZE, MALLOC_CAP_SPIRAM));
|
spi_mutex_ = xSemaphoreCreateMutex();
|
||||||
OLD_DRAW_BUFFER = static_cast<uint8_t*>(heap_caps_malloc(DISPLAY_BUFFER_SIZE, MALLOC_CAP_SPIRAM));
|
if (spi_mutex_ == nullptr) {
|
||||||
memset(black_data, 0xFF, DISPLAY_BUFFER_SIZE); // eink uses 1 for black
|
ESP_LOGE(TAG, "Failed to create SPI mutex");
|
||||||
memset(white_data, 0x00, DISPLAY_BUFFER_SIZE);
|
}
|
||||||
memset(DRAW_BUFFER, 0x00, DISPLAY_BUFFER_SIZE); // start with all white (0 = white in e-ink)
|
spi_transaction_mutex_ = xSemaphoreCreateMutex();
|
||||||
memset(OLD_DRAW_BUFFER, 0x00, DISPLAY_BUFFER_SIZE); // start with all white (0 = white in e-ink)
|
if (spi_transaction_mutex_ == nullptr) {
|
||||||
draw_buffer_ = DRAW_BUFFER;
|
ESP_LOGE(TAG, "Failed to create SPI transaction mutex");
|
||||||
old_buffer_ = OLD_DRAW_BUFFER;
|
}
|
||||||
|
|
||||||
refresh_mutex_ = xSemaphoreCreateMutex();
|
refresh_mutex_ = xSemaphoreCreateMutex();
|
||||||
if (refresh_mutex_ == nullptr) {
|
if (refresh_mutex_ == nullptr) {
|
||||||
ESP_LOGE(TAG, "Failed to create refresh mutex");
|
ESP_LOGE(TAG, "Failed to create refresh mutex");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EInkDisplayHandler::~EInkDisplayHandler() {
|
EInkDisplayHandler::~EInkDisplayHandler() {
|
||||||
|
if (spi_mutex_ != nullptr) {
|
||||||
|
vSemaphoreDelete(spi_mutex_);
|
||||||
|
}
|
||||||
|
if (spi_transaction_mutex_ != nullptr) {
|
||||||
|
vSemaphoreDelete(spi_transaction_mutex_);
|
||||||
|
}
|
||||||
if (refresh_mutex_ != nullptr) {
|
if (refresh_mutex_ != nullptr) {
|
||||||
vSemaphoreDelete(refresh_mutex_);
|
vSemaphoreDelete(refresh_mutex_);
|
||||||
}
|
}
|
||||||
|
if (spi_ != nullptr) {
|
||||||
|
spi_bus_remove_device(spi_);
|
||||||
|
}
|
||||||
if (tp_handle_ != nullptr) {
|
if (tp_handle_ != nullptr) {
|
||||||
esp_lcd_touch_del(tp_handle_);
|
esp_lcd_touch_del(tp_handle_);
|
||||||
}
|
}
|
||||||
if (tp_io_handle_ != nullptr) {
|
if (tp_io_handle_ != nullptr) {
|
||||||
esp_lcd_panel_io_del(tp_io_handle_);
|
esp_lcd_panel_io_del(tp_io_handle_);
|
||||||
}
|
}
|
||||||
if (black_data != nullptr) {
|
|
||||||
heap_caps_free(black_data);
|
|
||||||
}
|
|
||||||
if (white_data != nullptr) {
|
|
||||||
heap_caps_free(white_data);
|
|
||||||
}
|
|
||||||
if (DRAW_BUFFER != nullptr) {
|
|
||||||
heap_caps_free(DRAW_BUFFER);
|
|
||||||
}
|
|
||||||
if (OLD_DRAW_BUFFER != nullptr) {
|
|
||||||
heap_caps_free(OLD_DRAW_BUFFER);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t EInkDisplayHandler::deep_sleep_display(void) {
|
esp_err_t EInkDisplayHandler::deep_sleep_display(void) {
|
||||||
@@ -68,26 +63,26 @@ esp_err_t EInkDisplayHandler::deep_sleep_display(void) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
TransactionGuard transaction_guard(this->epd_handler_);
|
TransactionGuard transaction_guard(*this);
|
||||||
err = transaction_guard.begin(pdMS_TO_TICKS(5000));
|
err = transaction_guard.begin(pdMS_TO_TICKS(5000));
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to begin transaction for deep sleep: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to begin transaction for deep sleep: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
|
|
||||||
err = epd_handler_.epd_write_cmd(0x02, transaction_guard.transaction_id()); // power off
|
err = epd_write_cmd(0x02, transaction_guard.transaction_id()); // power off
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send power off command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send power off command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
err = epd_handler_.epd_write_cmd(0x07, transaction_guard.transaction_id()); //deep sleep
|
err = epd_write_cmd(0x07, transaction_guard.transaction_id()); //deep sleep
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send deep sleep command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send deep sleep command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = epd_handler_.epd_write_data(0xA5, transaction_guard.transaction_id());
|
err = epd_write_data(0xA5, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send deep sleep data: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send deep sleep data: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -100,43 +95,32 @@ esp_err_t EInkDisplayHandler::deep_sleep_display(void) {
|
|||||||
esp_err_t EInkDisplayHandler::refresh_display() {
|
esp_err_t EInkDisplayHandler::refresh_display() {
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
||||||
|
|
||||||
if (is_deep_sleep_) {
|
if (is_deep_sleep_) {
|
||||||
|
epd_init_();
|
||||||
err = full_write(draw_buffer_, true);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Full write failed during refresh_display: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// refresh does not correctly work after recovering from deep sleep due to sram reset
|
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Waiting for display to be idle...");
|
ESP_LOGI(TAG, "Waiting for display to be idle...");
|
||||||
TransactionGuard transaction_guard(this->epd_handler_);
|
TransactionGuard transaction_guard(*this);
|
||||||
err = transaction_guard.begin(pdMS_TO_TICKS(10000));
|
err = transaction_guard.begin(pdMS_TO_TICKS(10000));
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to begin transaction for display refresh: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to begin transaction for display refresh: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
if (is_deep_sleep_) {
|
wait_for_idle();
|
||||||
epd_init_internal_(transaction_guard.transaction_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
epd_handler_.wait_for_idle();
|
|
||||||
ESP_LOGI(TAG, "Starting display refresh...");
|
ESP_LOGI(TAG, "Starting display refresh...");
|
||||||
err = epd_handler_.epd_write_cmd(0x92, transaction_guard.transaction_id()); // enter normal mode
|
err = epd_write_cmd(0x92, transaction_guard.transaction_id()); // enter normal mode
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to enter normal mode: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to enter normal mode: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = epd_handler_.epd_write_cmd(0x12, transaction_guard.transaction_id()); // display refresh
|
err = epd_write_cmd(0x12, transaction_guard.transaction_id()); // display refresh
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send display refresh command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send display refresh command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS)); // at least 200us delay
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS)); // at least 200us delay
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -149,6 +133,12 @@ esp_err_t EInkDisplayHandler::refresh_display() {
|
|||||||
force_full_refresh_ = false;
|
force_full_refresh_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = deep_sleep_display();
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to enter deep sleep after refresh: %s", esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Refresh complete");
|
ESP_LOGI(TAG, "Refresh complete");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@@ -157,35 +147,33 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
|||||||
ESP_LOGI(TAG, "Starting full refresh (3 seconds)...");
|
ESP_LOGI(TAG, "Starting full refresh (3 seconds)...");
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
||||||
|
if (is_deep_sleep_) {
|
||||||
|
epd_init_();
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TransactionGuard transaction_guard(this->epd_handler_);
|
TransactionGuard transaction_guard(*this);
|
||||||
err = transaction_guard.begin(pdMS_TO_TICKS(10000));
|
err = transaction_guard.begin(pdMS_TO_TICKS(10000));
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to begin transaction for full refresh: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to begin transaction for full refresh: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
if (is_deep_sleep_) {
|
|
||||||
epd_init_internal_(transaction_guard.transaction_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
write_to_buffer_(framebuffer, RefreshArea { 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1 });
|
wait_for_idle();
|
||||||
|
|
||||||
epd_handler_.wait_for_idle();
|
|
||||||
// Step 0: Enter normal mode
|
// Step 0: Enter normal mode
|
||||||
err = epd_handler_.epd_write_cmd(0x92, transaction_guard.transaction_id()); // enter normal mode
|
err = epd_write_cmd(0x92, transaction_guard.transaction_id()); // enter normal mode
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to enter normal mode: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to enter normal mode: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
// Step 1: Write old data (0x10) - Arduino uses 0xFF (all white) for base map
|
// Step 1: Write old data (0x10) - Arduino uses 0xFF (all white) for base map
|
||||||
{
|
{
|
||||||
err = epd_handler_.epd_write_cmd(0x10, transaction_guard.transaction_id());
|
err = epd_write_cmd(0x10, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send old data command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send old data command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = epd_handler_.transfer_spi_data(white_basemap ? black_data : white_data, DISPLAY_BUFFER_SIZE, transaction_guard.transaction_id()); // Send all white data (0xFF)
|
err = transfer_spi_data(white_basemap ? white_data : black_data, DISPLAY_BUFFER_SIZE, transaction_guard.transaction_id()); // Send all white data (0xFF)
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send all white data for old data: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send all white data for old data: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -194,20 +182,20 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
|||||||
|
|
||||||
// Step 2: Write new data (0x13)
|
// Step 2: Write new data (0x13)
|
||||||
{
|
{
|
||||||
err = epd_handler_.epd_write_cmd(0x13, transaction_guard.transaction_id());
|
err = epd_write_cmd(0x13, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send new data command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send new data command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = epd_handler_.transfer_spi_data(draw_buffer_, DISPLAY_BUFFER_SIZE, transaction_guard.transaction_id()); // Send new framebuffer data
|
err = transfer_spi_data(framebuffer, DISPLAY_BUFFER_SIZE, transaction_guard.transaction_id()); // Send new framebuffer data
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send framebuffer data for new data: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send framebuffer data for new data: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Step 3: Trigger display refresh (DRF)
|
// Step 3: Trigger display refresh (DRF)
|
||||||
err = epd_handler_.epd_write_cmd(0x12, transaction_guard.transaction_id());
|
err = epd_write_cmd(0x12, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send display refresh command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send display refresh command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -217,7 +205,7 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
|||||||
ESP_LOGI(TAG, "Display refresh triggered, BUSY pin: %d", gpio_get_level(PIN_BUSY));
|
ESP_LOGI(TAG, "Display refresh triggered, BUSY pin: %d", gpio_get_level(PIN_BUSY));
|
||||||
|
|
||||||
// Wait for refresh to complete
|
// Wait for refresh to complete
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = deep_sleep_display();
|
err = deep_sleep_display();
|
||||||
@@ -226,96 +214,57 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_area_.reset();
|
|
||||||
memcpy(old_buffer_, draw_buffer_, DISPLAY_BUFFER_SIZE);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Full refresh complete");
|
ESP_LOGI(TAG, "Full refresh complete");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Partial refresh is inverted in color
|
esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* partial_framebuffer, const RefreshArea& area) {
|
||||||
esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_framebuffer, const RefreshArea& incoming_area, const bool is_last_partial_update) {
|
|
||||||
ESP_LOGI(TAG, "Starting partial refresh (0.3 seconds)...");
|
ESP_LOGI(TAG, "Starting partial refresh (0.3 seconds)...");
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
||||||
write_to_buffer_(incoming_partial_framebuffer, incoming_area);
|
|
||||||
|
|
||||||
// Always expand refresh_area_ to include incoming_area
|
|
||||||
refresh_area_.expand_to_include(incoming_area);
|
|
||||||
|
|
||||||
if (!is_last_partial_update) {
|
|
||||||
ESP_LOGI(TAG, "Partial refresh skipped (not last partial update)");
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
TransactionGuard transaction_guard(this->epd_handler_);
|
|
||||||
err = transaction_guard.begin(pdMS_TO_TICKS(5000));
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to begin transaction for partial refresh: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
// Wake display from deep sleep INSIDE the transaction to prevent race conditions
|
|
||||||
if (is_deep_sleep_) {
|
|
||||||
err = epd_init_internal_(transaction_guard.transaction_id());
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to initialize EPD for partial refresh: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
err = refresh_old_buffer_(transaction_guard.transaction_id());
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to refresh old buffer during partial refresh init: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
RefreshArea area = refresh_area_;
|
|
||||||
if (area.x1 % 8 != 0 || area.x2 % 8 != 7) {
|
|
||||||
ESP_LOGE(TAG, "Partial refresh area x1 and x2 must be byte-aligned (x1 %% 8 == 0 and x2 %% 8 == 7)");
|
|
||||||
ESP_LOGI(TAG, "Given area: x1=%d, x2=%d", area.x1, area.x2);
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate partial buffer size based on the refresh area
|
// Calculate partial buffer size based on the refresh area
|
||||||
const uint32_t area_width_bytes = (area.x2 - area.x1 + 1) / 8;
|
const uint32_t area_width_bytes = (area.x2 - area.x1 + 1) / 8;
|
||||||
const uint32_t area_height = area.y2 - area.y1 + 1;
|
const uint32_t area_height = area.y2 - area.y1 + 1;
|
||||||
const size_t partial_buffer_size = area_width_bytes * area_height;
|
const size_t partial_buffer_size = area_width_bytes * area_height;
|
||||||
|
|
||||||
// uint8_t* partial_buffer = new uint8_t[partial_buffer_size];
|
{
|
||||||
uint8_t* partial_buffer = static_cast<uint8_t*>(heap_caps_malloc(partial_buffer_size, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL));
|
TransactionGuard transaction_guard(*this);
|
||||||
|
err = transaction_guard.begin(pdMS_TO_TICKS(5000));
|
||||||
if (partial_buffer == nullptr) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate partial buffer for partial refresh");
|
ESP_LOGE(TAG, "Failed to begin transaction for partial refresh: %s", esp_err_to_name(err));
|
||||||
return ESP_ERR_NO_MEM;
|
return err;
|
||||||
}
|
|
||||||
// Copy the relevant area from draw_buffer_ to partial_buffer
|
|
||||||
for (int32_t row = 0; row < area_height; ++row) {
|
|
||||||
uint32_t fb_y = area.y1 + row;
|
|
||||||
uint32_t fb_x_byte_start = area.x1 / 8;
|
|
||||||
uint8_t* fb_ptr = &draw_buffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
|
||||||
uint8_t* dest_ptr = &partial_buffer[row * area_width_bytes];
|
|
||||||
memcpy(dest_ptr, fb_ptr, area_width_bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wake display from deep sleep INSIDE the transaction to prevent race conditions
|
||||||
|
if (is_deep_sleep_) {
|
||||||
|
err = epd_init_partial_internal_(transaction_guard.transaction_id());
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to initialize EPD for partial refresh: %s", esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
|
|
||||||
// Step 1 VCOM setting
|
// Step 1 VCOM setting
|
||||||
std::vector<uint8_t> vcom_data = { 0xA9, 0x07 };
|
std::vector<uint8_t> vcom_data = { 0xA9, 0x07 };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0x50, vcom_data, transaction_guard.transaction_id()); // VCOM for partial refresh
|
err = epd_write_cmd_with_data(0x50, vcom_data, transaction_guard.transaction_id()); // VCOM for partial refresh
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to set VCOM for partial refresh: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to set VCOM for partial refresh: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
// Step 2: Enter partial refresh mode
|
// Step 2: Enter partial refresh mode
|
||||||
err = epd_handler_.epd_write_cmd(0x91, transaction_guard.transaction_id()); // Enter partial mode
|
err = epd_write_cmd(0x91, transaction_guard.transaction_id()); // Enter partial mode
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to enter partial refresh mode: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to enter partial refresh mode: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
// Step 3: Set partial window
|
// Step 3: Set partial window
|
||||||
{
|
{
|
||||||
|
if (area.x1 % 8 != 0 || area.x2 % 8 != 7) {
|
||||||
|
ESP_LOGE(TAG, "Partial refresh area x1 and x2 must be byte-aligned (x1 %% 8 == 0 and x2 %% 8 == 7)");
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
// ------DD
|
// ------DD
|
||||||
// DDDDD000
|
// DDDDD000
|
||||||
// ------DD
|
// ------DD
|
||||||
@@ -353,41 +302,33 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_fr
|
|||||||
ESP_LOGI(TAG, "Partial window data: %02X %02X %02X %02X %02X %02X %02X %02X",
|
ESP_LOGI(TAG, "Partial window data: %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||||
window_data[0], window_data[1], window_data[2], window_data[3], window_data[4],
|
window_data[0], window_data[1], window_data[2], window_data[3], window_data[4],
|
||||||
window_data[5], window_data[6], window_data[7]);
|
window_data[5], window_data[6], window_data[7]);
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0x90, window_data, transaction_guard.transaction_id()); // Set partial window
|
err = epd_write_cmd_with_data(0x90, window_data, transaction_guard.transaction_id()); // Set partial window
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send set partial window command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send set partial window command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5: Write new data (0x13)
|
// Step 4: Write new data (0x13)
|
||||||
{
|
{
|
||||||
err = epd_handler_.epd_write_cmd(0x13, transaction_guard.transaction_id());
|
err = epd_write_cmd(0x13, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send new data command for partial refresh: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send new data command for partial refresh: %s", esp_err_to_name(err));
|
||||||
heap_caps_free(partial_buffer);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send only the partial area data, not the full display buffer
|
// Send only the partial area data, not the full display buffer
|
||||||
ESP_LOGI(TAG, "Sending new partial buffer: %zu bytes (area: %dx%d)",
|
ESP_LOGI(TAG, "Sending partial buffer: %zu bytes (area: %dx%d)",
|
||||||
partial_buffer_size, area_width_bytes * 8, area_height);
|
partial_buffer_size, area_width_bytes * 8, area_height);
|
||||||
err = epd_handler_.transfer_spi_data(partial_buffer, partial_buffer_size, transaction_guard.transaction_id(), true); // Inverted for partial refresh
|
err = transfer_spi_data(partial_framebuffer, partial_buffer_size, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send partial_buffer data for partial refresh: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send partial_framebuffer data for partial refresh: %s", esp_err_to_name(err));
|
||||||
heap_caps_free(partial_buffer);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(old_buffer_, draw_buffer_, DISPLAY_BUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up partial buffer
|
// Step 5: Trigger partial display refresh (DRF) by ending the data write
|
||||||
heap_caps_free(partial_buffer);
|
err = epd_write_cmd(0x11, transaction_guard.transaction_id());
|
||||||
|
|
||||||
// Step 6: Trigger partial display refresh (DRF)
|
|
||||||
// Use 0x12 (Display Update) command - same as full refresh, per sample code
|
|
||||||
err = epd_handler_.epd_write_cmd(0x12, transaction_guard.transaction_id());
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send display refresh command for partial refresh: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send display refresh command for partial refresh: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -395,22 +336,15 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_fr
|
|||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS)); // at least 200us delay
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS)); // at least 200us delay
|
||||||
|
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
// Step 7: Exit partial mode
|
// Step 6: Exit partial mode
|
||||||
err = epd_handler_.epd_write_cmd(0x92, transaction_guard.transaction_id());
|
err = epd_write_cmd(0x92, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to exit partial refresh mode: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to exit partial refresh mode: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "Partial refresh complete");
|
ESP_LOGI(TAG, "Partial refresh complete");
|
||||||
|
|
||||||
err = deep_sleep_display();
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to enter deep sleep after partial refresh: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force_full_refresh_) {
|
if (force_full_refresh_) {
|
||||||
ESP_LOGI(TAG, "Full refresh already requested, skipping partial refresh count increment");
|
ESP_LOGI(TAG, "Full refresh already requested, skipping partial refresh count increment");
|
||||||
err = refresh_display();
|
err = refresh_display();
|
||||||
@@ -420,7 +354,6 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_fr
|
|||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SemaphoreGuard guard(refresh_mutex_);
|
SemaphoreGuard guard(refresh_mutex_);
|
||||||
if (guard.take(pdMS_TO_TICKS(5000)) != pdTRUE) {
|
if (guard.take(pdMS_TO_TICKS(5000)) != pdTRUE) {
|
||||||
@@ -439,9 +372,11 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_fr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = deep_sleep_display();
|
||||||
|
if (err != ESP_OK) {
|
||||||
refresh_area_.reset();
|
ESP_LOGE(TAG, "Failed to enter deep sleep after partial refresh: %s", esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@@ -449,7 +384,7 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_fr
|
|||||||
esp_err_t EInkDisplayHandler::clear_display(void) {
|
esp_err_t EInkDisplayHandler::clear_display(void) {
|
||||||
ESP_LOGI(TAG, "Clearing display to all white...");
|
ESP_LOGI(TAG, "Clearing display to all white...");
|
||||||
|
|
||||||
esp_err_t err = full_write(white_data, false);
|
esp_err_t err = full_write(black_data, false);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to clear display: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to clear display: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -458,19 +393,7 @@ esp_err_t EInkDisplayHandler::clear_display(void) {
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EInkDisplayHandler::write_to_buffer_(const uint8_t* src_buffer, const RefreshArea& area) {
|
|
||||||
// Copy the relevant area from src_buffer to draw_buffer_
|
|
||||||
const uint32_t area_width_bytes = (area.x2 - area.x1 + 1) / 8;
|
|
||||||
const uint32_t area_height = area.y2 - area.y1 + 1;
|
|
||||||
|
|
||||||
for (int32_t row = 0; row < area_height; ++row) {
|
|
||||||
uint32_t fb_y = area.y1 + row;
|
|
||||||
uint32_t fb_x_byte_start = area.x1 / 8;
|
|
||||||
const uint8_t* src_ptr = &src_buffer[row * area_width_bytes];
|
|
||||||
uint8_t* dest_ptr = &draw_buffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
|
||||||
memcpy(dest_ptr, src_ptr, area_width_bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request a full refresh on next flush
|
// Request a full refresh on next flush
|
||||||
void EInkDisplayHandler::request_full_refresh(void) {
|
void EInkDisplayHandler::request_full_refresh(void) {
|
||||||
@@ -484,6 +407,26 @@ void EInkDisplayHandler::request_full_refresh(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if display is busy (refreshing)
|
||||||
|
bool EInkDisplayHandler::is_busy(void) const {
|
||||||
|
return gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL; // BUSY is active LOW
|
||||||
|
}
|
||||||
|
void EInkDisplayHandler::wait_for_idle(void) const {
|
||||||
|
ESP_LOGI(TAG, "Waiting for display ready (BUSY pin)...");
|
||||||
|
int initial_level = gpio_get_level(PIN_BUSY);
|
||||||
|
ESP_LOGI(TAG, "Initial BUSY pin level: %d (0=BUSY, 1=FREE)", initial_level);
|
||||||
|
|
||||||
|
// If already free, no need to wait
|
||||||
|
if (initial_level == BUSY_INACTIVE_LEVEL) {
|
||||||
|
ESP_LOGI(TAG, "Display already ready (BUSY pin = 1)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (gpio_get_level(PIN_BUSY) != BUSY_INACTIVE_LEVEL) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Display is now ready (BUSY pin = 1)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t EInkDisplayHandler::init_devices(EventGroupHandle_t system_event_group) {
|
esp_err_t EInkDisplayHandler::init_devices(EventGroupHandle_t system_event_group) {
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
@@ -492,9 +435,9 @@ esp_err_t EInkDisplayHandler::init_devices(EventGroupHandle_t system_event_group
|
|||||||
ESP_LOGE(TAG, "Failed to initialize display pins: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to initialize display pins: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = this->epd_handler_.init();
|
err = epd_init_();
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to initialize EPD handler: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to initialize EPD: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = init_touch_();
|
err = init_touch_();
|
||||||
@@ -502,6 +445,12 @@ esp_err_t EInkDisplayHandler::init_devices(EventGroupHandle_t system_event_group
|
|||||||
ESP_LOGE(TAG, "Failed to initialize touch: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to initialize touch: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
err = deep_sleep_display();
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to put display into deep sleep: %s", esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
// if system_event_group is provided, set display ready bits
|
// if system_event_group is provided, set display ready bits
|
||||||
if (system_event_group != nullptr) {
|
if (system_event_group != nullptr) {
|
||||||
// Indicate that display is ready
|
// Indicate that display is ready
|
||||||
@@ -540,13 +489,50 @@ esp_err_t EInkDisplayHandler::init_display_pins_(void) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize SPI bus
|
||||||
|
spi_bus_config_t buscfg = {};
|
||||||
|
buscfg.mosi_io_num = 11; // MOSI pin
|
||||||
|
buscfg.miso_io_num = -1; // No MISO for e-paper
|
||||||
|
buscfg.sclk_io_num = 12; // SCK pin
|
||||||
|
buscfg.quadwp_io_num = -1;
|
||||||
|
buscfg.quadhd_io_num = -1;
|
||||||
|
buscfg.max_transfer_sz = DISPLAY_BUFFER_SIZE;
|
||||||
|
|
||||||
|
ret = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add SPI device
|
||||||
|
spi_device_interface_config_t devcfg = {};
|
||||||
|
devcfg.clock_speed_hz = 10 * 1000 * 1000; // 10 MHz
|
||||||
|
devcfg.mode = 0; // SPI mode 0
|
||||||
|
devcfg.spics_io_num = PIN_CS;
|
||||||
|
devcfg.queue_size = 7; // Queue size for non-blocking transactions
|
||||||
|
devcfg.pre_cb = nullptr;
|
||||||
|
|
||||||
|
ret = spi_bus_add_device(SPI2_HOST, &devcfg, &spi_);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to add SPI device: %s", esp_err_to_name(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t EInkDisplayHandler::epd_init_internal_(uint32_t transaction_id) {
|
|
||||||
|
// required to be called by inheriting class after SPI device is created
|
||||||
|
esp_err_t EInkDisplayHandler::epd_init_(void) {
|
||||||
ESP_LOGI(TAG, "Initializing EPD...");
|
ESP_LOGI(TAG, "Initializing EPD...");
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
|
|
||||||
|
{
|
||||||
|
TransactionGuard transaction_guard(*this);
|
||||||
|
esp_err_t begin_err = transaction_guard.begin();
|
||||||
|
if (begin_err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to begin transaction: %s", esp_err_to_name(begin_err));
|
||||||
|
return begin_err;
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Hardware Reset
|
// 1. Hardware Reset
|
||||||
err = gpio_set_level(PIN_RST, 0);
|
err = gpio_set_level(PIN_RST, 0);
|
||||||
@@ -564,20 +550,20 @@ esp_err_t EInkDisplayHandler::epd_init_internal_(uint32_t transaction_id) {
|
|||||||
|
|
||||||
// 2. Initialization Sequence
|
// 2. Initialization Sequence
|
||||||
std::vector<uint8_t> panel_setting_data = { 0x1F };
|
std::vector<uint8_t> panel_setting_data = { 0x1F };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0x00, panel_setting_data, transaction_id); // Panel Setting
|
err = epd_write_cmd_with_data(0x00, panel_setting_data, transaction_guard.transaction_id()); // Panel Setting
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Panel Setting command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Panel Setting command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
||||||
std::vector<uint8_t> vcom_data = { 0x10, 0x07 };
|
std::vector<uint8_t> vcom_data = { 0x10, 0x07 };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0x50, vcom_data, transaction_id); // VCOM
|
err = epd_write_cmd_with_data(0x50, vcom_data, transaction_guard.transaction_id()); // VCOM
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send VCOM command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send VCOM command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
||||||
err = epd_handler_.epd_write_cmd(0x04, transaction_id); // Power ON
|
err = epd_write_cmd(0x04, transaction_guard.transaction_id()); // Power ON
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Power ON command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Power ON command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -588,9 +574,21 @@ esp_err_t EInkDisplayHandler::epd_init_internal_(uint32_t transaction_id) {
|
|||||||
ESP_LOGI(TAG, "Waiting for EPD to be ready after power on...");
|
ESP_LOGI(TAG, "Waiting for EPD to be ready after power on...");
|
||||||
ESP_LOGI(TAG, "BUSY pin level after power on: %d (0=BUSY, 1=FREE)", gpio_get_level(PIN_BUSY));
|
ESP_LOGI(TAG, "BUSY pin level after power on: %d (0=BUSY, 1=FREE)", gpio_get_level(PIN_BUSY));
|
||||||
|
|
||||||
epd_handler_.wait_for_idle();
|
int busy_timeout = 0;
|
||||||
|
while (gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL) { // BUSY is active LOW
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
||||||
|
busy_timeout++;
|
||||||
|
if (busy_timeout > 500) { // 5 second timeout
|
||||||
|
ESP_LOGE(TAG, "EPD power on timeout! BUSY pin stuck at 0");
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
if (busy_timeout % 50 == 0) { // Log every 500ms
|
||||||
|
ESP_LOGW(TAG, "Still waiting for EPD power on, timeout: %d/500", busy_timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "EPD power on complete after %d * 10ms, BUSY pin: %d", busy_timeout, gpio_get_level(PIN_BUSY));
|
||||||
std::vector<uint8_t> booster_data = { 0x27, 0x27, 0x18, 0x17 };
|
std::vector<uint8_t> booster_data = { 0x27, 0x27, 0x18, 0x17 };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0x06, booster_data, transaction_id); // Booster Soft Start
|
err = epd_write_cmd_with_data(0x06, booster_data, transaction_guard.transaction_id()); // Booster Soft Start
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Booster Soft Start command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Booster Soft Start command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -599,23 +597,32 @@ esp_err_t EInkDisplayHandler::epd_init_internal_(uint32_t transaction_id) {
|
|||||||
|
|
||||||
// Enhanced display drive commands
|
// Enhanced display drive commands
|
||||||
std::vector<uint8_t> e0_data = { 0x02 };
|
std::vector<uint8_t> e0_data = { 0x02 };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0xE0, e0_data, transaction_id);
|
err = epd_write_cmd_with_data(0xE0, e0_data, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
std::vector<uint8_t> e5_data = { 0x5A };
|
std::vector<uint8_t> e5_data = { 0x5A };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0xE5, e5_data, transaction_id);
|
err = epd_write_cmd_with_data(0xE5, e5_data, transaction_guard.transaction_id());
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
is_deep_sleep_ = false;
|
is_deep_sleep_ = false;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::epd_init_partial_(void) {
|
||||||
|
TransactionGuard transaction_guard(*this);
|
||||||
|
esp_err_t begin_err = transaction_guard.begin();
|
||||||
|
if (begin_err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to begin transaction: %s", esp_err_to_name(begin_err));
|
||||||
|
return begin_err;
|
||||||
|
}
|
||||||
|
return epd_init_partial_internal_(transaction_guard.transaction_id());
|
||||||
|
}
|
||||||
|
|
||||||
// Internal version that uses an existing transaction (no separate TransactionGuard)
|
// Internal version that uses an existing transaction (no separate TransactionGuard)
|
||||||
esp_err_t EInkDisplayHandler::epd_init_partial_internal_(uint32_t transaction_id) {
|
esp_err_t EInkDisplayHandler::epd_init_partial_internal_(uint32_t transaction_id) {
|
||||||
ESP_LOGI(TAG, "Initializing EPD for partial refresh (internal)...");
|
ESP_LOGI(TAG, "Initializing EPD for partial refresh (internal)...");
|
||||||
@@ -637,7 +644,7 @@ esp_err_t EInkDisplayHandler::epd_init_partial_internal_(uint32_t transaction_id
|
|||||||
|
|
||||||
// 2. Panel Setting
|
// 2. Panel Setting
|
||||||
std::vector<uint8_t> panel_setting_data = { 0x1F };
|
std::vector<uint8_t> panel_setting_data = { 0x1F };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0x00, panel_setting_data, transaction_id);
|
err = epd_write_cmd_with_data(0x00, panel_setting_data, transaction_id);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Panel Setting command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Panel Setting command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
@@ -645,37 +652,30 @@ esp_err_t EInkDisplayHandler::epd_init_partial_internal_(uint32_t transaction_id
|
|||||||
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_PIN_SETUP_DELAY_MS));
|
||||||
|
|
||||||
// 3. Power ON
|
// 3. Power ON
|
||||||
err = epd_handler_.epd_write_cmd(0x04, transaction_id);
|
err = epd_write_cmd(0x04, transaction_id);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Power ON command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Power ON command: %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(MINIMUM_POWER_ON_DELAY_MS));
|
vTaskDelay(pdMS_TO_TICKS(MINIMUM_POWER_ON_DELAY_MS));
|
||||||
epd_handler_.wait_for_idle();
|
wait_for_idle();
|
||||||
|
|
||||||
// 4. Partial initialization sequence - Enhanced Display Drive
|
// 4. Partial initialization sequence - Enhanced Display Drive
|
||||||
std::vector<uint8_t> e0_data = { 0x02 };
|
std::vector<uint8_t> e0_data = { 0x02 };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0xE0, e0_data, transaction_id);
|
err = epd_write_cmd_with_data(0xE0, e0_data, transaction_id);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command (E0): %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command (E0): %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> e5_data = { 0x6E };
|
std::vector<uint8_t> e5_data = { 0x6E };
|
||||||
err = epd_handler_.epd_write_cmd_with_data(0xE5, e5_data, transaction_id);
|
err = epd_write_cmd_with_data(0xE5, e5_data, transaction_id);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command (E5): %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command (E5): %s", esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_deep_sleep_ = false;
|
is_deep_sleep_ = false;
|
||||||
|
|
||||||
err = refresh_old_buffer_(transaction_id);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to refresh old buffer during partial init: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "EPD partial init (internal) complete");
|
ESP_LOGI(TAG, "EPD partial init (internal) complete");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@@ -742,48 +742,201 @@ esp_err_t EInkDisplayHandler::init_touch_() {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t EInkDisplayHandler::refresh_old_buffer_(uint32_t transaction_id) {
|
|
||||||
ESP_LOGI(TAG, "Refreshing display SRAM to restore state after wake...");
|
|
||||||
esp_err_t err;
|
|
||||||
|
|
||||||
err = epd_handler_.epd_write_cmd(0x92, transaction_id); // enter normal mode
|
esp_err_t EInkDisplayHandler::epd_write_cmd(const uint8_t cmd, uint32_t transaction_id) {
|
||||||
|
ESP_LOGI(TAG, "epd_write_cmd: waiting to send 0x%02X", cmd);
|
||||||
|
|
||||||
|
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
||||||
|
esp_err_t err =
|
||||||
|
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to enter normal mode: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending cmd 0x%02X: %s",
|
||||||
|
cmd, esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write OLD data (0x10) as all 0x00 (white in e-ink terms)
|
SemaphoreGuard guard(spi_mutex_);
|
||||||
// This tells the controller: "assume display was all white"
|
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
||||||
// Matches sample's EPD_WhiteScreen_ALL() which uses 0x00 for old SRAM
|
ESP_LOGE(TAG, "SPI mutex timeout for cmd 0x%02X", cmd);
|
||||||
// The differential refresh: old=0 + new=0 → stay white, old=0 + new=1 → drive to black
|
return ESP_ERR_TIMEOUT;
|
||||||
err = epd_handler_.epd_write_cmd(0x10, transaction_id);
|
}
|
||||||
if (err != ESP_OK) {
|
err = dangerous_epd_write_cmd_without_lock_(cmd);
|
||||||
ESP_LOGE(TAG, "Failed to send old data command: %s", esp_err_to_name(err));
|
ESP_LOGI(TAG, "epd_write_cmd: 0x%02X done", cmd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the old buffer as old data
|
esp_err_t EInkDisplayHandler::epd_write_data(const uint8_t data, uint32_t transaction_id) {
|
||||||
err = epd_handler_.transfer_spi_data(old_buffer_, DISPLAY_BUFFER_SIZE, transaction_id);
|
ESP_LOGI(TAG, "epd_write_data: waiting to send 0x%02X", data);
|
||||||
|
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
||||||
|
esp_err_t err =
|
||||||
|
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send white baseline to old SRAM: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending data 0x%02X: %s",
|
||||||
|
data, esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
SemaphoreGuard guard(spi_mutex_);
|
||||||
|
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
||||||
|
ESP_LOGE(TAG, "SPI mutex timeout for data 0x%02X", data);
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
err = dangerous_epd_write_data_without_lock_(data);
|
||||||
|
ESP_LOGI(TAG, "epd_write_data: 0x%02X done", data);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write NEW data (0x13) with the actual display content
|
esp_err_t EInkDisplayHandler::epd_write_cmd_with_data(const uint8_t cmd, std::vector<uint8_t>& data, uint32_t transaction_id) {
|
||||||
// This restores the display to show old_buffer_ content
|
const size_t data_len = data.size();
|
||||||
err = epd_handler_.epd_write_cmd(0x13, transaction_id);
|
ESP_LOGI(TAG, "epd_write_cmd_with_data: waiting to send cmd 0x%02X with %u bytes of data", cmd, data_len);
|
||||||
|
|
||||||
|
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
||||||
|
esp_err_t err =
|
||||||
|
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send new data command: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending cmd 0x%02X: %s, with data",
|
||||||
|
cmd, esp_err_to_name(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the last displayed content to new SRAM
|
SemaphoreGuard guard(spi_mutex_);
|
||||||
err = epd_handler_.transfer_spi_data(old_buffer_, DISPLAY_BUFFER_SIZE, transaction_id);
|
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
||||||
|
ESP_LOGE(TAG, "SPI mutex timeout for cmd with data 0x%02X", cmd);
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
err = dangerous_epd_write_cmd_without_lock_(cmd);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
};
|
||||||
|
for (size_t i = 0; i < data_len; ++i) {
|
||||||
|
err = dangerous_epd_write_data_without_lock_(data[i]);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send display content to new SRAM: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ESP_LOGI(TAG, "Display SRAM restored successfully");
|
ESP_LOGI(TAG, "epd_write_cmd_with_data: cmd 0x%02X with %u bytes of data done", cmd, data_len);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::dangerous_epd_write_cmd_without_lock_(const uint8_t cmd) {
|
||||||
|
ESP_LOGI(TAG, "dangerous_epd_write_cmd_without_lock_: sending 0x%02X", cmd);
|
||||||
|
gpio_set_level(PIN_DC, 0); // Command mode
|
||||||
|
spi_transaction_t t {};
|
||||||
|
t.length = 8;t.tx_buffer = &cmd;
|
||||||
|
esp_err_t err = spi_device_polling_transmit(spi_, &t);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to send data 0x%02X", cmd);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "dangerous_epd_write_cmd_without_lock_: 0x%02X sent", cmd);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::dangerous_epd_write_data_without_lock_(const uint8_t data) {
|
||||||
|
ESP_LOGI(TAG, "dangerous_epd_write_data_without_lock_: sending 0x%02X", data);
|
||||||
|
gpio_set_level(PIN_DC, 1); // Data mode
|
||||||
|
spi_transaction_t t = { };
|
||||||
|
t.length = 8; t.tx_buffer = &data;
|
||||||
|
esp_err_t err = spi_device_polling_transmit(spi_, &t);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to send data 0x%02X", data);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "dangerous_epd_write_data_without_lock_: 0x%02X sent", data);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::transfer_spi_data(const uint8_t* data, const size_t& length, uint32_t transaction_id) {
|
||||||
|
ESP_LOGI(TAG, "transfer_spi_data: waiting to send %zu bytes of data", length);
|
||||||
|
|
||||||
|
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
||||||
|
esp_err_t err =
|
||||||
|
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending data of %zu bytes: %s",
|
||||||
|
length, esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
SemaphoreGuard guard(spi_mutex_);
|
||||||
|
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
||||||
|
ESP_LOGE(TAG, "SPI mutex timeout for data transfer of %zu bytes", length);
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "transfer_spi_data: starting to send %zu bytes of data", length);
|
||||||
|
|
||||||
|
size_t offset = 0;
|
||||||
|
size_t remaining = length;
|
||||||
|
gpio_set_level(PIN_DC, 1); // Data mode
|
||||||
|
while (remaining > 0) {
|
||||||
|
size_t transfer_size = (remaining < DMA_TRANSFER_CHUNK_SIZE) ? remaining : DMA_TRANSFER_CHUNK_SIZE;
|
||||||
|
|
||||||
|
spi_transaction_t t = {};
|
||||||
|
t.length = transfer_size * 8; // Length in bits
|
||||||
|
t.tx_buffer = data + offset;
|
||||||
|
|
||||||
|
esp_err_t ret = spi_device_polling_transmit(spi_, &t);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to send SPI chunk at offset %zu: %s", offset, esp_err_to_name(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining -= transfer_size;
|
||||||
|
offset += transfer_size;
|
||||||
|
|
||||||
|
// Yield every 16KB to prevent watchdog timeout
|
||||||
|
if (offset % (16 * 1024) == 0) {
|
||||||
|
ESP_LOGI(TAG, "New data progress: %zu/%zu bytes sent, yielding...", offset, length);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "transfer_spi_data: completed sending %zu bytes of data", length);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::begin_transaction_(TickType_t timeout, uint32_t& out_id) {
|
||||||
|
ESP_LOGI(TAG, "begin_transaction_: waiting to obtain transaction mutex");
|
||||||
|
if (xSemaphoreTake(spi_transaction_mutex_, timeout) != pdTRUE) {
|
||||||
|
ESP_LOGE(TAG, "begin_transaction_: transaction mutex timeout");
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
out_id = ++spi_transaction_id;
|
||||||
|
ESP_LOGI(TAG, "begin_transaction_: transaction mutex obtained");
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::end_transaction_(void) {
|
||||||
|
ESP_LOGI(TAG, "end_transaction_: releasing transaction mutex");
|
||||||
|
if (xSemaphoreGive(spi_transaction_mutex_) != pdTRUE) {
|
||||||
|
ESP_LOGE(TAG, "end_transaction_: failed to release transaction mutex");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "end_transaction_: transaction mutex released");
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t EInkDisplayHandler::wait_for_transaction_end_(TickType_t timeout, uint32_t awaiting_transaction_id, SemaphoreGuard& out_transaction_guard) {
|
||||||
|
// Validate transaction ID if provided
|
||||||
|
if (awaiting_transaction_id != 0 && awaiting_transaction_id != spi_transaction_id) {
|
||||||
|
// Invalid transaction ID
|
||||||
|
ESP_LOGE(TAG, "Invalid transaction ID 0x%08X while waiting, current transaction ID: 0x%08X",
|
||||||
|
awaiting_transaction_id, spi_transaction_id);
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
||||||
|
if (awaiting_transaction_id == 0) {
|
||||||
|
// wait for current transaction to complete
|
||||||
|
ESP_LOGV(TAG, "Waiting for current transaction 0x%08X to complete",
|
||||||
|
spi_transaction_id);
|
||||||
|
// take the mutex to ensure no transaction is active
|
||||||
|
if (!transaction_guard.take(timeout)) {
|
||||||
|
ESP_LOGE(TAG, "SPI transaction mutex timeout while waiting for transaction end");
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// awaited_transaction_id is valid and matches current transaction ID or 0
|
||||||
|
out_transaction_guard = std::move(transaction_guard);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
661
main/display/eink_display_handler.cpp.old
Normal file
661
main/display/eink_display_handler.cpp.old
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
#include "display/eink_display_handler.h"
|
||||||
|
#include "display/constants.h"
|
||||||
|
#include "common/constants.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
#include "esp_task_wdt.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#define TAG "EInkDisplayHandler"
|
||||||
|
#define BUSY_ACTIVE_LEVEL 0 // BUSY pin is active low
|
||||||
|
#define BUSY_INACTIVE_LEVEL 1
|
||||||
|
|
||||||
|
EInkDisplayHandler::EInkDisplayHandler(EventGroupHandle_t system_event_group)
|
||||||
|
: DisplayHandler(system_event_group) {
|
||||||
|
_refresh_mutex = xSemaphoreCreateMutex();
|
||||||
|
if (_refresh_mutex == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create refresh mutex");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EInkDisplayHandler::~EInkDisplayHandler() {
|
||||||
|
if (_refresh_task_handle != nullptr) {
|
||||||
|
vTaskDelete(_refresh_task_handle);
|
||||||
|
}
|
||||||
|
if (_touch_task_handle != nullptr) {
|
||||||
|
vTaskDelete(_touch_task_handle);
|
||||||
|
}
|
||||||
|
if (_refresh_queue != nullptr) {
|
||||||
|
vQueueDelete(_refresh_queue);
|
||||||
|
}
|
||||||
|
if (_lvgl_display != nullptr) {
|
||||||
|
lv_display_delete(_lvgl_display);
|
||||||
|
_lvgl_display = nullptr;
|
||||||
|
if (_lvgl_draw_buf != nullptr) {
|
||||||
|
lv_draw_buf_destroy(_lvgl_draw_buf);
|
||||||
|
_lvgl_draw_buf = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_lvgl_touch_indev != nullptr) {
|
||||||
|
lvgl_port_remove_touch(_lvgl_touch_indev);
|
||||||
|
}
|
||||||
|
if (_framebuffer != nullptr) {
|
||||||
|
heap_caps_free(_framebuffer);
|
||||||
|
}
|
||||||
|
if (_refresh_mutex != nullptr) {
|
||||||
|
vSemaphoreDelete(_refresh_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::init() {
|
||||||
|
ESP_LOGI(TAG, "Initializing E-Ink display handler...");
|
||||||
|
|
||||||
|
// Initialize GPIO pins
|
||||||
|
gpio_config_t io_conf = {};
|
||||||
|
io_conf.pin_bit_mask = (1ULL << PIN_DC) | (1ULL << PIN_RST);
|
||||||
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
|
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
|
||||||
|
// Configure BUSY pin as input (no pull-up like sample code)
|
||||||
|
io_conf.pin_bit_mask = (1ULL << PIN_BUSY);
|
||||||
|
io_conf.mode = GPIO_MODE_INPUT;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
|
||||||
|
// Initialize SPI bus
|
||||||
|
spi_bus_config_t buscfg = {};
|
||||||
|
buscfg.mosi_io_num = 11; // MOSI pin
|
||||||
|
buscfg.miso_io_num = -1; // No MISO for e-paper
|
||||||
|
buscfg.sclk_io_num = 12; // SCK pin
|
||||||
|
buscfg.quadwp_io_num = -1;
|
||||||
|
buscfg.quadhd_io_num = -1;
|
||||||
|
buscfg.max_transfer_sz = DISPLAY_BUFFER_SIZE;
|
||||||
|
|
||||||
|
esp_err_t ret = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add SPI device
|
||||||
|
spi_device_interface_config_t devcfg = {};
|
||||||
|
devcfg.clock_speed_hz = 6 * 1000 * 1000; // 6 MHz (reduced for reliability)
|
||||||
|
devcfg.mode = 0; // SPI mode 0
|
||||||
|
devcfg.spics_io_num = PIN_CS;
|
||||||
|
devcfg.queue_size = 7; // Queue size for non-blocking transactions
|
||||||
|
devcfg.pre_cb = nullptr;
|
||||||
|
|
||||||
|
ret = spi_bus_add_device(SPI2_HOST, &devcfg, &_spi);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to add SPI device: %s", esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize base display and touch devices
|
||||||
|
init_devices(false); // Don't set ready bit yet
|
||||||
|
|
||||||
|
// Create refresh queue (queue 5 refresh requests)
|
||||||
|
_refresh_queue = xQueueCreate(5, sizeof(bool));
|
||||||
|
if (_refresh_queue == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create refresh queue");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create refresh task
|
||||||
|
BaseType_t ret_task = xTaskCreatePinnedToCore(
|
||||||
|
_refresh_task,
|
||||||
|
"eink_refresh",
|
||||||
|
8192,
|
||||||
|
this,
|
||||||
|
5, // Priority - lower than LVGL task
|
||||||
|
&_refresh_task_handle,
|
||||||
|
1 // Pin to core 1
|
||||||
|
);
|
||||||
|
if (ret_task != pdPASS) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create refresh task");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate framebuffer - try PSRAM first, fallback to internal RAM
|
||||||
|
// Note: Internal framebuffer excludes the 8-byte palette (raw pixel data only)
|
||||||
|
const size_t fb_size = DISPLAY_BUFFER_SIZE - 8; // Exclude palette from internal storage
|
||||||
|
_framebuffer = (uint8_t*)heap_caps_malloc(fb_size, MALLOC_CAP_SPIRAM);
|
||||||
|
if (_framebuffer != nullptr) {
|
||||||
|
_framebuffer_in_psram = true;
|
||||||
|
ESP_LOGI(TAG, "Framebuffer allocated in PSRAM (%zu bytes, LVGL buffer: %d bytes)",
|
||||||
|
fb_size, DISPLAY_BUFFER_SIZE);
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "PSRAM not available, allocating framebuffer in internal RAM");
|
||||||
|
_framebuffer = (uint8_t*)heap_caps_malloc(fb_size, MALLOC_CAP_INTERNAL);
|
||||||
|
_framebuffer_in_psram = false;
|
||||||
|
if (_framebuffer == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to allocate framebuffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Framebuffer allocated in internal RAM (%zu bytes, LVGL buffer: %d bytes)",
|
||||||
|
fb_size, DISPLAY_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
memset(_framebuffer, 0xFF, fb_size); // Initialize to white
|
||||||
|
|
||||||
|
// Perform initial full refresh to clear display BEFORE creating LVGL display
|
||||||
|
// This prevents LVGL from trying to render during the initial clear
|
||||||
|
ESP_LOGI(TAG, "Performing initial display clear...");
|
||||||
|
_perform_full_refresh(_framebuffer);
|
||||||
|
ESP_LOGI(TAG, "Initial display clear complete");
|
||||||
|
|
||||||
|
// Create LVGL display manually (no esp_lcd panel for e-paper)
|
||||||
|
lv_display_t* disp = lv_display_create(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||||
|
if (disp == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create LVGL display");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 1-bit e-paper display */
|
||||||
|
lv_display_set_color_format(disp, LV_COLOR_FORMAT_I1);
|
||||||
|
|
||||||
|
/* Disable antialiasing for monochrome display to ensure crisp 1px lines */
|
||||||
|
lv_display_set_antialiasing(disp, false);
|
||||||
|
|
||||||
|
/* Create a draw buffer covering ~40 lines */
|
||||||
|
_lvgl_draw_buf = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
||||||
|
if (_lvgl_draw_buf == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create LVGL draw buffer");
|
||||||
|
lv_display_delete(disp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_display_set_draw_buffers(disp, _lvgl_draw_buf, NULL);
|
||||||
|
lv_display_set_render_mode(disp, LV_DISPLAY_RENDER_MODE_DIRECT);
|
||||||
|
|
||||||
|
// Set custom flush callback and user data
|
||||||
|
lv_display_set_flush_cb(disp, _lvgl_flush_cb);
|
||||||
|
lv_display_set_user_data(disp, this);
|
||||||
|
|
||||||
|
_lvgl_display = disp;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "LVGL display registered");
|
||||||
|
|
||||||
|
// Register GT911 touch input with LVGL, only if touch handle is valid
|
||||||
|
esp_lcd_touch_handle_t tp_handle = get_touch_handle();
|
||||||
|
if (tp_handle == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Touch handle is NULL — touch initialization failed; skipping LVGL touch registration");
|
||||||
|
} else {
|
||||||
|
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||||
|
.disp = _lvgl_display,
|
||||||
|
.handle = tp_handle,
|
||||||
|
.scale = {}, // Default scaling
|
||||||
|
};
|
||||||
|
|
||||||
|
_lvgl_touch_indev = lvgl_port_add_touch(&touch_cfg);
|
||||||
|
if (_lvgl_touch_indev == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to register LVGL touch input");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override touch read callback to check BUSY pin
|
||||||
|
lv_indev_set_read_cb(_lvgl_touch_indev, _lvgl_touch_read_cb);
|
||||||
|
lv_indev_set_user_data(_lvgl_touch_indev, this);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "LVGL touch input registered");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set display ready bits
|
||||||
|
xEventGroupSetBits(_system_event_group, DISPLAY_READY_BIT | TOUCH_CALIBRATED_BIT);
|
||||||
|
ESP_LOGI(TAG, "E-Ink display handler initialized successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::start_touch_task() {
|
||||||
|
// Note: With lvgl_port_add_touch, the ESP-IDF LVGL port handles touch reading internally
|
||||||
|
// We don't need a separate touch task unless we want custom processing
|
||||||
|
ESP_LOGI(TAG, "Touch input handled by LVGL port");
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::request_full_refresh() {
|
||||||
|
if (xSemaphoreTake(_refresh_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
|
||||||
|
_force_full_refresh = true;
|
||||||
|
_partial_refresh_count = 0;
|
||||||
|
xSemaphoreGive(_refresh_mutex);
|
||||||
|
ESP_LOGI(TAG, "Full refresh requested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EInkDisplayHandler::is_busy() const {
|
||||||
|
return gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL; // BUSY is active LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_lvgl_flush_cb(lv_display_t* disp, const lv_area_t* area, uint8_t* px_map) {
|
||||||
|
EInkDisplayHandler* handler = static_cast<EInkDisplayHandler*>(lv_display_get_user_data(disp));
|
||||||
|
if (handler == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Invalid handler in flush callback");
|
||||||
|
lv_display_flush_ready(disp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if display is busy with detailed logging
|
||||||
|
int busy_level = gpio_get_level(PIN_BUSY);
|
||||||
|
ESP_LOGI(TAG, "Flush callback: BUSY pin = %d, is_busy() = %d", busy_level, handler->is_busy());
|
||||||
|
|
||||||
|
if (handler->is_busy()) {
|
||||||
|
ESP_LOGW(TAG, "Display busy (BUSY pin = 0), skipping flush");
|
||||||
|
lv_display_flush_ready(disp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for any ongoing refresh to complete
|
||||||
|
handler->_wait_for_busy();
|
||||||
|
|
||||||
|
bool perform_full_refresh = false;
|
||||||
|
|
||||||
|
if (xSemaphoreTake(handler->_refresh_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
|
||||||
|
// Check if full refresh is needed
|
||||||
|
if (handler->_force_full_refresh) {
|
||||||
|
perform_full_refresh = true;
|
||||||
|
handler->_force_full_refresh = false;
|
||||||
|
handler->_partial_refresh_count = 0;
|
||||||
|
} else {
|
||||||
|
handler->_partial_refresh_count++;
|
||||||
|
if (handler->_partial_refresh_count >= PARTIAL_REFRESH_THRESHOLD) {
|
||||||
|
perform_full_refresh = true;
|
||||||
|
handler->_partial_refresh_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xSemaphoreGive(handler->_refresh_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy LVGL buffer to framebuffer
|
||||||
|
// For 1-bit mode, LVGL provides data in packed format (8 pixels per byte)
|
||||||
|
// CRITICAL: Skip first 8 bytes (LVGL I1 palette) as per LVGL documentation
|
||||||
|
uint8_t* pixel_data = px_map + 8; // Skip 8-byte palette
|
||||||
|
int32_t w = lv_area_get_width(area);
|
||||||
|
int32_t h = lv_area_get_height(area);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Flushing area: x=%d, y=%d, w=%d, h=%d, full_refresh=%d",
|
||||||
|
area->x1, area->y1, w, h, perform_full_refresh);
|
||||||
|
ESP_LOGI(TAG, "Buffer: px_map=%p, pixel_data=%p, palette skipped: %d bytes",
|
||||||
|
(void*)px_map, (void*)pixel_data, 8);
|
||||||
|
|
||||||
|
// Check if this is a full screen update - if so, simple copy
|
||||||
|
if (area->x1 == 0 && area->y1 == 0 && w == DISPLAY_WIDTH && h == DISPLAY_HEIGHT) {
|
||||||
|
ESP_LOGI(TAG, "Full screen update, direct copy (skipping palette)");
|
||||||
|
memcpy(handler->_framebuffer, pixel_data, DISPLAY_BUFFER_SIZE - 8);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Partial area update");
|
||||||
|
// In DIRECT render mode, px_map points to the full screen buffer
|
||||||
|
// The stride is always the full display width
|
||||||
|
const uint32_t stride = DISPLAY_WIDTH / 8; // 800 / 8 = 100 bytes per row
|
||||||
|
|
||||||
|
// Check if we can do row-by-row copy (byte-aligned on both x1 and width)
|
||||||
|
bool byte_aligned = (area->x1 % 8 == 0) && (w % 8 == 0);
|
||||||
|
|
||||||
|
if (byte_aligned) {
|
||||||
|
// Optimized: byte-aligned row copy
|
||||||
|
ESP_LOGI(TAG, "Byte-aligned copy: x=%ld, y=%ld, w=%ld, h=%ld",
|
||||||
|
(long)area->x1, (long)area->y1, (long)w, (long)h);
|
||||||
|
|
||||||
|
uint32_t x_byte = area->x1 / 8;
|
||||||
|
uint32_t width_bytes = w / 8;
|
||||||
|
|
||||||
|
for (int32_t y = 0; y < h; y++) {
|
||||||
|
int32_t fb_y = area->y1 + y;
|
||||||
|
if (fb_y >= DISPLAY_HEIGHT) break;
|
||||||
|
|
||||||
|
uint8_t* src = pixel_data + (fb_y * stride + x_byte);
|
||||||
|
uint8_t* dst = handler->_framebuffer + (fb_y * stride + x_byte);
|
||||||
|
memcpy(dst, src, width_bytes);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Bit-level copy for non-aligned regions
|
||||||
|
ESP_LOGI(TAG, "Bit-level copy: x=%ld, y=%ld, w=%ld, h=%ld",
|
||||||
|
(long)area->x1, (long)area->y1, (long)w, (long)h);
|
||||||
|
|
||||||
|
for (int32_t y = 0; y < h; y++) {
|
||||||
|
int32_t fb_y = area->y1 + y;
|
||||||
|
if (fb_y >= DISPLAY_HEIGHT) break;
|
||||||
|
|
||||||
|
for (int32_t x = 0; x < w; x++) {
|
||||||
|
int32_t fb_x = area->x1 + x;
|
||||||
|
if (fb_x >= DISPLAY_WIDTH) break;
|
||||||
|
|
||||||
|
// Get pixel from source buffer (using full screen coordinates)
|
||||||
|
size_t src_byte_idx = fb_y * stride + (fb_x / 8);
|
||||||
|
size_t src_bit_idx = fb_x % 8;
|
||||||
|
uint8_t src_bit = (pixel_data[src_byte_idx] >> (7 - src_bit_idx)) & 0x01;
|
||||||
|
|
||||||
|
// Set pixel in destination buffer
|
||||||
|
size_t dst_byte_idx = fb_y * stride + (fb_x / 8);
|
||||||
|
size_t dst_bit_idx = fb_x % 8;
|
||||||
|
|
||||||
|
if (dst_byte_idx < (DISPLAY_BUFFER_SIZE - 8)) {
|
||||||
|
if (src_bit) {
|
||||||
|
handler->_framebuffer[dst_byte_idx] |= (1 << (7 - dst_bit_idx));
|
||||||
|
} else {
|
||||||
|
handler->_framebuffer[dst_byte_idx] &= ~(1 << (7 - dst_bit_idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue refresh request (non-blocking)
|
||||||
|
if (handler->_refresh_queue != nullptr) {
|
||||||
|
if (xQueueSend(handler->_refresh_queue, &perform_full_refresh, 0) != pdPASS) {
|
||||||
|
ESP_LOGW(TAG, "Refresh queue full, skipping refresh");
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Queued %s refresh", perform_full_refresh ? "full" : "partial");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_display_flush_ready(disp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_lvgl_touch_read_cb(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||||
|
EInkDisplayHandler* handler = static_cast<EInkDisplayHandler*>(lv_indev_get_user_data(indev));
|
||||||
|
|
||||||
|
// Disable touch input during display refresh (BUSY)
|
||||||
|
if (handler->is_busy()) {
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
data->continue_reading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_lcd_touch_handle_t tp_handle = handler->get_touch_handle();
|
||||||
|
if (tp_handle == nullptr) {
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Read touch data from GT911
|
||||||
|
esp_err_t ret = esp_lcd_touch_read_data(tp_handle);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
uint8_t touch_cnt = 0;
|
||||||
|
// Get touch data using new API
|
||||||
|
esp_lcd_touch_point_data_t point_data[1];
|
||||||
|
esp_lcd_touch_get_data(tp_handle, point_data, &touch_cnt, 1);
|
||||||
|
|
||||||
|
if (touch_cnt > 0) {
|
||||||
|
ESP_LOGI(TAG, "Touch data read successfully: x=%d, y=%d", point_data[0].x, point_data[0].y);
|
||||||
|
data->point.x = point_data[0].x;
|
||||||
|
data->point.y = point_data[0].y;
|
||||||
|
data->state = LV_INDEV_STATE_PRESSED;
|
||||||
|
} else {
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->continue_reading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_perform_full_refresh(const uint8_t* framebuffer) {
|
||||||
|
ESP_LOGI(TAG, "Starting full refresh (3 seconds)...");
|
||||||
|
|
||||||
|
_wait_for_busy();
|
||||||
|
|
||||||
|
// Step 1: Write old data (0x10) - Arduino uses 0xFF (all white) for base map
|
||||||
|
epd_write_cmd(0x10);
|
||||||
|
|
||||||
|
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
|
||||||
|
ESP_LOGE(TAG, "SPI mutex timeout in full refresh step 1");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gpio_set_level(PIN_DC, 1); // Data mode
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Starting SPI data transmission for old data (0x10)...");
|
||||||
|
|
||||||
|
// Send 0xFF (white) for all old data, matching Arduino EPD_SetRAMValue_BaseMap
|
||||||
|
// Use DMA transfers in chunks for better performance
|
||||||
|
static uint8_t white_buffer[4096]; // 4KB chunk buffer
|
||||||
|
memset(white_buffer, 0xFF, sizeof(white_buffer));
|
||||||
|
|
||||||
|
const size_t CHUNK_SIZE = sizeof(white_buffer);
|
||||||
|
size_t remaining = DISPLAY_BUFFER_SIZE - 8; // Exclude palette from transmission
|
||||||
|
size_t offset = 0;
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
size_t transfer_size = (remaining < CHUNK_SIZE) ? remaining : CHUNK_SIZE;
|
||||||
|
|
||||||
|
spi_transaction_t t = {};
|
||||||
|
t.length = transfer_size * 8; // Length in bits
|
||||||
|
t.tx_buffer = white_buffer;
|
||||||
|
|
||||||
|
esp_err_t ret = spi_device_polling_transmit(_spi, &t);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to send SPI chunk at offset %zu: %s", offset, esp_err_to_name(ret));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining -= transfer_size;
|
||||||
|
offset += transfer_size;
|
||||||
|
|
||||||
|
// Yield every 16KB to prevent watchdog timeout
|
||||||
|
if (offset % (16 * 1024) == 0) {
|
||||||
|
ESP_LOGI(TAG, "Old data progress: %zu/%zu bytes (%.1f%%)", offset, remaining,
|
||||||
|
(float)offset * 100.0f / (float)remaining);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Completed SPI data transmission for old data");
|
||||||
|
xSemaphoreGive(_spi_mutex);
|
||||||
|
|
||||||
|
// Step 2: Write new data (0x13)
|
||||||
|
epd_write_cmd(0x13);
|
||||||
|
|
||||||
|
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
|
||||||
|
ESP_LOGE(TAG, "SPI mutex timeout in full refresh step 2");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gpio_set_level(PIN_DC, 1); // Data mode
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Starting SPI data transmission for new data (0x13)...");
|
||||||
|
|
||||||
|
// Send actual framebuffer data in chunks using DMA for better performance
|
||||||
|
offset = 0;
|
||||||
|
remaining = DISPLAY_BUFFER_SIZE - 8; // Reset remaining for step 2
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
size_t transfer_size = (remaining < CHUNK_SIZE) ? remaining : CHUNK_SIZE;
|
||||||
|
|
||||||
|
spi_transaction_t t = {};
|
||||||
|
t.length = transfer_size * 8; // Length in bits
|
||||||
|
t.tx_buffer = framebuffer + offset;
|
||||||
|
|
||||||
|
esp_err_t ret = spi_device_polling_transmit(_spi, &t);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to send SPI chunk at offset %zu: %s", offset, esp_err_to_name(ret));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining -= transfer_size;
|
||||||
|
offset += transfer_size;
|
||||||
|
|
||||||
|
// Yield every 16KB to prevent watchdog timeout
|
||||||
|
if (offset % (16 * 1024) == 0) {
|
||||||
|
ESP_LOGI(TAG, "New data progress: %zu/%zu bytes (%.1f%%)", offset, remaining,
|
||||||
|
(float)offset * 100.0f / (float)remaining);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Completed SPI data transmission for new data");
|
||||||
|
xSemaphoreGive(_spi_mutex);
|
||||||
|
|
||||||
|
// Step 3: Trigger display refresh (DRF)
|
||||||
|
epd_write_cmd(0x12);
|
||||||
|
// Critical delay - sample code says "!!!The delay here is necessary, 200uS at least!!!"
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
ESP_LOGI(TAG, "Display refresh triggered, BUSY pin: %d", gpio_get_level(PIN_BUSY));
|
||||||
|
|
||||||
|
// Wait for refresh to complete
|
||||||
|
_wait_for_busy();
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Full refresh complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_perform_partial_refresh(const uint8_t* framebuffer) {
|
||||||
|
ESP_LOGI(TAG, "Starting partial refresh (0.3 seconds)...");
|
||||||
|
|
||||||
|
_wait_for_busy();
|
||||||
|
|
||||||
|
// Step 1: Configure VCOM for partial refresh
|
||||||
|
const uint8_t vcom_data[] = { 0xA9, 0x07 };
|
||||||
|
epd_write_cmd_with_data(0x50, vcom_data, 2);
|
||||||
|
|
||||||
|
// Step 2: Enter partial refresh mode
|
||||||
|
epd_write_cmd(0x91);
|
||||||
|
|
||||||
|
// Step 3: Define partial window (full screen for now)
|
||||||
|
// Format: 0x90 + 9 bytes (x_start_H, x_start_L, x_end_H, x_end_L, y_start_H, y_start_L, y_end_H, y_end_L, 0x01)
|
||||||
|
// For full screen: x=0 to 799 (0x031F), y=0 to 479 (0x01DF)
|
||||||
|
const uint8_t window_data[] = {
|
||||||
|
0x00, 0x00, // x_start = 0
|
||||||
|
0x03, 0x1F, // x_end = 799 (0x31F)
|
||||||
|
0x00, 0x00, // y_start = 0
|
||||||
|
0x01, 0xDF, // y_end = 479 (0x1DF)
|
||||||
|
0x01 // PT_SCAN
|
||||||
|
};
|
||||||
|
epd_write_cmd_with_data(0x90, window_data, 9);
|
||||||
|
|
||||||
|
// Step 4: Write new data (0x13 command)
|
||||||
|
epd_write_cmd(0x13);
|
||||||
|
|
||||||
|
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
|
||||||
|
ESP_LOGE(TAG, "SPI mutex timeout in partial refresh");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gpio_set_level(PIN_DC, 1); // Data mode
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Starting SPI data transmission for partial refresh...");
|
||||||
|
|
||||||
|
// Send framebuffer data in chunks using DMA for better performance
|
||||||
|
const size_t CHUNK_SIZE = 4096; // 4KB chunks
|
||||||
|
size_t remaining = DISPLAY_BUFFER_SIZE - 8; // Exclude palette from transmission
|
||||||
|
size_t offset = 0;
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
size_t transfer_size = (remaining < CHUNK_SIZE) ? remaining : CHUNK_SIZE;
|
||||||
|
|
||||||
|
spi_transaction_t t = {};
|
||||||
|
t.length = transfer_size * 8; // Length in bits
|
||||||
|
t.tx_buffer = framebuffer + offset;
|
||||||
|
|
||||||
|
esp_err_t ret = spi_device_polling_transmit(_spi, &t);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to send SPI chunk at offset %zu: %s", offset, esp_err_to_name(ret));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining -= transfer_size;
|
||||||
|
offset += transfer_size;
|
||||||
|
|
||||||
|
// Yield every 16KB to prevent watchdog timeout
|
||||||
|
if (offset % (16 * 1024) == 0) {
|
||||||
|
ESP_LOGI(TAG, "Partial refresh progress: %zu/%zu bytes (%.1f%%)", offset, remaining,
|
||||||
|
(float)offset * 100.0f / (float)remaining);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Completed SPI data transmission for partial refresh");
|
||||||
|
xSemaphoreGive(_spi_mutex);
|
||||||
|
|
||||||
|
// Step 5: Trigger partial display refresh (DRF)
|
||||||
|
epd_write_cmd(0x12);
|
||||||
|
// Critical delay - sample code says "!!!The delay here is necessary, 200uS at least!!!"
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
ESP_LOGI(TAG, "Partial refresh triggered, BUSY pin: %d", gpio_get_level(PIN_BUSY));
|
||||||
|
|
||||||
|
// Wait for refresh to complete
|
||||||
|
_wait_for_busy();
|
||||||
|
|
||||||
|
// Step 6: Exit partial refresh mode
|
||||||
|
epd_write_cmd(0x92);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Partial refresh complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_refresh_task(void* param) {
|
||||||
|
EInkDisplayHandler* handler = static_cast<EInkDisplayHandler*>(param);
|
||||||
|
bool perform_full_refresh = false;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Refresh task started");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
// Wait for refresh request
|
||||||
|
if (xQueueReceive(handler->_refresh_queue, &perform_full_refresh, portMAX_DELAY) == pdTRUE) {
|
||||||
|
// Perform the requested refresh type
|
||||||
|
if (perform_full_refresh) {
|
||||||
|
ESP_LOGI(TAG, "Refresh task: Performing full refresh...");
|
||||||
|
handler->_perform_full_refresh(handler->_framebuffer);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Refresh task: Performing partial refresh...");
|
||||||
|
handler->_perform_partial_refresh(handler->_framebuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_wait_for_busy() {
|
||||||
|
ESP_LOGI(TAG, "Waiting for display ready (BUSY pin)...");
|
||||||
|
int initial_level = gpio_get_level(PIN_BUSY);
|
||||||
|
ESP_LOGI(TAG, "Initial BUSY pin level: %d (0=BUSY, 1=FREE)", initial_level);
|
||||||
|
|
||||||
|
// If already free, no need to wait
|
||||||
|
if (initial_level == BUSY_INACTIVE_LEVEL) {
|
||||||
|
ESP_LOGI(TAG, "Display already ready (BUSY pin = 1)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int timeout = 0;
|
||||||
|
while (gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL) { // 0=BUSY, 1=FREE
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
timeout++;
|
||||||
|
if (timeout > 100) { // 10 second timeout
|
||||||
|
ESP_LOGE(TAG, "Display BUSY timeout! Pin level: %d", gpio_get_level(PIN_BUSY));
|
||||||
|
ESP_LOGW(TAG, "Attempting hardware reset...");
|
||||||
|
|
||||||
|
// Hardware reset sequence
|
||||||
|
gpio_set_level(PIN_RST, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
gpio_set_level(PIN_RST, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// Re-initialize display
|
||||||
|
ESP_LOGI(TAG, "Re-initializing display after reset...");
|
||||||
|
_epd_init();
|
||||||
|
|
||||||
|
// Check if reset worked
|
||||||
|
int reset_timeout = 0;
|
||||||
|
while (gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
reset_timeout++;
|
||||||
|
if (reset_timeout > 50) { // 5 second timeout after reset
|
||||||
|
ESP_LOGE(TAG, "Display reset failed! Still busy after reset.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gpio_get_level(PIN_BUSY) != BUSY_ACTIVE_LEVEL) {
|
||||||
|
ESP_LOGI(TAG, "Display reset successful after %d tenths of a second", reset_timeout);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log every 2 seconds to track progress
|
||||||
|
if (timeout % 20 == 0) {
|
||||||
|
ESP_LOGW(TAG, "Still waiting for BUSY pin, timeout: %d/100, level: %d",
|
||||||
|
timeout, gpio_get_level(PIN_BUSY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Display ready after %d tenths of a second", timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EInkDisplayHandler::_convert_buffer_to_epaper(const uint8_t* lvgl_buf, uint8_t* epd_buf, size_t size) {
|
||||||
|
// LVGL 1-bit format is already compatible with e-paper
|
||||||
|
// Just copy directly
|
||||||
|
memcpy(epd_buf, lvgl_buf, size);
|
||||||
|
}
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
#include "common/semaphore_guard.h"
|
#include "common/semaphore_guard.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include "epd_handler.h"
|
|
||||||
|
|
||||||
// Refresh mode configuration
|
// Refresh mode configuration
|
||||||
|
#define PARTIAL_REFRESH_THRESHOLD 10 // Full refresh every N partial refreshes
|
||||||
#define DISPLAY_WIDTH 800
|
#define DISPLAY_WIDTH 800
|
||||||
#define DISPLAY_HEIGHT 480
|
#define DISPLAY_HEIGHT 480
|
||||||
|
|
||||||
@@ -56,43 +56,71 @@ public:
|
|||||||
|
|
||||||
esp_err_t refresh_display(void);
|
esp_err_t refresh_display(void);
|
||||||
esp_err_t full_write(const uint8_t* framebuffer, const bool white_basemap = true);
|
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, const bool is_last_partial_update = true);
|
esp_err_t partial_refresh(const uint8_t* framebuffer, const RefreshArea& area);
|
||||||
esp_err_t clear_display(void);
|
esp_err_t clear_display(void);
|
||||||
esp_err_t deep_sleep_display(void);
|
esp_err_t deep_sleep_display(void);
|
||||||
// Request a full refresh on next flush
|
// Request a full refresh on next flush
|
||||||
void request_full_refresh(void);
|
void request_full_refresh(void);
|
||||||
|
|
||||||
bool is_busy() {
|
// Check if display is busy (refreshing)
|
||||||
return epd_handler_.is_busy();
|
bool is_busy(void) const;
|
||||||
}
|
void wait_for_idle(void) const;
|
||||||
|
|
||||||
esp_lcd_touch_handle_t get_touch_handle() const { return tp_handle_; }
|
esp_lcd_touch_handle_t get_touch_handle() const { return tp_handle_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
esp_err_t epd_write_cmd(const uint8_t cmd, uint32_t transaction_id);
|
||||||
|
esp_err_t epd_write_data(const uint8_t data, uint32_t transaction_id);
|
||||||
|
esp_err_t epd_write_cmd_with_data(const uint8_t cmd, std::vector<uint8_t>& data, uint32_t transaction_id);
|
||||||
|
esp_err_t transfer_spi_data(const uint8_t* data, const size_t& length, uint32_t transaction_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
esp_err_t init_display_pins_(void);
|
esp_err_t init_display_pins_(void);
|
||||||
esp_err_t epd_init_internal_(uint32_t transaction_id); // full fast refresh init
|
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 epd_init_partial_internal_(uint32_t transaction_id); // partial refresh init (within existing transaction)
|
||||||
esp_err_t init_touch_(void);
|
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);
|
||||||
|
|
||||||
// write to the internal draw buffer
|
esp_err_t begin_transaction_(TickType_t timeout, uint32_t& out_id);
|
||||||
void write_to_buffer_(const uint8_t* src, const RefreshArea& area);
|
esp_err_t end_transaction_(void);
|
||||||
// write the internal draw buffer to the display's old sram
|
// given a transaction ID, wait for current transaction to complete. The transaction ID will determine if the wait is needed.
|
||||||
esp_err_t refresh_old_buffer_(uint32_t transaction_id);
|
esp_err_t wait_for_transaction_end_(TickType_t timeout, uint32_t awaiting_transaction_id, SemaphoreGuard& out_transaction_guard);
|
||||||
|
|
||||||
|
friend class TransactionGuard;
|
||||||
|
|
||||||
EPDHandler epd_handler_;
|
|
||||||
uint32_t partial_refresh_count_ = 0;
|
uint32_t partial_refresh_count_ = 0;
|
||||||
bool force_full_refresh_ = false;
|
bool force_full_refresh_ = false;
|
||||||
std::atomic<bool> is_deep_sleep_ { false };
|
std::atomic<bool> is_deep_sleep_ { false };
|
||||||
|
|
||||||
|
SemaphoreHandle_t spi_mutex_ = nullptr;
|
||||||
|
SemaphoreHandle_t spi_transaction_mutex_ = nullptr;
|
||||||
SemaphoreHandle_t refresh_mutex_ = nullptr;
|
SemaphoreHandle_t refresh_mutex_ = nullptr;
|
||||||
|
uint32_t spi_transaction_id = 0; // For tracking SPI transactions
|
||||||
|
spi_device_handle_t spi_ = nullptr;
|
||||||
esp_lcd_panel_io_handle_t tp_io_handle_ = nullptr;
|
esp_lcd_panel_io_handle_t tp_io_handle_ = nullptr;
|
||||||
esp_lcd_touch_handle_t tp_handle_ = nullptr;
|
esp_lcd_touch_handle_t tp_handle_ = nullptr;
|
||||||
|
|
||||||
// this buffer reflects the current display state (1=black, 0=white)
|
|
||||||
uint8_t* draw_buffer_ = nullptr;
|
|
||||||
uint8_t* old_buffer_ = nullptr;
|
|
||||||
RefreshArea refresh_area_ = { 0, 0, 0, 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TransactionGuard {
|
||||||
|
public:
|
||||||
|
TransactionGuard(EInkDisplayHandler& handler, TickType_t timeout = portMAX_DELAY)
|
||||||
|
: handler_(handler) { }
|
||||||
|
~TransactionGuard() { if (transaction_id_) handler_.end_transaction_(); }
|
||||||
|
|
||||||
|
esp_err_t begin(TickType_t timeout = portMAX_DELAY) {
|
||||||
|
esp_err_t err = handler_.begin_transaction_(timeout, transaction_id_);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
uint32_t transaction_id() const { return transaction_id_; }
|
||||||
|
bool is_active() const { return transaction_id_ != 0; }
|
||||||
|
private:
|
||||||
|
// delete copy constructor and assignment operator
|
||||||
|
TransactionGuard(const TransactionGuard&) = delete;
|
||||||
|
TransactionGuard& operator=(const TransactionGuard&) = delete;
|
||||||
|
EInkDisplayHandler& handler_;
|
||||||
|
uint32_t transaction_id_ = 0;
|
||||||
|
};
|
||||||
|
|||||||
66
main/display/eink_display_handler.h.old
Normal file
66
main/display/eink_display_handler.h.old
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "display/display.h"
|
||||||
|
#include "lvgl.h"
|
||||||
|
#include "esp_lvgl_port.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
|
||||||
|
// Refresh mode configuration
|
||||||
|
#define PARTIAL_REFRESH_THRESHOLD 10 // Full refresh every N partial refreshes
|
||||||
|
#define DISPLAY_WIDTH 800
|
||||||
|
#define DISPLAY_HEIGHT 480
|
||||||
|
#define DISPLAY_BUFFER_SIZE (((DISPLAY_WIDTH * DISPLAY_HEIGHT) / 8) + 8) // 1-bit per pixel + 8-byte palette
|
||||||
|
|
||||||
|
class EInkDisplayHandler : public DisplayHandler {
|
||||||
|
public:
|
||||||
|
EInkDisplayHandler(EventGroupHandle_t system_event_group);
|
||||||
|
virtual ~EInkDisplayHandler();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void start_touch_task();
|
||||||
|
|
||||||
|
// Request a full refresh on next flush
|
||||||
|
void request_full_refresh();
|
||||||
|
|
||||||
|
// Check if display is busy (refreshing)
|
||||||
|
bool is_busy() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// LVGL display and input device handles
|
||||||
|
lv_display_t* _lvgl_display = nullptr;
|
||||||
|
lv_indev_t* _lvgl_touch_indev = nullptr;
|
||||||
|
lv_draw_buf_t* _lvgl_draw_buf = nullptr;
|
||||||
|
|
||||||
|
// Framebuffer
|
||||||
|
uint8_t* _framebuffer = nullptr;
|
||||||
|
bool _framebuffer_in_psram = false;
|
||||||
|
|
||||||
|
// Refresh tracking
|
||||||
|
uint32_t _partial_refresh_count = 0;
|
||||||
|
bool _force_full_refresh = false;
|
||||||
|
SemaphoreHandle_t _refresh_mutex = nullptr;
|
||||||
|
|
||||||
|
// Touch task
|
||||||
|
TaskHandle_t _touch_task_handle = nullptr;
|
||||||
|
|
||||||
|
// Refresh task and queue
|
||||||
|
TaskHandle_t _refresh_task_handle = nullptr;
|
||||||
|
QueueHandle_t _refresh_queue = nullptr;
|
||||||
|
|
||||||
|
// LVGL callbacks
|
||||||
|
static void _lvgl_flush_cb(lv_display_t* disp, const lv_area_t* area, uint8_t* px_map);
|
||||||
|
static void _lvgl_touch_read_cb(lv_indev_t* indev, lv_indev_data_t* data);
|
||||||
|
|
||||||
|
// Display operations
|
||||||
|
void _perform_full_refresh(const uint8_t* framebuffer);
|
||||||
|
void _perform_partial_refresh(const uint8_t* framebuffer);
|
||||||
|
void _wait_for_busy();
|
||||||
|
|
||||||
|
// Touch task
|
||||||
|
static void _touch_task(void* param);
|
||||||
|
|
||||||
|
// Refresh task
|
||||||
|
static void _refresh_task(void* param);
|
||||||
|
|
||||||
|
// Helper to convert LVGL 1-bit buffer to e-paper format
|
||||||
|
void _convert_buffer_to_epaper(const uint8_t* lvgl_buf, uint8_t* epd_buf, size_t size);
|
||||||
|
};
|
||||||
@@ -1,326 +0,0 @@
|
|||||||
#include "display/epd_handler.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "display/constants.h"
|
|
||||||
#include "common/constants.h"
|
|
||||||
#include "esp_lcd_touch_gt911.h"
|
|
||||||
#include <driver/i2c.h>
|
|
||||||
#define TAG "EPDHandler"
|
|
||||||
|
|
||||||
#define BUSY_ACTIVE_LEVEL 0 // BUSY pin is active low
|
|
||||||
#define BUSY_INACTIVE_LEVEL 1
|
|
||||||
#define DMA_TRANSFER_CHUNK_SIZE 4096 // 4KB chunk size for DMA transfers
|
|
||||||
|
|
||||||
EPDHandler::EPDHandler() {
|
|
||||||
spi_mutex_ = xSemaphoreCreateMutex();
|
|
||||||
if (spi_mutex_ == nullptr) {
|
|
||||||
ESP_LOGE(TAG, "Failed to create SPI mutex");
|
|
||||||
}
|
|
||||||
spi_transaction_mutex_ = xSemaphoreCreateMutex();
|
|
||||||
if (spi_transaction_mutex_ == nullptr) {
|
|
||||||
ESP_LOGE(TAG, "Failed to create SPI transaction mutex");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EPDHandler::~EPDHandler() {
|
|
||||||
if (spi_mutex_ != nullptr) {
|
|
||||||
vSemaphoreDelete(spi_mutex_);
|
|
||||||
}
|
|
||||||
if (spi_transaction_mutex_ != nullptr) {
|
|
||||||
vSemaphoreDelete(spi_transaction_mutex_);
|
|
||||||
}
|
|
||||||
if (spi_ != nullptr) {
|
|
||||||
spi_bus_remove_device(spi_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::init() {
|
|
||||||
esp_err_t err;
|
|
||||||
|
|
||||||
// Initialize SPI bus
|
|
||||||
spi_bus_config_t buscfg = {};
|
|
||||||
buscfg.mosi_io_num = 11; // MOSI pin
|
|
||||||
buscfg.miso_io_num = -1; // No MISO for e-paper
|
|
||||||
buscfg.sclk_io_num = 12; // SCK pin
|
|
||||||
buscfg.quadwp_io_num = -1;
|
|
||||||
buscfg.quadhd_io_num = -1;
|
|
||||||
buscfg.max_transfer_sz = DMA_TRANSFER_CHUNK_SIZE;
|
|
||||||
|
|
||||||
err = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add SPI device
|
|
||||||
spi_device_interface_config_t devcfg = {};
|
|
||||||
devcfg.clock_speed_hz = 10 * 1000 * 1000; // 10 MHz
|
|
||||||
devcfg.mode = 0; // SPI mode 0
|
|
||||||
devcfg.spics_io_num = PIN_CS;
|
|
||||||
devcfg.queue_size = 7; // Queue size for non-blocking transactions
|
|
||||||
devcfg.pre_cb = nullptr;
|
|
||||||
|
|
||||||
err = spi_bus_add_device(SPI2_HOST, &devcfg, &spi_);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to add SPI device: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if display is busy (refreshing)
|
|
||||||
bool EPDHandler::is_busy(void) const {
|
|
||||||
return gpio_get_level(PIN_BUSY) != BUSY_ACTIVE_LEVEL; // BUSY is active LOW
|
|
||||||
}
|
|
||||||
void EPDHandler::wait_for_idle(void) const {
|
|
||||||
ESP_LOGI(TAG, "Waiting for display ready (BUSY pin)...");
|
|
||||||
int initial_level = gpio_get_level(PIN_BUSY);
|
|
||||||
ESP_LOGI(TAG, "Initial BUSY pin level: %d (0=BUSY, 1=FREE)", initial_level);
|
|
||||||
|
|
||||||
// If already free, no need to wait
|
|
||||||
if (initial_level == BUSY_INACTIVE_LEVEL) {
|
|
||||||
ESP_LOGI(TAG, "Display already ready (BUSY pin = 1)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (gpio_get_level(PIN_BUSY) != BUSY_INACTIVE_LEVEL) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "Display is now ready (BUSY pin = 1)");
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::epd_write_cmd(const uint8_t cmd, uint32_t transaction_id) {
|
|
||||||
ESP_LOGI(TAG, "epd_write_cmd: waiting to send 0x%02X", cmd);
|
|
||||||
|
|
||||||
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
|
||||||
esp_err_t err =
|
|
||||||
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending cmd 0x%02X: %s",
|
|
||||||
cmd, esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreGuard guard(spi_mutex_);
|
|
||||||
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
|
||||||
ESP_LOGE(TAG, "SPI mutex timeout for cmd 0x%02X", cmd);
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
err = dangerous_epd_write_cmd_without_lock_(cmd);
|
|
||||||
ESP_LOGI(TAG, "epd_write_cmd: 0x%02X done", cmd);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::epd_write_data(const uint8_t data, uint32_t transaction_id) {
|
|
||||||
ESP_LOGI(TAG, "epd_write_data: waiting to send 0x%02X", data);
|
|
||||||
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
|
||||||
esp_err_t err =
|
|
||||||
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending data 0x%02X: %s",
|
|
||||||
data, esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
SemaphoreGuard guard(spi_mutex_);
|
|
||||||
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
|
||||||
ESP_LOGE(TAG, "SPI mutex timeout for data 0x%02X", data);
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
err = dangerous_epd_write_data_without_lock_(data);
|
|
||||||
ESP_LOGI(TAG, "epd_write_data: 0x%02X done", data);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::epd_write_cmd_with_data(const uint8_t cmd, std::vector<uint8_t>& data, uint32_t transaction_id) {
|
|
||||||
const size_t data_len = data.size();
|
|
||||||
ESP_LOGI(TAG, "epd_write_cmd_with_data: waiting to send cmd 0x%02X with %u bytes of data", cmd, data_len);
|
|
||||||
|
|
||||||
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
|
||||||
esp_err_t err =
|
|
||||||
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending cmd 0x%02X: %s, with data",
|
|
||||||
cmd, esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreGuard guard(spi_mutex_);
|
|
||||||
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
|
||||||
ESP_LOGE(TAG, "SPI mutex timeout for cmd with data 0x%02X", cmd);
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
err = dangerous_epd_write_cmd_without_lock_(cmd);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
return err;
|
|
||||||
};
|
|
||||||
for (size_t i = 0; i < data_len; ++i) {
|
|
||||||
err = dangerous_epd_write_data_without_lock_(data[i]);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "epd_write_cmd_with_data: cmd 0x%02X with %u bytes of data done", cmd, data_len);
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::dangerous_epd_write_cmd_without_lock_(const uint8_t cmd) {
|
|
||||||
ESP_LOGI(TAG, "dangerous_epd_write_cmd_without_lock_: sending 0x%02X", cmd);
|
|
||||||
gpio_set_level(PIN_DC, 0); // Command mode
|
|
||||||
spi_transaction_t t {};
|
|
||||||
t.length = 8;t.tx_buffer = &cmd;
|
|
||||||
esp_err_t err = spi_device_polling_transmit(spi_, &t);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to send data 0x%02X", cmd);
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "dangerous_epd_write_cmd_without_lock_: 0x%02X sent", cmd);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::dangerous_epd_write_data_without_lock_(const uint8_t data) {
|
|
||||||
ESP_LOGI(TAG, "dangerous_epd_write_data_without_lock_: sending 0x%02X", data);
|
|
||||||
gpio_set_level(PIN_DC, 1); // Data mode
|
|
||||||
spi_transaction_t t = { };
|
|
||||||
t.length = 8; t.tx_buffer = &data;
|
|
||||||
esp_err_t err = spi_device_polling_transmit(spi_, &t);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to send data 0x%02X", data);
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "dangerous_epd_write_data_without_lock_: 0x%02X sent", data);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::transfer_spi_data(const uint8_t* data, const size_t& length, uint32_t transaction_id, bool inverted) {
|
|
||||||
ESP_LOGI(TAG, "transfer_spi_data: waiting to send %zu bytes of data", length);
|
|
||||||
|
|
||||||
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
|
||||||
esp_err_t err =
|
|
||||||
wait_for_transaction_end_(pdMS_TO_TICKS(5000), transaction_id, transaction_guard);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to wait for previous transaction end before sending data of %zu bytes: %s",
|
|
||||||
length, esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
SemaphoreGuard guard(spi_mutex_);
|
|
||||||
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
|
||||||
ESP_LOGE(TAG, "SPI mutex timeout for data transfer of %zu bytes", length);
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "transfer_spi_data: starting to send %zu bytes of data", length);
|
|
||||||
|
|
||||||
size_t offset = 0;
|
|
||||||
size_t remaining = length;
|
|
||||||
gpio_set_level(PIN_DC, 1); // Data mode
|
|
||||||
|
|
||||||
// Allocate a temporary buffer for inverted data (only if inverted)
|
|
||||||
uint8_t* temp_transfer_buffer = nullptr;
|
|
||||||
if (inverted) {
|
|
||||||
temp_transfer_buffer = (uint8_t*)heap_caps_malloc(DMA_TRANSFER_CHUNK_SIZE, MALLOC_CAP_DMA);
|
|
||||||
if (temp_transfer_buffer == nullptr) {
|
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory for inverted data transfer buffer");
|
|
||||||
ESP_LOGI(TAG, "Current free heap size: %u bytes", esp_get_free_heap_size());
|
|
||||||
ESP_LOGI(TAG, "Current free DMA-capable memory size: %u bytes",
|
|
||||||
heap_caps_get_free_size(MALLOC_CAP_DMA));
|
|
||||||
return ESP_ERR_NO_MEM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (remaining > 0) {
|
|
||||||
size_t transfer_size = (remaining < DMA_TRANSFER_CHUNK_SIZE) ? remaining : DMA_TRANSFER_CHUNK_SIZE;
|
|
||||||
|
|
||||||
const uint8_t* transfer_buffer = nullptr;
|
|
||||||
if (inverted) {
|
|
||||||
// Invert only the current chunk into the temporary buffer
|
|
||||||
for (size_t i = 0; i < transfer_size; ++i) {
|
|
||||||
temp_transfer_buffer[i] = ~data[offset + i];
|
|
||||||
}
|
|
||||||
transfer_buffer = temp_transfer_buffer;
|
|
||||||
} else {
|
|
||||||
transfer_buffer = data + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi_transaction_t t = {};
|
|
||||||
t.length = transfer_size * 8; // Length in bits
|
|
||||||
t.tx_buffer = transfer_buffer;
|
|
||||||
|
|
||||||
esp_err_t ret = spi_device_polling_transmit(spi_, &t);
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to send SPI chunk at offset %zu: %s", offset, esp_err_to_name(ret));
|
|
||||||
if (ret == ESP_ERR_NO_MEM) {
|
|
||||||
ESP_LOGE(TAG, "Current free heap size: %u bytes", esp_get_free_heap_size());
|
|
||||||
ESP_LOGE(TAG, "Current free DMA-capable memory size: %u bytes",
|
|
||||||
heap_caps_get_free_size(MALLOC_CAP_DMA));
|
|
||||||
}
|
|
||||||
if (inverted && temp_transfer_buffer != nullptr) {
|
|
||||||
// Free the temporary inverted buffer
|
|
||||||
heap_caps_free(temp_transfer_buffer);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
remaining -= transfer_size;
|
|
||||||
offset += transfer_size;
|
|
||||||
|
|
||||||
// Yield every 16KB to prevent watchdog timeout
|
|
||||||
if (offset % (16 * 1024) == 0) {
|
|
||||||
ESP_LOGI(TAG, "New data progress: %zu/%zu bytes sent, yielding...", offset, length);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inverted && temp_transfer_buffer != nullptr) {
|
|
||||||
// Free the temporary inverted buffer
|
|
||||||
heap_caps_free(temp_transfer_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "transfer_spi_data: completed sending %zu bytes of data", length);
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::begin_transaction_(TickType_t timeout, uint32_t& out_id) {
|
|
||||||
ESP_LOGI(TAG, "begin_transaction_: waiting to obtain transaction mutex");
|
|
||||||
if (xSemaphoreTake(spi_transaction_mutex_, timeout) != pdTRUE) {
|
|
||||||
ESP_LOGE(TAG, "begin_transaction_: transaction mutex timeout");
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
out_id = ++spi_transaction_id;
|
|
||||||
ESP_LOGI(TAG, "begin_transaction_: transaction mutex obtained");
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::end_transaction_(void) {
|
|
||||||
ESP_LOGI(TAG, "end_transaction_: releasing transaction mutex");
|
|
||||||
if (xSemaphoreGive(spi_transaction_mutex_) != pdTRUE) {
|
|
||||||
ESP_LOGE(TAG, "end_transaction_: failed to release transaction mutex");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "end_transaction_: transaction mutex released");
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t EPDHandler::wait_for_transaction_end_(TickType_t timeout, uint32_t awaiting_transaction_id, SemaphoreGuard& out_transaction_guard) {
|
|
||||||
// Validate transaction ID if provided
|
|
||||||
if (awaiting_transaction_id != 0 && awaiting_transaction_id != spi_transaction_id) {
|
|
||||||
// Invalid transaction ID
|
|
||||||
ESP_LOGE(TAG, "Invalid transaction ID 0x%08X while waiting, current transaction ID: 0x%08X",
|
|
||||||
awaiting_transaction_id, spi_transaction_id);
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
SemaphoreGuard transaction_guard(spi_transaction_mutex_);
|
|
||||||
if (awaiting_transaction_id == 0) {
|
|
||||||
// wait for current transaction to complete
|
|
||||||
ESP_LOGV(TAG, "Waiting for current transaction 0x%08X to complete",
|
|
||||||
spi_transaction_id);
|
|
||||||
// take the mutex to ensure no transaction is active
|
|
||||||
if (!transaction_guard.take(timeout)) {
|
|
||||||
ESP_LOGE(TAG, "SPI transaction mutex timeout while waiting for transaction end");
|
|
||||||
return ESP_ERR_TIMEOUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// awaited_transaction_id is valid and matches current transaction ID or 0
|
|
||||||
out_transaction_guard = std::move(transaction_guard);
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include "driver/spi_master.h"
|
|
||||||
#include "common/semaphore_guard.h"
|
|
||||||
#include <vector>
|
|
||||||
#include "display/transaction_guard.h"
|
|
||||||
|
|
||||||
class EPDHandler : public WithTransaction {
|
|
||||||
public:
|
|
||||||
EPDHandler();
|
|
||||||
~EPDHandler();
|
|
||||||
esp_err_t init();
|
|
||||||
|
|
||||||
esp_err_t epd_write_cmd(const uint8_t cmd, uint32_t transaction_id);
|
|
||||||
esp_err_t epd_write_data(const uint8_t data, uint32_t transaction_id);
|
|
||||||
esp_err_t epd_write_cmd_with_data(const uint8_t cmd, std::vector<uint8_t>& data, uint32_t transaction_id);
|
|
||||||
esp_err_t transfer_spi_data(const uint8_t* data, const size_t& length, uint32_t transaction_id, bool inverted = false);
|
|
||||||
|
|
||||||
bool is_busy(void) const;
|
|
||||||
void wait_for_idle(void) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
esp_err_t begin_transaction_(TickType_t timeout, uint32_t& out_id) override;
|
|
||||||
esp_err_t end_transaction_(void) override;
|
|
||||||
// given a transaction ID, wait for current transaction to complete. The transaction ID will determine if the wait is needed.
|
|
||||||
esp_err_t wait_for_transaction_end_(TickType_t timeout, uint32_t awaiting_transaction_id, SemaphoreGuard& out_transaction_guard);
|
|
||||||
|
|
||||||
spi_device_handle_t spi_ = nullptr;
|
|
||||||
|
|
||||||
SemaphoreHandle_t spi_mutex_ = nullptr;
|
|
||||||
SemaphoreHandle_t spi_transaction_mutex_ = nullptr;
|
|
||||||
|
|
||||||
uint32_t spi_transaction_id = 0; // For tracking SPI transactions
|
|
||||||
|
|
||||||
friend class TransactionGuard;
|
|
||||||
};
|
|
||||||
@@ -11,7 +11,12 @@
|
|||||||
|
|
||||||
LVGLHandler::LVGLHandler(
|
LVGLHandler::LVGLHandler(
|
||||||
std::unique_ptr<EInkDisplayHandler> display_handler_in
|
std::unique_ptr<EInkDisplayHandler> display_handler_in
|
||||||
) : display_handler_(std::move(display_handler_in)) { }
|
) : display_handler_(std::move(display_handler_in)) {
|
||||||
|
lvgl_mutex_ = xSemaphoreCreateMutex();
|
||||||
|
if (lvgl_mutex_ == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create LVGL mutex");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LVGLHandler::~LVGLHandler() {
|
LVGLHandler::~LVGLHandler() {
|
||||||
if (lvgl_display_ != nullptr) {
|
if (lvgl_display_ != nullptr) {
|
||||||
@@ -26,6 +31,14 @@ LVGLHandler::~LVGLHandler() {
|
|||||||
lv_draw_buf_destroy(lvgl_draw_buf_);
|
lv_draw_buf_destroy(lvgl_draw_buf_);
|
||||||
lvgl_draw_buf_ = nullptr;
|
lvgl_draw_buf_ = nullptr;
|
||||||
}
|
}
|
||||||
|
if (framebuffer_ != nullptr) {
|
||||||
|
heap_caps_free(framebuffer_);
|
||||||
|
framebuffer_ = nullptr;
|
||||||
|
}
|
||||||
|
if (lvgl_mutex_ != nullptr) {
|
||||||
|
vSemaphoreDelete(lvgl_mutex_);
|
||||||
|
lvgl_mutex_ = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t LVGLHandler::initLVGL(EventGroupHandle_t system_event_group) {
|
esp_err_t LVGLHandler::initLVGL(EventGroupHandle_t system_event_group) {
|
||||||
@@ -90,64 +103,102 @@ void LVGLHandler::flush_cb_(lv_display_t* disp, const lv_area_t* area, uint8_t*
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LVGLHandler* handler = static_cast<LVGLHandler*>(lv_display_get_user_data(disp));
|
LVGLHandler* handler = static_cast<LVGLHandler*>(lv_display_get_user_data(disp));
|
||||||
if (handler == nullptr || handler->display_handler_ == nullptr) {
|
if (handler == nullptr || handler->display_handler_ == nullptr || handler->framebuffer_ == nullptr) {
|
||||||
ESP_LOGE(TAG, "Invalid handler in flush callback");
|
ESP_LOGE(TAG, "Invalid handler or framebuffer in flush callback");
|
||||||
lv_display_flush_ready(disp);
|
lv_display_flush_ready(disp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint8_t* pixel_data = px_map + 8; // Skip palette
|
uint8_t* pixel_data = px_map + 8; // Skip palette
|
||||||
//
|
//
|
||||||
ESP_LOGI(TAG, "Flush callback: x1=%d, y1=%d, x2=%d, y2=%d", area->x1, area->y1, area->x2, area->y2);
|
ESP_LOGI(TAG, "Flush callback: x1=%d, y1=%d, x2=%d, y2=%d", area->x1, area->y1, area->x2, area->y2);
|
||||||
|
// take mutex
|
||||||
|
SemaphoreGuard guard(handler->lvgl_mutex_);
|
||||||
|
if (!guard.take(pdMS_TO_TICKS(5000))) {
|
||||||
|
ESP_LOGE(TAG, "LVGL mutex timeout in flush callback");
|
||||||
|
lv_display_flush_ready(disp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// copy data to framebuffer
|
// copy data to framebuffer
|
||||||
int32_t area_w = lv_area_get_width(area);
|
int32_t area_w = lv_area_get_width(area);
|
||||||
int32_t area_h = lv_area_get_height(area);
|
int32_t area_h = lv_area_get_height(area);
|
||||||
if (area->x1 == 0 && area->y1 == 0 && area_w == DISPLAY_WIDTH && area_h == DISPLAY_HEIGHT) {
|
if (area->x1 == 0 && area->y1 == 0 && area_w == DISPLAY_WIDTH && area_h == DISPLAY_HEIGHT) {
|
||||||
// revert the pixel data for e-ink (LVGL: 1=white, 0=black; E-Ink: 1=black, 0=white)
|
// Check if content actually changed before triggering expensive e-ink refresh
|
||||||
for (size_t i = 0; i < DISPLAY_BUFFER_SIZE; ++i) {
|
if (memcmp(handler->framebuffer_, pixel_data, DISPLAY_BUFFER_SIZE) == 0) {
|
||||||
pixel_data[i] = ~pixel_data[i];
|
ESP_LOGD(TAG, "Full screen flush with no changes - skipping e-ink refresh");
|
||||||
|
lv_display_flush_ready(disp);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
esp_err_t err = handler->display_handler_->full_write(
|
ESP_LOGI(TAG, "Full screen update");
|
||||||
pixel_data,
|
memcpy(handler->framebuffer_, pixel_data, DISPLAY_BUFFER_SIZE);
|
||||||
true // white basemap
|
// invert the framebuffer for e-ink display
|
||||||
);
|
for (size_t i = 0; i < DISPLAY_BUFFER_SIZE; ++i) {
|
||||||
|
handler->framebuffer_[i] = ~handler->framebuffer_[i];
|
||||||
|
}
|
||||||
|
// request full refresh
|
||||||
|
esp_err_t err = handler->display_handler_->full_write(handler->framebuffer_, true);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Full refresh request failed: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Full refresh request failed: %s", esp_err_to_name(err));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// partial update
|
// partial update
|
||||||
ESP_LOGI(TAG, "Partial update: x1=%d, y1=%d, w=%d, h=%d", area->x1, area->y1, area_w, area_h);
|
ESP_LOGI(TAG, "Partial update: x1=%d, y1=%d, w=%d, h=%d", area->x1, area->y1, area_w, area_h);
|
||||||
|
// update the framebuffer with the partial data
|
||||||
|
for (int32_t row = 0; row < area_h; ++row) {
|
||||||
|
int32_t fb_y = area->y1 + row;
|
||||||
|
int32_t fb_x_byte_start = area->x1 / 8;
|
||||||
|
int32_t fb_x_byte_end = area->x2 / 8;
|
||||||
|
uint8_t* fb_ptr = &handler->framebuffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
||||||
|
const uint8_t* src_ptr = &pixel_data[row * (area_w / 8)];
|
||||||
|
// invert the partial framebuffer data for e-ink display
|
||||||
|
for (int32_t i = 0; i < (fb_x_byte_end - fb_x_byte_start + 1); ++i) {
|
||||||
|
fb_ptr[i] = ~src_ptr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update the refresh area
|
||||||
|
handler->refresh_area_.expand_to_include(area->x1, area->y1, area->x2, area->y2);
|
||||||
|
//
|
||||||
|
|
||||||
// Prepare partial buffer
|
if (lv_display_flush_is_last(disp) && !handler->refresh_area_.is_empty()) {
|
||||||
const uint32_t area_width_bytes = (area->x2 - area->x1 + 1) / 8;
|
ESP_LOGI(TAG, "Last flush in batch - performing partial refresh");
|
||||||
const uint32_t area_height = area->y2 - area->y1 + 1;
|
ESP_LOGI(TAG, "Refresh area: x1=%d, y1=%d, x2=%d, y2=%d",
|
||||||
const size_t partial_buffer_size = area_width_bytes * area_height;
|
handler->refresh_area_.x1, handler->refresh_area_.y1,
|
||||||
uint8_t* partial_buffer = new uint8_t[partial_buffer_size];
|
handler->refresh_area_.x2, handler->refresh_area_.y2);
|
||||||
|
// copy the area to refresh
|
||||||
|
uint8_t* partial_buffer = new uint8_t[handler->refresh_area_.area() / 8];
|
||||||
if (partial_buffer == nullptr) {
|
if (partial_buffer == nullptr) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate partial buffer for flush callback");
|
ESP_LOGE(TAG, "Failed to allocate partial buffer for refresh");
|
||||||
lv_display_flush_ready(disp);
|
lv_display_flush_ready(disp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Copy pixel data to partial buffer and invert for e-ink
|
// loop the refresh area and copy data
|
||||||
for (int32_t row = 0; row < area_height; ++row) {
|
uint32_t x1 = handler->refresh_area_.x1;
|
||||||
for (int32_t col = 0; col < area_width_bytes; ++col) {
|
uint32_t x2 = handler->refresh_area_.x2;
|
||||||
size_t src_index = row * area_width_bytes + col;
|
uint32_t y1 = handler->refresh_area_.y1;
|
||||||
partial_buffer[src_index] = ~pixel_data[src_index];
|
uint32_t y2 = handler->refresh_area_.y2;
|
||||||
|
uint32_t height = y2 - y1 + 1;
|
||||||
|
uint32_t width = x2 - x1 + 1;
|
||||||
|
|
||||||
|
for (uint32_t row = 0; row < height; ++row) {
|
||||||
|
uint32_t fb_y = y1 + row;
|
||||||
|
uint32_t fb_x_byte_start = x1 / 8;
|
||||||
|
uint32_t fb_x_byte_end = x2 / 8;
|
||||||
|
uint8_t* fb_ptr = &handler->framebuffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
||||||
|
uint8_t* dest_ptr = &partial_buffer[row * (width / 8)];
|
||||||
|
for (uint32_t i = 0; i < (fb_x_byte_end - fb_x_byte_start + 1); ++i) {
|
||||||
|
dest_ptr[i] = ~fb_ptr[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t err = handler->display_handler_->partial_refresh(partial_buffer,
|
esp_err_t err = handler->display_handler_->partial_refresh(partial_buffer,
|
||||||
RefreshArea {
|
handler->refresh_area_);
|
||||||
area->x1,
|
|
||||||
area->y1,
|
|
||||||
area->x2,
|
|
||||||
area->y2
|
|
||||||
}, lv_display_flush_is_last(disp));
|
|
||||||
delete[] partial_buffer;
|
delete[] partial_buffer;
|
||||||
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Partial refresh request failed: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Partial refresh request failed: %s", esp_err_to_name(err));
|
||||||
}
|
}
|
||||||
|
handler->refresh_area_.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
lv_display_flush_ready(disp);
|
lv_display_flush_ready(disp);
|
||||||
@@ -183,7 +234,7 @@ void LVGLHandler::touch_read_cb_(lv_indev_t* indev, lv_indev_data_t* data) {
|
|||||||
esp_lcd_touch_get_data(tp_handle, point_data, &touch_cnt, 1);
|
esp_lcd_touch_get_data(tp_handle, point_data, &touch_cnt, 1);
|
||||||
|
|
||||||
if (touch_cnt > 0) {
|
if (touch_cnt > 0) {
|
||||||
// ESP_LOGI(TAG, "Touch data read successfully: x=%d, y=%d", point_data[0].x, point_data[0].y);
|
ESP_LOGI(TAG, "Touch data read successfully: x=%d, y=%d", point_data[0].x, point_data[0].y);
|
||||||
data->point.x = point_data[0].x;
|
data->point.x = point_data[0].x;
|
||||||
data->point.y = point_data[0].y;
|
data->point.y = point_data[0].y;
|
||||||
data->state = LV_INDEV_STATE_PRESSED;
|
data->state = LV_INDEV_STATE_PRESSED;
|
||||||
@@ -217,10 +268,31 @@ esp_err_t LVGLHandler::initLVGLDisplay_() {
|
|||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set framebuffer
|
||||||
|
framebuffer_ = (uint8_t*)heap_caps_malloc(LVGL_BUFFER_SIZE, MALLOC_CAP_SPIRAM);
|
||||||
|
if (framebuffer_ != nullptr) {
|
||||||
|
framebuffer_in_psram_ = true;
|
||||||
|
ESP_LOGI(TAG, "Framebuffer allocated in PSRAM (%zu bytes)", LVGL_BUFFER_SIZE);
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "PSRAM not available, allocating framebuffer in internal RAM");
|
||||||
|
framebuffer_ = (uint8_t*)heap_caps_malloc(LVGL_BUFFER_SIZE, MALLOC_CAP_INTERNAL);
|
||||||
|
framebuffer_in_psram_ = false;
|
||||||
|
if (framebuffer_ == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to allocate framebuffer");
|
||||||
|
lv_display_delete(lvgl_display_);
|
||||||
|
lvgl_display_ = nullptr;
|
||||||
|
lvgl_port_unlock();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Framebuffer allocated in internal RAM (%zu bytes)", LVGL_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
memset(framebuffer_, 0xFF, LVGL_BUFFER_SIZE); // Initialize to white
|
||||||
// Create a draw buffer covering the entire display
|
// Create a draw buffer covering the entire display
|
||||||
lvgl_draw_buf_ = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
lvgl_draw_buf_ = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
||||||
if (lvgl_draw_buf_ == nullptr) {
|
if (lvgl_draw_buf_ == nullptr) {
|
||||||
ESP_LOGE(TAG, "Failed to create LVGL draw buffer");
|
ESP_LOGE(TAG, "Failed to create LVGL draw buffer");
|
||||||
|
heap_caps_free(framebuffer_);
|
||||||
|
framebuffer_ = nullptr;
|
||||||
lv_display_delete(lvgl_display_);
|
lv_display_delete(lvgl_display_);
|
||||||
lvgl_display_ = nullptr;
|
lvgl_display_ = nullptr;
|
||||||
lvgl_port_unlock();
|
lvgl_port_unlock();
|
||||||
|
|||||||
@@ -31,4 +31,10 @@ private:
|
|||||||
lv_display_t* lvgl_display_ = nullptr;
|
lv_display_t* lvgl_display_ = nullptr;
|
||||||
lv_indev_t* lvgl_touch_indev_ = nullptr;
|
lv_indev_t* lvgl_touch_indev_ = nullptr;
|
||||||
lv_draw_buf_t* lvgl_draw_buf_ = nullptr;
|
lv_draw_buf_t* lvgl_draw_buf_ = nullptr;
|
||||||
|
uint8_t* framebuffer_ = nullptr;
|
||||||
|
bool framebuffer_in_psram_ = false;
|
||||||
|
RefreshArea refresh_area_ = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
|
||||||
|
SemaphoreHandle_t lvgl_mutex_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include <esp_err.h>
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
class WithTransaction {
|
|
||||||
protected:
|
|
||||||
virtual esp_err_t end_transaction_() = 0;
|
|
||||||
virtual esp_err_t begin_transaction_(TickType_t timeout, uint32_t& out_id) = 0;
|
|
||||||
|
|
||||||
friend class TransactionGuard;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TransactionGuard {
|
|
||||||
public:
|
|
||||||
TransactionGuard(WithTransaction& handler, TickType_t timeout = portMAX_DELAY)
|
|
||||||
: handler_(handler) { }
|
|
||||||
~TransactionGuard() { if (transaction_id_) handler_.end_transaction_(); }
|
|
||||||
|
|
||||||
esp_err_t begin(TickType_t timeout = portMAX_DELAY) {
|
|
||||||
esp_err_t err = handler_.begin_transaction_(timeout, transaction_id_);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
uint32_t transaction_id() const { return transaction_id_; }
|
|
||||||
bool is_active() const { return transaction_id_ != 0; }
|
|
||||||
private:
|
|
||||||
// delete copy constructor and assignment operator
|
|
||||||
TransactionGuard(const TransactionGuard&) = delete;
|
|
||||||
TransactionGuard& operator=(const TransactionGuard&) = delete;
|
|
||||||
WithTransaction& handler_;
|
|
||||||
uint32_t transaction_id_ = 0;
|
|
||||||
};
|
|
||||||
@@ -23,8 +23,7 @@ void display_chip_info() {
|
|||||||
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
|
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
|
||||||
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread), " : "",
|
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread), " : "",
|
||||||
// psram
|
// psram
|
||||||
(chip_info.features & CHIP_FEATURE_EMB_PSRAM) ? "with embedded PSRAM, " : ""
|
(chip_info.features & CHIP_FEATURE_EMB_PSRAM) ? "with embedded PSRAM, " : "");
|
||||||
);
|
|
||||||
|
|
||||||
unsigned major_rev = chip_info.revision / 100;
|
unsigned major_rev = chip_info.revision / 100;
|
||||||
unsigned minor_rev = chip_info.revision % 100;
|
unsigned minor_rev = chip_info.revision % 100;
|
||||||
@@ -40,8 +39,5 @@ void display_chip_info() {
|
|||||||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
||||||
// psram
|
// psram
|
||||||
printf("PSRAM size: %u bytes\n", esp_psram_get_size());
|
printf("PSRAM size: %u bytes\n", esp_psram_get_size());
|
||||||
// dma size
|
|
||||||
printf("DMA-capable memory size: %u bytes\n", heap_caps_get_free_size(MALLOC_CAP_DMA));
|
|
||||||
printf("DMA-capable internal memory size: %u bytes\n", heap_caps_get_free_size(MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,6 @@ NVSStorageHandler::~NVSStorageHandler() {
|
|||||||
void NVSStorageHandler::init(const EventGroupHandle_t& system_event_group) {
|
void NVSStorageHandler::init(const EventGroupHandle_t& system_event_group) {
|
||||||
esp_err_t err = nvs_flash_init();
|
esp_err_t err = nvs_flash_init();
|
||||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
ESP_LOGW(TAG, "NVS Flash init failed with %s, erasing and retrying...", esp_err_to_name(err));
|
|
||||||
nvs_flash_erase();
|
nvs_flash_erase();
|
||||||
err = nvs_flash_init();
|
err = nvs_flash_init();
|
||||||
}
|
}
|
||||||
@@ -44,26 +43,11 @@ void NVSStorageHandler::put(const std::string& key, const std::string& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t err = nvs_set_str(this->nvsHandle, key.c_str(), value.c_str());
|
esp_err_t err = nvs_set_str(this->nvsHandle, key.c_str(), value.c_str());
|
||||||
if (err == ESP_ERR_NVS_NOT_ENOUGH_SPACE) {
|
|
||||||
ESP_LOGE(TAG, "NVS storage full! Cannot store key '%s'. Consider clearing old data.", key.c_str());
|
|
||||||
ESP_LOGI(TAG, "Attempting to erase and retry...");
|
|
||||||
// Try to commit pending changes first
|
|
||||||
nvs_commit(this->nvsHandle);
|
|
||||||
// Retry once
|
|
||||||
err = nvs_set_str(this->nvsHandle, key.c_str(), value.c_str());
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Retry failed: %s", esp_err_to_name(err));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Error (%s) setting key-value pair in NVS!", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Error (%s) setting key-value pair in NVS!", esp_err_to_name(err));
|
||||||
return;
|
} else {
|
||||||
}
|
nvs_commit(this->nvsHandle);
|
||||||
|
// ESP_LOGI(TAG, "Key-value pair (%s, %s) stored in NVS.", key.c_str(), value.c_str());
|
||||||
// Commit successful write
|
|
||||||
err = nvs_commit(this->nvsHandle);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Error (%s) committing to NVS!", esp_err_to_name(err));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
315
main/main.cpp
315
main/main.cpp
@@ -42,6 +42,221 @@ void init_queues(
|
|||||||
EventGroupHandle_t& system_lifecycle_event_group
|
EventGroupHandle_t& system_lifecycle_event_group
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void EInk_Checkerboard(
|
||||||
|
EInkDisplayHandler* display_handler
|
||||||
|
) {
|
||||||
|
struct CheckerboardTaskParams {
|
||||||
|
EInkDisplayHandler* display_handler;
|
||||||
|
};
|
||||||
|
auto checkerboard_task_fn = [](void* pvParameters) {
|
||||||
|
CheckerboardTaskParams* params = static_cast<CheckerboardTaskParams*>(pvParameters);
|
||||||
|
if (params != nullptr && params->display_handler != nullptr) {
|
||||||
|
// Add this task to the watchdog timer
|
||||||
|
esp_err_t wdt_err = esp_task_wdt_add(NULL);
|
||||||
|
if (wdt_err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "Failed to add checkerboard task to watchdog: %s", esp_err_to_name(wdt_err));
|
||||||
|
}
|
||||||
|
|
||||||
|
EInkDisplayHandler* display_handler = params->display_handler;
|
||||||
|
const size_t DISPLAY_BUFFER_SIZE = DISPLAY_WIDTH * DISPLAY_HEIGHT / 8;
|
||||||
|
uint8_t* framebuffer = new uint8_t[DISPLAY_BUFFER_SIZE];
|
||||||
|
if (framebuffer == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to allocate framebuffer for checkerboard task");
|
||||||
|
if (wdt_err == ESP_OK) {
|
||||||
|
esp_task_wdt_delete(NULL);
|
||||||
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Create checkerboard pattern
|
||||||
|
for (size_t y = 0; y < DISPLAY_HEIGHT; y++) {
|
||||||
|
for (size_t x = 0; x < DISPLAY_WIDTH; x++) {
|
||||||
|
size_t byte_index = (y * DISPLAY_WIDTH + x) / 8;
|
||||||
|
size_t bit_index = 7 - (x % 8);
|
||||||
|
bool is_white = ((x / 20) % 2) == ((y / 20) % 2);
|
||||||
|
if (is_white) {
|
||||||
|
framebuffer[byte_index] |= (1 << bit_index); // Set bit to 1 for white
|
||||||
|
} else {
|
||||||
|
framebuffer[byte_index] &= ~(1 << bit_index); // Clear bit to 0 for black
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Yield and reset watchdog periodically
|
||||||
|
const size_t YIELD_INTERVAL = 16;
|
||||||
|
if (y % YIELD_INTERVAL == 0) {
|
||||||
|
if (wdt_err == ESP_OK) {
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
}
|
||||||
|
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||||
|
// partial refresh to show progress
|
||||||
|
int32_t y_start = static_cast<int32_t>((y >= YIELD_INTERVAL - 1) ? (y - (YIELD_INTERVAL - 1)) : 0);
|
||||||
|
int32_t y_end = static_cast<int32_t>(y);
|
||||||
|
// get the partial framebuffer for this area
|
||||||
|
uint8_t* partial_framebuffer = &framebuffer[y_start * (DISPLAY_WIDTH / 8)];
|
||||||
|
esp_err_t err = display_handler->partial_refresh(partial_framebuffer, RefreshArea { 0, y_start, DISPLAY_WIDTH - 1, y_end });
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Partial refresh failed at y=%d: %s", y, esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
// wait for 4 seconds to prevent spamming the display
|
||||||
|
// vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Perform full write to display
|
||||||
|
// esp_err_t err = display_handler->full_write(framebuffer);
|
||||||
|
// if (err != ESP_OK) {
|
||||||
|
// ESP_LOGE(TAG, "Checkerboard full write failed: %s", esp_err_to_name(err));
|
||||||
|
// } else {
|
||||||
|
// ESP_LOGI(TAG, "Checkerboard pattern displayed successfully.");
|
||||||
|
// }
|
||||||
|
delete[] framebuffer;
|
||||||
|
|
||||||
|
// Remove task from watchdog before deletion
|
||||||
|
if (wdt_err == ESP_OK) {
|
||||||
|
esp_task_wdt_delete(NULL);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "Invalid parameters for checkerboard task");
|
||||||
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
};
|
||||||
|
CheckerboardTaskParams* checker_params = new CheckerboardTaskParams();
|
||||||
|
checker_params->display_handler = display_handler;
|
||||||
|
BaseType_t res = xTaskCreate(
|
||||||
|
checkerboard_task_fn,
|
||||||
|
"checkerboard_task",
|
||||||
|
8192,
|
||||||
|
static_cast<void*>(checker_params),
|
||||||
|
tskIDLE_PRIORITY + 1,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res != pdPASS) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create checkerboard task");
|
||||||
|
delete checker_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LVGL_Checkerboard(
|
||||||
|
LVGLHandler* lvgl_handler
|
||||||
|
) {
|
||||||
|
struct CheckerboardTaskParams {
|
||||||
|
LVGLHandler* lvgl_handler;
|
||||||
|
};
|
||||||
|
auto checkerboard_task_fn = [](void* pvParameters) {
|
||||||
|
CheckerboardTaskParams* params = static_cast<CheckerboardTaskParams*>(pvParameters);
|
||||||
|
if (params == nullptr || params->lvgl_handler == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Invalid parameters for LVGL checkerboard task");
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto* handler = static_cast<LVGLHandler*>(params->lvgl_handler);
|
||||||
|
|
||||||
|
// Add safety checks
|
||||||
|
if (!handler) {
|
||||||
|
ESP_LOGE("LVGL", "Handler is null!");
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI("HEAP", "Free: %d", esp_get_free_heap_size());
|
||||||
|
|
||||||
|
// Wait for LVGL system to fully initialize
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
|
||||||
|
// Acquire LVGL lock with proper timeout
|
||||||
|
if (!lvgl_port_lock(pdMS_TO_TICKS(5000))) {
|
||||||
|
ESP_LOGE(TAG, "Failed to acquire LVGL lock for checkerboard");
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify LVGL is properly initialized
|
||||||
|
if (lv_display_get_default() == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "LVGL default display not available");
|
||||||
|
lvgl_port_unlock();
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create LVGL objects for checkerboard
|
||||||
|
lv_obj_t* scr = lv_scr_act();
|
||||||
|
if (scr == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to get active LVGL screen");
|
||||||
|
lvgl_port_unlock();
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lv_obj_t* checkerboard = lv_obj_create(scr);
|
||||||
|
if (checkerboard == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create LVGL checkerboard object");
|
||||||
|
lvgl_port_unlock();
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lv_obj_set_size(checkerboard, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||||
|
// remove border and padding
|
||||||
|
lv_obj_set_style_pad_all(checkerboard, 0, 0);
|
||||||
|
lv_obj_set_style_border_width(checkerboard, 0, 0);
|
||||||
|
const int CELL_SIZE = 40;
|
||||||
|
lvgl_port_unlock();
|
||||||
|
// Create checkerboard pattern using LVGL
|
||||||
|
for (int y = 0; y < DISPLAY_HEIGHT; y += CELL_SIZE) {
|
||||||
|
lvgl_port_lock(pdMS_TO_TICKS(1000));
|
||||||
|
for (int x = 0; x < DISPLAY_WIDTH; x += CELL_SIZE) {
|
||||||
|
lv_color_t color = (((x / CELL_SIZE) % 2) == ((y / CELL_SIZE) % 2)) ? lv_color_hex(0xFFFFFF) : lv_color_hex(0x000000);
|
||||||
|
lv_obj_t* cell = lv_obj_create(checkerboard);
|
||||||
|
if (cell == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create LVGL checkerboard cell");
|
||||||
|
lvgl_port_unlock();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lv_obj_set_size(cell, CELL_SIZE, CELL_SIZE);
|
||||||
|
lv_obj_set_style_bg_color(cell, color, 0);
|
||||||
|
lv_obj_set_pos(cell, x, y);
|
||||||
|
// remove border and padding
|
||||||
|
lv_obj_set_style_pad_all(cell, 0, 0);
|
||||||
|
lv_obj_set_style_border_width(cell, 0, 0);
|
||||||
|
lv_obj_t* label = lv_label_create(cell);
|
||||||
|
if (label != nullptr) {
|
||||||
|
lv_label_set_text_fmt(label, "(%d,%d)", x, y);
|
||||||
|
lv_obj_center(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lvgl_port_unlock();
|
||||||
|
// Yield to allow LVGL to process rendering
|
||||||
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "LVGL Checkerboard pattern displayed successfully.");
|
||||||
|
delete params;
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
};
|
||||||
|
CheckerboardTaskParams* checker_params = new CheckerboardTaskParams();
|
||||||
|
checker_params->lvgl_handler = lvgl_handler;
|
||||||
|
BaseType_t res = xTaskCreate(
|
||||||
|
checkerboard_task_fn,
|
||||||
|
"lvgl_checkerboard_task",
|
||||||
|
8192,
|
||||||
|
static_cast<void*>(checker_params),
|
||||||
|
tskIDLE_PRIORITY + 1,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (res != pdPASS) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create LVGL checkerboard task");
|
||||||
|
delete checker_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
display_chip_info();
|
display_chip_info();
|
||||||
|
|
||||||
@@ -57,14 +272,14 @@ void app_main(void) {
|
|||||||
ESP_LOGI(TAG, "Queues initialized.\n");
|
ESP_LOGI(TAG, "Queues initialized.\n");
|
||||||
|
|
||||||
//
|
//
|
||||||
KVStorageHandler* kv_storage_handler = new NVSStorageHandler(
|
// KVStorageHandler* kv_storage_handler = new NVSStorageHandler(
|
||||||
DEFAULT_STORAGE_NAMESPACE
|
// DEFAULT_STORAGE_NAMESPACE
|
||||||
);
|
// );
|
||||||
|
|
||||||
auto wifi_handler = std::make_unique<WifiHandler>(
|
// auto wifi_handler = std::make_unique<WifiHandler>(
|
||||||
std::unique_ptr<KVStorageHandler>(new NVSStorageHandler(WIFI_CREDENTIALS_STORAGE_NAMESPACE))
|
// std::unique_ptr<KVStorageHandler>(new NVSStorageHandler(WIFI_CREDENTIALS_STORAGE_NAMESPACE))
|
||||||
);
|
// );
|
||||||
NetworkHandler* network_handler = new NetworkHandler(std::move(wifi_handler));
|
// NetworkHandler* network_handler = new NetworkHandler(std::move(wifi_handler));
|
||||||
EInkDisplayHandler* display_handler = new EInkDisplayHandler();
|
EInkDisplayHandler* display_handler = new EInkDisplayHandler();
|
||||||
// Initialize display and touch
|
// Initialize display and touch
|
||||||
// display_handler->init_devices(system_event_group);
|
// display_handler->init_devices(system_event_group);
|
||||||
@@ -81,8 +296,8 @@ void app_main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
kv_storage_handler->init(system_event_group);
|
// kv_storage_handler->init(system_event_group);
|
||||||
network_handler->init(system_event_group);
|
// network_handler->init(system_event_group);
|
||||||
|
|
||||||
//
|
//
|
||||||
ESP_LOGI(TAG, "Waiting for system to be ready...\n");
|
ESP_LOGI(TAG, "Waiting for system to be ready...\n");
|
||||||
@@ -97,73 +312,39 @@ void app_main(void) {
|
|||||||
);
|
);
|
||||||
ESP_LOGI(TAG, "System is ready. Starting main application...\n");
|
ESP_LOGI(TAG, "System is ready. Starting main application...\n");
|
||||||
|
|
||||||
DiscordAppDescriptor::instance();
|
|
||||||
UIHandler ui_handler;
|
|
||||||
err = ui_handler.init();
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to initialize UI handler: %s", esp_err_to_name(err));
|
|
||||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
|
||||||
return esp_restart();
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "UI handler initialized.\n");
|
|
||||||
|
|
||||||
// Allow LVGL system to stabilize before creating objects
|
// Allow LVGL system to stabilize before creating objects
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
// Create main screen and button for random rectangle demo
|
// Show checkerboard pattern on display for testing
|
||||||
// lv_obj_t* scr = lv_scr_act();
|
// EInk_Checkerboard(display_handler);
|
||||||
|
LVGL_Checkerboard(&lvgl_handler);
|
||||||
|
|
||||||
// // Create a button
|
// Register apps with AppRegistry by creating their descriptors
|
||||||
// lv_obj_t* btn = lv_btn_create(scr);
|
// Each descriptor will create and register the app instance
|
||||||
// lv_obj_set_size(btn, 200, 60);
|
// DemoAppDescriptor* demo_descriptor = new DemoAppDescriptor();
|
||||||
// lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 20);
|
// ShutdownAppDescriptor* shutdown_descriptor = new ShutdownAppDescriptor();
|
||||||
// lv_obj_set_style_border_width(btn, 2, 0);
|
// DiscordAppDescriptor::instance(); // Use singleton pattern for Discord app
|
||||||
// lv_obj_set_style_border_color(btn, lv_color_make(0, 0, 0), 0);
|
// MtrAppDescriptor* mtr_descriptor = new MtrAppDescriptor();
|
||||||
|
|
||||||
// // Add label to button
|
// Pass network handler to MtrApp so it can fetch arrival data
|
||||||
// lv_obj_t* label = lv_label_create(btn);
|
// MtrApp* mtr_app = dynamic_cast<MtrApp*>(mtr_descriptor->get_app_instance());
|
||||||
// lv_label_set_text(label, "Create Random Rect");
|
// if (mtr_app) {
|
||||||
// lv_obj_center(label);
|
// mtr_app->set_network_handler(network_handler);
|
||||||
// lv_obj_set_style_text_color(label, lv_color_make(0, 0, 0), 0);
|
// }
|
||||||
|
|
||||||
// // Event handler for button - creates random rectangles
|
// ESP_LOGI(TAG, "Apps registered with AppRegistry\n");
|
||||||
// auto btn_event_cb = [](lv_event_t* e) {
|
|
||||||
// lv_obj_t* scr = lv_scr_act();
|
|
||||||
|
|
||||||
// // Create a random rectangle
|
// Initialize UI Handler (will render app icons from registry)
|
||||||
// lv_obj_t* rect = lv_obj_create(scr);
|
// UIHandler ui_handler;
|
||||||
|
// if (ui_handler.init() != ESP_OK) {
|
||||||
|
// ESP_LOGE(TAG, "Failed to initialize UI handler");
|
||||||
|
// vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
|
// return esp_restart();
|
||||||
|
// }
|
||||||
|
// ESP_LOGI(TAG, "UI handler initialized successfully\n");
|
||||||
|
// ESP_LOGI(TAG, "Main screen displayed with app icons. Tap an icon to launch an app.\n");
|
||||||
|
|
||||||
// // Random size (30-100 pixels)
|
|
||||||
// lv_coord_t width = 30 + (esp_random() % 70);
|
|
||||||
// lv_coord_t height = 30 + (esp_random() % 70);
|
|
||||||
// lv_obj_set_size(rect, width, height);
|
|
||||||
|
|
||||||
// // Random position (avoid top 100px where button is)
|
|
||||||
// lv_coord_t x = esp_random() % (LV_HOR_RES - width);
|
|
||||||
// lv_coord_t y = 100 + (esp_random() % (LV_VER_RES - 100 - height));
|
|
||||||
// lv_obj_set_pos(rect, x, y);
|
|
||||||
|
|
||||||
// lv_obj_set_style_bg_color(rect, lv_color_make(0, 0, 0), 0);
|
|
||||||
// lv_obj_set_style_bg_opa(rect, LV_OPA_COVER, 0);
|
|
||||||
|
|
||||||
// // Make rectangle clickable
|
|
||||||
// lv_obj_add_flag(rect, LV_OBJ_FLAG_CLICKABLE);
|
|
||||||
|
|
||||||
// // Event handler to delete rectangle when clicked
|
|
||||||
// auto rect_event_cb = [](lv_event_t* e) {
|
|
||||||
// lv_obj_t* rect = static_cast<lv_obj_t*>(lv_event_get_target(e));
|
|
||||||
// lv_obj_del(rect);
|
|
||||||
// ESP_LOGI(TAG, "Rectangle deleted");
|
|
||||||
// };
|
|
||||||
|
|
||||||
// lv_obj_add_event_cb(rect, rect_event_cb, LV_EVENT_CLICKED, NULL);
|
|
||||||
|
|
||||||
// ESP_LOGI(TAG, "Created rectangle at (%d, %d) with size %dx%d", x, y, width, height);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL);
|
|
||||||
|
|
||||||
// ESP_LOGI(TAG, "Random rectangle demo initialized. Tap button to create rectangles.\n");
|
|
||||||
|
|
||||||
// wait for shutdown signal
|
// wait for shutdown signal
|
||||||
ESP_LOGI(TAG, "Waiting for shutdown signal...\n");
|
ESP_LOGI(TAG, "Waiting for shutdown signal...\n");
|
||||||
|
|||||||
@@ -160,7 +160,6 @@ esp_err_t WifiHandler::connect(const std::string& ssid, const std::string& passw
|
|||||||
this->current_ssid.clear();
|
this->current_ssid.clear();
|
||||||
}
|
}
|
||||||
this->current_ssid = ssid;
|
this->current_ssid = ssid;
|
||||||
this->current_password = password;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
wifi_config_t wifi_config = {};
|
wifi_config_t wifi_config = {};
|
||||||
@@ -183,8 +182,8 @@ esp_err_t WifiHandler::connect(const std::string& ssid, const std::string& passw
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Credentials will be stored in the event handler after successful connection
|
// store credentials after successful connection attempt
|
||||||
// to avoid storing credentials for failed connection attempts
|
this->store_wifi_credentials(this->current_ssid, password);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@@ -306,10 +305,6 @@ void WifiHandler::wifi_event_handler(void* arg, esp_event_base_t event_base, int
|
|||||||
self->s_wifi_event_group,
|
self->s_wifi_event_group,
|
||||||
WIFI_CONNECTED_BIT
|
WIFI_CONNECTED_BIT
|
||||||
);
|
);
|
||||||
// Store credentials only after successful connection
|
|
||||||
if (!self->current_ssid.empty() && !self->current_password.empty()) {
|
|
||||||
self->store_wifi_credentials(self->current_ssid, self->current_password);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -333,11 +328,7 @@ void WifiHandler::store_wifi_credentials(const std::string& ssid, const std::str
|
|||||||
ESP_LOGE(TAG, "Failed to take credential mutex");
|
ESP_LOGE(TAG, "Failed to take credential mutex");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// store the password according to the JSON structure
|
||||||
// Store current SSID
|
|
||||||
kvs->put(WIFI_SSID_KEY, ssid);
|
|
||||||
|
|
||||||
// Store the password according to the JSON structure
|
|
||||||
std::string password_key_store = kvs->get(WIFI_PASSWORD_STORE_KEY);
|
std::string password_key_store = kvs->get(WIFI_PASSWORD_STORE_KEY);
|
||||||
cJSON* json = nullptr;
|
cJSON* json = nullptr;
|
||||||
if (password_key_store.empty()) {
|
if (password_key_store.empty()) {
|
||||||
@@ -357,37 +348,17 @@ void WifiHandler::store_wifi_credentials(const std::string& ssid, const std::str
|
|||||||
credentials = cJSON_CreateObject();
|
credentials = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(json, "credentials", credentials);
|
cJSON_AddItemToObject(json, "credentials", credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit stored credentials to prevent NVS overflow (keep max 10 SSIDs)
|
|
||||||
int credential_count = cJSON_GetArraySize(credentials);
|
|
||||||
if (credential_count >= 10) {
|
|
||||||
ESP_LOGW(TAG, "Too many stored credentials (%d), clearing old ones", credential_count);
|
|
||||||
// Keep only the current SSID's credentials, clear others
|
|
||||||
cJSON_DeleteItemFromObject(credentials, ssid.c_str()); // Remove if exists
|
|
||||||
cJSON* new_credentials = cJSON_CreateObject();
|
|
||||||
cJSON_ReplaceItemInObject(json, "credentials", new_credentials);
|
|
||||||
credentials = new_credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove existing entry for this SSID to update it
|
|
||||||
cJSON_DeleteItemFromObject(credentials, ssid.c_str());
|
|
||||||
|
|
||||||
// create SSID object
|
// create SSID object
|
||||||
cJSON* ssid_item = cJSON_CreateObject();
|
cJSON* ssid_item = cJSON_CreateObject();
|
||||||
// add password field
|
// add password field
|
||||||
cJSON_AddStringToObject(ssid_item, "password", password.c_str());
|
cJSON_AddStringToObject(ssid_item, "password", password.c_str());
|
||||||
// add SSID object to credentials
|
// add SSID object to credentials
|
||||||
cJSON_AddItemToObject(credentials, ssid.c_str(), ssid_item);
|
cJSON_AddItemToObject(credentials, ssid.c_str(), ssid_item);
|
||||||
|
|
||||||
// store updated JSON string
|
// store updated JSON string
|
||||||
char* updated_json_str = cJSON_PrintUnformatted(json);
|
char* updated_json_str = cJSON_PrintUnformatted(json);
|
||||||
if (updated_json_str) {
|
if (updated_json_str) {
|
||||||
esp_err_t err = ESP_OK;
|
|
||||||
kvs->put(WIFI_PASSWORD_STORE_KEY, std::string(updated_json_str));
|
kvs->put(WIFI_PASSWORD_STORE_KEY, std::string(updated_json_str));
|
||||||
// Note: Error handling is done in nvs_handler.cpp put() method
|
|
||||||
cJSON_free(updated_json_str);
|
cJSON_free(updated_json_str);
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Failed to serialize WiFi credentials JSON");
|
|
||||||
}
|
}
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ private:
|
|||||||
SemaphoreHandle_t credential_mutex = nullptr;
|
SemaphoreHandle_t credential_mutex = nullptr;
|
||||||
// current connected / preferred SSID
|
// current connected / preferred SSID
|
||||||
std::string current_ssid;
|
std::string current_ssid;
|
||||||
// current password (temporarily stored for successful connection event)
|
|
||||||
std::string current_password;
|
|
||||||
// prevent auto-reconnect on expected disconnection, e.g. when user calls disconnect()
|
// prevent auto-reconnect on expected disconnection, e.g. when user calls disconnect()
|
||||||
// should be reset to false after connect()
|
// should be reset to false after connect()
|
||||||
bool expect_disconnected = false;
|
bool expect_disconnected = false;
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
# Name, Type, SubType, Offset, Size, Flags
|
|
||||||
# NVS 256KB
|
|
||||||
nvs, data, nvs, , 0x40000,
|
|
||||||
# OTA Data 8KB
|
|
||||||
otadata, data, ota, , 0x2000,
|
|
||||||
# PHY Init 4KB
|
|
||||||
phy_init, data, phy, , 0x1000,
|
|
||||||
# OTA Partitions 10MB
|
|
||||||
ota_0, app, ota_0, , 0xA00000,
|
|
||||||
ota_1, app, ota_1, , 0xA00000,
|
|
||||||
# SPIFFS 11MB
|
|
||||||
storage, data, spiffs, , 0xB00000,
|
|
||||||
|
@@ -430,9 +430,9 @@ CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
|||||||
# end of Recovery Bootloader and Rollback
|
# end of Recovery Bootloader and Rollback
|
||||||
|
|
||||||
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0
|
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0
|
||||||
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE is not set
|
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||||
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set
|
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set
|
||||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF=y
|
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set
|
||||||
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set
|
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -469,7 +469,8 @@ CONFIG_BOOTLOADER_LOG_MODE_TEXT=y
|
|||||||
# CONFIG_BOOTLOADER_FLASH_DC_AWARE is not set
|
# CONFIG_BOOTLOADER_FLASH_DC_AWARE is not set
|
||||||
CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
|
CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT=y
|
||||||
CONFIG_BOOTLOADER_FLASH_32BIT_ADDR=y
|
CONFIG_BOOTLOADER_FLASH_32BIT_ADDR=y
|
||||||
CONFIG_BOOTLOADER_CACHE_32BIT_ADDR_OCTAL_FLASH=y
|
CONFIG_BOOTLOADER_FLASH_NEEDS_32BIT_FEAT=y
|
||||||
|
CONFIG_BOOTLOADER_FLASH_NEEDS_32BIT_ADDR_QUAD_FLASH=y
|
||||||
# end of Serial Flash Configurations
|
# end of Serial Flash Configurations
|
||||||
|
|
||||||
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
|
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
|
||||||
@@ -551,12 +552,14 @@ CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
|
|||||||
# Serial flasher config
|
# Serial flasher config
|
||||||
#
|
#
|
||||||
# CONFIG_ESPTOOLPY_NO_STUB is not set
|
# CONFIG_ESPTOOLPY_NO_STUB is not set
|
||||||
CONFIG_ESPTOOLPY_OCT_FLASH=y
|
# CONFIG_ESPTOOLPY_OCT_FLASH is not set
|
||||||
CONFIG_ESPTOOLPY_FLASH_MODE_AUTO_DETECT=y
|
CONFIG_ESPTOOLPY_FLASH_MODE_AUTO_DETECT=y
|
||||||
CONFIG_ESPTOOLPY_FLASHMODE_OPI=y
|
# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set
|
||||||
|
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
|
||||||
|
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
|
||||||
|
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
|
||||||
CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
|
CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
|
||||||
# CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_DTR is not set
|
CONFIG_ESPTOOLPY_FLASHMODE="dio"
|
||||||
CONFIG_ESPTOOLPY_FLASHMODE="dout"
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
|
# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
|
||||||
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
||||||
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
|
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
|
||||||
@@ -1105,14 +1108,14 @@ CONFIG_SPIRAM_SPEED=80
|
|||||||
CONFIG_SPIRAM_BOOT_HW_INIT=y
|
CONFIG_SPIRAM_BOOT_HW_INIT=y
|
||||||
CONFIG_SPIRAM_BOOT_INIT=y
|
CONFIG_SPIRAM_BOOT_INIT=y
|
||||||
CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION=y
|
CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION=y
|
||||||
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
|
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
|
||||||
# CONFIG_SPIRAM_USE_MEMMAP is not set
|
# CONFIG_SPIRAM_USE_MEMMAP is not set
|
||||||
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
|
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
|
||||||
CONFIG_SPIRAM_USE_MALLOC=y
|
CONFIG_SPIRAM_USE_MALLOC=y
|
||||||
CONFIG_SPIRAM_MEMTEST=y
|
# CONFIG_SPIRAM_MEMTEST is not set
|
||||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
|
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
|
||||||
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
|
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
|
||||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536
|
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
|
||||||
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
|
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
|
||||||
# CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set
|
# CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set
|
||||||
# end of SPI RAM config
|
# end of SPI RAM config
|
||||||
@@ -1266,9 +1269,9 @@ CONFIG_ESP_WIFI_ENABLED=y
|
|||||||
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10
|
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10
|
||||||
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
||||||
CONFIG_ESP_WIFI_STATIC_TX_BUFFER=y
|
CONFIG_ESP_WIFI_STATIC_TX_BUFFER=y
|
||||||
|
# CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER is not set
|
||||||
CONFIG_ESP_WIFI_TX_BUFFER_TYPE=0
|
CONFIG_ESP_WIFI_TX_BUFFER_TYPE=0
|
||||||
CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=16
|
CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=16
|
||||||
CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=32
|
|
||||||
CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
|
CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
|
||||||
# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
|
# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
|
||||||
CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
|
CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
|
||||||
@@ -1278,15 +1281,14 @@ CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y
|
|||||||
CONFIG_ESP_WIFI_TX_BA_WIN=6
|
CONFIG_ESP_WIFI_TX_BA_WIN=6
|
||||||
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
|
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
|
||||||
CONFIG_ESP_WIFI_RX_BA_WIN=6
|
CONFIG_ESP_WIFI_RX_BA_WIN=6
|
||||||
# CONFIG_ESP_WIFI_AMSDU_TX_ENABLED is not set
|
|
||||||
CONFIG_ESP_WIFI_NVS_ENABLED=y
|
CONFIG_ESP_WIFI_NVS_ENABLED=y
|
||||||
# CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0 is not set
|
# CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0 is not set
|
||||||
CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_1=y
|
CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_1=y
|
||||||
CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
||||||
CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32
|
CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32
|
||||||
# CONFIG_ESP_WIFI_IRAM_OPT is not set
|
CONFIG_ESP_WIFI_IRAM_OPT=y
|
||||||
# CONFIG_ESP_WIFI_EXTRA_IRAM_OPT is not set
|
# CONFIG_ESP_WIFI_EXTRA_IRAM_OPT is not set
|
||||||
# CONFIG_ESP_WIFI_RX_IRAM_OPT is not set
|
CONFIG_ESP_WIFI_RX_IRAM_OPT=y
|
||||||
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y
|
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y
|
||||||
CONFIG_ESP_WIFI_ENABLE_SAE_PK=y
|
CONFIG_ESP_WIFI_ENABLE_SAE_PK=y
|
||||||
CONFIG_ESP_WIFI_ENABLE_SAE_H2E=y
|
CONFIG_ESP_WIFI_ENABLE_SAE_H2E=y
|
||||||
@@ -1566,7 +1568,6 @@ CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4
|
|||||||
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
|
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
|
||||||
# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set
|
# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set
|
||||||
# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set
|
# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set
|
||||||
# CONFIG_LWIP_WND_SCALE is not set
|
|
||||||
CONFIG_LWIP_TCP_RTO_TIME=1500
|
CONFIG_LWIP_TCP_RTO_TIME=1500
|
||||||
# end of TCP
|
# end of TCP
|
||||||
|
|
||||||
@@ -1670,9 +1671,9 @@ CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT=y
|
|||||||
#
|
#
|
||||||
# mbedTLS
|
# mbedTLS
|
||||||
#
|
#
|
||||||
# CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC is not set
|
CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y
|
||||||
# CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC is not set
|
# CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC is not set
|
||||||
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
|
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
|
||||||
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
|
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
|
||||||
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
|
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
|
||||||
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
|
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
|
||||||
@@ -1834,7 +1835,7 @@ CONFIG_STDATOMIC_S32C1I_SPIRAM_WORKAROUND=y
|
|||||||
# CONFIG_NVS_ENCRYPTION is not set
|
# CONFIG_NVS_ENCRYPTION is not set
|
||||||
# CONFIG_NVS_ASSERT_ERROR_CHECK is not set
|
# CONFIG_NVS_ASSERT_ERROR_CHECK is not set
|
||||||
# CONFIG_NVS_LEGACY_DUP_KEYS_COMPATIBILITY is not set
|
# CONFIG_NVS_LEGACY_DUP_KEYS_COMPATIBILITY is not set
|
||||||
CONFIG_NVS_ALLOCATE_CACHE_IN_SPIRAM=y
|
# CONFIG_NVS_ALLOCATE_CACHE_IN_SPIRAM is not set
|
||||||
# end of NVS
|
# end of NVS
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -1876,6 +1877,12 @@ CONFIG_SPI_FLASH_BROWNOUT_RESET=y
|
|||||||
#
|
#
|
||||||
# Features here require specific hardware (READ DOCS FIRST!)
|
# Features here require specific hardware (READ DOCS FIRST!)
|
||||||
#
|
#
|
||||||
|
# CONFIG_SPI_FLASH_HPM_ENA is not set
|
||||||
|
CONFIG_SPI_FLASH_HPM_AUTO=y
|
||||||
|
# CONFIG_SPI_FLASH_HPM_DIS is not set
|
||||||
|
CONFIG_SPI_FLASH_HPM_ON=y
|
||||||
|
CONFIG_SPI_FLASH_HPM_DC_AUTO=y
|
||||||
|
# CONFIG_SPI_FLASH_HPM_DC_DISABLE is not set
|
||||||
# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set
|
# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set
|
||||||
CONFIG_SPI_FLASH_SUSPEND_TSUS_VAL_US=50
|
CONFIG_SPI_FLASH_SUSPEND_TSUS_VAL_US=50
|
||||||
# CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND is not set
|
# CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND is not set
|
||||||
@@ -1890,6 +1897,7 @@ CONFIG_SPI_FLASH_PLACE_FUNCTIONS_IN_IRAM=y
|
|||||||
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
|
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
|
||||||
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
|
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
|
||||||
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
|
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
|
||||||
|
# CONFIG_SPI_FLASH_ROM_IMPL is not set
|
||||||
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
|
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
|
||||||
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
|
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
|
||||||
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
|
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
|
||||||
@@ -2396,8 +2404,11 @@ CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
|
|||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
|
||||||
CONFIG_LOG_BOOTLOADER_LEVEL=3
|
CONFIG_LOG_BOOTLOADER_LEVEL=3
|
||||||
CONFIG_SPI_FLASH_OCTAL_32BIT_ADDR_ENABLE=y
|
|
||||||
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
|
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
|
||||||
|
# CONFIG_FLASHMODE_QIO is not set
|
||||||
|
# CONFIG_FLASHMODE_QOUT is not set
|
||||||
|
CONFIG_FLASHMODE_DIO=y
|
||||||
|
# CONFIG_FLASHMODE_DOUT is not set
|
||||||
CONFIG_MONITOR_BAUD=115200
|
CONFIG_MONITOR_BAUD=115200
|
||||||
# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set
|
# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set
|
||||||
# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
|
# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
|
||||||
@@ -2490,22 +2501,21 @@ CONFIG_ESP32_WIFI_ENABLED=y
|
|||||||
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10
|
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10
|
||||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
||||||
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y
|
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y
|
||||||
|
# CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER is not set
|
||||||
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0
|
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0
|
||||||
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16
|
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16
|
||||||
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=32
|
|
||||||
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
|
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
|
||||||
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
|
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
|
||||||
CONFIG_ESP32_WIFI_TX_BA_WIN=6
|
CONFIG_ESP32_WIFI_TX_BA_WIN=6
|
||||||
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
|
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
|
||||||
CONFIG_ESP32_WIFI_RX_BA_WIN=6
|
CONFIG_ESP32_WIFI_RX_BA_WIN=6
|
||||||
# CONFIG_ESP32_WIFI_AMSDU_TX_ENABLED is not set
|
|
||||||
CONFIG_ESP32_WIFI_NVS_ENABLED=y
|
CONFIG_ESP32_WIFI_NVS_ENABLED=y
|
||||||
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 is not set
|
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 is not set
|
||||||
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1=y
|
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1=y
|
||||||
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
||||||
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
|
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
|
||||||
# CONFIG_ESP32_WIFI_IRAM_OPT is not set
|
CONFIG_ESP32_WIFI_IRAM_OPT=y
|
||||||
# CONFIG_ESP32_WIFI_RX_IRAM_OPT is not set
|
CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
|
||||||
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
|
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
|
||||||
CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=y
|
CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=y
|
||||||
CONFIG_WPA_MBEDTLS_CRYPTO=y
|
CONFIG_WPA_MBEDTLS_CRYPTO=y
|
||||||
|
|||||||
Reference in New Issue
Block a user