ESPHome  2024.11.1
inkplate.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
7 
8 #ifdef USE_ESP32_FRAMEWORK_ARDUINO
9 
10 namespace esphome {
11 namespace inkplate6 {
12 
13 enum InkplateModel : uint8_t {
20 };
21 
23  public:
24  const uint8_t LUT2[16] = {0xAA, 0xA9, 0xA6, 0xA5, 0x9A, 0x99, 0x96, 0x95,
25  0x6A, 0x69, 0x66, 0x65, 0x5A, 0x59, 0x56, 0x55};
26  const uint8_t LUTW[16] = {0xFF, 0xFE, 0xFB, 0xFA, 0xEF, 0xEE, 0xEB, 0xEA,
27  0xBF, 0xBE, 0xBB, 0xBA, 0xAF, 0xAE, 0xAB, 0xAA};
28  const uint8_t LUTB[16] = {0xFF, 0xFD, 0xF7, 0xF5, 0xDF, 0xDD, 0xD7, 0xD5,
29  0x7F, 0x7D, 0x77, 0x75, 0x5F, 0x5D, 0x57, 0x55};
30 
31  const uint8_t pixelMaskLUT[8] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};
32  const uint8_t pixelMaskGLUT[2] = {0x0F, 0xF0};
33 
34  const uint8_t waveform3BitAll[6][8][9] = {// INKPLATE_6
35  {{0, 1, 1, 0, 0, 1, 1, 0, 0},
36  {0, 1, 2, 1, 1, 2, 1, 0, 0},
37  {1, 1, 1, 2, 2, 1, 0, 0, 0},
38  {0, 0, 0, 1, 1, 1, 2, 0, 0},
39  {2, 1, 1, 1, 2, 1, 2, 0, 0},
40  {2, 2, 1, 1, 2, 1, 2, 0, 0},
41  {1, 1, 1, 2, 1, 2, 2, 0, 0},
42  {0, 0, 0, 0, 0, 0, 2, 0, 0}},
43  // INKPLATE_10
44  {{0, 0, 0, 0, 0, 0, 0, 1, 0},
45  {0, 0, 0, 2, 2, 2, 1, 1, 0},
46  {0, 0, 2, 1, 1, 2, 2, 1, 0},
47  {0, 1, 2, 2, 1, 2, 2, 1, 0},
48  {0, 0, 2, 1, 2, 2, 2, 1, 0},
49  {0, 2, 2, 2, 2, 2, 2, 1, 0},
50  {0, 0, 0, 0, 0, 2, 1, 2, 0},
51  {0, 0, 0, 2, 2, 2, 2, 2, 0}},
52  // INKPLATE_6_PLUS
53  {{0, 0, 0, 0, 0, 2, 1, 1, 0},
54  {0, 0, 2, 1, 1, 1, 2, 1, 0},
55  {0, 2, 2, 2, 1, 1, 2, 1, 0},
56  {0, 0, 2, 2, 2, 1, 2, 1, 0},
57  {0, 0, 0, 0, 2, 2, 2, 1, 0},
58  {0, 0, 2, 1, 2, 1, 1, 2, 0},
59  {0, 0, 2, 2, 2, 1, 1, 2, 0},
60  {0, 0, 0, 0, 2, 2, 2, 2, 0}},
61  // INKPLATE_6_V2
62  {{1, 0, 1, 0, 1, 1, 1, 0, 0},
63  {0, 0, 0, 1, 1, 1, 1, 0, 0},
64  {1, 1, 1, 1, 0, 2, 1, 0, 0},
65  {1, 1, 1, 2, 2, 1, 1, 0, 0},
66  {1, 1, 1, 1, 2, 2, 1, 0, 0},
67  {0, 1, 1, 1, 2, 2, 1, 0, 0},
68  {0, 0, 0, 0, 1, 1, 2, 0, 0},
69  {0, 0, 0, 0, 0, 1, 2, 0, 0}},
70  // INKPLATE_5
71  {{0, 0, 1, 1, 0, 1, 1, 1, 0},
72  {0, 1, 1, 1, 1, 2, 0, 1, 0},
73  {1, 2, 2, 0, 2, 1, 1, 1, 0},
74  {1, 1, 1, 2, 0, 1, 1, 2, 0},
75  {0, 1, 1, 1, 2, 0, 1, 2, 0},
76  {0, 0, 0, 1, 1, 2, 1, 2, 0},
77  {1, 1, 1, 2, 0, 2, 1, 2, 0},
78  {0, 0, 0, 0, 0, 0, 0, 0, 0}},
79  // INKPLATE_5_V2
80  {{0, 0, 1, 1, 2, 1, 1, 1, 0},
81  {1, 1, 2, 2, 1, 2, 1, 1, 0},
82  {0, 1, 2, 2, 1, 1, 2, 1, 0},
83  {0, 0, 1, 1, 1, 1, 1, 2, 0},
84  {1, 2, 1, 2, 1, 1, 1, 2, 0},
85  {0, 1, 1, 1, 2, 0, 1, 2, 0},
86  {1, 1, 1, 2, 2, 2, 1, 2, 0},
87  {0, 0, 0, 0, 0, 0, 0, 0, 0}}};
88 
89  void set_greyscale(bool greyscale) {
90  this->greyscale_ = greyscale;
91  this->block_partial_ = true;
92  if (this->is_ready())
93  this->initialize_();
94  }
95  void set_partial_updating(bool partial_updating) { this->partial_updating_ = partial_updating; }
96  void set_full_update_every(uint32_t full_update_every) { this->full_update_every_ = full_update_every; }
97 
98  void set_model(InkplateModel model) { this->model_ = model; }
99 
108 
109  void set_ckv_pin(GPIOPin *ckv) { this->ckv_pin_ = ckv; }
110  void set_cl_pin(InternalGPIOPin *cl) { this->cl_pin_ = cl; }
111  void set_gpio0_enable_pin(GPIOPin *gpio0_enable) { this->gpio0_enable_pin_ = gpio0_enable; }
112  void set_gmod_pin(GPIOPin *gmod) { this->gmod_pin_ = gmod; }
113  void set_le_pin(InternalGPIOPin *le) { this->le_pin_ = le; }
114  void set_oe_pin(GPIOPin *oe) { this->oe_pin_ = oe; }
115  void set_powerup_pin(GPIOPin *powerup) { this->powerup_pin_ = powerup; }
116  void set_sph_pin(GPIOPin *sph) { this->sph_pin_ = sph; }
117  void set_spv_pin(GPIOPin *spv) { this->spv_pin_ = spv; }
118  void set_vcom_pin(GPIOPin *vcom) { this->vcom_pin_ = vcom; }
119  void set_wakeup_pin(GPIOPin *wakeup) { this->wakeup_pin_ = wakeup; }
120 
121  float get_setup_priority() const override;
122 
123  void dump_config() override;
124 
125  void display();
126  void clean();
127  void fill(Color color) override;
128 
129  void update() override;
130 
131  void setup() override;
132 
133  uint8_t get_panel_state() { return this->panel_on_; }
134  bool get_greyscale() { return this->greyscale_; }
135  bool get_partial_updating() { return this->partial_updating_; }
136  uint8_t get_temperature() { return this->temperature_; }
137 
138  void block_partial() { this->block_partial_ = true; }
139 
142  }
143 
144  protected:
145  void draw_absolute_pixel_internal(int x, int y, Color color) override;
146  void display1b_();
147  void display3b_();
148  void initialize_();
149  bool partial_update_();
150  void clean_fast_(uint8_t c, uint8_t rep);
151 
152  void hscan_start_(uint32_t d);
153  void vscan_end_();
154  void vscan_start_();
155 
156  void eink_off_();
157  void eink_on_();
158  bool read_power_status_();
159 
160  void setup_pins_();
161  void pins_z_state_();
162  void pins_as_outputs_();
163 
164  int get_width_internal() override {
165  if (this->model_ == INKPLATE_6 || this->model_ == INKPLATE_6_V2) {
166  return 800;
167  } else if (this->model_ == INKPLATE_10) {
168  return 1200;
169  } else if (this->model_ == INKPLATE_5) {
170  return 960;
171  } else if (this->model_ == INKPLATE_5_V2) {
172  return 1280;
173  } else if (this->model_ == INKPLATE_6_PLUS) {
174  return 1024;
175  }
176  return 0;
177  }
178 
179  int get_height_internal() override {
180  if (this->model_ == INKPLATE_6 || this->model_ == INKPLATE_6_V2) {
181  return 600;
182  } else if (this->model_ == INKPLATE_5) {
183  return 540;
184  } else if (this->model_ == INKPLATE_5_V2) {
185  return 720;
186  } else if (this->model_ == INKPLATE_10) {
187  return 825;
188  } else if (this->model_ == INKPLATE_6_PLUS) {
189  return 758;
190  }
191  return 0;
192  }
193 
194  size_t get_buffer_length_();
195 
197  int data = 0;
198  data |= (1 << this->display_data_0_pin_->get_pin());
199  data |= (1 << this->display_data_1_pin_->get_pin());
200  data |= (1 << this->display_data_2_pin_->get_pin());
201  data |= (1 << this->display_data_3_pin_->get_pin());
202  data |= (1 << this->display_data_4_pin_->get_pin());
203  data |= (1 << this->display_data_5_pin_->get_pin());
204  data |= (1 << this->display_data_6_pin_->get_pin());
205  data |= (1 << this->display_data_7_pin_->get_pin());
206  return data;
207  }
208 
209  bool panel_on_{false};
210  uint8_t temperature_;
211 
212  uint8_t *partial_buffer_{nullptr};
213  uint8_t *partial_buffer_2_{nullptr};
214 
215  uint32_t *glut_{nullptr};
216  uint32_t *glut2_{nullptr};
217  uint32_t pin_lut_[256];
218 
220  uint32_t partial_updates_{0};
221 
222  bool block_partial_{true};
225 
227 
236 
248 };
249 
250 } // namespace inkplate6
251 } // namespace esphome
252 
253 #endif // USE_ESP32_FRAMEWORK_ARDUINO
float get_setup_priority() const override
Definition: inkplate.cpp:135
void set_greyscale(bool greyscale)
Definition: inkplate.h:89
const uint8_t LUTW[16]
Definition: inkplate.h:26
int get_height_internal() override
Definition: inkplate.h:179
void set_cl_pin(InternalGPIOPin *cl)
Definition: inkplate.h:110
InternalGPIOPin * display_data_2_pin_
Definition: inkplate.h:230
void set_partial_updating(bool partial_updating)
Definition: inkplate.h:95
uint16_t x
Definition: tt21100.cpp:17
void initialize_()
Allocate buffers.
Definition: inkplate.cpp:61
void set_le_pin(InternalGPIOPin *le)
Definition: inkplate.h:113
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition: inkplate.cpp:155
void set_powerup_pin(GPIOPin *powerup)
Definition: inkplate.h:115
void set_gpio0_enable_pin(GPIOPin *gpio0_enable)
Definition: inkplate.h:111
void set_model(InkplateModel model)
Definition: inkplate.h:98
InternalGPIOPin * display_data_1_pin_
Definition: inkplate.h:229
void set_display_data_4_pin(InternalGPIOPin *data)
Definition: inkplate.h:104
void set_gmod_pin(GPIOPin *gmod)
Definition: inkplate.h:112
uint16_t y
Definition: tt21100.cpp:18
bool is_ready() const
Definition: component.cpp:144
void clean_fast_(uint8_t c, uint8_t rep)
Definition: inkplate.cpp:631
virtual uint8_t get_pin() const =0
InternalGPIOPin * display_data_4_pin_
Definition: inkplate.h:232
void set_oe_pin(GPIOPin *oe)
Definition: inkplate.h:114
InternalGPIOPin * cl_pin_
Definition: inkplate.h:238
void set_spv_pin(GPIOPin *spv)
Definition: inkplate.h:117
void set_vcom_pin(GPIOPin *vcom)
Definition: inkplate.h:118
void set_display_data_1_pin(InternalGPIOPin *data)
Definition: inkplate.h:101
InternalGPIOPin * le_pin_
Definition: inkplate.h:241
void set_display_data_2_pin(InternalGPIOPin *data)
Definition: inkplate.h:102
void set_wakeup_pin(GPIOPin *wakeup)
Definition: inkplate.h:119
const uint8_t LUTB[16]
Definition: inkplate.h:28
void set_display_data_3_pin(InternalGPIOPin *data)
Definition: inkplate.h:103
void fill(Color color) override
Definition: inkplate.cpp:290
InternalGPIOPin * display_data_0_pin_
Definition: inkplate.h:228
const uint8_t pixelMaskLUT[8]
Definition: inkplate.h:31
void dump_config() override
Definition: inkplate.cpp:181
display::DisplayType get_display_type() override
Definition: inkplate.h:140
void set_display_data_0_pin(InternalGPIOPin *data)
Definition: inkplate.h:100
int get_width_internal() override
Definition: inkplate.h:164
void set_ckv_pin(GPIOPin *ckv)
Definition: inkplate.h:109
void set_display_data_7_pin(InternalGPIOPin *data)
Definition: inkplate.h:107
void set_display_data_6_pin(InternalGPIOPin *data)
Definition: inkplate.h:106
InternalGPIOPin * display_data_6_pin_
Definition: inkplate.h:234
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
InternalGPIOPin * display_data_7_pin_
Definition: inkplate.h:235
void set_display_data_5_pin(InternalGPIOPin *data)
Definition: inkplate.h:105
const uint8_t pixelMaskGLUT[2]
Definition: inkplate.h:32
InternalGPIOPin * display_data_3_pin_
Definition: inkplate.h:231
void hscan_start_(uint32_t d)
Definition: inkplate.cpp:601
const uint8_t waveform3BitAll[6][8][9]
Definition: inkplate.h:34
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
void set_sph_pin(GPIOPin *sph)
Definition: inkplate.h:116
void set_full_update_every(uint32_t full_update_every)
Definition: inkplate.h:96
const uint8_t LUT2[16]
Definition: inkplate.h:24
InternalGPIOPin * display_data_5_pin_
Definition: inkplate.h:233