6 #ifdef USE_ESP32_FRAMEWORK_ARDUINO 8 #include <esp32-hal-gpio.h> 13 static const char *
const TAG =
"inkplate";
16 for (uint32_t i = 0; i < 256; i++) {
17 this->
pin_lut_[i] = ((i & 0b00000011) << 4) | (((i & 0b00001100) >> 2) << 18) | (((i & 0b00010000) >> 4) << 23) |
18 (((i & 0b11100000) >> 5) << 25);
74 if (this->
glut_ !=
nullptr)
76 if (this->
glut2_ !=
nullptr)
81 ESP_LOGE(TAG,
"Could not allocate buffer for display!");
86 uint8_t glut_size = 9;
89 if (this->
glut_ ==
nullptr) {
90 ESP_LOGE(TAG,
"Could not allocate glut!");
95 if (this->
glut2_ ==
nullptr) {
96 ESP_LOGE(TAG,
"Could not allocate glut2!");
103 for (
int i = 0; i < glut_size; i++) {
104 for (uint32_t j = 0; j < 256; j++) {
105 uint8_t z = (waveform3_bit[j & 0x07][i] << 2) | (waveform3_bit[(j >> 4) & 0x07][i]);
106 this->
glut_[i * 256 + j] = ((z & 0b00000011) << 4) | (((z & 0b00001100) >> 2) << 18) |
107 (((z & 0b00010000) >> 4) << 23) | (((z & 0b11100000) >> 5) << 25);
108 z = ((waveform3_bit[j & 0x07][i] << 2) | (waveform3_bit[(j >> 4) & 0x07][i])) << 4;
109 this->
glut2_[i * 256 + j] = ((z & 0b00000011) << 4) | (((z & 0b00001100) >> 2) << 18) |
110 (((z & 0b00010000) >> 4) << 23) | (((z & 0b11100000) >> 5) << 25);
117 ESP_LOGE(TAG,
"Could not allocate partial buffer for display!");
123 ESP_LOGE(TAG,
"Could not allocate partial buffer 2 for display!");
132 memset(this->
buffer_, 0, buffer_size);
163 uint8_t current = this->
buffer_[pos];
169 uint8_t gs = ((color.
red * 2126 / 10000) + (color.
green * 7152 / 10000) + (color.
blue * 722 / 10000)) >> 5;
182 LOG_DISPLAY(
"",
"Inkplate",
this);
183 ESP_LOGCONFIG(TAG,
" Greyscale: %s", YESNO(this->
greyscale_));
187 LOG_PIN(
" CKV Pin: ", this->
ckv_pin_);
188 LOG_PIN(
" CL Pin: ", this->
cl_pin_);
191 LOG_PIN(
" LE Pin: ", this->
le_pin_);
192 LOG_PIN(
" OE Pin: ", this->
oe_pin_);
194 LOG_PIN(
" SPH Pin: ", this->
sph_pin_);
195 LOG_PIN(
" SPV Pin: ", this->
spv_pin_);
208 LOG_UPDATE_INTERVAL(
this);
212 ESP_LOGV(TAG,
"Eink off called");
240 ESP_LOGV(TAG,
"Eink on called");
265 uint32_t timer =
millis();
269 if ((
millis() - timer) >= 250) {
270 ESP_LOGW(TAG,
"Power supply not detected");
285 return data == 0b11111010;
291 ESP_LOGV(TAG,
"Fill called");
292 uint32_t start_time =
millis();
295 uint8_t
fill = ((color.
red * 2126 / 10000) + (color.
green * 7152 / 10000) + (color.
blue * 722 / 10000)) >> 5;
298 uint8_t
fill = color.
is_on() ? 0x00 : 0xFF;
302 ESP_LOGV(TAG,
"Fill finished (%ums)",
millis() - start_time);
306 ESP_LOGV(TAG,
"Display called");
307 uint32_t start_time =
millis();
313 ESP_LOGV(TAG,
"Display finished (partial) (%ums)",
millis() - start_time);
318 ESP_LOGV(TAG,
"Display finished (full) (%ums)",
millis() - start_time);
322 ESP_LOGV(TAG,
"Display1b called");
323 uint32_t start_time =
millis();
328 uint8_t buffer_value;
329 const uint8_t *buffer_ptr;
352 ESP_LOGV(TAG,
"Display1b start loops (%ums)",
millis() - start_time);
356 for (
int k = 0; k < rep; k++) {
360 buffer_value = *(buffer_ptr--);
364 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
365 GPIO.out_w1tc = data_mask | clock;
368 buffer_value = *(buffer_ptr--);
370 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
371 GPIO.out_w1tc = data_mask | clock;
373 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
374 GPIO.out_w1tc = data_mask | clock;
378 GPIO.out_w1ts = clock;
379 GPIO.out_w1tc = data_mask | clock;
385 ESP_LOGV(TAG,
"Display1b first loop x %d (%ums)", 4,
millis() - start_time);
390 buffer_value = *(buffer_ptr--);
394 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
395 GPIO.out_w1tc = data_mask | clock;
398 buffer_value = *(buffer_ptr--);
400 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
401 GPIO.out_w1tc = data_mask | clock;
403 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
404 GPIO.out_w1tc = data_mask | clock;
408 GPIO.out_w1ts = clock;
409 GPIO.out_w1tc = data_mask | clock;
414 ESP_LOGV(TAG,
"Display1b second loop (%ums)",
millis() - start_time);
424 GPIO.out_w1ts = send | clock;
425 GPIO.out_w1tc = data_mask | clock;
427 GPIO.out_w1ts = send | clock;
428 GPIO.out_w1tc = data_mask | clock;
429 GPIO.out_w1ts = send | clock;
430 GPIO.out_w1tc = data_mask | clock;
434 GPIO.out_w1ts = clock;
435 GPIO.out_w1tc = data_mask | clock;
440 ESP_LOGV(TAG,
"Display1b third loop (%ums)",
millis() - start_time);
446 ESP_LOGV(TAG,
"Display1b finished (%ums)",
millis() - start_time);
450 ESP_LOGV(TAG,
"Display3b called");
451 uint32_t start_time =
millis();
477 uint8_t glut_size = 9;
478 for (
int k = 0; k < glut_size; k++) {
483 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
485 data = this->
glut2_[k * 256 + this->buffer_[--pos]];
486 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
487 GPIO.out_w1ts = data | clock;
488 GPIO.out_w1tc = data_mask | clock;
491 data = this->
glut2_[k * 256 + this->buffer_[--pos]];
492 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
493 GPIO.out_w1ts = data | clock;
494 GPIO.out_w1tc = data_mask | clock;
495 data = this->
glut2_[k * 256 + this->buffer_[--pos]];
496 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
497 GPIO.out_w1ts = data | clock;
498 GPIO.out_w1tc = data_mask | clock;
502 GPIO.out_w1ts = clock;
503 GPIO.out_w1tc = data_mask | clock;
512 ESP_LOGV(TAG,
"Display3b finished (%ums)",
millis() - start_time);
516 ESP_LOGV(TAG,
"Partial update called");
517 uint32_t start_time =
millis();
527 uint8_t diffw, diffb;
539 ESP_LOGV(TAG,
"Partial update buffer built after (%ums)",
millis() - start_time);
546 for (
int k = 0; k < rep; k++) {
550 data = *(data_ptr--);
553 data = *(data_ptr--);
554 GPIO.out_w1ts = this->
pin_lut_[data] | clock;
555 GPIO.out_w1tc = data_mask | clock;
559 GPIO.out_w1ts = clock;
560 GPIO.out_w1tc = data_mask | clock;
565 ESP_LOGV(TAG,
"Partial update loop k=%d (%ums)", k,
millis() - start_time);
573 ESP_LOGV(TAG,
"Partial update finished (%ums)",
millis() - start_time);
604 GPIO.out_w1ts = d | clock;
618 ESP_LOGV(TAG,
"Clean called");
619 uint32_t start_time =
millis();
628 ESP_LOGV(TAG,
"Clean finished (%ums)",
millis() - start_time);
632 ESP_LOGV(TAG,
"Clean fast called with: (%d, %d)", c, rep);
633 uint32_t start_time =
millis();
647 uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
648 (((data & 0b11100000) >> 5) << 25);
651 for (
int k = 0; k < rep; k++) {
655 GPIO.out_w1ts = send | clock;
656 GPIO.out_w1tc = clock;
658 GPIO.out_w1ts = clock;
659 GPIO.out_w1tc = clock;
660 GPIO.out_w1ts = clock;
661 GPIO.out_w1tc = clock;
665 GPIO.out_w1ts = send | clock;
666 GPIO.out_w1tc = clock;
671 ESP_LOGV(TAG,
"Clean fast rep loop %d finished (%ums)", k,
millis() - start_time);
673 ESP_LOGV(TAG,
"Clean fast finished (%ums)",
millis() - start_time);
719 #endif // USE_ESP32_FRAMEWORK_ARDUINO virtual void digital_write(bool value)=0
float get_setup_priority() const override
int get_height_internal() override
GPIOPin * gpio0_enable_pin_
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
InternalGPIOPin * display_data_2_pin_
void initialize_()
Allocate buffers.
void draw_absolute_pixel_internal(int x, int y, Color color) override
virtual void pin_mode(gpio::Flags flags)=0
bool read_power_status_()
void deallocate(T *p, size_t n)
InternalGPIOPin * display_data_1_pin_
uint32_t full_update_every_
bool is_on() ESPHOME_ALWAYS_INLINE
uint32_t IRAM_ATTR HOT millis()
void clean_fast_(uint8_t c, uint8_t rep)
virtual uint8_t get_pin() const =0
InternalGPIOPin * display_data_4_pin_
InternalGPIOPin * cl_pin_
InternalGPIOPin * le_pin_
No error found during execution of method.
const float PROCESSOR
For components that use data from sensors like displays.
void fill(Color color) override
InternalGPIOPin * display_data_0_pin_
const uint8_t pixelMaskLUT[8]
void dump_config() override
uint8_t * partial_buffer_2_
int get_width_internal() override
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
virtual void mark_failed()
Mark this component as failed.
InternalGPIOPin * display_data_6_pin_
uint8_t * partial_buffer_
Implementation of SPI Controller mode.
size_t get_buffer_length_()
InternalGPIOPin * display_data_7_pin_
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
const uint8_t pixelMaskGLUT[2]
InternalGPIOPin * display_data_3_pin_
void hscan_start_(uint32_t d)
const uint8_t waveform3BitAll[6][8][9]
void IRAM_ATTR HOT delay(uint32_t ms)
InternalGPIOPin * display_data_5_pin_
uint32_t partial_updates_
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)