ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
epaper_spi_ssd1681.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
5#include "esphome/core/hal.h"
6#include "esphome/core/log.h"
7
8namespace esphome::epaper_spi {
9ESPHOME_LOG_TAG(TAG, "epaper_spi.ssd1681");
10
12 const uint32_t start_time = millis();
13 if (this->current_data_index_ == 0) {
14 this->set_window();
15 this->command(0x26);
16 }
17 this->start_data_();
18 const size_t end = this->sent_.size();
19 while (this->current_data_index_ != end) {
20 size_t length;
21 const uint8_t *bytes = this->sent_.get_span(this->current_data_index_, length);
22 length = std::min<size_t>({length, end - this->current_data_index_, this->row_width_});
23 this->write_array(bytes, length);
25 if (millis() - start_time > MAX_TRANSFER_TIME) {
26 // Let the main loop run and come back next loop
27 this->disable();
28 return false;
29 }
30 }
31 this->disable();
32 this->current_data_index_ = 0;
33 this->send_red_ = false;
34 return false;
35}
36
38 if (this->current_data_index_ == 0 && this->send_red_) {
39 // Both banks always get the whole frame: the RAM ping-pong the panel's OTP enables swaps the bank each
40 // command writes after every refresh, so a bank that is only partly written keeps an image from two frames ago
41 this->x_low_ = 0;
42 this->x_high_ = this->width_;
43 this->y_low_ = 0;
44 this->y_high_ = this->height_;
45 // Without the previous frame there is nothing to compare against, so refresh the whole panel
46 if (this->partial_ && !this->sent_valid_)
47 this->partial_ = false;
48 }
49 if (this->partial_ && this->send_red_)
50 return this->transfer_previous_frame_();
52}
53
55 ESP_LOGV(TAG, "Refresh screen");
56 this->cmd_data(0x3C, {partial ? (uint8_t) 0x80 : (uint8_t) 0x01});
57 // 0x26 is compared as it is on a partial refresh and ignored on a full one
58 this->cmd_data(0x21, {partial ? (uint8_t) 0x00 : (uint8_t) 0x40, (uint8_t) 0x00});
59 // Both end with analog and OSC off before the panel goes to sleep
60 this->cmd_data(0x22, {partial ? (uint8_t) 0xFF : (uint8_t) 0xF7});
61 this->command(0x20);
62}
63
64} // namespace esphome::epaper_spi
void command(uint8_t value)
void cmd_data(uint8_t command, const uint8_t *ptr, size_t length)
split_buffer::SplitBuffer sent_
Definition epaper_spi.h:219
void refresh_screen(bool partial) override
const uint8_t * get_span(size_t index, size_t &length) const
ESPHOME_LOG_TAG(TAG, "display")
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25
static void uint32_t
uint8_t end[39]
Definition sun_gtil2.cpp:17
uint16_t length
Definition tt21100.cpp:0