1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-14 06:38:17 +00:00

feat: (Components WaveshareEpaper) Add 4.2inch e-Paper Module support for red colour

This commit is contained in:
rrachasak 2024-12-20 13:56:23 +07:00
parent f33b4a714e
commit 2ec2b505af
No known key found for this signature in database
4 changed files with 108 additions and 0 deletions

View File

@ -61,6 +61,9 @@ WaveshareEPaper4P2In = waveshare_epaper_ns.class_(
WaveshareEPaper4P2InBV2 = waveshare_epaper_ns.class_(
"WaveshareEPaper4P2InBV2", WaveshareEPaper
)
WaveshareEPaper4P2InBV2BWR = waveshare_epaper_ns.class_(
"WaveshareEPaper4P2InBV2BWR", WaveshareEPaperBWR
)
WaveshareEPaper5P8In = waveshare_epaper_ns.class_(
"WaveshareEPaper5P8In", WaveshareEPaper
)
@ -131,6 +134,7 @@ MODELS = {
"2.90in-dke": ("c", WaveshareEPaper2P9InDKE),
"4.20in": ("b", WaveshareEPaper4P2In),
"4.20in-bv2": ("b", WaveshareEPaper4P2InBV2),
"4.20in-bv2-bwr": ("b", WaveshareEPaper4P2InBV2BWR),
"5.83in": ("b", WaveshareEPaper5P8In),
"5.83inv2": ("b", WaveshareEPaper5P8InV2),
"7.50in": ("b", WaveshareEPaper7P5In),

View File

@ -1993,6 +1993,63 @@ void WaveshareEPaper4P2InBV2::dump_config() {
LOG_UPDATE_INTERVAL(this);
}
// ========================================================
// 4.20in Type B With Red colour support (LUT from OTP)
// Datasheet:
// - https://www.waveshare.com/w/upload/2/20/4.2inch-e-paper-module-user-manual-en.pdf
// - https://github.com/waveshare/e-Paper/blob/master/RaspberryPi_JetsonNano/c/lib/e-Paper/EPD_4in2b_V2.c
// The implementation is an adaptation of WaveshareEPaper4P2InBV2 class
// ========================================================
void WaveshareEPaper4P2InBV2BWR::initialize() {
// these exact timings are required for a proper reset/init
this->reset_pin_->digital_write(false);
delay(2);
this->reset_pin_->digital_write(true);
delay(200); // NOLINT
// COMMAND POWER ON
this->command(0x04);
this->wait_until_idle_();
// COMMAND PANEL SETTING
this->command(0x00);
this->data(0x0f); // LUT from OTP
}
void HOT WaveshareEPaper4P2InBV2BWR::display() {
// COMMAND DATA START TRANSMISSION 1 (B/W data)
this->command(0x10);
this->start_data_();
this->write_array(this->buffer_, this->get_buffer_length_());
this->end_data_();
// COMMAND DATA START TRANSMISSION 2 (RED data)
this->command(0x13);
this->start_data_();
for (size_t i = 0; i < this->get_buffer_length_(); i++)
this->write_byte(0xFF);
this->end_data_();
delay(2);
// COMMAND DISPLAY REFRESH
this->command(0x12);
this->wait_until_idle_();
// COMMAND POWER OFF
// NOTE: power off < deep sleep
this->command(0x02);
}
int WaveshareEPaper4P2InBV2BWR::get_width_internal() { return 400; }
int WaveshareEPaper4P2InBV2BWR::get_height_internal() { return 300; }
void WaveshareEPaper4P2InBV2BWR::dump_config() {
LOG_DISPLAY("", "Waveshare E-Paper", this);
ESP_LOGCONFIG(TAG, " Model: 4.2in (B V2) BWR-Mode");
LOG_PIN(" Reset Pin: ", this->reset_pin_);
LOG_PIN(" DC Pin: ", this->dc_pin_);
LOG_PIN(" Busy Pin: ", this->busy_pin_);
LOG_UPDATE_INTERVAL(this);
}
void WaveshareEPaper5P8In::initialize() {
// COMMAND POWER SETTING
this->command(0x01);

View File

@ -487,6 +487,34 @@ class WaveshareEPaper4P2InBV2 : public WaveshareEPaper {
int get_height_internal() override;
};
class WaveshareEPaper4P2InBV2BWR : public WaveshareEPaperBWR {
public:
void initialize() override;
void display() override;
void dump_config() override;
void deep_sleep() override {
// COMMAND VCOM AND DATA INTERVAL SETTING
this->command(0x50);
this->data(0xF7); // border floating
// COMMAND POWER OFF
this->command(0x02);
this->wait_until_idle_();
// COMMAND DEEP SLEEP
this->command(0x07);
this->data(0xA5); // check code
}
protected:
int get_width_internal() override;
int get_height_internal() override;
};
class WaveshareEPaper5P8In : public WaveshareEPaper {
public:
void initialize() override;

View File

@ -205,3 +205,22 @@ display:
number: GPIO32
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: waveshare_epaper
model: 4.20in-bv2-bwr
spi_id: spi_id_1
cs_pin:
allow_other_uses: true
number: GPIO25
dc_pin:
allow_other_uses: true
number: GPIO26
busy_pin:
allow_other_uses: true
number: GPIO27
reset_pin:
allow_other_uses: true
number: GPIO32
lambda: |-
auto const red = Color(255, 0, 0);
it.rectangle(0, 0, it.get_width() / 2, it.get_height() / 2);
it.rectangle(it.get_width() / 2, get_height() / 2, it.get_width(), it.get_height(), red);