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