ESPHome  2024.12.2
waveshare_epaper.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace waveshare_epaper {
9 
11  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
12  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ> {
13  public:
14  void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
15  float get_setup_priority() const override;
17  void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
18  void set_reset_duration(uint32_t reset_duration) { this->reset_duration_ = reset_duration; }
19 
20  void command(uint8_t value);
21  void data(uint8_t value);
22  void cmd_data(const uint8_t *data, size_t length);
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 setup() override {
31  this->setup_pins_();
32  this->initialize();
33  }
34 
35  void on_safe_shutdown() override;
36 
37  protected:
38  bool wait_until_idle_();
39 
40  void setup_pins_();
41 
42  void reset_() {
43  if (this->reset_pin_ != nullptr) {
44  this->reset_pin_->digital_write(false);
45  delay(reset_duration_); // NOLINT
46  this->reset_pin_->digital_write(true);
47  delay(20);
48  }
49  }
50 
51  virtual int get_width_controller() { return this->get_width_internal(); };
52 
53  virtual uint32_t get_buffer_length_() = 0; // NOLINT(readability-identifier-naming)
54  uint32_t reset_duration_{200};
55 
56  void start_command_();
57  void end_command_();
58  void start_data_();
59  void end_data_();
60 
61  GPIOPin *reset_pin_{nullptr};
63  GPIOPin *busy_pin_{nullptr};
64  virtual uint32_t idle_timeout_() { return 1000u; } // NOLINT(readability-identifier-naming)
65 };
66 
68  public:
69  void fill(Color color) override;
70 
72 
73  protected:
74  void draw_absolute_pixel_internal(int x, int y, Color color) override;
75  uint32_t get_buffer_length_() override;
76 };
77 
79  public:
80  void fill(Color color) override;
81 
83 
84  protected:
85  void draw_absolute_pixel_internal(int x, int y, Color color) override;
86  uint32_t get_buffer_length_() override;
87 };
88 
100 };
101 
103  public:
105 
106  void initialize() override;
107 
108  void dump_config() override;
109 
110  void display() override;
111 
112  void deep_sleep() override {
113  switch (this->model_) {
114  // Models with specific deep sleep command and data
119  // COMMAND DEEP SLEEP MODE
120  this->command(0x10);
121  this->data(0x01);
122  break;
123  // Other models default to simple deep sleep command
124  default:
125  // COMMAND DEEP SLEEP
126  this->command(0x10);
127  break;
128  }
129  if (this->model_ != WAVESHARE_EPAPER_2_13_IN_V2) {
130  // From panel specification:
131  // "After this command initiated, the chip will enter Deep Sleep Mode, BUSY pad will keep output high."
132  this->wait_until_idle_();
133  }
134  }
135 
136  void set_full_update_every(uint32_t full_update_every);
137 
138  protected:
139  void write_lut_(const uint8_t *lut, uint8_t size);
140 
141  void init_display_();
142 
143  int get_width_internal() override;
144 
145  int get_height_internal() override;
146 
147  int get_width_controller() override;
148 
149  uint32_t full_update_every_{30};
150  uint32_t at_update_{0};
152  uint32_t idle_timeout_() override;
153 
154  bool deep_sleep_between_updates_{false};
155 };
156 
167 };
168 
170  public:
171  void initialize() override;
172 
173  void display() override;
174 
175  void dump_config() override;
176 
177  void deep_sleep() override {
178  this->command(0x10);
179  this->data(0x01);
180  }
181 
182  protected:
183  int get_width_internal() override;
184  int get_height_internal() override;
185 };
186 
188  public:
189  void initialize() override;
190 
191  void display() override;
192 
193  void dump_config() override;
194 
195  void deep_sleep() override {
196  // COMMAND DEEP SLEEP
197  this->command(0x07);
198  this->data(0xA5); // check byte
199  }
200 
201  protected:
202  int get_width_internal() override;
203  int get_height_internal() override;
204 };
205 
207  public:
208  void initialize() override;
209 
210  void display() override;
211 
212  void dump_config() override;
213 
214  void deep_sleep() override {
215  // COMMAND VCOM_AND_DATA_INTERVAL_SETTING
216  this->command(0x50);
217  // COMMAND POWER OFF
218  this->command(0x02);
219  this->wait_until_idle_();
220  // COMMAND DEEP SLEEP
221  this->command(0x07); // deep sleep
222  this->data(0xA5); // check byte
223  }
224 
225  protected:
226  int get_width_internal() override;
227  int get_height_internal() override;
228 };
229 
231  public:
232  void initialize() override;
233 
234  void display() override;
235 
236  void dump_config() override;
237 
238  void deep_sleep() override {
239  // COMMAND DEEP SLEEP
240  this->command(0x10);
241  this->data(0x01);
242  }
243 
244  protected:
245  int get_width_internal() override;
246  int get_height_internal() override;
247 };
248 
249 class GDEW029T5 : public WaveshareEPaper {
250  public:
251  void initialize() override;
252 
253  void display() override;
254 
255  void dump_config() override;
256 
257  void deep_sleep() override {
258  // COMMAND DEEP SLEEP
259  this->command(0x07);
260  this->data(0xA5); // check byte
261  }
262 
263  protected:
264  int get_width_internal() override;
265 
266  int get_height_internal() override;
267 };
268 
270  public:
271  void initialize() override;
272 
273  void display() override;
274 
275  void dump_config() override;
276 
277  void deep_sleep() override { ; }
278 
279  protected:
280  int get_width_internal() override;
281 
282  int get_height_internal() override;
283 };
284 
285 class GDEW0154M09 : public WaveshareEPaper {
286  public:
287  void initialize() override;
288  void display() override;
289  void dump_config() override;
290  void deep_sleep() override;
291 
292  protected:
293  int get_width_internal() override;
294  int get_height_internal() override;
295 
296  private:
297  static const uint8_t CMD_DTM1_DATA_START_TRANS = 0x10;
298  static const uint8_t CMD_DTM2_DATA_START_TRANS2 = 0x13;
299  static const uint8_t CMD_DISPLAY_REFRESH = 0x12;
300  static const uint8_t CMD_AUTO_SEQ = 0x17;
301  static const uint8_t DATA_AUTO_PON_DSR_POF_DSLP = 0xA7;
302  static const uint8_t CMD_PSR_PANEL_SETTING = 0x00;
303  static const uint8_t CMD_UNDOCUMENTED_0x4D = 0x4D; // NOLINT
304  static const uint8_t CMD_UNDOCUMENTED_0xAA = 0xaa; // NOLINT
305  static const uint8_t CMD_UNDOCUMENTED_0xE9 = 0xe9; // NOLINT
306  static const uint8_t CMD_UNDOCUMENTED_0xB6 = 0xb6; // NOLINT
307  static const uint8_t CMD_UNDOCUMENTED_0xF3 = 0xf3; // NOLINT
308  static const uint8_t CMD_TRES_RESOLUTION_SETTING = 0x61;
309  static const uint8_t CMD_TCON_TCONSETTING = 0x60;
310  static const uint8_t CMD_CDI_VCOM_DATA_INTERVAL = 0x50;
311  static const uint8_t CMD_POF_POWER_OFF = 0x02;
312  static const uint8_t CMD_DSLP_DEEP_SLEEP = 0x07;
313  static const uint8_t DATA_DSLP_DEEP_SLEEP = 0xA5;
314  static const uint8_t CMD_PWS_POWER_SAVING = 0xe3;
315  static const uint8_t CMD_PON_POWER_ON = 0x04;
316  static const uint8_t CMD_PTL_PARTIAL_WINDOW = 0x90;
317 
318  uint8_t *lastbuff_ = nullptr;
319  void reset_();
320  void clear_();
321  void write_init_list_(const uint8_t *list);
322  void init_internal_();
323 };
324 
326  public:
327  void initialize() override;
328 
329  void display() override;
330 
331  void dump_config() override;
332 
333  void deep_sleep() override {
334  // COMMAND DEEP SLEEP
335  this->command(0x07);
336  this->data(0xA5); // check byte
337  }
338 
339  protected:
340  int get_width_internal() override;
341 
342  int get_height_internal() override;
343 };
344 
346  public:
347  void initialize() override;
348 
349  void display() override;
350 
351  void dump_config() override;
352 
353  void deep_sleep() override {
354  // COMMAND DEEP SLEEP
355  this->command(0x07);
356  this->data(0xA5); // check byte
357  }
358 
359  protected:
360  int get_width_internal() override;
361 
362  int get_height_internal() override;
363 };
364 
366  public:
368 
369  void initialize() override;
370 
371  void display() override;
372 
373  void dump_config() override;
374 
375  void deep_sleep() override;
376 
377  void set_full_update_every(uint32_t full_update_every);
378 
379  protected:
380  void write_lut_(const uint8_t *lut, uint8_t size);
381 
382  int get_width_internal() override;
383 
384  int get_height_internal() override;
385 
386  int get_width_controller() override;
387 
388  uint32_t full_update_every_{30};
389  uint32_t at_update_{0};
390 
391  private:
392  void reset_();
393 };
394 
396  public:
397  void initialize() override;
398 
399  void display() override;
400 
401  void dump_config() override;
402 
403  void deep_sleep() override {
404  // COMMAND DEEP SLEEP
405  this->command(0x10);
406  this->data(0x01);
407  }
408 
409  void set_full_update_every(uint32_t full_update_every);
410 
411  protected:
412  uint32_t full_update_every_{30};
413  uint32_t at_update_{0};
414  int get_width_internal() override;
415 
416  int get_height_internal() override;
417 };
418 
420  public:
421  void initialize() override;
422 
423  void display() override;
424 
425  void dump_config() override;
426 
427  void deep_sleep() override {
428  // COMMAND VCOM AND DATA INTERVAL SETTING
429  this->command(0x50);
430  this->data(0x17); // border floating
431 
432  // COMMAND VCM DC SETTING
433  this->command(0x82);
434  // COMMAND PANEL SETTING
435  this->command(0x00);
436 
437  delay(100); // NOLINT
438 
439  // COMMAND POWER SETTING
440  this->command(0x01);
441  this->data(0x00);
442  this->data(0x00);
443  this->data(0x00);
444  this->data(0x00);
445  this->data(0x00);
446  delay(100); // NOLINT
447 
448  // COMMAND POWER OFF
449  this->command(0x02);
450  this->wait_until_idle_();
451  // COMMAND DEEP SLEEP
452  this->command(0x07);
453  this->data(0xA5); // check byte
454  }
455 
456  protected:
457  int get_width_internal() override;
458 
459  int get_height_internal() override;
460 };
461 
463  public:
464  void initialize() override;
465 
466  void display() override;
467 
468  void dump_config() override;
469 
470  void deep_sleep() override {
471  // COMMAND VCOM AND DATA INTERVAL SETTING
472  this->command(0x50);
473  this->data(0xF7); // border floating
474 
475  // COMMAND POWER OFF
476  this->command(0x02);
477  this->wait_until_idle_();
478 
479  // COMMAND DEEP SLEEP
480  this->command(0x07);
481  this->data(0xA5); // check code
482  }
483 
484  protected:
485  int get_width_internal() override;
486 
487  int get_height_internal() override;
488 };
489 
491  public:
492  void initialize() override;
493 
494  void display() override;
495 
496  void dump_config() override;
497 
498  void deep_sleep() override {
499  // COMMAND POWER OFF
500  this->command(0x02);
501  this->wait_until_idle_();
502  // COMMAND DEEP SLEEP
503  this->command(0x07);
504  this->data(0xA5); // check byte
505  }
506 
507  protected:
508  int get_width_internal() override;
509 
510  int get_height_internal() override;
511 };
512 
514  public:
515  void initialize() override;
516 
517  void display() override;
518 
519  void dump_config() override;
520 
521  void deep_sleep() override {
522  // COMMAND VCOM AND DATA INTERVAL SETTING
523  this->command(0x50);
524  this->data(0x17); // border floating
525 
526  // COMMAND VCM DC SETTING
527  this->command(0x82);
528  // COMMAND PANEL SETTING
529  this->command(0x00);
530 
531  delay(100); // NOLINT
532 
533  // COMMAND POWER SETTING
534  this->command(0x01);
535  this->data(0x00);
536  this->data(0x00);
537  this->data(0x00);
538  this->data(0x00);
539  this->data(0x00);
540  delay(100); // NOLINT
541 
542  // COMMAND POWER OFF
543  this->command(0x02);
544  this->wait_until_idle_();
545  // COMMAND DEEP SLEEP
546  this->command(0x07);
547  this->data(0xA5); // check byte
548  }
549 
550  protected:
551  int get_width_internal() override;
552 
553  int get_height_internal() override;
554 };
555 
557  public:
558  void initialize() override;
559 
560  void display() override;
561 
562  void dump_config() override;
563 
564  void deep_sleep() override {
565  // COMMAND POWER OFF
566  this->command(0x02);
567  this->wait_until_idle_();
568  // COMMAND DEEP SLEEP
569  this->command(0x07);
570  this->data(0xA5); // check byte
571  }
572 
573  protected:
574  int get_width_internal() override;
575 
576  int get_height_internal() override;
577 };
578 
580  public:
581  void initialize() override;
582 
583  void display() override;
584 
585  void dump_config() override;
586 
587  void deep_sleep() override {
588  // COMMAND POWER OFF
589  this->command(0x02);
590  this->wait_until_idle_();
591  // COMMAND DEEP SLEEP
592  this->command(0x07); // deep sleep
593  this->data(0xA5); // check byte
594  }
595 
596  protected:
597  int get_width_internal() override;
598 
599  int get_height_internal() override;
600 };
601 
603  public:
604  bool wait_until_idle_();
605 
606  void initialize() override;
607 
608  void display() override;
609 
610  void dump_config() override;
611 
612  void deep_sleep() override {
613  this->command(0x02); // Power off
614  this->wait_until_idle_();
615  this->command(0x07); // Deep sleep
616  this->data(0xA5);
617  }
618 
619  void clear_screen();
620 
621  protected:
622  int get_width_internal() override;
623 
624  int get_height_internal() override;
625 
626  void reset_() {
627  if (this->reset_pin_ != nullptr) {
628  this->reset_pin_->digital_write(true);
629  delay(200); // NOLINT
630  this->reset_pin_->digital_write(false);
631  delay(5);
632  this->reset_pin_->digital_write(true);
633  delay(200); // NOLINT
634  }
635  };
636 
637  void init_display_();
638 };
639 
641  public:
642  bool wait_until_idle_();
643 
644  void initialize() override;
645 
646  void display() override;
647 
648  void dump_config() override;
649 
650  void deep_sleep() override {
651  this->command(0x02); // Power off
652  this->wait_until_idle_();
653  this->command(0x07); // Deep sleep
654  this->data(0xA5);
655  }
656 
657  void clear_screen();
658 
659  protected:
660  int get_width_internal() override;
661 
662  int get_height_internal() override;
663 
664  void reset_() {
665  if (this->reset_pin_ != nullptr) {
666  this->reset_pin_->digital_write(true);
667  delay(200); // NOLINT
668  this->reset_pin_->digital_write(false);
669  delay(5);
670  this->reset_pin_->digital_write(true);
671  delay(200); // NOLINT
672  }
673  };
674 
675  void init_display_();
676 };
677 
679  public:
680  void initialize() override;
681 
682  void display() override;
683 
684  void dump_config() override;
685 
686  void deep_sleep() override {
687  // COMMAND POWER OFF
688  this->command(0x02);
689  this->wait_until_idle_();
690  // COMMAND DEEP SLEEP
691  this->command(0x07);
692  this->data(0xA5); // check byte
693  }
694 
695  protected:
696  int get_width_internal() override;
697 
698  int get_height_internal() override;
699 };
700 
702  public:
703  bool wait_until_idle_();
704 
705  void initialize() override;
706 
707  void display() override;
708 
709  void dump_config() override;
710 
711  void deep_sleep() override {
712  // COMMAND POWER OFF
713  this->command(0x02);
714  this->wait_until_idle_();
715  // COMMAND DEEP SLEEP
716  this->command(0x07);
717  this->data(0xA5); // check byte
718  }
719 
720  protected:
721  int get_width_internal() override;
722 
723  int get_height_internal() override;
724 
725  uint32_t idle_timeout_() override;
726 };
727 
729  public:
730  bool wait_until_idle_();
731  void initialize() override;
732  void dump_config() override;
733 
734  protected:
735  void reset_() {
736  if (this->reset_pin_ != nullptr) {
737  this->reset_pin_->digital_write(true);
738  delay(200); // NOLINT
739  this->reset_pin_->digital_write(false);
740  delay(2);
741  this->reset_pin_->digital_write(true);
742  delay(20);
743  }
744  };
745 };
746 
748  public:
749  void initialize() override;
750 
751  void display() override;
752 
753  void dump_config() override;
754 
755  void deep_sleep() override {
756  // deep sleep
757  this->command(0x10);
758  this->data(0x01);
759  }
760 
761  protected:
762  int get_width_internal() override;
763 
764  int get_height_internal() override;
765 };
766 
768  public:
769  void initialize() override;
770 
771  void display() override;
772 
773  void dump_config() override;
774 
775  void deep_sleep() override {
776  // COMMAND POWER DOWN
777  this->command(0x10);
778  this->data(0x01);
779  // cannot wait until idle here, the device no longer responds
780  }
781 
782  void set_full_update_every(uint32_t full_update_every);
783 
784  protected:
785  int get_width_internal() override;
786 
787  int get_height_internal() override;
788 
789  uint32_t idle_timeout_() override;
790 
791  uint32_t full_update_every_{30};
792  uint32_t at_update_{0};
793 };
794 
796  public:
797  void display() override;
798 
799  void dump_config() override;
800 
801  void deep_sleep() override {
802  // COMMAND POWER DOWN
803  this->command(0x10);
804  this->data(0x01);
805  // cannot wait until idle here, the device no longer responds
806  }
807 
808  void set_full_update_every(uint32_t full_update_every);
809 
810  void setup() override;
811  void initialize() override;
812 
813  protected:
814  int get_width_internal() override;
815  int get_height_internal() override;
816  uint32_t idle_timeout_() override;
817 
818  void write_buffer_(uint8_t cmd, int top, int bottom);
819  void set_window_(int t, int b);
820  void send_reset_();
821  void partial_update_();
822  void full_update_();
823 
824  uint32_t full_update_every_{30};
825  uint32_t at_update_{0};
826  bool is_busy_{false};
827  void write_lut_(const uint8_t *lut);
828 };
829 
831  public:
832  void initialize() override;
833 
834  void display() override;
835 
836  void dump_config() override;
837 
838  void deep_sleep() override {
839  // COMMAND DEEP SLEEP
840  this->command(0x10);
841  this->data(0x01);
842  }
843 
844  protected:
845  int get_width_internal() override;
846 
847  int get_height_internal() override;
848 
849  uint32_t idle_timeout_() override;
850 };
851 
852 } // namespace waveshare_epaper
853 } // namespace esphome
virtual void digital_write(bool value)=0
void set_reset_duration(uint32_t reset_duration)
virtual void draw_absolute_pixel_internal(int x, int y, Color color)=0
uint16_t x
Definition: tt21100.cpp:17
display::DisplayType get_display_type() override
virtual void fill(Color color)
Fill the entire screen with the given color.
Definition: display.cpp:15
virtual void dump_config()
Definition: component.cpp:186
uint16_t y
Definition: tt21100.cpp:18
void init_internal_(uint32_t buffer_length)
The SPIDevice is what components using the SPI will create.
Definition: spi.h:391
virtual int get_height_internal()=0
virtual int get_width_internal()=0
uint16_t reset
Definition: ina226.h:39
display::DisplayType get_display_type() override
uint16_t length
Definition: tt21100.cpp:12
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
stm32_cmd_t * cmd
Definition: stm32flash.h:96
void cmd_data(const uint8_t *data, size_t length)
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26