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