ESPHome  2023.9.1
waveshare_epaper.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace waveshare_epaper {
9 
12  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
13  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ> {
14  public:
15  void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
16  float get_setup_priority() const override;
17  void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
18  void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
19  void set_reset_duration(uint32_t reset_duration) { this->reset_duration_ = reset_duration; }
20 
21  void command(uint8_t value);
22  void data(uint8_t value);
23 
24  virtual void display() = 0;
25  virtual void initialize() = 0;
26  virtual void deep_sleep() = 0;
27 
28  void update() override;
29 
30  void fill(Color color) override;
31 
32  void setup() override {
33  this->setup_pins_();
34  this->initialize();
35  }
36 
37  void on_safe_shutdown() override;
38 
40 
41  protected:
42  void draw_absolute_pixel_internal(int x, int y, Color color) override;
43 
44  bool wait_until_idle_();
45 
46  void setup_pins_();
47 
48  void reset_() {
49  if (this->reset_pin_ != nullptr) {
50  this->reset_pin_->digital_write(false);
51  delay(reset_duration_); // NOLINT
52  this->reset_pin_->digital_write(true);
53  delay(200); // NOLINT
54  }
55  }
56 
57  virtual int get_width_controller() { return this->get_width_internal(); };
58 
59  uint32_t get_buffer_length_();
60  uint32_t reset_duration_{200};
61 
62  void start_command_();
63  void end_command_();
64  void start_data_();
65  void end_data_();
66 
67  GPIOPin *reset_pin_{nullptr};
69  GPIOPin *busy_pin_{nullptr};
70  virtual uint32_t idle_timeout_() { return 1000u; } // NOLINT(readability-identifier-naming)
71 };
72 
83 };
84 
86  public:
88 
89  void initialize() override;
90 
91  void dump_config() override;
92 
93  void display() override;
94 
95  void deep_sleep() override {
96  if (this->model_ == WAVESHARE_EPAPER_2_9_IN_V2 || this->model_ == WAVESHARE_EPAPER_1_54_IN_V2) {
97  // COMMAND DEEP SLEEP MODE
98  this->command(0x10);
99  this->data(0x01);
100  } else {
101  // COMMAND DEEP SLEEP MODE
102  this->command(0x10);
103  }
104  this->wait_until_idle_();
105  }
106 
107  void set_full_update_every(uint32_t full_update_every);
108 
109  protected:
110  void write_lut_(const uint8_t *lut, uint8_t size);
111 
112  int get_width_internal() override;
113 
114  int get_height_internal() override;
115 
116  int get_width_controller() override;
117 
118  uint32_t full_update_every_{30};
119  uint32_t at_update_{0};
121  uint32_t idle_timeout_() override;
122 };
123 
131 };
132 
134  public:
135  void initialize() override;
136 
137  void display() override;
138 
139  void dump_config() override;
140 
141  void deep_sleep() override {
142  // COMMAND DEEP SLEEP
143  this->command(0x07);
144  this->data(0xA5); // check byte
145  }
146 
147  protected:
148  int get_width_internal() override;
149 
150  int get_height_internal() override;
151 };
152 
153 class GDEY029T94 : public WaveshareEPaper {
154  public:
155  void initialize() override;
156 
157  void display() override;
158 
159  void dump_config() override;
160 
161  void deep_sleep() override {
162  // COMMAND DEEP SLEEP
163  this->command(0x07);
164  this->data(0xA5); // check byte
165  }
166 
167  protected:
168  int get_width_internal() override;
169 
170  int get_height_internal() override;
171 };
172 
173 class GDEW0154M09 : public WaveshareEPaper {
174  public:
175  void initialize() override;
176  void display() override;
177  void dump_config() override;
178  void deep_sleep() override;
179 
180  protected:
181  int get_width_internal() override;
182  int get_height_internal() override;
183 
184  private:
185  static const uint8_t CMD_DTM1_DATA_START_TRANS = 0x10;
186  static const uint8_t CMD_DTM2_DATA_START_TRANS2 = 0x13;
187  static const uint8_t CMD_DISPLAY_REFRESH = 0x12;
188  static const uint8_t CMD_AUTO_SEQ = 0x17;
189  static const uint8_t DATA_AUTO_PON_DSR_POF_DSLP = 0xA7;
190  static const uint8_t CMD_PSR_PANEL_SETTING = 0x00;
191  static const uint8_t CMD_UNDOCUMENTED_0x4D = 0x4D; // NOLINT
192  static const uint8_t CMD_UNDOCUMENTED_0xAA = 0xaa; // NOLINT
193  static const uint8_t CMD_UNDOCUMENTED_0xE9 = 0xe9; // NOLINT
194  static const uint8_t CMD_UNDOCUMENTED_0xB6 = 0xb6; // NOLINT
195  static const uint8_t CMD_UNDOCUMENTED_0xF3 = 0xf3; // NOLINT
196  static const uint8_t CMD_TRES_RESOLUTION_SETTING = 0x61;
197  static const uint8_t CMD_TCON_TCONSETTING = 0x60;
198  static const uint8_t CMD_CDI_VCOM_DATA_INTERVAL = 0x50;
199  static const uint8_t CMD_POF_POWER_OFF = 0x02;
200  static const uint8_t CMD_DSLP_DEEP_SLEEP = 0x07;
201  static const uint8_t DATA_DSLP_DEEP_SLEEP = 0xA5;
202  static const uint8_t CMD_PWS_POWER_SAVING = 0xe3;
203  static const uint8_t CMD_PON_POWER_ON = 0x04;
204  static const uint8_t CMD_PTL_PARTIAL_WINDOW = 0x90;
205 
206  uint8_t *lastbuff_ = nullptr;
207  void reset_();
208  void clear_();
209  void write_init_list_(const uint8_t *list);
210  void init_internal_();
211 };
212 
214  public:
215  void initialize() override;
216 
217  void display() override;
218 
219  void dump_config() override;
220 
221  void deep_sleep() override {
222  // COMMAND DEEP SLEEP
223  this->command(0x07);
224  this->data(0xA5); // check byte
225  }
226 
227  protected:
228  int get_width_internal() override;
229 
230  int get_height_internal() override;
231 };
232 
234  public:
235  void initialize() override;
236 
237  void display() override;
238 
239  void dump_config() override;
240 
241  void deep_sleep() override {
242  // COMMAND VCOM AND DATA INTERVAL SETTING
243  this->command(0x50);
244  this->data(0x17); // border floating
245 
246  // COMMAND VCM DC SETTING
247  this->command(0x82);
248  // COMMAND PANEL SETTING
249  this->command(0x00);
250 
251  delay(100); // NOLINT
252 
253  // COMMAND POWER SETTING
254  this->command(0x01);
255  this->data(0x00);
256  this->data(0x00);
257  this->data(0x00);
258  this->data(0x00);
259  this->data(0x00);
260  delay(100); // NOLINT
261 
262  // COMMAND POWER OFF
263  this->command(0x02);
264  this->wait_until_idle_();
265  // COMMAND DEEP SLEEP
266  this->command(0x07);
267  this->data(0xA5); // check byte
268  }
269 
270  protected:
271  int get_width_internal() override;
272 
273  int get_height_internal() override;
274 };
275 
277  public:
278  void initialize() override;
279 
280  void display() override;
281 
282  void dump_config() override;
283 
284  void deep_sleep() override {
285  // COMMAND VCOM AND DATA INTERVAL SETTING
286  this->command(0x50);
287  this->data(0xF7); // border floating
288 
289  // COMMAND POWER OFF
290  this->command(0x02);
291  this->wait_until_idle_();
292 
293  // COMMAND DEEP SLEEP
294  this->command(0x07);
295  this->data(0xA5); // check code
296  }
297 
298  protected:
299  int get_width_internal() override;
300 
301  int get_height_internal() override;
302 };
303 
305  public:
306  void initialize() override;
307 
308  void display() override;
309 
310  void dump_config() override;
311 
312  void deep_sleep() override {
313  // COMMAND POWER OFF
314  this->command(0x02);
315  this->wait_until_idle_();
316  // COMMAND DEEP SLEEP
317  this->command(0x07);
318  this->data(0xA5); // check byte
319  }
320 
321  protected:
322  int get_width_internal() override;
323 
324  int get_height_internal() override;
325 };
326 
328  public:
329  void initialize() override;
330 
331  void display() override;
332 
333  void dump_config() override;
334 
335  void deep_sleep() override {
336  // COMMAND VCOM AND DATA INTERVAL SETTING
337  this->command(0x50);
338  this->data(0x17); // border floating
339 
340  // COMMAND VCM DC SETTING
341  this->command(0x82);
342  // COMMAND PANEL SETTING
343  this->command(0x00);
344 
345  delay(100); // NOLINT
346 
347  // COMMAND POWER SETTING
348  this->command(0x01);
349  this->data(0x00);
350  this->data(0x00);
351  this->data(0x00);
352  this->data(0x00);
353  this->data(0x00);
354  delay(100); // NOLINT
355 
356  // COMMAND POWER OFF
357  this->command(0x02);
358  this->wait_until_idle_();
359  // COMMAND DEEP SLEEP
360  this->command(0x07);
361  this->data(0xA5); // check byte
362  }
363 
364  protected:
365  int get_width_internal() override;
366 
367  int get_height_internal() override;
368 };
369 
371  public:
372  void initialize() override;
373 
374  void display() override;
375 
376  void dump_config() override;
377 
378  void deep_sleep() override {
379  // COMMAND POWER OFF
380  this->command(0x02);
381  this->wait_until_idle_();
382  // COMMAND DEEP SLEEP
383  this->command(0x07);
384  this->data(0xA5); // check byte
385  }
386 
387  protected:
388  int get_width_internal() override;
389 
390  int get_height_internal() override;
391 };
392 
394  public:
395  void initialize() override;
396 
397  void display() override;
398 
399  void dump_config() override;
400 
401  void deep_sleep() override {
402  // COMMAND POWER OFF
403  this->command(0x02);
404  this->wait_until_idle_();
405  // COMMAND DEEP SLEEP
406  this->command(0x07); // deep sleep
407  this->data(0xA5); // check byte
408  }
409 
410  protected:
411  int get_width_internal() override;
412 
413  int get_height_internal() override;
414 };
415 
417  public:
418  bool wait_until_idle_();
419 
420  void initialize() override;
421 
422  void display() override;
423 
424  void dump_config() override;
425 
426  void deep_sleep() override {
427  this->command(0x02); // Power off
428  this->wait_until_idle_();
429  this->command(0x07); // Deep sleep
430  this->data(0xA5);
431  }
432 
433  protected:
434  int get_width_internal() override;
435 
436  int get_height_internal() override;
437 
438  void reset_() {
439  if (this->reset_pin_ != nullptr) {
440  this->reset_pin_->digital_write(true);
441  delay(200); // NOLINT
442  this->reset_pin_->digital_write(false);
443  delay(5);
444  this->reset_pin_->digital_write(true);
445  delay(200); // NOLINT
446  }
447  };
448 };
449 
451  public:
452  void initialize() override;
453 
454  void display() override;
455 
456  void dump_config() override;
457 
458  void deep_sleep() override {
459  // COMMAND POWER OFF
460  this->command(0x02);
461  this->wait_until_idle_();
462  // COMMAND DEEP SLEEP
463  this->command(0x07);
464  this->data(0xA5); // check byte
465  }
466 
467  protected:
468  int get_width_internal() override;
469 
470  int get_height_internal() override;
471 };
472 
474  public:
475  bool wait_until_idle_();
476 
477  void initialize() override;
478 
479  void display() override;
480 
481  void dump_config() override;
482 
483  void deep_sleep() override {
484  // COMMAND POWER OFF
485  this->command(0x02);
486  this->wait_until_idle_();
487  // COMMAND DEEP SLEEP
488  this->command(0x07);
489  this->data(0xA5); // check byte
490  }
491 
492  protected:
493  int get_width_internal() override;
494 
495  int get_height_internal() override;
496 
497  uint32_t idle_timeout_() override;
498 };
499 
501  public:
502  bool wait_until_idle_();
503  void initialize() override;
504  void dump_config() override;
505 
506  protected:
507  void reset_() {
508  if (this->reset_pin_ != nullptr) {
509  this->reset_pin_->digital_write(true);
510  delay(200); // NOLINT
511  this->reset_pin_->digital_write(false);
512  delay(2);
513  this->reset_pin_->digital_write(true);
514  delay(20);
515  }
516  };
517 };
518 
520  public:
521  void initialize() override;
522 
523  void display() override;
524 
525  void dump_config() override;
526 
527  void deep_sleep() override {
528  // deep sleep
529  this->command(0x10);
530  this->data(0x01);
531  }
532 
533  protected:
534  int get_width_internal() override;
535 
536  int get_height_internal() override;
537 };
538 
540  public:
541  void initialize() override;
542 
543  void display() override;
544 
545  void dump_config() override;
546 
547  void deep_sleep() override {
548  // COMMAND POWER DOWN
549  this->command(0x10);
550  this->data(0x01);
551  // cannot wait until idle here, the device no longer responds
552  }
553 
554  void set_full_update_every(uint32_t full_update_every);
555 
556  protected:
557  int get_width_internal() override;
558 
559  int get_height_internal() override;
560 
561  uint32_t idle_timeout_() override;
562 
563  uint32_t full_update_every_{30};
564  uint32_t at_update_{0};
565 };
566 
567 } // namespace waveshare_epaper
568 } // namespace esphome
virtual void digital_write(bool value)=0
uint16_t x
Definition: tt21100.cpp:17
void draw_absolute_pixel_internal(int x, int y, Color color) override
virtual int get_width_internal()=0
This class simplifies creating components that periodically check a state.
Definition: component.h:282
virtual void dump_config()
Definition: component.cpp:163
uint16_t y
Definition: tt21100.cpp:18
void set_reset_duration(uint32_t reset_duration)
void init_internal_(uint32_t buffer_length)
The SPIDevice is what components using the SPI will create.
Definition: spi.h:383
virtual int get_height_internal()=0
display::DisplayType get_display_type() override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26