mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 19:54:14 +01:00
3bb6430495
* Add support for TTGO ePaper module Use 2.13in-ttgo as type. Only different LUTs were needed, everything else is the same. relates to issue #233. * fix styling errors * styling fixes Co-authored-by: null <mandy.klingbeil@student.hpi.uni-potsdam.de>
196 lines
4.2 KiB
C++
196 lines
4.2 KiB
C++
#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 {
|
|
|
|
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> {
|
|
public:
|
|
void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
|
|
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;
|
|
virtual void initialize() = 0;
|
|
virtual void deep_sleep() = 0;
|
|
|
|
void update() override;
|
|
|
|
void fill(int color) override;
|
|
|
|
void setup() override {
|
|
this->setup_pins_();
|
|
this->initialize();
|
|
}
|
|
|
|
void on_safe_shutdown() override;
|
|
|
|
protected:
|
|
void draw_absolute_pixel_internal(int x, int y, int color) override;
|
|
|
|
bool wait_until_idle_();
|
|
|
|
void setup_pins_();
|
|
|
|
void reset_() {
|
|
if (this->reset_pin_ != nullptr) {
|
|
this->reset_pin_->digital_write(false);
|
|
delay(200);
|
|
this->reset_pin_->digital_write(true);
|
|
delay(200);
|
|
}
|
|
}
|
|
|
|
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,
|
|
TTGO_EPAPER_2_13_IN,
|
|
};
|
|
|
|
class WaveshareEPaperTypeA : public WaveshareEPaper {
|
|
public:
|
|
WaveshareEPaperTypeA(WaveshareEPaperTypeAModel model);
|
|
|
|
void initialize() override;
|
|
|
|
void dump_config() override;
|
|
|
|
void display() override;
|
|
|
|
void deep_sleep() override {
|
|
// COMMAND DEEP SLEEP MODE
|
|
this->command(0x10);
|
|
this->wait_until_idle_();
|
|
}
|
|
|
|
void set_full_update_every(uint32_t full_update_every);
|
|
|
|
protected:
|
|
void write_lut_(const uint8_t *lut, uint8_t size);
|
|
|
|
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:
|
|
void initialize() override;
|
|
|
|
void display() override;
|
|
|
|
void dump_config() override;
|
|
|
|
void deep_sleep() override {
|
|
// COMMAND DEEP SLEEP
|
|
this->command(0x07);
|
|
this->data(0xA5); // check byte
|
|
}
|
|
|
|
protected:
|
|
int get_width_internal() override;
|
|
|
|
int get_height_internal() override;
|
|
};
|
|
|
|
class WaveshareEPaper4P2In : public WaveshareEPaper {
|
|
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(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
|
|
}
|
|
|
|
protected:
|
|
int get_width_internal() override;
|
|
|
|
int get_height_internal() override;
|
|
};
|
|
|
|
class WaveshareEPaper7P5In : public WaveshareEPaper {
|
|
public:
|
|
void initialize() override;
|
|
|
|
void display() override;
|
|
|
|
void dump_config() override;
|
|
|
|
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
|
|
}
|
|
|
|
protected:
|
|
int get_width_internal() override;
|
|
|
|
int get_height_internal() override;
|
|
};
|
|
|
|
} // namespace waveshare_epaper
|
|
} // namespace esphome
|