ESPHome  2022.8.0
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  uint32_t get_buffer_length_();
58  uint32_t reset_duration_{200};
59 
60  void start_command_();
61  void end_command_();
62  void start_data_();
63  void end_data_();
64 
65  GPIOPin *reset_pin_{nullptr};
67  GPIOPin *busy_pin_{nullptr};
68  virtual uint32_t idle_timeout_() { return 1000u; } // NOLINT(readability-identifier-naming)
69 };
70 
81 };
82 
84  public:
86 
87  void initialize() override;
88 
89  void dump_config() override;
90 
91  void display() override;
92 
93  void deep_sleep() override {
94  if (this->model_ == WAVESHARE_EPAPER_2_9_IN_V2 || this->model_ == WAVESHARE_EPAPER_1_54_IN_V2) {
95  // COMMAND DEEP SLEEP MODE
96  this->command(0x10);
97  this->data(0x01);
98  } else {
99  // COMMAND DEEP SLEEP MODE
100  this->command(0x10);
101  }
102  this->wait_until_idle_();
103  }
104 
105  void set_full_update_every(uint32_t full_update_every);
106 
107  protected:
108  void write_lut_(const uint8_t *lut, uint8_t size);
109 
110  int get_width_internal() override;
111 
112  int get_height_internal() override;
113 
114  uint32_t full_update_every_{30};
115  uint32_t at_update_{0};
117  uint32_t idle_timeout_() override;
118 };
119 
127 };
128 
130  public:
131  void initialize() override;
132 
133  void display() override;
134 
135  void dump_config() override;
136 
137  void deep_sleep() override {
138  // COMMAND DEEP SLEEP
139  this->command(0x07);
140  this->data(0xA5); // check byte
141  }
142 
143  protected:
144  int get_width_internal() override;
145 
146  int get_height_internal() override;
147 };
148 
150  public:
151  void initialize() override;
152 
153  void display() override;
154 
155  void dump_config() override;
156 
157  void deep_sleep() override {
158  // COMMAND DEEP SLEEP
159  this->command(0x07);
160  this->data(0xA5); // check byte
161  }
162 
163  protected:
164  int get_width_internal() override;
165 
166  int get_height_internal() override;
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 VCOM AND DATA INTERVAL SETTING
179  this->command(0x50);
180  this->data(0x17); // border floating
181 
182  // COMMAND VCM DC SETTING
183  this->command(0x82);
184  // COMMAND PANEL SETTING
185  this->command(0x00);
186 
187  delay(100); // NOLINT
188 
189  // COMMAND POWER SETTING
190  this->command(0x01);
191  this->data(0x00);
192  this->data(0x00);
193  this->data(0x00);
194  this->data(0x00);
195  this->data(0x00);
196  delay(100); // NOLINT
197 
198  // COMMAND POWER OFF
199  this->command(0x02);
200  this->wait_until_idle_();
201  // COMMAND DEEP SLEEP
202  this->command(0x07);
203  this->data(0xA5); // check byte
204  }
205 
206  protected:
207  int get_width_internal() override;
208 
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 VCOM AND DATA INTERVAL SETTING
222  this->command(0x50);
223  this->data(0xF7); // border floating
224 
225  // COMMAND POWER OFF
226  this->command(0x02);
227  this->wait_until_idle_();
228 
229  // COMMAND DEEP SLEEP
230  this->command(0x07);
231  this->data(0xA5); // check code
232  }
233 
234  protected:
235  int get_width_internal() override;
236 
237  int get_height_internal() override;
238 };
239 
241  public:
242  void initialize() override;
243 
244  void display() override;
245 
246  void dump_config() override;
247 
248  void deep_sleep() override {
249  // COMMAND POWER OFF
250  this->command(0x02);
251  this->wait_until_idle_();
252  // COMMAND DEEP SLEEP
253  this->command(0x07);
254  this->data(0xA5); // check byte
255  }
256 
257  protected:
258  int get_width_internal() override;
259 
260  int get_height_internal() override;
261 };
262 
264  public:
265  void initialize() override;
266 
267  void display() override;
268 
269  void dump_config() override;
270 
271  void deep_sleep() override {
272  // COMMAND POWER OFF
273  this->command(0x02);
274  this->wait_until_idle_();
275  // COMMAND DEEP SLEEP
276  this->command(0x07);
277  this->data(0xA5); // check byte
278  }
279 
280  protected:
281  int get_width_internal() override;
282 
283  int get_height_internal() override;
284 };
285 
287  public:
288  void initialize() override;
289 
290  void display() override;
291 
292  void dump_config() override;
293 
294  void deep_sleep() override {
295  // COMMAND POWER OFF
296  this->command(0x02);
297  this->wait_until_idle_();
298  // COMMAND DEEP SLEEP
299  this->command(0x07); // deep sleep
300  this->data(0xA5); // check byte
301  }
302 
303  protected:
304  int get_width_internal() override;
305 
306  int get_height_internal() override;
307 };
308 
310  public:
311  void initialize() override;
312 
313  void display() override;
314 
315  void dump_config() override;
316 
317  void deep_sleep() override {
318  // COMMAND POWER OFF
319  this->command(0x02);
320  this->wait_until_idle_();
321  // COMMAND DEEP SLEEP
322  this->command(0x07);
323  this->data(0xA5); // check byte
324  }
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 
336  void display() override;
337 
338  void dump_config() override;
339 
340  void deep_sleep() override {
341  // COMMAND POWER OFF
342  this->command(0x02);
343  this->wait_until_idle_();
344  // COMMAND DEEP SLEEP
345  this->command(0x07);
346  this->data(0xA5); // check byte
347  }
348 
349  protected:
350  int get_width_internal() override;
351 
352  int get_height_internal() override;
353 };
354 
356  public:
357  bool wait_until_idle_();
358  void initialize() override;
359  void dump_config() override;
360 
361  protected:
362  void reset_() {
363  if (this->reset_pin_ != nullptr) {
364  this->reset_pin_->digital_write(true);
365  delay(200); // NOLINT
366  this->reset_pin_->digital_write(false);
367  delay(2);
368  this->reset_pin_->digital_write(true);
369  delay(20);
370  }
371  };
372 };
373 
375  public:
376  void initialize() override;
377 
378  void display() override;
379 
380  void dump_config() override;
381 
382  void deep_sleep() override {
383  // deep sleep
384  this->command(0x10);
385  this->data(0x01);
386  }
387 
388  protected:
389  int get_width_internal() override;
390 
391  int get_height_internal() override;
392 };
393 
395  public:
396  void initialize() override;
397 
398  void display() override;
399 
400  void dump_config() override;
401 
402  void deep_sleep() override {
403  // COMMAND POWER DOWN
404  this->command(0x10);
405  this->data(0x01);
406  // cannot wait until idle here, the device no longer responds
407  }
408 
409  void set_full_update_every(uint32_t full_update_every);
410 
411  protected:
412  int get_width_internal() override;
413 
414  int get_height_internal() override;
415 
416  uint32_t idle_timeout_() override;
417 
418  uint32_t full_update_every_{30};
419  uint32_t at_update_{0};
420 };
421 
422 } // namespace waveshare_epaper
423 } // namespace esphome
virtual void digital_write(bool value)=0
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:266
virtual void dump_config()
Definition: component.cpp:158
void set_reset_duration(uint32_t reset_duration)
virtual int get_height_internal()=0
display::DisplayType get_display_type() override
Definition: a4988.cpp:4
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:27