ESPHome 2026.1.4
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 this->command(0x10);
19}
20
22 if (EPaperBase::reset()) {
23 this->command(0x12);
24 return true;
25 }
26 return false;
27}
28
30 // round x-coordinates to byte boundaries
31 this->x_low_ &= ~7;
32 this->x_high_ += 7;
33 this->x_high_ &= ~7;
34 this->cmd_data(0x44, {(uint8_t) this->x_low_, (uint8_t) (this->x_low_ / 256), (uint8_t) (this->x_high_ - 1),
35 (uint8_t) ((this->x_high_ - 1) / 256)});
36 this->cmd_data(0x4E, {(uint8_t) this->x_low_, (uint8_t) (this->x_low_ / 256)});
37 this->cmd_data(0x45, {(uint8_t) this->y_low_, (uint8_t) (this->y_low_ / 256), (uint8_t) (this->y_high_ - 1),
38 (uint8_t) ((this->y_high_ - 1) / 256)});
39 this->cmd_data(0x4F, {(uint8_t) this->y_low_, (uint8_t) (this->y_low_ / 256)});
40}
41
43 auto start_time = millis();
44 if (this->current_data_index_ == 0) {
45 // round to byte boundaries
46 this->set_window();
47 // for monochrome, we still need to clear the red data buffer at least once to prevent it
48 // causing dirty pixels after partial refresh.
49 this->command(this->send_red_ ? 0x26 : 0x24);
50 this->current_data_index_ = this->y_low_; // actually current line
51 }
52 size_t row_length = (this->x_high_ - this->x_low_) / 8;
53 FixedVector<uint8_t> bytes_to_send{};
54 bytes_to_send.init(row_length);
55 ESP_LOGV(TAG, "Writing %u bytes at line %zu at %ums", row_length, this->current_data_index_, (unsigned) millis());
56 this->start_data_();
57 while (this->current_data_index_ != this->y_high_) {
58 size_t data_idx = this->current_data_index_ * this->row_width_ + this->x_low_ / 8;
59 for (size_t i = 0; i != row_length; i++) {
60 bytes_to_send[i] = this->send_red_ ? 0 : this->buffer_[data_idx++];
61 }
62 ++this->current_data_index_;
63 this->write_array(&bytes_to_send.front(), row_length); // NOLINT
64 if (millis() - start_time > MAX_TRANSFER_TIME) {
65 // Let the main loop run and come back next loop
66 this->disable();
67 return false;
68 }
69 }
70
71 this->disable();
72 this->current_data_index_ = 0;
73 if (this->send_red_) {
74 this->send_red_ = false;
75 return false;
76 }
77 return true;
78}
79
80} // namespace esphome::epaper_spi
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:188
void init(size_t n)
Definition helpers.h:278
void command(uint8_t value)
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:165
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