ESPHome  2022.5.1
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 
39  protected:
40  void draw_absolute_pixel_internal(int x, int y, Color color) override;
41 
42  bool wait_until_idle_();
43 
44  void setup_pins_();
45 
46  void reset_() {
47  if (this->reset_pin_ != nullptr) {
48  this->reset_pin_->digital_write(false);
49  delay(reset_duration_); // NOLINT
50  this->reset_pin_->digital_write(true);
51  delay(200); // NOLINT
52  }
53  }
54 
55  uint32_t get_buffer_length_();
56  uint32_t reset_duration_{200};
57 
58  void start_command_();
59  void end_command_();
60  void start_data_();
61  void end_data_();
62 
63  GPIOPin *reset_pin_{nullptr};
65  GPIOPin *busy_pin_{nullptr};
66  virtual uint32_t idle_timeout_() { return 1000u; } // NOLINT(readability-identifier-naming)
67 };
68 
79 };
80 
82  public:
84 
85  void initialize() override;
86 
87  void dump_config() override;
88 
89  void display() override;
90 
91  void deep_sleep() override {
92  if (this->model_ == WAVESHARE_EPAPER_2_9_IN_V2 || this->model_ == WAVESHARE_EPAPER_1_54_IN_V2) {
93  // COMMAND DEEP SLEEP MODE
94  this->command(0x10);
95  this->data(0x01);
96  } else {
97  // COMMAND DEEP SLEEP MODE
98  this->command(0x10);
99  }
100  this->wait_until_idle_();
101  }
102 
103  void set_full_update_every(uint32_t full_update_every);
104 
105  protected:
106  void write_lut_(const uint8_t *lut, uint8_t size);
107 
108  int get_width_internal() override;
109 
110  int get_height_internal() override;
111 
112  uint32_t full_update_every_{30};
113  uint32_t at_update_{0};
115  uint32_t idle_timeout_() override;
116 };
117 
125 };
126 
128  public:
129  void initialize() override;
130 
131  void display() override;
132 
133  void dump_config() override;
134 
135  void deep_sleep() override {
136  // COMMAND DEEP SLEEP
137  this->command(0x07);
138  this->data(0xA5); // check byte
139  }
140 
141  protected:
142  int get_width_internal() override;
143 
144  int get_height_internal() override;
145 };
146 
148  public:
149  void initialize() override;
150 
151  void display() override;
152 
153  void dump_config() override;
154 
155  void deep_sleep() override {
156  // COMMAND DEEP SLEEP
157  this->command(0x07);
158  this->data(0xA5); // check byte
159  }
160 
161  protected:
162  int get_width_internal() override;
163 
164  int get_height_internal() override;
165 };
166 
168  public:
169  void initialize() override;
170 
171  void display() override;
172 
173  void dump_config() override;
174 
175  void deep_sleep() override {
176  // COMMAND VCOM AND DATA INTERVAL SETTING
177  this->command(0x50);
178  this->data(0x17); // border floating
179 
180  // COMMAND VCM DC SETTING
181  this->command(0x82);
182  // COMMAND PANEL SETTING
183  this->command(0x00);
184 
185  delay(100); // NOLINT
186 
187  // COMMAND POWER SETTING
188  this->command(0x01);
189  this->data(0x00);
190  this->data(0x00);
191  this->data(0x00);
192  this->data(0x00);
193  this->data(0x00);
194  delay(100); // NOLINT
195 
196  // COMMAND POWER OFF
197  this->command(0x02);
198  this->wait_until_idle_();
199  // COMMAND DEEP SLEEP
200  this->command(0x07);
201  this->data(0xA5); // check byte
202  }
203 
204  protected:
205  int get_width_internal() override;
206 
207  int get_height_internal() override;
208 };
209 
211  public:
212  void initialize() override;
213 
214  void display() override;
215 
216  void dump_config() override;
217 
218  void deep_sleep() override {
219  // COMMAND VCOM AND DATA INTERVAL SETTING
220  this->command(0x50);
221  this->data(0xF7); // border floating
222 
223  // COMMAND POWER OFF
224  this->command(0x02);
225  this->wait_until_idle_();
226 
227  // COMMAND DEEP SLEEP
228  this->command(0x07);
229  this->data(0xA5); // check code
230  }
231 
232  protected:
233  int get_width_internal() override;
234 
235  int get_height_internal() override;
236 };
237 
239  public:
240  void initialize() override;
241 
242  void display() override;
243 
244  void dump_config() override;
245 
246  void deep_sleep() override {
247  // COMMAND POWER OFF
248  this->command(0x02);
249  this->wait_until_idle_();
250  // COMMAND DEEP SLEEP
251  this->command(0x07);
252  this->data(0xA5); // check byte
253  }
254 
255  protected:
256  int get_width_internal() override;
257 
258  int get_height_internal() override;
259 };
260 
262  public:
263  void initialize() override;
264 
265  void display() override;
266 
267  void dump_config() override;
268 
269  void deep_sleep() override {
270  // COMMAND POWER OFF
271  this->command(0x02);
272  this->wait_until_idle_();
273  // COMMAND DEEP SLEEP
274  this->command(0x07);
275  this->data(0xA5); // check byte
276  }
277 
278  protected:
279  int get_width_internal() override;
280 
281  int get_height_internal() override;
282 };
283 
285  public:
286  void initialize() override;
287 
288  void display() override;
289 
290  void dump_config() override;
291 
292  void deep_sleep() override {
293  // COMMAND POWER OFF
294  this->command(0x02);
295  this->wait_until_idle_();
296  // COMMAND DEEP SLEEP
297  this->command(0x07); // deep sleep
298  this->data(0xA5); // check byte
299  }
300 
301  protected:
302  int get_width_internal() override;
303 
304  int get_height_internal() override;
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 POWER OFF
317  this->command(0x02);
318  this->wait_until_idle_();
319  // COMMAND DEEP SLEEP
320  this->command(0x07);
321  this->data(0xA5); // check byte
322  }
323 
324  protected:
325  int get_width_internal() override;
326 
327  int get_height_internal() override;
328 };
329 
331  public:
332  void initialize() override;
333 
334  void display() override;
335 
336  void dump_config() override;
337 
338  void deep_sleep() override {
339  // COMMAND POWER OFF
340  this->command(0x02);
341  this->wait_until_idle_();
342  // COMMAND DEEP SLEEP
343  this->command(0x07);
344  this->data(0xA5); // check byte
345  }
346 
347  protected:
348  int get_width_internal() override;
349 
350  int get_height_internal() override;
351 };
352 
354  public:
355  bool wait_until_idle_();
356  void initialize() override;
357  void dump_config() override;
358 
359  protected:
360  void reset_() {
361  if (this->reset_pin_ != nullptr) {
362  this->reset_pin_->digital_write(true);
363  delay(200); // NOLINT
364  this->reset_pin_->digital_write(false);
365  delay(2);
366  this->reset_pin_->digital_write(true);
367  delay(20);
368  }
369  };
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  // deep sleep
382  this->command(0x10);
383  this->data(0x01);
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 POWER DOWN
402  this->command(0x10);
403  this->data(0x01);
404  // cannot wait until idle here, the device no longer responds
405  }
406 
407  void set_full_update_every(uint32_t full_update_every);
408 
409  protected:
410  int get_width_internal() override;
411 
412  int get_height_internal() override;
413 
414  uint32_t idle_timeout_() override;
415 
416  uint32_t full_update_every_{30};
417  uint32_t at_update_{0};
418 };
419 
420 } // namespace waveshare_epaper
421 } // 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
Definition: a4988.cpp:4
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:27