ESPHome 2026.11.0b6
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
12 if (!this->is_failed())
14}
15
20
21void EPaperMono::refresh_screen(bool partial) {
22 ESP_LOGV(TAG, "Refresh screen");
23 this->cmd_data(0x22, {partial ? (uint8_t) 0xFF : (uint8_t) 0xF7});
24 this->command(0x20);
25}
26
28 // Deep sleep loses RAM so cannot be used with partial update
29 if (!this->is_using_partial_update_()) {
30 ESP_LOGV(TAG, "Deep sleep");
31 this->cmd_data(0x10, {0x03}); // deep sleep
32 }
33}
34
36 if (!EPaperBase::reset())
37 return false;
39 if (this->software_reset_)
40 this->command(0x12);
41 return true;
42}
43
45 // if not using partial update, the display will go into deep sleep, so must rewrite entire
46 // buffer since the display RAM will not retain contents
47 if (!this->is_using_partial_update_()) {
48 this->x_low_ = 0;
49 this->x_high_ = this->width_;
50 this->y_low_ = 0;
51 this->y_high_ = this->height_;
52 }
53 // round x-coordinates to byte boundaries
54 this->x_low_ &= ~7;
55 this->x_high_ += 7;
56 this->x_high_ &= ~7;
57 this->cmd_data(0x44, {(uint8_t) this->x_low_, (uint8_t) (this->x_low_ / 256), (uint8_t) (this->x_high_ - 1),
58 (uint8_t) ((this->x_high_ - 1) / 256)});
59 this->cmd_data(0x4E, {(uint8_t) this->x_low_, (uint8_t) (this->x_low_ / 256)});
60 this->cmd_data(0x45, {(uint8_t) this->y_low_, (uint8_t) (this->y_low_ / 256), (uint8_t) (this->y_high_ - 1),
61 (uint8_t) ((this->y_high_ - 1) / 256)});
62 this->cmd_data(0x4F, {(uint8_t) this->y_low_, (uint8_t) (this->y_low_ / 256)});
63}
64
66 auto start_time = millis();
67 if (this->current_data_index_ == 0) {
68 // round to byte boundaries
69 this->set_window();
70 // for monochrome, we still need to clear the red data buffer at least once to prevent it
71 // causing dirty pixels after partial refresh.
72 this->command(this->send_red_ ? 0x26 : 0x24);
73 this->current_data_index_ = this->y_low_; // actually current line
74 }
75 size_t row_length = (this->x_high_ - this->x_low_) / 8;
76 FixedVector<uint8_t> bytes_to_send{};
77 bytes_to_send.init(row_length);
78 ESP_LOGV(TAG, "Writing %u bytes at line %zu at %ums", row_length, this->current_data_index_, (unsigned) millis());
79 this->start_data_();
80 while (this->current_data_index_ != this->y_high_) {
81 const size_t row_start = this->current_data_index_ * this->row_width_ + this->x_low_ / 8;
82 size_t data_idx = row_start;
83 for (size_t i = 0; i != row_length; i++) {
84 bytes_to_send[i] = this->send_red_ && !this->send_red_as_image_ ? 0 : this->buffer_[data_idx++];
85 }
86 ++this->current_data_index_;
87 this->write_array(&bytes_to_send.front(), row_length); // NOLINT
88 if (millis() - start_time > MAX_TRANSFER_TIME) {
89 // Let the main loop run and come back next loop
90 this->disable();
91 return false;
92 }
93 }
94
95 this->disable();
96 this->current_data_index_ = 0;
97 if (this->send_red_) {
98 this->send_red_ = false;
99 return false;
100 }
101 return true;
102}
103
104} // namespace esphome::epaper_spi
bool is_failed() const
Definition component.h:287
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
Definition helpers.h:669
void init(size_t n)
Definition helpers.h:759
void command(uint8_t value)
bool init_sent_frame_(size_t length)
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:218
void cmd_data(uint8_t command, const uint8_t *ptr, size_t length)
virtual bool needs_previous_frame() const
Definition epaper_spi.h:148
split_buffer::SplitBuffer sent_
Definition epaper_spi.h:219
void refresh_screen(bool partial) override
virtual size_t sent_frame_length() const
ESPHOME_LOG_TAG(TAG, "display")
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25