6#include <hal/gpio_hal.h>
11static const char *
const TAG =
"inkplate";
14 for (uint32_t i = 0; i < 256; i++) {
15 this->
pin_lut_[i] = ((i & 0b00000011) << 4) | (((i & 0b00001100) >> 2) << 18) | (((i & 0b00010000) >> 4) << 23) |
16 (((i & 0b11100000) >> 5) << 25);
72 if (this->
glut_ !=
nullptr)
74 if (this->
glut2_ !=
nullptr)
79 ESP_LOGE(TAG,
"Could not allocate buffer for display!");
85 if (this->
glut_ ==
nullptr) {
86 ESP_LOGE(TAG,
"Could not allocate glut!");
91 if (this->
glut2_ ==
nullptr) {
92 ESP_LOGE(TAG,
"Could not allocate glut2!");
97 for (uint8_t i = 0; i < GLUT_SIZE; i++) {
98 for (uint32_t j = 0; j < 256; j++) {
100 this->
glut_[i * 256 + j] = ((
z & 0b00000011) << 4) | (((
z & 0b00001100) >> 2) << 18) |
101 (((
z & 0b00010000) >> 4) << 23) | (((
z & 0b11100000) >> 5) << 25);
103 this->
glut2_[i * 256 + j] = ((
z & 0b00000011) << 4) | (((
z & 0b00001100) >> 2) << 18) |
104 (((
z & 0b00010000) >> 4) << 23) | (((
z & 0b11100000) >> 5) << 25);
111 ESP_LOGE(TAG,
"Could not allocate partial buffer for display!");
117 ESP_LOGE(TAG,
"Could not allocate partial buffer 2 for display!");
126 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;
170 this->
buffer_[pos] = (PIXEL_MASK_GLUT[x_sub] & current) | (x_sub ? gs : gs << 4);
177 this->
partial_buffer_[pos] = (~PIXEL_MASK_LUT[x_sub] & current) | (color.
is_on() ? 0 : PIXEL_MASK_LUT[x_sub]);
182 LOG_DISPLAY(
"",
"Inkplate",
this);
185 " Partial Updating: %s\n"
186 " Full Update Every: %d",
189 LOG_PIN(
" CKV Pin: ", this->
ckv_pin_);
190 LOG_PIN(
" CL Pin: ", this->
cl_pin_);
193 LOG_PIN(
" LE Pin: ", this->
le_pin_);
194 LOG_PIN(
" OE Pin: ", this->
oe_pin_);
196 LOG_PIN(
" SPH Pin: ", this->
sph_pin_);
197 LOG_PIN(
" SPV Pin: ", this->
spv_pin_);
210 LOG_UPDATE_INTERVAL(
this);
214 ESP_LOGV(TAG,
"Eink off called");
242 ESP_LOGV(TAG,
"Eink on called");
267 uint32_t timer =
millis();
271 if ((
millis() - timer) >= 250) {
272 ESP_LOGW(TAG,
"Power supply not detected");
287 return data == 0b11111010;
293 ESP_LOGV(TAG,
"Fill called");
294 uint32_t start_time =
millis();
297 uint8_t
fill = ((color.
red * 2126 / 10000) + (color.
green * 7152 / 10000) + (color.
blue * 722 / 10000)) >> 5;
300 uint8_t
fill = color.
is_on() ? 0x00 : 0xFF;
304 ESP_LOGV(TAG,
"Fill finished (%ums)",
millis() - start_time);
308 ESP_LOGV(TAG,
"Display called");
309 uint32_t start_time =
millis();
315 ESP_LOGV(TAG,
"Display finished (partial) (%ums)",
millis() - start_time);
320 ESP_LOGV(TAG,
"Display finished (full) (%ums)",
millis() - start_time);
324 ESP_LOGV(TAG,
"Display1b called");
325 uint32_t start_time =
millis();
330 uint8_t buffer_value;
331 const uint8_t *buffer_ptr;
395 ESP_LOGV(TAG,
"Display1b start loops (%ums)",
millis() - start_time);
397 for (uint8_t k = 0; k < rep; k++) {
401 buffer_value = *(buffer_ptr--);
406 GPIO.out_w1tc = data_mask | clock;
409 buffer_value = *(buffer_ptr--);
412 GPIO.out_w1tc = data_mask | clock;
415 GPIO.out_w1tc = data_mask | clock;
419 GPIO.out_w1ts = clock;
420 GPIO.out_w1tc = data_mask | clock;
426 ESP_LOGV(TAG,
"Display1b first loop x %d (%ums)", 4,
millis() - start_time);
431 buffer_value = *(buffer_ptr--);
436 GPIO.out_w1tc = data_mask | clock;
439 buffer_value = *(buffer_ptr--);
442 GPIO.out_w1tc = data_mask | clock;
445 GPIO.out_w1tc = data_mask | clock;
449 GPIO.out_w1ts = clock;
450 GPIO.out_w1tc = data_mask | clock;
455 ESP_LOGV(TAG,
"Display1b second loop (%ums)",
millis() - start_time);
465 GPIO.out_w1ts = send | clock;
466 GPIO.out_w1tc = data_mask | clock;
468 GPIO.out_w1ts = send | clock;
469 GPIO.out_w1tc = data_mask | clock;
470 GPIO.out_w1ts = send | clock;
471 GPIO.out_w1tc = data_mask | clock;
475 GPIO.out_w1ts = clock;
476 GPIO.out_w1tc = data_mask | clock;
481 ESP_LOGV(TAG,
"Display1b third loop (%ums)",
millis() - start_time);
487 ESP_LOGV(TAG,
"Display1b finished (%ums)",
millis() - start_time);
491 ESP_LOGV(TAG,
"Display3b called");
492 uint32_t start_time =
millis();
565 uint8_t glut_size = 9;
566 for (
int k = 0; k < glut_size; k++) {
571 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
573 data = this->
glut2_[k * 256 + this->buffer_[--pos]];
574 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
575 GPIO.out_w1ts =
data | clock;
576 GPIO.out_w1tc = data_mask | clock;
579 data = this->
glut2_[k * 256 + this->buffer_[--pos]];
580 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
581 GPIO.out_w1ts =
data | clock;
582 GPIO.out_w1tc = data_mask | clock;
583 data = this->
glut2_[k * 256 + this->buffer_[--pos]];
584 data |= this->
glut_[k * 256 + this->buffer_[--pos]];
585 GPIO.out_w1ts =
data | clock;
586 GPIO.out_w1tc = data_mask | clock;
590 GPIO.out_w1ts = clock;
591 GPIO.out_w1tc = data_mask | clock;
600 ESP_LOGV(TAG,
"Display3b finished (%ums)",
millis() - start_time);
604 ESP_LOGV(TAG,
"Partial update called");
605 uint32_t start_time =
millis();
615 uint8_t diffw, diffb;
627 ESP_LOGV(TAG,
"Partial update buffer built after (%ums)",
millis() - start_time);
634 for (
int k = 0; k < rep; k++) {
638 data = *(data_ptr--);
641 data = *(data_ptr--);
643 GPIO.out_w1tc = data_mask | clock;
647 GPIO.out_w1ts = clock;
648 GPIO.out_w1tc = data_mask | clock;
653 ESP_LOGV(TAG,
"Partial update loop k=%d (%ums)", k,
millis() - start_time);
661 ESP_LOGV(TAG,
"Partial update finished (%ums)",
millis() - start_time);
692 GPIO.out_w1ts = d | clock;
706 ESP_LOGV(TAG,
"Clean called");
707 uint32_t start_time =
millis();
716 ESP_LOGV(TAG,
"Clean finished (%ums)",
millis() - start_time);
720 ESP_LOGV(TAG,
"Clean fast called with: (%d, %d)", c, rep);
721 uint32_t start_time =
millis();
735 uint32_t send = ((
data & 0b00000011) << 4) | (((
data & 0b00001100) >> 2) << 18) | (((
data & 0b00010000) >> 4) << 23) |
736 (((
data & 0b11100000) >> 5) << 25);
739 for (
int k = 0; k < rep; k++) {
743 GPIO.out_w1ts = send | clock;
744 GPIO.out_w1tc = clock;
746 GPIO.out_w1ts = clock;
747 GPIO.out_w1tc = clock;
748 GPIO.out_w1ts = clock;
749 GPIO.out_w1tc = clock;
753 GPIO.out_w1ts = send | clock;
754 GPIO.out_w1tc = clock;
759 ESP_LOGV(TAG,
"Clean fast rep loop %d finished (%ums)", k,
millis() - start_time);
761 ESP_LOGV(TAG,
"Clean fast finished (%ums)",
millis() - start_time);
virtual void mark_failed()
Mark this component as failed.
virtual void pin_mode(gpio::Flags flags)=0
virtual void digital_write(bool value)=0
virtual uint8_t get_pin() const =0
An STL allocator that uses SPI or internal RAM.
void deallocate(T *p, size_t n)
bool write_byte(uint8_t a_register, uint8_t data) const
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
size_t get_buffer_length_()
InternalGPIOPin * cl_pin_
void fill(Color color) override
InternalGPIOPin * display_data_0_pin_
uint32_t partial_updates_
void clean_fast_(uint8_t c, uint8_t rep)
void hscan_start_(uint32_t d)
InternalGPIOPin * display_data_7_pin_
InternalGPIOPin * le_pin_
InternalGPIOPin * display_data_4_pin_
GPIOPin * gpio0_enable_pin_
InternalGPIOPin * display_data_1_pin_
void draw_absolute_pixel_internal(int x, int y, Color color) override
uint32_t full_update_every_
uint8_t waveform_[GLUT_COUNT][GLUT_SIZE]
void dump_config() override
int get_width_internal() override
InternalGPIOPin * display_data_6_pin_
bool read_power_status_()
InternalGPIOPin * display_data_3_pin_
InternalGPIOPin * display_data_5_pin_
InternalGPIOPin * display_data_2_pin_
int get_height_internal() override
float get_setup_priority() const override
uint8_t * partial_buffer_2_
void initialize_()
Allocate buffers.
uint8_t * partial_buffer_
@ ERROR_OK
No error found during execution of method.
const float PROCESSOR
For components that use data from sensors like displays.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
bool is_on() ESPHOME_ALWAYS_INLINE