ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
epaper_spi_mono.cpp
Go to the documentation of this file.
1#include "epaper_spi_mono.h"
2
3#include <algorithm>
4
5#include "esphome/core/log.h"
6
7namespace esphome::epaper_spi {
8ESPHOME_LOG_TAG(TAG, "epaper_spi.mono");
9
10void EPaperMono::refresh_screen(bool partial) {
11 ESP_LOGV(TAG, "Refresh screen");
12 this->cmd_data(0x22, {partial ? (uint8_t) 0xFF : (uint8_t) 0xF7});
13 this->command(0x20);
14}
15
17 // Deep sleep loses RAM so cannot be used with partial update
18 if (!this->is_using_partial_update_()) {
19 ESP_LOGV(TAG, "Deep sleep");
20 this->cmd_data(0x10, {0x03}); // deep sleep
21 }
22}
23
25 if (!EPaperBase::reset())
26 return false;
28 if (this->software_reset_)
29 this->command(0x12);
30 return true;
31}
32
34 // if not using partial update, the display will go into deep sleep, so must rewrite entire
35 // buffer since the display RAM will not retain contents
36 if (!this->is_using_partial_update_()) {
37 this->x_low_ = 0;
38 this->x_high_ = this->width_;
39 this->y_low_ = 0;
40 this->y_high_ = this->height_;
41 }
42 // round x-coordinates to byte boundaries
43 this->x_low_ &= ~7;
44 this->x_high_ += 7;
45 this->x_high_ &= ~7;
46 this->cmd_data(0x44, {(uint8_t) this->x_low_, (uint8_t) (this->x_low_ / 256), (uint8_t) (this->x_high_ - 1),
47 (uint8_t) ((this->x_high_ - 1) / 256)});
48 this->cmd_data(0x4E, {(uint8_t) this->x_low_, (uint8_t) (this->x_low_ / 256)});
49 this->cmd_data(0x45, {(uint8_t) this->y_low_, (uint8_t) (this->y_low_ / 256), (uint8_t) (this->y_high_ - 1),
50 (uint8_t) ((this->y_high_ - 1) / 256)});
51 this->cmd_data(0x4F, {(uint8_t) this->y_low_, (uint8_t) (this->y_low_ / 256)});
52}
53
55 auto start_time = millis();
56 if (this->current_data_index_ == 0) {
57 // round to byte boundaries
58 this->set_window();
59 // for monochrome, we still need to clear the red data buffer at least once to prevent it
60 // causing dirty pixels after partial refresh.
61 this->command(this->send_red_ ? 0x26 : 0x24);
62 this->current_data_index_ = this->y_low_; // actually current line
63 }
64 size_t row_length = (this->x_high_ - this->x_low_) / 8;
65 FixedVector<uint8_t> bytes_to_send{};
66 bytes_to_send.init(row_length);
67 ESP_LOGV(TAG, "Writing %u bytes at line %zu at %ums", row_length, this->current_data_index_, (unsigned) millis());
68 this->start_data_();
69 while (this->current_data_index_ != this->y_high_) {
70 const size_t row_start = this->current_data_index_ * this->row_width_ + this->x_low_ / 8;
71 size_t data_idx = row_start;
72 for (size_t i = 0; i != row_length; i++) {
73 bytes_to_send[i] = this->send_red_ && !this->send_red_as_image_ ? 0 : this->buffer_[data_idx++];
74 }
75 ++this->current_data_index_;
76 this->write_array(&bytes_to_send.front(), row_length); // NOLINT
77 if (millis() - start_time > MAX_TRANSFER_TIME) {
78 // Let the main loop run and come back next loop
79 this->disable();
80 return false;
81 }
82 }
83
84 this->disable();
85 this->current_data_index_ = 0;
86 if (this->send_red_) {
87 this->send_red_ = false;
88 return false;
89 }
90 return true;
91}
92
93} // namespace esphome::epaper_spi
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
Definition helpers.h:769
void init(size_t n)
Definition helpers.h:859
void command(uint8_t value)
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:229
void cmd_data(uint8_t command, const uint8_t *ptr, size_t length)
void refresh_screen(bool partial) override
ESPHOME_LOG_TAG(TAG, "display")
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25