ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
epaper_spi_ssd1677.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
5#include "esphome/core/log.h"
6
7namespace esphome::epaper_spi {
8static constexpr const char *const TAG = "epaper_spi.ssd1677";
9
11 ESP_LOGV(TAG, "Refresh screen");
12 this->command(0x22);
13 this->data(partial ? 0xFF : 0xF7);
14 this->command(0x20);
15}
16
18 ESP_LOGV(TAG, "Deep sleep");
19 this->command(0x10);
20}
21
23 if (EPaperBase::reset()) {
24 this->command(0x12);
25 return true;
26 }
27 return false;
28}
29
31 auto start_time = millis();
32 if (this->current_data_index_ == 0) {
33 uint8_t data[4]{};
34 // round to byte boundaries
35 this->x_low_ &= ~7;
36 this->y_low_ &= ~7;
37 this->x_high_ += 7;
38 this->x_high_ &= ~7;
39 this->y_high_ += 7;
40 this->y_high_ &= ~7;
41 data[0] = this->x_low_;
42 data[1] = this->x_low_ / 256;
43 data[2] = this->x_high_ - 1;
44 data[3] = (this->x_high_ - 1) / 256;
45 cmd_data(0x4E, data, 2);
46 cmd_data(0x44, data, sizeof(data));
47 data[0] = this->y_low_;
48 data[1] = this->y_low_ / 256;
49 data[2] = this->y_high_ - 1;
50 data[3] = (this->y_high_ - 1) / 256;
51 cmd_data(0x4F, data, 2);
52 this->cmd_data(0x45, data, sizeof(data));
53 // for monochrome, we still need to clear the red data buffer at least once to prevent it
54 // causing dirty pixels after partial refresh.
55 this->command(this->send_red_ ? 0x26 : 0x24);
56 this->current_data_index_ = this->y_low_; // actually current line
57 }
58 size_t row_length = (this->x_high_ - this->x_low_) / 8;
59 FixedVector<uint8_t> bytes_to_send{};
60 bytes_to_send.init(row_length);
61 ESP_LOGV(TAG, "Writing bytes at line %zu at %ums", this->current_data_index_, (unsigned) millis());
62 this->start_data_();
63 while (this->current_data_index_ != this->y_high_) {
64 size_t data_idx = (this->current_data_index_ * this->width_ + this->x_low_) / 8;
65 for (size_t i = 0; i != row_length; i++) {
66 bytes_to_send[i] = this->send_red_ ? 0 : this->buffer_[data_idx++];
67 }
68 ++this->current_data_index_;
69 this->write_array(&bytes_to_send.front(), row_length); // NOLINT
70 if (millis() - start_time > MAX_TRANSFER_TIME) {
71 // Let the main loop run and come back next loop
72 this->end_data_();
73 return false;
74 }
75 }
76
77 this->end_data_();
78 this->current_data_index_ = 0;
79 if (this->send_red_) {
80 this->send_red_ = false;
81 return false;
82 }
83 return true;
84}
85
86} // namespace esphome::epaper_spi
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:184
void init(size_t n)
Definition helpers.h:274
void command(uint8_t value)
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:155
void cmd_data(uint8_t command, const uint8_t *ptr, size_t length)
void refresh_screen(bool partial) override
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:25