ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
epaper_spi_ssd1677.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
6#include "esphome/core/log.h"
7
8namespace esphome::epaper_spi {
9
10// Nothing a partial update needs is kept in controller RAM any more, so skip the reset for those.
12 if (this->update_count_ != 0 && this->sent_.is_valid())
13 return true;
14 return EPaperMono::reset();
15}
16
17// The window always covers the whole panel, so each plane is the frame's bytes in order. Where
18// those bytes are already stored as the plane needs them (the comparison frame, and a 1-bit
19// buffer) they are written straight from the buffer, as many at a time as the time slice allows;
20// otherwise they are built a row at a time by mono_row().
22 if (!this->sent_.is_valid())
24
25 const auto start_time = millis();
26 if (this->current_data_index_ == 0) {
27 if (this->plane_ == 0) {
28 this->x_low_ = 0;
29 this->x_high_ = this->width_;
30 this->y_low_ = 0;
31 this->y_high_ = this->height_;
32 }
33 this->set_window();
34 this->command(this->plane_ == 0 ? 0x26 : 0x24);
35 }
36 // A full update ignores 0x26, and the copy may not hold a real frame yet (first update after
37 // boot): send the new frame to both planes.
38 const bool send_copy = this->plane_ == 0 && this->update_count_ != 0;
39 // A 1 bit per pixel buffer already holds the frame as a RAM plane does, so it can be sent as it is; a
40 // deeper buffer (the four-level model, 2 bits per pixel) packs the plane in mono_row() instead.
41 const bool direct = send_copy || this->buffer_is_mono_();
42 const auto &source = send_copy ? this->sent_ : this->buffer_;
43 const size_t row_length = this->mono_row_length_();
44 const size_t plane_length = row_length * this->height_;
45 // Roughly what the bus moves in one time slice, so a slice is not overrun by much
46 const size_t max_chunk = std::max<size_t>(this->data_rate_ / 8000 * MAX_TRANSFER_TIME, MAX_TRANSFER_SIZE);
47 SmallBufferWithHeapFallback<128> row_alloc(direct ? 0 : row_length);
48 this->start_data_();
49 while (this->current_data_index_ != plane_length) {
50 size_t length;
51 const uint8_t *data;
52 if (direct) {
53 data = source.get_span(this->current_data_index_, length);
54 length = std::min(length, max_chunk);
55 } else {
56 // Always at the start of a row here, since this path sends whole rows only
57 this->mono_row(this->current_data_index_ / row_length, row_alloc.get());
58 data = row_alloc.get();
59 length = row_length;
60 }
61 this->write_array(data, length);
62 if (this->plane_ == 1)
63 this->record_sent_(this->current_data_index_, data, length);
65 if (this->current_data_index_ != plane_length && millis() - start_time > MAX_TRANSFER_TIME) {
66 // Let the main loop run and come back next loop
67 this->disable();
68 return false;
69 }
70 }
71 this->disable();
72 this->current_data_index_ = 0;
73 if (this->plane_ == 0) {
74 this->plane_ = 1;
75 return false;
76 }
77 this->plane_ = 0;
78 return true;
79}
80
81} // namespace esphome::epaper_spi
Helper class for efficient buffer allocation - uses stack for small sizes, heap for large This is use...
Definition helpers.h:1019
void command(uint8_t value)
void record_sent_(size_t index, const uint8_t *data, size_t length)
Definition epaper_spi.h:140
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:229
split_buffer::SplitBuffer sent_
Definition epaper_spi.h:230
virtual void mono_row(size_t y, uint8_t *out)
uint32_t data_rate_
Definition spi.h:425
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25