ESPHome 2026.5.0b1
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 {
8static constexpr const char *const 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 ESP_LOGV(TAG, "Deep sleep");
18 if (this->is_using_partial_update_()) {
19 this->cmd_data(0x10, {0x00}); // sleep in power on mode
20 } else {
21 this->cmd_data(0x10, {0x03}); // deep sleep
22 }
23}
24
26 if (EPaperBase::reset()) {
27 this->command(0x12);
28 return true;
29 }
30 return false;
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 size_t data_idx = this->current_data_index_ * this->row_width_ + this->x_low_ / 8;
71 for (size_t i = 0; i != row_length; i++) {
72 bytes_to_send[i] = this->send_red_ ? 0 : this->buffer_[data_idx++];
73 }
74 ++this->current_data_index_;
75 this->write_array(&bytes_to_send.front(), row_length); // NOLINT
76 if (millis() - start_time > MAX_TRANSFER_TIME) {
77 // Let the main loop run and come back next loop
78 this->disable();
79 return false;
80 }
81 }
82
83 this->disable();
84 this->current_data_index_ = 0;
85 if (this->send_red_) {
86 this->send_red_ = false;
87 return false;
88 }
89 return true;
90}
91
92} // namespace esphome::epaper_spi
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:529
void init(size_t n)
Definition helpers.h:619
void command(uint8_t value)
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:176
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 hal.cpp:28