2019-04-17 12:06:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
|
|
|
#include "esphome/components/spi/spi.h"
|
|
|
|
#include "esphome/components/display/display_buffer.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace waveshare_epaper {
|
|
|
|
|
2019-06-07 14:25:57 +02:00
|
|
|
class WaveshareEPaper : public PollingComponent,
|
|
|
|
public display::DisplayBuffer,
|
|
|
|
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
|
|
|
|
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ> {
|
2019-04-17 12:06:00 +02:00
|
|
|
public:
|
2019-04-22 21:56:30 +02:00
|
|
|
void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
|
2019-04-17 12:06:00 +02:00
|
|
|
float get_setup_priority() const override;
|
|
|
|
void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
|
|
|
|
void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
|
|
|
|
|
|
|
|
void command(uint8_t value);
|
|
|
|
void data(uint8_t value);
|
|
|
|
|
|
|
|
virtual void display() = 0;
|
2019-05-28 20:22:50 +02:00
|
|
|
virtual void initialize() = 0;
|
|
|
|
virtual void deep_sleep() = 0;
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
|
|
|
void fill(int color) override;
|
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void setup() override {
|
|
|
|
this->setup_pins_();
|
|
|
|
this->initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_safe_shutdown() override;
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
protected:
|
|
|
|
void draw_absolute_pixel_internal(int x, int y, int color) override;
|
|
|
|
|
|
|
|
bool wait_until_idle_();
|
|
|
|
|
|
|
|
void setup_pins_();
|
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void reset_() {
|
|
|
|
if (this->reset_pin_ != nullptr) {
|
|
|
|
this->reset_pin_->digital_write(false);
|
|
|
|
delay(200);
|
|
|
|
this->reset_pin_->digital_write(true);
|
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
uint32_t get_buffer_length_();
|
|
|
|
|
|
|
|
void start_command_();
|
|
|
|
void end_command_();
|
|
|
|
void start_data_();
|
|
|
|
void end_data_();
|
|
|
|
|
|
|
|
GPIOPin *reset_pin_{nullptr};
|
|
|
|
GPIOPin *dc_pin_;
|
|
|
|
GPIOPin *busy_pin_{nullptr};
|
|
|
|
};
|
|
|
|
|
|
|
|
enum WaveshareEPaperTypeAModel {
|
|
|
|
WAVESHARE_EPAPER_1_54_IN = 0,
|
|
|
|
WAVESHARE_EPAPER_2_13_IN,
|
|
|
|
WAVESHARE_EPAPER_2_9_IN,
|
2019-10-17 20:55:27 +02:00
|
|
|
TTGO_EPAPER_2_13_IN,
|
2019-04-17 12:06:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class WaveshareEPaperTypeA : public WaveshareEPaper {
|
|
|
|
public:
|
2019-04-22 21:56:30 +02:00
|
|
|
WaveshareEPaperTypeA(WaveshareEPaperTypeAModel model);
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void initialize() override;
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void dump_config() override;
|
|
|
|
|
|
|
|
void display() override;
|
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void deep_sleep() override {
|
|
|
|
// COMMAND DEEP SLEEP MODE
|
|
|
|
this->command(0x10);
|
|
|
|
this->wait_until_idle_();
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
void set_full_update_every(uint32_t full_update_every);
|
|
|
|
|
|
|
|
protected:
|
2019-10-17 20:55:27 +02:00
|
|
|
void write_lut_(const uint8_t *lut, uint8_t size);
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
int get_width_internal() override;
|
|
|
|
|
|
|
|
int get_height_internal() override;
|
|
|
|
|
|
|
|
uint32_t full_update_every_{30};
|
|
|
|
uint32_t at_update_{0};
|
|
|
|
WaveshareEPaperTypeAModel model_;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum WaveshareEPaperTypeBModel {
|
|
|
|
WAVESHARE_EPAPER_2_7_IN = 0,
|
|
|
|
WAVESHARE_EPAPER_4_2_IN,
|
|
|
|
WAVESHARE_EPAPER_7_5_IN,
|
|
|
|
};
|
|
|
|
|
|
|
|
class WaveshareEPaper2P7In : public WaveshareEPaper {
|
|
|
|
public:
|
2019-05-28 20:22:50 +02:00
|
|
|
void initialize() override;
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void display() override;
|
|
|
|
|
|
|
|
void dump_config() override;
|
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void deep_sleep() override {
|
|
|
|
// COMMAND DEEP SLEEP
|
|
|
|
this->command(0x07);
|
|
|
|
this->data(0xA5); // check byte
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
protected:
|
|
|
|
int get_width_internal() override;
|
|
|
|
|
|
|
|
int get_height_internal() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WaveshareEPaper4P2In : public WaveshareEPaper {
|
|
|
|
public:
|
2019-05-28 20:22:50 +02:00
|
|
|
void initialize() override;
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void display() override;
|
|
|
|
|
|
|
|
void dump_config() override;
|
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void deep_sleep() override {
|
|
|
|
// COMMAND VCOM AND DATA INTERVAL SETTING
|
|
|
|
this->command(0x50);
|
|
|
|
this->data(0x17); // border floating
|
|
|
|
|
|
|
|
// COMMAND VCM DC SETTING
|
|
|
|
this->command(0x82);
|
|
|
|
// COMMAND PANEL SETTING
|
|
|
|
this->command(0x00);
|
|
|
|
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
// COMMAND POWER SETTING
|
|
|
|
this->command(0x01);
|
|
|
|
this->data(0x00);
|
|
|
|
this->data(0x00);
|
|
|
|
this->data(0x00);
|
|
|
|
this->data(0x00);
|
|
|
|
this->data(0x00);
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
// COMMAND POWER OFF
|
|
|
|
this->command(0x02);
|
|
|
|
this->wait_until_idle_();
|
|
|
|
// COMMAND DEEP SLEEP
|
|
|
|
this->command(0x07);
|
|
|
|
this->data(0xA5); // check byte
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
protected:
|
|
|
|
int get_width_internal() override;
|
|
|
|
|
|
|
|
int get_height_internal() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WaveshareEPaper7P5In : public WaveshareEPaper {
|
|
|
|
public:
|
2019-05-28 20:22:50 +02:00
|
|
|
void initialize() override;
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void display() override;
|
|
|
|
|
|
|
|
void dump_config() override;
|
|
|
|
|
2019-05-28 20:22:50 +02:00
|
|
|
void deep_sleep() override {
|
|
|
|
// COMMAND POWER OFF
|
|
|
|
this->command(0x02);
|
|
|
|
this->wait_until_idle_();
|
|
|
|
// COMMAND DEEP SLEEP
|
|
|
|
this->command(0x07);
|
|
|
|
this->data(0xA5); // check byte
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
protected:
|
|
|
|
int get_width_internal() override;
|
|
|
|
|
|
|
|
int get_height_internal() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waveshare_epaper
|
|
|
|
} // namespace esphome
|