ESPHome  2024.7.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  // COMMAND DEEP SLEEP
179  this->command(0x07);
180  this->data(0xA5); // check byte
181  }
182 
183  protected:
184  int get_width_internal() override;
185  int get_height_internal() override;
186 };
187 
189  public:
190  void initialize() override;
191 
192  void display() override;
193 
194  void dump_config() override;
195 
196  void deep_sleep() override {
197  // COMMAND VCOM_AND_DATA_INTERVAL_SETTING
198  this->command(0x50);
199  // COMMAND POWER OFF
200  this->command(0x02);
201  this->wait_until_idle_();
202  // COMMAND DEEP SLEEP
203  this->command(0x07); // deep sleep
204  this->data(0xA5); // check byte
205  }
206 
207  protected:
208  int get_width_internal() override;
209  int get_height_internal() override;
210 };
211 
213  public:
214  void initialize() override;
215 
216  void display() override;
217 
218  void dump_config() override;
219 
220  void deep_sleep() override {
221  // COMMAND DEEP SLEEP
222  this->command(0x10);
223  this->data(0x01);
224  }
225 
226  protected:
227  int get_width_internal() override;
228  int get_height_internal() override;
229 };
230 
231 class GDEW029T5 : public WaveshareEPaper {
232  public:
233  void initialize() override;
234 
235  void display() override;
236 
237  void dump_config() override;
238 
239  void deep_sleep() override {
240  // COMMAND DEEP SLEEP
241  this->command(0x07);
242  this->data(0xA5); // check byte
243  }
244 
245  protected:
246  int get_width_internal() override;
247 
248  int get_height_internal() override;
249 };
250 
252  public:
253  void initialize() override;
254 
255  void display() override;
256 
257  void dump_config() override;
258 
259  void deep_sleep() override { ; }
260 
261  protected:
262  int get_width_internal() override;
263 
264  int get_height_internal() override;
265 };
266 
267 class GDEW0154M09 : public WaveshareEPaper {
268  public:
269  void initialize() override;
270  void display() override;
271  void dump_config() override;
272  void deep_sleep() override;
273 
274  protected:
275  int get_width_internal() override;
276  int get_height_internal() override;
277 
278  private:
279  static const uint8_t CMD_DTM1_DATA_START_TRANS = 0x10;
280  static const uint8_t CMD_DTM2_DATA_START_TRANS2 = 0x13;
281  static const uint8_t CMD_DISPLAY_REFRESH = 0x12;
282  static const uint8_t CMD_AUTO_SEQ = 0x17;
283  static const uint8_t DATA_AUTO_PON_DSR_POF_DSLP = 0xA7;
284  static const uint8_t CMD_PSR_PANEL_SETTING = 0x00;
285  static const uint8_t CMD_UNDOCUMENTED_0x4D = 0x4D; // NOLINT
286  static const uint8_t CMD_UNDOCUMENTED_0xAA = 0xaa; // NOLINT
287  static const uint8_t CMD_UNDOCUMENTED_0xE9 = 0xe9; // NOLINT
288  static const uint8_t CMD_UNDOCUMENTED_0xB6 = 0xb6; // NOLINT
289  static const uint8_t CMD_UNDOCUMENTED_0xF3 = 0xf3; // NOLINT
290  static const uint8_t CMD_TRES_RESOLUTION_SETTING = 0x61;
291  static const uint8_t CMD_TCON_TCONSETTING = 0x60;
292  static const uint8_t CMD_CDI_VCOM_DATA_INTERVAL = 0x50;
293  static const uint8_t CMD_POF_POWER_OFF = 0x02;
294  static const uint8_t CMD_DSLP_DEEP_SLEEP = 0x07;
295  static const uint8_t DATA_DSLP_DEEP_SLEEP = 0xA5;
296  static const uint8_t CMD_PWS_POWER_SAVING = 0xe3;
297  static const uint8_t CMD_PON_POWER_ON = 0x04;
298  static const uint8_t CMD_PTL_PARTIAL_WINDOW = 0x90;
299 
300  uint8_t *lastbuff_ = nullptr;
301  void reset_();
302  void clear_();
303  void write_init_list_(const uint8_t *list);
304  void init_internal_();
305 };
306 
308  public:
309  void initialize() override;
310 
311  void display() override;
312 
313  void dump_config() override;
314 
315  void deep_sleep() override {
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 DEEP SLEEP
337  this->command(0x07);
338  this->data(0xA5); // check byte
339  }
340 
341  protected:
342  int get_width_internal() override;
343 
344  int get_height_internal() override;
345 };
346 
348  public:
350 
351  void initialize() override;
352 
353  void display() override;
354 
355  void dump_config() override;
356 
357  void deep_sleep() override;
358 
359  void set_full_update_every(uint32_t full_update_every);
360 
361  protected:
362  void write_lut_(const uint8_t *lut, uint8_t size);
363 
364  int get_width_internal() override;
365 
366  int get_height_internal() override;
367 
368  int get_width_controller() override;
369 
370  uint32_t full_update_every_{30};
371  uint32_t at_update_{0};
372 
373  private:
374  void reset_();
375 };
376 
378  public:
379  void initialize() override;
380 
381  void display() override;
382 
383  void dump_config() override;
384 
385  void deep_sleep() override {
386  // COMMAND DEEP SLEEP
387  this->command(0x10);
388  this->data(0x01);
389  }
390 
391  void set_full_update_every(uint32_t full_update_every);
392 
393  protected:
394  uint32_t full_update_every_{30};
395  uint32_t at_update_{0};
396  int get_width_internal() override;
397 
398  int get_height_internal() override;
399 };
400 
402  public:
403  void initialize() override;
404 
405  void display() override;
406 
407  void dump_config() override;
408 
409  void deep_sleep() override {
410  // COMMAND VCOM AND DATA INTERVAL SETTING
411  this->command(0x50);
412  this->data(0x17); // border floating
413 
414  // COMMAND VCM DC SETTING
415  this->command(0x82);
416  // COMMAND PANEL SETTING
417  this->command(0x00);
418 
419  delay(100); // NOLINT
420 
421  // COMMAND POWER SETTING
422  this->command(0x01);
423  this->data(0x00);
424  this->data(0x00);
425  this->data(0x00);
426  this->data(0x00);
427  this->data(0x00);
428  delay(100); // NOLINT
429 
430  // COMMAND POWER OFF
431  this->command(0x02);
432  this->wait_until_idle_();
433  // COMMAND DEEP SLEEP
434  this->command(0x07);
435  this->data(0xA5); // check byte
436  }
437 
438  protected:
439  int get_width_internal() override;
440 
441  int get_height_internal() override;
442 };
443 
445  public:
446  void initialize() override;
447 
448  void display() override;
449 
450  void dump_config() override;
451 
452  void deep_sleep() override {
453  // COMMAND VCOM AND DATA INTERVAL SETTING
454  this->command(0x50);
455  this->data(0xF7); // border floating
456 
457  // COMMAND POWER OFF
458  this->command(0x02);
459  this->wait_until_idle_();
460 
461  // COMMAND DEEP SLEEP
462  this->command(0x07);
463  this->data(0xA5); // check code
464  }
465 
466  protected:
467  int get_width_internal() override;
468 
469  int get_height_internal() override;
470 };
471 
473  public:
474  void initialize() override;
475 
476  void display() override;
477 
478  void dump_config() override;
479 
480  void deep_sleep() override {
481  // COMMAND POWER OFF
482  this->command(0x02);
483  this->wait_until_idle_();
484  // COMMAND DEEP SLEEP
485  this->command(0x07);
486  this->data(0xA5); // check byte
487  }
488 
489  protected:
490  int get_width_internal() override;
491 
492  int get_height_internal() override;
493 };
494 
496  public:
497  void initialize() override;
498 
499  void display() override;
500 
501  void dump_config() override;
502 
503  void deep_sleep() override {
504  // COMMAND VCOM AND DATA INTERVAL SETTING
505  this->command(0x50);
506  this->data(0x17); // border floating
507 
508  // COMMAND VCM DC SETTING
509  this->command(0x82);
510  // COMMAND PANEL SETTING
511  this->command(0x00);
512 
513  delay(100); // NOLINT
514 
515  // COMMAND POWER SETTING
516  this->command(0x01);
517  this->data(0x00);
518  this->data(0x00);
519  this->data(0x00);
520  this->data(0x00);
521  this->data(0x00);
522  delay(100); // NOLINT
523 
524  // COMMAND POWER OFF
525  this->command(0x02);
526  this->wait_until_idle_();
527  // COMMAND DEEP SLEEP
528  this->command(0x07);
529  this->data(0xA5); // check byte
530  }
531 
532  protected:
533  int get_width_internal() override;
534 
535  int get_height_internal() override;
536 };
537 
539  public:
540  void initialize() override;
541 
542  void display() override;
543 
544  void dump_config() override;
545 
546  void deep_sleep() override {
547  // COMMAND POWER OFF
548  this->command(0x02);
549  this->wait_until_idle_();
550  // COMMAND DEEP SLEEP
551  this->command(0x07);
552  this->data(0xA5); // check byte
553  }
554 
555  protected:
556  int get_width_internal() override;
557 
558  int get_height_internal() override;
559 };
560 
562  public:
563  void initialize() override;
564 
565  void display() override;
566 
567  void dump_config() override;
568 
569  void deep_sleep() override {
570  // COMMAND POWER OFF
571  this->command(0x02);
572  this->wait_until_idle_();
573  // COMMAND DEEP SLEEP
574  this->command(0x07); // deep sleep
575  this->data(0xA5); // check byte
576  }
577 
578  protected:
579  int get_width_internal() override;
580 
581  int get_height_internal() override;
582 };
583 
585  public:
586  bool wait_until_idle_();
587 
588  void initialize() override;
589 
590  void display() override;
591 
592  void dump_config() override;
593 
594  void deep_sleep() override {
595  this->command(0x02); // Power off
596  this->wait_until_idle_();
597  this->command(0x07); // Deep sleep
598  this->data(0xA5);
599  }
600 
601  void clear_screen();
602 
603  protected:
604  int get_width_internal() override;
605 
606  int get_height_internal() override;
607 
608  void reset_() {
609  if (this->reset_pin_ != nullptr) {
610  this->reset_pin_->digital_write(true);
611  delay(200); // NOLINT
612  this->reset_pin_->digital_write(false);
613  delay(5);
614  this->reset_pin_->digital_write(true);
615  delay(200); // NOLINT
616  }
617  };
618 
619  void init_display_();
620 };
621 
623  public:
624  void initialize() override;
625 
626  void display() override;
627 
628  void dump_config() override;
629 
630  void deep_sleep() override {
631  // COMMAND POWER OFF
632  this->command(0x02);
633  this->wait_until_idle_();
634  // COMMAND DEEP SLEEP
635  this->command(0x07);
636  this->data(0xA5); // check byte
637  }
638 
639  protected:
640  int get_width_internal() override;
641 
642  int get_height_internal() override;
643 };
644 
646  public:
647  bool wait_until_idle_();
648 
649  void initialize() override;
650 
651  void display() override;
652 
653  void dump_config() override;
654 
655  void deep_sleep() override {
656  // COMMAND POWER OFF
657  this->command(0x02);
658  this->wait_until_idle_();
659  // COMMAND DEEP SLEEP
660  this->command(0x07);
661  this->data(0xA5); // check byte
662  }
663 
664  protected:
665  int get_width_internal() override;
666 
667  int get_height_internal() override;
668 
669  uint32_t idle_timeout_() override;
670 };
671 
673  public:
674  bool wait_until_idle_();
675  void initialize() override;
676  void dump_config() override;
677 
678  protected:
679  void reset_() {
680  if (this->reset_pin_ != nullptr) {
681  this->reset_pin_->digital_write(true);
682  delay(200); // NOLINT
683  this->reset_pin_->digital_write(false);
684  delay(2);
685  this->reset_pin_->digital_write(true);
686  delay(20);
687  }
688  };
689 };
690 
692  public:
693  void initialize() override;
694 
695  void display() override;
696 
697  void dump_config() override;
698 
699  void deep_sleep() override {
700  // deep sleep
701  this->command(0x10);
702  this->data(0x01);
703  }
704 
705  protected:
706  int get_width_internal() override;
707 
708  int get_height_internal() override;
709 };
710 
712  public:
713  void initialize() override;
714 
715  void display() override;
716 
717  void dump_config() override;
718 
719  void deep_sleep() override {
720  // COMMAND POWER DOWN
721  this->command(0x10);
722  this->data(0x01);
723  // cannot wait until idle here, the device no longer responds
724  }
725 
726  void set_full_update_every(uint32_t full_update_every);
727 
728  protected:
729  int get_width_internal() override;
730 
731  int get_height_internal() override;
732 
733  uint32_t idle_timeout_() override;
734 
735  uint32_t full_update_every_{30};
736  uint32_t at_update_{0};
737 };
738 
740  public:
741  void display() override;
742 
743  void dump_config() override;
744 
745  void deep_sleep() override {
746  // COMMAND POWER DOWN
747  this->command(0x10);
748  this->data(0x01);
749  // cannot wait until idle here, the device no longer responds
750  }
751 
752  void set_full_update_every(uint32_t full_update_every);
753 
754  void setup() override;
755  void initialize() override;
756 
757  protected:
758  int get_width_internal() override;
759  int get_height_internal() override;
760  uint32_t idle_timeout_() override;
761 
762  void write_buffer_(uint8_t cmd, int top, int bottom);
763  void set_window_(int t, int b);
764  void send_reset_();
765  void partial_update_();
766  void full_update_();
767 
768  uint32_t full_update_every_{30};
769  uint32_t at_update_{0};
770  bool is_busy_{false};
771  void write_lut_(const uint8_t *lut);
772 };
773 
775  public:
776  void initialize() override;
777 
778  void display() override;
779 
780  void dump_config() override;
781 
782  void deep_sleep() override {
783  // COMMAND DEEP SLEEP
784  this->command(0x10);
785  this->data(0x01);
786  }
787 
788  protected:
789  int get_width_internal() override;
790 
791  int get_height_internal() override;
792 
793  uint32_t idle_timeout_() override;
794 };
795 
796 } // namespace waveshare_epaper
797 } // 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:408
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