Skip to content

Commit

Permalink
Fix Waveshare 7.5v2 epaper screens are always powered on (esphome#5283)
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixswiss committed Sep 14, 2023
1 parent 280b090 commit 55b5c0f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
66 changes: 57 additions & 9 deletions esphome/components/waveshare_epaper/waveshare_epaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,17 +1561,45 @@ void WaveshareEPaper7P5In::dump_config() {
LOG_PIN(" Busy Pin: ", this->busy_pin_);
LOG_UPDATE_INTERVAL(this);
}
bool WaveshareEPaper7P5InV2::wait_until_idle_() {
if (this->busy_pin_ == nullptr) {
return true;
}

const uint32_t start = millis();
while (this->busy_pin_->digital_read()) {
this->command(0x71);
if (millis() - start > this->idle_timeout_()) {
ESP_LOGE(TAG, "Timeout while displaying image!");
return false;
}
App.feed_wdt();
delay(10);
}
return true;
}
void WaveshareEPaper7P5InV2::initialize() {
// COMMAND POWER SETTING
this->command(0x01);
this->data(0x07);
this->data(0x07);
this->data(0x3f);
this->data(0x3f);
this->command(0x04);

// We don't want the display to be powered at this point

delay(100); // NOLINT
this->wait_until_idle_();

// COMMAND VCOM AND DATA INTERVAL SETTING
this->command(0x50);
this->data(0x10);
this->data(0x07);

// COMMAND TCON SETTING
this->command(0x60);
this->data(0x22);

// COMMAND PANEL SETTING
this->command(0x00);
this->data(0x1F);
Expand All @@ -1582,34 +1610,54 @@ void WaveshareEPaper7P5InV2::initialize() {
this->data(0x20);
this->data(0x01);
this->data(0xE0);
// COMMAND ...?

// COMMAND DUAL SPI MM_EN, DUSPI_EN
this->command(0x15);
this->data(0x00);
// COMMAND VCOM AND DATA INTERVAL SETTING
this->command(0x50);
this->data(0x10);
this->data(0x07);
// COMMAND TCON SETTING
this->command(0x60);
this->data(0x22);

// COMMAND POWER DRIVER HAT DOWN
// This command will turn off booster, controller, source driver, gate driver, VCOM, and
// temperature sensor, but register data will be kept until VDD turned OFF or Deep Sleep Mode.
// Source/Gate/Border/VCOM will be released to floating.
this->command(0x02);
}
void HOT WaveshareEPaper7P5InV2::display() {
uint32_t buf_len = this->get_buffer_length_();

// COMMAND POWER ON
ESP_LOGI(TAG, "Power on the display and hat");

// This command will turn on booster, controller, regulators, and temperature sensor will be
// activated for one-time sensing before enabling booster. When all voltages are ready, the
// BUSY_N signal will return to high.
this->command(0x04);
delay(200); // NOLINT
this->wait_until_idle_();

// COMMAND DATA START TRANSMISSION NEW DATA
this->command(0x13);
delay(2);
for (uint32_t i = 0; i < buf_len; i++) {
this->data(~(this->buffer_[i]));
}

delay(100); // NOLINT
this->wait_until_idle_();

// COMMAND DISPLAY REFRESH
this->command(0x12);
delay(100); // NOLINT
this->wait_until_idle_();

ESP_LOGV(TAG, "Before command(0x02) (>> power off)");
this->command(0x02);
this->wait_until_idle_();
ESP_LOGV(TAG, "After command(0x02) (>> power off)");
}

int WaveshareEPaper7P5InV2::get_width_internal() { return 800; }
int WaveshareEPaper7P5InV2::get_height_internal() { return 480; }
uint32_t WaveshareEPaper7P5InV2::idle_timeout_() { return 10000; }
void WaveshareEPaper7P5InV2::dump_config() {
LOG_DISPLAY("", "Waveshare E-Paper", this);
ESP_LOGCONFIG(TAG, " Model: 7.5inV2rev2");
Expand Down
4 changes: 4 additions & 0 deletions esphome/components/waveshare_epaper/waveshare_epaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ class WaveshareEPaper7P5InBC : public WaveshareEPaper {

class WaveshareEPaper7P5InV2 : public WaveshareEPaper {
public:
bool wait_until_idle_();

void initialize() override;

void display() override;
Expand All @@ -491,6 +493,8 @@ class WaveshareEPaper7P5InV2 : public WaveshareEPaper {
int get_width_internal() override;

int get_height_internal() override;

uint32_t idle_timeout_() override;
};

class WaveshareEPaper7P5InV2alt : public WaveshareEPaper7P5InV2 {
Expand Down

0 comments on commit 55b5c0f

Please sign in to comment.