ESPHome 2026.5.1
Loading...
Searching...
No Matches
waveshare_epaper.h
Go to the documentation of this file.
1#pragma once
2
6
8
10 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
11 spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ> {
12 public:
13 void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
14 float get_setup_priority() const override;
16 void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
17 void set_reset_duration(uint32_t reset_duration) { this->reset_duration_ = reset_duration; }
18
19 void command(uint8_t value);
20 void data(uint8_t value);
21 void cmd_data(const uint8_t *data, size_t length);
22
23 virtual void display() = 0;
24 virtual void initialize() = 0;
25 virtual void deep_sleep() = 0;
26
27 void update() override;
28
29 void setup() override;
30
31 void on_safe_shutdown() override;
32
33 protected:
34 bool wait_until_idle_();
35
36 void setup_pins_();
37
38 void reset_() {
39 if (this->reset_pin_ != nullptr) {
40 this->reset_pin_->digital_write(false);
41 delay(reset_duration_); // NOLINT
42 this->reset_pin_->digital_write(true);
43 delay(20);
44 }
45 }
46
47 virtual int get_width_controller() { return this->get_width_internal(); };
48
49 virtual uint32_t get_buffer_length_() = 0; // NOLINT(readability-identifier-naming)
51
52 void start_command_();
53 void end_command_();
54 void start_data_();
55 void end_data_();
56
59 GPIOPin *busy_pin_{nullptr};
60 virtual uint32_t idle_timeout_() { return 1000u; } // NOLINT(readability-identifier-naming)
61};
62
64 public:
65 void fill(Color color) override;
66
68
69 protected:
70 void draw_absolute_pixel_internal(int x, int y, Color color) override;
72};
73
75 public:
76 void fill(Color color) override;
77
79
80 protected:
81 void draw_absolute_pixel_internal(int x, int y, Color color) override;
83};
84
86 public:
87 uint8_t color_to_hex(Color color);
88 void fill(Color color) override;
89
91
92 protected:
93 void draw_absolute_pixel_internal(int x, int y, Color color) override;
95 void setup() override;
96
97 void init_internal_7c_(uint32_t buffer_length);
98 void send_buffers_();
99 void reset_();
100
101 static const int NUM_BUFFERS = 10;
103};
104
117
119 public:
121
122 void initialize() override;
123
124 void dump_config() override;
125
126 void display() override;
127
128 void deep_sleep() override {
129 switch (this->model_) {
130 // Models with specific deep sleep command and data
135 // COMMAND DEEP SLEEP MODE
136 this->command(0x10);
137 this->data(0x01);
138 break;
139 // Other models default to simple deep sleep command
140 default:
141 // COMMAND DEEP SLEEP
142 this->command(0x10);
143 break;
144 }
145 if (this->model_ != WAVESHARE_EPAPER_2_13_IN_V2) {
146 // From panel specification:
147 // "After this command initiated, the chip will enter Deep Sleep Mode, BUSY pad will keep output high."
148 this->wait_until_idle_();
149 }
150 }
151
152 void set_full_update_every(uint32_t full_update_every);
153
154 protected:
155 void write_lut_(const uint8_t *lut, uint8_t size);
156
157 void init_display_();
158
159 int get_width_internal() override;
160
161 int get_height_internal() override;
162
163 int get_width_controller() override;
164
168 uint32_t idle_timeout_() override;
169
171};
172
185
187 public:
188 void initialize() override;
189
190 void display() override;
191
192 void dump_config() override;
193
194 void deep_sleep() override {
195 this->command(0x10);
196 this->data(0x01);
197 }
198
199 protected:
200 int get_width_internal() override;
201 int get_height_internal() override;
202};
203
205 public:
206 void initialize() override;
207
208 void display() override;
209
210 void dump_config() override;
211
212 void deep_sleep() override {
213 // COMMAND DEEP SLEEP
214 this->command(0x07);
215 this->data(0xA5); // check byte
216 }
217
218 protected:
219 int get_width_internal() override;
220 int get_height_internal() override;
221};
222
224 public:
225 void initialize() override;
226
227 void display() override;
228
229 void dump_config() override;
230
231 void deep_sleep() override {
232 // COMMAND VCOM_AND_DATA_INTERVAL_SETTING
233 this->command(0x50);
234 // COMMAND POWER OFF
235 this->command(0x02);
236 this->wait_until_idle_();
237 // COMMAND DEEP SLEEP
238 this->command(0x07); // deep sleep
239 this->data(0xA5); // check byte
240 }
241
242 protected:
243 int get_width_internal() override;
244 int get_height_internal() override;
245};
246
248 public:
249 void initialize() override;
250
251 void display() override;
252
253 void dump_config() override;
254
255 void deep_sleep() override {
256 // COMMAND DEEP SLEEP
257 this->command(0x10);
258 this->data(0x01);
259 }
260
261 protected:
262 int get_width_internal() override;
263 int get_height_internal() override;
264};
265
267 public:
268 void initialize() override;
269
270 void display() override;
271
272 void dump_config() override;
273
274 void deep_sleep() override;
275 void set_full_update_every(uint32_t full_update_every);
276
277 protected:
278 void init_display_();
279 void init_full_();
280 void init_partial_();
281 void write_lut_(const uint8_t *lut, uint8_t size);
282 void power_off_();
283 void power_on_();
284 int get_width_internal() override;
285
286 int get_height_internal() override;
287
288 private:
289 uint32_t full_update_every_{30};
290 uint32_t at_update_{0};
291 bool deep_sleep_between_updates_{false};
292 bool power_is_on_{false};
293 bool is_deep_sleep_{false};
294 uint8_t *old_buffer_{nullptr};
295};
296
298 public:
299 void initialize() override;
300
301 void display() override;
302
303 void dump_config() override;
304
305 void deep_sleep() override {
306 this->command(0x10); // Enter deep sleep
307 this->data(0x01);
308 }
309
310 protected:
311 int get_width_internal() override;
312
313 int get_height_internal() override;
314};
315
317 public:
318 void initialize() override;
319
320 void display() override;
321
322 void dump_config() override;
323
324 void deep_sleep() override { ; }
325
326 protected:
327 int get_width_internal() override;
328
329 int get_height_internal() override;
330};
331
333 public:
334 void initialize() override;
335 void display() override;
336 void dump_config() override;
337 void deep_sleep() override;
338
339 protected:
340 int get_width_internal() override;
341 int get_height_internal() override;
342
343 private:
344 static const uint8_t CMD_DTM1_DATA_START_TRANS = 0x10;
345 static const uint8_t CMD_DTM2_DATA_START_TRANS2 = 0x13;
346 static const uint8_t CMD_DISPLAY_REFRESH = 0x12;
347 static const uint8_t CMD_AUTO_SEQ = 0x17;
348 static const uint8_t DATA_AUTO_PON_DSR_POF_DSLP = 0xA7;
349 static const uint8_t CMD_PSR_PANEL_SETTING = 0x00;
350 static const uint8_t CMD_UNDOCUMENTED_0x4D = 0x4D; // NOLINT
351 static const uint8_t CMD_UNDOCUMENTED_0xAA = 0xaa; // NOLINT
352 static const uint8_t CMD_UNDOCUMENTED_0xE9 = 0xe9; // NOLINT
353 static const uint8_t CMD_UNDOCUMENTED_0xB6 = 0xb6; // NOLINT
354 static const uint8_t CMD_UNDOCUMENTED_0xF3 = 0xf3; // NOLINT
355 static const uint8_t CMD_TRES_RESOLUTION_SETTING = 0x61;
356 static const uint8_t CMD_TCON_TCONSETTING = 0x60;
357 static const uint8_t CMD_CDI_VCOM_DATA_INTERVAL = 0x50;
358 static const uint8_t CMD_POF_POWER_OFF = 0x02;
359 static const uint8_t CMD_DSLP_DEEP_SLEEP = 0x07;
360 static const uint8_t DATA_DSLP_DEEP_SLEEP = 0xA5;
361 static const uint8_t CMD_PWS_POWER_SAVING = 0xe3;
362 static const uint8_t CMD_PON_POWER_ON = 0x04;
363 static const uint8_t CMD_PTL_PARTIAL_WINDOW = 0x90;
364
365 uint8_t *lastbuff_ = nullptr;
366 void reset_();
367 void clear_();
368 void write_init_list_(const uint8_t *list);
369 void init_internal_();
370};
371
373 public:
374 void initialize() override;
375
376 void display() override;
377
378 void dump_config() override;
379
380 void deep_sleep() override {
381 // COMMAND DEEP SLEEP
382 this->command(0x07);
383 this->data(0xA5); // check byte
384 }
385
386 protected:
387 int get_width_internal() override;
388
389 int get_height_internal() override;
390};
391
393 public:
394 void initialize() override;
395
396 void display() override;
397
398 void dump_config() override;
399
400 void deep_sleep() override {
401 // COMMAND DEEP SLEEP
402 this->command(0x07);
403 this->data(0xA5); // check byte
404 }
405
406 protected:
407 int get_width_internal() override;
408
409 int get_height_internal() override;
410};
411
413 public:
415
416 void initialize() override;
417
418 void display() override;
419
420 void dump_config() override;
421
422 void deep_sleep() override;
423
424 void set_full_update_every(uint32_t full_update_every);
425
426 protected:
427 void write_lut_(const uint8_t *lut, uint8_t size);
428
429 int get_width_internal() override;
430
431 int get_height_internal() override;
432
433 int get_width_controller() override;
434
437
438 private:
439 void reset_();
440};
441
443 public:
444 void initialize() override;
445
446 void display() override;
447
448 void dump_config() override;
449
450 void deep_sleep() override {
451 // COMMAND DEEP SLEEP
452 this->command(0x10);
453 this->data(0x01);
454 }
455
456 void set_full_update_every(uint32_t full_update_every);
457
458 protected:
461 int get_width_internal() override;
462
463 int get_height_internal() override;
464};
465
467 public:
468 void initialize() override;
469
470 void display() override;
471
472 void dump_config() override;
473
474 void deep_sleep() override {
475 // COMMAND DEEP SLEEP
476 this->command(0x07);
477 this->data(0xA5);
478 }
479
480 protected:
481 int get_width_internal() override;
482
483 int get_height_internal() override;
484};
485
487 public:
488 GDEY042T81();
489
490 void initialize() override;
491
492 void display() override;
493
494 void dump_config() override;
495
496 void deep_sleep() override {
497 // COMMAND POWER OFF
498 this->command(0x22);
499 this->data(0x83);
500 this->command(0x20);
501 // COMMAND DEEP SLEEP
502 this->command(0x10);
503 this->data(0x01);
504 }
505
506 void set_full_update_every(uint32_t full_update_every);
507
508 protected:
511
512 int get_width_internal() override;
513 int get_height_internal() override;
514 uint32_t idle_timeout_() override;
515
516 private:
517 void reset_();
518 void update_full_();
519 void update_part_();
520 void init_display_();
521};
522
524 public:
525 void initialize() override;
526
527 void display() override;
528
529 void dump_config() override;
530
531 void deep_sleep() override {
532 // COMMAND VCOM AND DATA INTERVAL SETTING
533 this->command(0x50);
534 this->data(0x17); // border floating
535
536 // COMMAND VCM DC SETTING
537 this->command(0x82);
538 // COMMAND PANEL SETTING
539 this->command(0x00);
540
541 delay(100); // NOLINT
542
543 // COMMAND POWER SETTING
544 this->command(0x01);
545 this->data(0x00);
546 this->data(0x00);
547 this->data(0x00);
548 this->data(0x00);
549 this->data(0x00);
550 delay(100); // NOLINT
551
552 // COMMAND POWER OFF
553 this->command(0x02);
554 this->wait_until_idle_();
555 // COMMAND DEEP SLEEP
556 this->command(0x07);
557 this->data(0xA5); // check byte
558 }
559
560 protected:
561 int get_width_internal() override;
562
563 int get_height_internal() override;
564};
565
567 public:
568 void initialize() override;
569
570 void display() override;
571
572 void dump_config() override;
573
574 void deep_sleep() override {
575 // COMMAND VCOM AND DATA INTERVAL SETTING
576 this->command(0x50);
577 this->data(0xF7); // border floating
578
579 // COMMAND POWER OFF
580 this->command(0x02);
581 this->wait_until_idle_();
582
583 // COMMAND DEEP SLEEP
584 this->command(0x07);
585 this->data(0xA5); // check code
586 }
587
588 protected:
589 int get_width_internal() override;
590
591 int get_height_internal() override;
592};
593
595 public:
596 void initialize() override;
597
598 void display() override;
599
600 void dump_config() override;
601
602 void deep_sleep() override {
603 // COMMAND VCOM AND DATA INTERVAL SETTING
604 this->command(0x50);
605 this->data(0xF7); // border floating
606
607 // COMMAND POWER OFF
608 this->command(0x02);
609 this->wait_until_idle_();
610
611 // COMMAND DEEP SLEEP
612 this->command(0x07);
613 this->data(0xA5); // check code
614 }
615
616 protected:
617 int get_width_internal() override;
618
619 int get_height_internal() override;
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 void initialize() override;
648
649 void display() override;
650
651 void dump_config() override;
652
653 void deep_sleep() override {
654 // COMMAND VCOM AND DATA INTERVAL SETTING
655 this->command(0x50);
656 this->data(0x17); // border floating
657
658 // COMMAND VCM DC SETTING
659 this->command(0x82);
660 // COMMAND PANEL SETTING
661 this->command(0x00);
662
663 delay(100); // NOLINT
664
665 // COMMAND POWER SETTING
666 this->command(0x01);
667 this->data(0x00);
668 this->data(0x00);
669 this->data(0x00);
670 this->data(0x00);
671 this->data(0x00);
672 delay(100); // NOLINT
673
674 // COMMAND POWER OFF
675 this->command(0x02);
676 this->wait_until_idle_();
677 // COMMAND DEEP SLEEP
678 this->command(0x07);
679 this->data(0xA5); // check byte
680 }
681
682 protected:
683 int get_width_internal() override;
684
685 int get_height_internal() override;
686};
687
689 public:
690 void initialize() override;
691
692 void display() override;
693
694 void dump_config() override;
695
696 void deep_sleep() override;
697
698 void set_full_update_every(uint32_t full_update_every);
699
700 protected:
701 int get_width_internal() override;
702 int get_height_internal() override;
703 uint32_t idle_timeout_() override;
704
705 private:
706 void power_on_();
707 void power_off_();
708 void reset_();
709 void update_full_();
710 void update_part_();
711 void init_full_();
712 void init_partial_();
713 void init_display_();
714
715 uint32_t full_update_every_{30};
716 uint32_t at_update_{0};
717 bool power_is_on_{false};
718 bool is_deep_sleep_{false};
719 uint8_t *old_buffer_{nullptr};
720};
721
723 public:
724 void initialize() override;
725
726 void display() override;
727
728 void dump_config() override;
729
730 protected:
731 int get_width_internal() override;
732
733 int get_height_internal() override;
734
735 uint32_t idle_timeout_() override;
736
737 void deep_sleep() override { ; }
738
739 enum WaitForState { BUSY = true, IDLE = false };
741
743};
744
746 public:
747 void initialize() override;
748
749 void display() override;
750
751 void dump_config() override;
752
753 protected:
754 int get_width_internal() override;
755
756 int get_height_internal() override;
757
758 uint32_t idle_timeout_() override;
759
760 void deep_sleep() override { ; }
761
762 bool wait_until_idle_();
763
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 OFF
777 this->command(0x02);
778 this->wait_until_idle_();
779 // COMMAND DEEP SLEEP
780 this->command(0x07);
781 this->data(0xA5); // check byte
782 }
783
784 protected:
785 int get_width_internal() override;
786
787 int get_height_internal() override;
788};
789
791 public:
792 void initialize() override;
793
794 void display() override;
795
796 void dump_config() override;
797
798 void deep_sleep() override {
799 // COMMAND POWER OFF
800 this->command(0x02);
801 this->wait_until_idle_();
802 // COMMAND DEEP SLEEP
803 this->command(0x07); // deep sleep
804 this->data(0xA5); // check byte
805 }
806
807 protected:
808 int get_width_internal() override;
809
810 int get_height_internal() override;
811};
812
814 public:
815 bool wait_until_idle_();
816
817 void initialize() override;
818
819 void display() override;
820
821 void dump_config() override;
822
823 void deep_sleep() override {
824 this->command(0x02); // Power off
825 this->wait_until_idle_();
826 this->command(0x07); // Deep sleep
827 this->data(0xA5);
828 }
829
831
832 protected:
833 int get_width_internal() override;
834
835 int get_height_internal() override;
836
837 void reset_() {
838 if (this->reset_pin_ != nullptr) {
839 this->reset_pin_->digital_write(true);
840 delay(200); // NOLINT
841 this->reset_pin_->digital_write(false);
842 delay(5);
843 this->reset_pin_->digital_write(true);
844 delay(200); // NOLINT
845 }
846 };
847
848 void init_display_();
849};
850
852 public:
853 bool wait_until_idle_();
854
855 void initialize() override;
856
857 void display() override;
858
859 void dump_config() override;
860
861 void deep_sleep() override {
862 this->command(0x02); // Power off
863 this->wait_until_idle_();
864 this->command(0x07); // Deep sleep
865 this->data(0xA5);
866 }
867
869
870 protected:
871 int get_width_internal() override;
872
873 int get_height_internal() override;
874
875 void reset_() {
876 if (this->reset_pin_ != nullptr) {
877 this->reset_pin_->digital_write(true);
878 delay(200); // NOLINT
879 this->reset_pin_->digital_write(false);
880 delay(5);
881 this->reset_pin_->digital_write(true);
882 delay(200); // NOLINT
883 }
884 };
885
886 void init_display_();
887};
888
890 public:
891 void initialize() override;
892
893 void display() override;
894
895 void dump_config() override;
896
897 void deep_sleep() override {
898 // COMMAND POWER OFF
899 this->command(0x02);
900 this->wait_until_idle_();
901 // COMMAND DEEP SLEEP
902 this->command(0x07);
903 this->data(0xA5); // check byte
904 }
905
906 protected:
907 int get_width_internal() override;
908
909 int get_height_internal() override;
910};
911
913 public:
914 bool wait_until_idle_();
915
916 void initialize() override;
917
918 void display() override;
919
920 void dump_config() override;
921
922 void deep_sleep() override {
923 // COMMAND POWER OFF
924 this->command(0x02);
925 this->wait_until_idle_();
926 // COMMAND DEEP SLEEP
927 this->command(0x07);
928 this->data(0xA5); // check byte
929 }
930
931 protected:
932 int get_width_internal() override;
933
934 int get_height_internal() override;
935
936 uint32_t idle_timeout_() override;
937};
938
940 public:
941 bool wait_until_idle_();
942 void initialize() override;
943 void dump_config() override;
944
945 protected:
946 void reset_() {
947 if (this->reset_pin_ != nullptr) {
948 this->reset_pin_->digital_write(true);
949 delay(200); // NOLINT
950 this->reset_pin_->digital_write(false);
951 delay(2);
952 this->reset_pin_->digital_write(true);
953 delay(20);
954 }
955 };
956};
957
959 public:
960 bool wait_until_idle_();
961
962 void initialize() override;
963
964 void display() override;
965
966 void dump_config() override;
967
968 void deep_sleep() override {
969 // COMMAND POWER OFF
970 this->command(0x02);
971 this->wait_until_idle_();
972 // COMMAND DEEP SLEEP
973 this->command(0x07);
974 this->data(0xA5); // check byte
975 }
976
977 void set_full_update_every(uint32_t full_update_every);
978
979 protected:
980 int get_width_internal() override;
981
982 int get_height_internal() override;
983
984 uint32_t idle_timeout_() override;
985
988
989 private:
990 void reset_();
991
992 void turn_on_display_();
993};
994
996 public:
997 void initialize() override;
998
999 void display() override;
1000
1001 void dump_config() override;
1002
1003 void deep_sleep() override {
1004 // deep sleep
1005 this->command(0x10);
1006 this->data(0x01);
1007 }
1008
1009 protected:
1010 int get_width_internal() override;
1011
1012 int get_height_internal() override;
1013};
1014
1016 public:
1017 void initialize() override;
1018
1019 void display() override;
1020
1021 void dump_config() override;
1022
1023 void deep_sleep() override {
1024 // COMMAND POWER DOWN
1025 this->command(0x10);
1026 this->data(0x01);
1027 // cannot wait until idle here, the device no longer responds
1028 }
1029
1030 void set_full_update_every(uint32_t full_update_every);
1031
1032 protected:
1033 int get_width_internal() override;
1034
1035 int get_height_internal() override;
1036
1037 uint32_t idle_timeout_() override;
1038
1041};
1042
1044 public:
1045 void display() override;
1046
1047 void dump_config() override;
1048
1049 void deep_sleep() override {
1050 // COMMAND POWER DOWN
1051 this->command(0x10);
1052 this->data(0x01);
1053 // cannot wait until idle here, the device no longer responds
1054 }
1055
1056 void set_full_update_every(uint32_t full_update_every);
1057
1058 void setup() override;
1059 void initialize() override;
1060
1061 protected:
1062 int get_width_controller() override;
1063 int get_width_internal() override;
1064 int get_height_internal() override;
1065 uint32_t idle_timeout_() override;
1066
1067 void write_buffer_(uint8_t cmd, int top, int bottom);
1068 void set_window_(int t, int b);
1069 void send_reset_();
1070 void partial_update_();
1071 void full_update_();
1072
1075 bool is_busy_{false};
1076 void write_lut_(const uint8_t *lut);
1077};
1078
1080 public:
1081 void initialize() override;
1082
1083 void display() override;
1084
1085 void dump_config() override;
1086
1087 void deep_sleep() override {
1088 // COMMAND DEEP SLEEP
1089 this->command(0x10);
1090 this->data(0x01);
1091 }
1092
1093 protected:
1094 int get_width_internal() override;
1095
1096 int get_height_internal() override;
1097
1098 uint32_t idle_timeout_() override;
1099};
1100
1101} // namespace esphome::waveshare_epaper
virtual void digital_write(bool value)=0
virtual int get_width_internal()=0
The SPIDevice is what components using the SPI will create.
Definition spi.h:429
void set_full_update_every(uint32_t full_update_every)
void write_lut_(const uint8_t *lut, uint8_t size)
void set_full_update_every(uint32_t full_update_every)
void set_full_update_every(uint32_t full_update_every)
void set_full_update_every(uint32_t full_update_every)
void write_buffer_(uint8_t cmd, int top, int bottom)
void write_lut_(const uint8_t *lut, uint8_t size)
void draw_absolute_pixel_internal(int x, int y, Color color) override
display::DisplayType get_display_type() override
void draw_absolute_pixel_internal(int x, int y, Color color) override
display::DisplayType get_display_type() override
void set_reset_duration(uint32_t reset_duration)
void cmd_data(const uint8_t *data, size_t length)
void draw_absolute_pixel_internal(int x, int y, Color color) override
display::DisplayType get_display_type() override
void set_full_update_every(uint32_t full_update_every)
WaveshareEPaperTypeA(WaveshareEPaperTypeAModel model)
void write_lut_(const uint8_t *lut, uint8_t size)
bool state
Definition fan.h:2
uint16_t reset
Definition ina226.h:5
uint16_t size
Definition helpers.cpp:25
void HOT delay(uint32_t ms)
Definition hal.cpp:85
static void uint32_t
uint16_t length
Definition tt21100.cpp:0
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6