ESPHome  2024.4.0
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 
166 };
167 
169  public:
170  void initialize() override;
171 
172  void display() override;
173 
174  void dump_config() override;
175 
176  void deep_sleep() override {
177  // COMMAND DEEP SLEEP
178  this->command(0x07);
179  this->data(0xA5); // check byte
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 VCOM_AND_DATA_INTERVAL_SETTING
197  this->command(0x50);
198  // COMMAND POWER OFF
199  this->command(0x02);
200  this->wait_until_idle_();
201  // COMMAND DEEP SLEEP
202  this->command(0x07); // deep sleep
203  this->data(0xA5); // check byte
204  }
205 
206  protected:
207  int get_width_internal() override;
208  int get_height_internal() override;
209 };
210 
212  public:
213  void initialize() override;
214 
215  void display() override;
216 
217  void dump_config() override;
218 
219  void deep_sleep() override {
220  // COMMAND DEEP SLEEP
221  this->command(0x10);
222  this->data(0x01);
223  }
224 
225  protected:
226  int get_width_internal() override;
227  int get_height_internal() override;
228 };
229 
230 class GDEY029T94 : public WaveshareEPaper {
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(0x07);
241  this->data(0xA5); // check byte
242  }
243 
244  protected:
245  int get_width_internal() override;
246 
247  int get_height_internal() override;
248 };
249 
251  public:
252  void initialize() override;
253 
254  void display() override;
255 
256  void dump_config() override;
257 
258  void deep_sleep() override { ; }
259 
260  protected:
261  int get_width_internal() override;
262 
263  int get_height_internal() override;
264 };
265 
266 class GDEW0154M09 : public WaveshareEPaper {
267  public:
268  void initialize() override;
269  void display() override;
270  void dump_config() override;
271  void deep_sleep() override;
272 
273  protected:
274  int get_width_internal() override;
275  int get_height_internal() override;
276 
277  private:
278  static const uint8_t CMD_DTM1_DATA_START_TRANS = 0x10;
279  static const uint8_t CMD_DTM2_DATA_START_TRANS2 = 0x13;
280  static const uint8_t CMD_DISPLAY_REFRESH = 0x12;
281  static const uint8_t CMD_AUTO_SEQ = 0x17;
282  static const uint8_t DATA_AUTO_PON_DSR_POF_DSLP = 0xA7;
283  static const uint8_t CMD_PSR_PANEL_SETTING = 0x00;
284  static const uint8_t CMD_UNDOCUMENTED_0x4D = 0x4D; // NOLINT
285  static const uint8_t CMD_UNDOCUMENTED_0xAA = 0xaa; // NOLINT
286  static const uint8_t CMD_UNDOCUMENTED_0xE9 = 0xe9; // NOLINT
287  static const uint8_t CMD_UNDOCUMENTED_0xB6 = 0xb6; // NOLINT
288  static const uint8_t CMD_UNDOCUMENTED_0xF3 = 0xf3; // NOLINT
289  static const uint8_t CMD_TRES_RESOLUTION_SETTING = 0x61;
290  static const uint8_t CMD_TCON_TCONSETTING = 0x60;
291  static const uint8_t CMD_CDI_VCOM_DATA_INTERVAL = 0x50;
292  static const uint8_t CMD_POF_POWER_OFF = 0x02;
293  static const uint8_t CMD_DSLP_DEEP_SLEEP = 0x07;
294  static const uint8_t DATA_DSLP_DEEP_SLEEP = 0xA5;
295  static const uint8_t CMD_PWS_POWER_SAVING = 0xe3;
296  static const uint8_t CMD_PON_POWER_ON = 0x04;
297  static const uint8_t CMD_PTL_PARTIAL_WINDOW = 0x90;
298 
299  uint8_t *lastbuff_ = nullptr;
300  void reset_();
301  void clear_();
302  void write_init_list_(const uint8_t *list);
303  void init_internal_();
304 };
305 
307  public:
308  void initialize() override;
309 
310  void display() override;
311 
312  void dump_config() override;
313 
314  void deep_sleep() override {
315  // COMMAND DEEP SLEEP
316  this->command(0x07);
317  this->data(0xA5); // check byte
318  }
319 
320  protected:
321  int get_width_internal() override;
322 
323  int get_height_internal() override;
324 };
325 
327  public:
328  void initialize() override;
329 
330  void display() override;
331 
332  void dump_config() override;
333 
334  void deep_sleep() override {
335  // COMMAND DEEP SLEEP
336  this->command(0x07);
337  this->data(0xA5); // check byte
338  }
339 
340  protected:
341  int get_width_internal() override;
342 
343  int get_height_internal() override;
344 };
345 
347  public:
349 
350  void initialize() override;
351 
352  void display() override;
353 
354  void dump_config() override;
355 
356  void deep_sleep() override;
357 
358  void set_full_update_every(uint32_t full_update_every);
359 
360  protected:
361  void write_lut_(const uint8_t *lut, uint8_t size);
362 
363  int get_width_internal() override;
364 
365  int get_height_internal() override;
366 
367  int get_width_controller() override;
368 
369  uint32_t full_update_every_{30};
370  uint32_t at_update_{0};
371 
372  private:
373  void reset_();
374 };
375 
377  public:
378  void initialize() override;
379 
380  void display() override;
381 
382  void dump_config() override;
383 
384  void deep_sleep() override {
385  // COMMAND VCOM AND DATA INTERVAL SETTING
386  this->command(0x50);
387  this->data(0x17); // border floating
388 
389  // COMMAND VCM DC SETTING
390  this->command(0x82);
391  // COMMAND PANEL SETTING
392  this->command(0x00);
393 
394  delay(100); // NOLINT
395 
396  // COMMAND POWER SETTING
397  this->command(0x01);
398  this->data(0x00);
399  this->data(0x00);
400  this->data(0x00);
401  this->data(0x00);
402  this->data(0x00);
403  delay(100); // NOLINT
404 
405  // COMMAND POWER OFF
406  this->command(0x02);
407  this->wait_until_idle_();
408  // COMMAND DEEP SLEEP
409  this->command(0x07);
410  this->data(0xA5); // check byte
411  }
412 
413  protected:
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(0xF7); // border floating
431 
432  // COMMAND POWER OFF
433  this->command(0x02);
434  this->wait_until_idle_();
435 
436  // COMMAND DEEP SLEEP
437  this->command(0x07);
438  this->data(0xA5); // check code
439  }
440 
441  protected:
442  int get_width_internal() override;
443 
444  int get_height_internal() override;
445 };
446 
448  public:
449  void initialize() override;
450 
451  void display() override;
452 
453  void dump_config() override;
454 
455  void deep_sleep() override {
456  // COMMAND POWER OFF
457  this->command(0x02);
458  this->wait_until_idle_();
459  // COMMAND DEEP SLEEP
460  this->command(0x07);
461  this->data(0xA5); // check byte
462  }
463 
464  protected:
465  int get_width_internal() override;
466 
467  int get_height_internal() override;
468 };
469 
471  public:
472  void initialize() override;
473 
474  void display() override;
475 
476  void dump_config() override;
477 
478  void deep_sleep() override {
479  // COMMAND VCOM AND DATA INTERVAL SETTING
480  this->command(0x50);
481  this->data(0x17); // border floating
482 
483  // COMMAND VCM DC SETTING
484  this->command(0x82);
485  // COMMAND PANEL SETTING
486  this->command(0x00);
487 
488  delay(100); // NOLINT
489 
490  // COMMAND POWER SETTING
491  this->command(0x01);
492  this->data(0x00);
493  this->data(0x00);
494  this->data(0x00);
495  this->data(0x00);
496  this->data(0x00);
497  delay(100); // NOLINT
498 
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 POWER OFF
523  this->command(0x02);
524  this->wait_until_idle_();
525  // COMMAND DEEP SLEEP
526  this->command(0x07);
527  this->data(0xA5); // check byte
528  }
529 
530  protected:
531  int get_width_internal() override;
532 
533  int get_height_internal() override;
534 };
535 
537  public:
538  void initialize() override;
539 
540  void display() override;
541 
542  void dump_config() override;
543 
544  void deep_sleep() override {
545  // COMMAND POWER OFF
546  this->command(0x02);
547  this->wait_until_idle_();
548  // COMMAND DEEP SLEEP
549  this->command(0x07); // deep sleep
550  this->data(0xA5); // check byte
551  }
552 
553  protected:
554  int get_width_internal() override;
555 
556  int get_height_internal() override;
557 };
558 
560  public:
561  bool wait_until_idle_();
562 
563  void initialize() override;
564 
565  void display() override;
566 
567  void dump_config() override;
568 
569  void deep_sleep() override {
570  this->command(0x02); // Power off
571  this->wait_until_idle_();
572  this->command(0x07); // Deep sleep
573  this->data(0xA5);
574  }
575 
576  void clear_screen();
577 
578  protected:
579  int get_width_internal() override;
580 
581  int get_height_internal() override;
582 
583  void reset_() {
584  if (this->reset_pin_ != nullptr) {
585  this->reset_pin_->digital_write(true);
586  delay(200); // NOLINT
587  this->reset_pin_->digital_write(false);
588  delay(5);
589  this->reset_pin_->digital_write(true);
590  delay(200); // NOLINT
591  }
592  };
593 
594  void init_display_();
595 };
596 
598  public:
599  void initialize() override;
600 
601  void display() override;
602 
603  void dump_config() override;
604 
605  void deep_sleep() override {
606  // COMMAND POWER OFF
607  this->command(0x02);
608  this->wait_until_idle_();
609  // COMMAND DEEP SLEEP
610  this->command(0x07);
611  this->data(0xA5); // check byte
612  }
613 
614  protected:
615  int get_width_internal() override;
616 
617  int get_height_internal() override;
618 };
619 
621  public:
622  bool wait_until_idle_();
623 
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  uint32_t idle_timeout_() override;
645 };
646 
648  public:
649  bool wait_until_idle_();
650  void initialize() override;
651  void dump_config() override;
652 
653  protected:
654  void reset_() {
655  if (this->reset_pin_ != nullptr) {
656  this->reset_pin_->digital_write(true);
657  delay(200); // NOLINT
658  this->reset_pin_->digital_write(false);
659  delay(2);
660  this->reset_pin_->digital_write(true);
661  delay(20);
662  }
663  };
664 };
665 
667  public:
668  void initialize() override;
669 
670  void display() override;
671 
672  void dump_config() override;
673 
674  void deep_sleep() override {
675  // deep sleep
676  this->command(0x10);
677  this->data(0x01);
678  }
679 
680  protected:
681  int get_width_internal() override;
682 
683  int get_height_internal() override;
684 };
685 
687  public:
688  void initialize() override;
689 
690  void display() override;
691 
692  void dump_config() override;
693 
694  void deep_sleep() override {
695  // COMMAND POWER DOWN
696  this->command(0x10);
697  this->data(0x01);
698  // cannot wait until idle here, the device no longer responds
699  }
700 
701  void set_full_update_every(uint32_t full_update_every);
702 
703  protected:
704  int get_width_internal() override;
705 
706  int get_height_internal() override;
707 
708  uint32_t idle_timeout_() override;
709 
710  uint32_t full_update_every_{30};
711  uint32_t at_update_{0};
712 };
713 
715  public:
716  void display() override;
717 
718  void dump_config() override;
719 
720  void deep_sleep() override {
721  // COMMAND POWER DOWN
722  this->command(0x10);
723  this->data(0x01);
724  // cannot wait until idle here, the device no longer responds
725  }
726 
727  void set_full_update_every(uint32_t full_update_every);
728 
729  void setup() override;
730  void initialize() override;
731 
732  protected:
733  int get_width_internal() override;
734  int get_height_internal() override;
735  uint32_t idle_timeout_() override;
736 
737  void write_buffer_(uint8_t cmd, int top, int bottom);
738  void set_window_(int t, int b);
739  void send_reset_();
740  void partial_update_();
741  void full_update_();
742 
743  uint32_t full_update_every_{30};
744  uint32_t at_update_{0};
745  bool is_busy_{false};
746  void write_lut_(const uint8_t *lut);
747 };
748 } // namespace waveshare_epaper
749 } // 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
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
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