1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

[epaper_spi] Refactor initialise for future use (#13774)

This commit is contained in:
schrob
2026-02-05 14:26:47 +01:00
committed by GitHub
parent 9ea8461440
commit bbdb202e2c
4 changed files with 14 additions and 7 deletions

View File

@@ -182,7 +182,9 @@ void EPaperBase::process_state_() {
this->set_state_(EPaperState::RESET);
break;
case EPaperState::INITIALISE:
this->initialise(this->update_count_ != 0);
if (!this->initialise(this->update_count_ != 0)) {
return; // Not done yet, come back next loop
}
this->set_state_(EPaperState::TRANSFER_DATA);
break;
case EPaperState::TRANSFER_DATA:
@@ -239,11 +241,9 @@ void EPaperBase::start_data_() {
void EPaperBase::on_safe_shutdown() { this->deep_sleep(); }
void EPaperBase::initialise(bool partial) {
void EPaperBase::send_init_sequence_(const uint8_t *sequence, size_t length) {
size_t index = 0;
auto *sequence = this->init_sequence_;
auto length = this->init_sequence_length_;
while (index != length) {
if (length - index < 2) {
this->mark_failed(LOG_STR("Malformed init sequence"));
@@ -266,6 +266,11 @@ void EPaperBase::initialise(bool partial) {
}
}
bool EPaperBase::initialise(bool partial) {
this->send_init_sequence_(this->init_sequence_, this->init_sequence_length_);
return true;
}
/**
* Check and rotate coordinates based on the transform flags.
* @param x

View File

@@ -115,7 +115,8 @@ class EPaperBase : public Display,
bool is_idle_() const;
void setup_pins_() const;
virtual bool reset();
virtual void initialise(bool partial);
virtual bool initialise(bool partial);
void send_init_sequence_(const uint8_t *sequence, size_t length);
void wait_for_idle_(bool should_wait);
bool init_buffer_(size_t buffer_length);
bool rotate_coordinates_(int &x, int &y);

View File

@@ -4,7 +4,7 @@ namespace esphome::epaper_spi {
static const char *const TAG = "epaper_spi.waveshare";
void EpaperWaveshare::initialise(bool partial) {
bool EpaperWaveshare::initialise(bool partial) {
EPaperBase::initialise(partial);
if (partial) {
this->cmd_data(0x32, this->partial_lut_, this->partial_lut_length_);
@@ -17,6 +17,7 @@ void EpaperWaveshare::initialise(bool partial) {
this->cmd_data(0x3C, {0x05});
}
this->send_red_ = true;
return true;
}
void EpaperWaveshare::set_window() {

View File

@@ -18,7 +18,7 @@ class EpaperWaveshare : public EPaperMono {
partial_lut_length_(partial_lut_length) {}
protected:
void initialise(bool partial) override;
bool initialise(bool partial) override;
void set_window() override;
void refresh_screen(bool partial) override;
void deep_sleep() override;