ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
epaper_weact_3c.cpp
Go to the documentation of this file.
1#include "epaper_weact_3c.h"
2
3#include "esphome/core/log.h"
4
5namespace esphome::epaper_spi {
6
7ESPHOME_LOG_TAG(TAG, "epaper_weact_3c");
8
10 // For full screen refresh, we always start from (0,0)
11 // The y_low_/y_high_ values track the dirty region for optimization,
12 // but for display refresh we need to write from the beginning
13 uint16_t x_start = 0;
14 uint16_t x_end = this->width_ - 1;
15 uint16_t y_start = 0;
16 uint16_t y_end = this->height_ - 1; // height = 296 for 2.9" display
17
18 // Set RAM X address boundaries (0x44)
19 // X coordinates are byte-aligned (divided by 8)
20 this->cmd_data(0x44, {(uint8_t) (x_start / 8), (uint8_t) (x_end / 8)});
21
22 // Set RAM Y address boundaries (0x45)
23 // Format: Y start (LSB, MSB), Y end (LSB, MSB)
24 this->cmd_data(0x45, {(uint8_t) y_start, (uint8_t) (y_start >> 8), (uint8_t) (y_end & 0xFF), (uint8_t) (y_end >> 8)});
25
26 // Reset RAM X counter to start (0x4E) - 1 byte
27 this->cmd_data(0x4E, {(uint8_t) (x_start / 8)});
28
29 // Reset RAM Y counter to start (0x4F) - 2 bytes (LSB, MSB)
30 this->cmd_data(0x4F, {(uint8_t) y_start, (uint8_t) (y_start >> 8)});
31}
32
34 const uint32_t start_time = millis();
35 const size_t half_buffer = this->buffer_length_ / 2u;
36
37 // current_data_index_ is the position in buffer_: 0 before the push starts, then the red plane
38 // [half_buffer, buffer_length_), sent first, then the black/white plane (0, half_buffer).
39 // A push only yields after sending some data, so it never stops at exactly 0 or half_buffer.
40 if (this->current_data_index_ == 0) {
41 ESP_LOGV(TAG, "transfer_data: sending RED buffer (0x26)");
42 this->set_window_(); // Reset RAM X/Y counters to start position
43 this->command(0x26);
44 this->current_data_index_ = half_buffer;
45 }
46 if (this->current_data_index_ >= half_buffer) {
47 if (!this->send_buffer_range_(this->buffer_length_, this->invert_red_ ? 0xFF : 0x00, start_time))
48 return false;
49 ESP_LOGV(TAG, "transfer_data: finished red buffer, sending BLACK buffer (0x24)");
50 // Do NOT reset RAM counters here for WeAct displays (Reference implementation behavior)
51 this->command(0x24);
52 this->current_data_index_ = 0;
53 }
54 if (!this->send_buffer_range_(half_buffer, 0xFF, start_time)) // the panel wants 1=white
55 return false;
56
57 this->current_data_index_ = 0;
58 ESP_LOGV(TAG, "transfer_data: completed (red=%u, black=%u bytes)", half_buffer, half_buffer);
59 return true;
60}
61
63 // SSD1680 refresh sequence:
64 // Reset RAM X/Y address counters to 0,0 so display reads from start
65 // 0x4E: RAM X counter - 1 byte (X / 8)
66 // 0x4F: RAM Y counter - 2 bytes (Y LSB, Y MSB)
67 this->cmd_data(0x4E, {0x00}); // RAM X counter = 0 (1 byte)
68 this->cmd_data(0x4F, {0x00, 0x00}); // RAM Y counter = 0 (2 bytes)
69
70 // Send UPDATE_FULL command (0x22) with display update control parameter
71 // Both WeAct and waveshare reference use 0xF7: {0x22, 0xF7}
72 // 0xF7 = Display update: Load temperature, Load LUT, Enable RAM content
73 this->cmd_data(0x22, {0xF7}); // Command 0x22 with parameter 0xF7
74 this->command(0x20); // Activate display update
75
76 // COMMAND TERMINATE FRAME READ WRITE (required by SSD1680)
77 // Removed 0xFF based on working reference implementation
78 // this->command(0xFF);
79}
80
82 // Power on sequence - send command to turn on power
83 // According to SSD1680 spec: 0x22, 0xF8 powers on the display
84 this->cmd_data(0x22, {0xF8}); // Power on
85 this->command(0x20); // Activate
86}
87
89 // Power off sequence - send command to turn off power
90 // According to SSD1680 spec: 0x22, 0x83 powers off the display
91 this->cmd_data(0x22, {0x83}); // Power off
92 this->command(0x20); // Activate
93}
94
96 // Deep sleep sequence
97 this->cmd_data(0x10, {0x01}); // Deep sleep mode
98}
99
100} // namespace esphome::epaper_spi
bool send_buffer_range_(size_t end, uint8_t invert_mask, uint32_t start_time)
void command(uint8_t value)
void cmd_data(uint8_t command, const uint8_t *ptr, size_t length)
void refresh_screen(bool partial) override
static void int x_start
Definition display.cpp:62
static void int int y_start
Definition display.cpp:62
ESPHOME_LOG_TAG(TAG, "display")
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25
static void uint32_t