ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
it8951.cpp
Go to the documentation of this file.
1#include "it8951.h"
2
3#include <algorithm>
4#include <cstring>
5
7#include "esphome/core/hal.h"
9#include "esphome/core/log.h"
10
11namespace esphome::it8951 {
12
13ESPHOME_LOG_TAG(TAG, "it8951");
14
15// Soft cap for time spent in a single XFER_ROWS Op so we yield back to the
16// loop within one tick budget.
17static constexpr uint32_t MAX_TRANSFER_TIME_MS = 20;
18
19// --- Loop / scheduling -------------------------------------------------------
20
21void IT8951Display::enqueue_(OpType type, uint16_t a, uint16_t b) {
22 if (!this->queue_.push(Op{type, a, b})) {
23 ESP_LOGE(TAG, "Op queue overflow (cap=%u); dropping op type=%u", static_cast<unsigned>(OP_QUEUE_SIZE),
24 static_cast<unsigned>(type));
25 }
26}
27
28void IT8951Display::prepend_(OpType type, uint16_t a, uint16_t b) {
29 if (!this->queue_.push_front(Op{type, a, b})) {
30 ESP_LOGE(TAG, "Op queue overflow (cap=%u); dropping op type=%u", static_cast<unsigned>(OP_QUEUE_SIZE),
31 static_cast<unsigned>(type));
32 }
33}
34
36 // IT8951 Hardware Ready (HW_RDY): HIGH = ready, LOW = busy.
37 return !this->busy_pin_->digital_read();
38}
39
41
43 // Power is cut after teardown, so finish a queued update and let the panel
44 // refresh end first; a refresh cut short leaves a faded image.
45 if (this->is_failed() || (!this->initialised_ && !this->update_pending_))
46 return true;
47 if (this->phase_ == Phase::IDLE && !this->update_pending_) {
49 if (!this->asleep_) {
51 this->enqueue_(OpType::CMD, TCON_SLEEP);
52 this->asleep_ = true;
53 }
54 }
55 this->run_next_op_();
56 return this->phase_ == Phase::SHUTDOWN_DONE;
57}
58
60 const uint32_t now = millis();
61 if (static_cast<int32_t>(now - this->delay_until_) < 0)
62 return;
63
64 // Nothing queued — either the current phase has more work to enqueue, or
65 // we're done.
66 if (this->queue_.empty()) {
67 if (this->phase_ == Phase::IDLE) {
68 this->disable_loop();
69 return;
70 }
71 this->advance_phase_();
72 if (this->queue_.empty())
73 return;
74 }
75
76 // Gate SPI ops on HW_RDY. GPIO/DELAY ops run unconditionally — they're how
77 // we get the controller out of a stuck-busy state in the first place
78 // (e.g. during reset, HW_RDY is undefined/low until ROM boot completes).
79 Op queued_op = this->queue_.front();
80 const bool needs_hardware_ready = queued_op.type != OpType::GPIO_RESET_LOW &&
81 queued_op.type != OpType::GPIO_RESET_HIGH && queued_op.type != OpType::DELAY_MS;
82 if (needs_hardware_ready && this->is_busy_()) {
83 // Signed elapsed: any pending DELAY_MS or scheduled work in the near
84 // future shows up as <= 0 elapsed and won't trigger a false timeout.
85 const int32_t elapsed = static_cast<int32_t>(now - this->phase_started_at_);
86 ESP_LOGV(TAG, "HW_RDY is LOW (busy) in phase %u, elapsed=%" PRId32 "ms", static_cast<unsigned>(this->phase_),
87 elapsed);
88 if (elapsed > static_cast<int32_t>(BUSY_TIMEOUT_MS)) {
89 ESP_LOGW(TAG, "Busy timeout (%" PRIu32 "ms) in phase %u, recovering", elapsed,
90 static_cast<unsigned>(this->phase_));
91 this->recover_();
92 }
93 return;
94 }
95
96 this->queue_.pop();
97 this->process_op_(queued_op);
98}
99
101 ESP_LOGV(TAG, "Processing op type=%u a=0x%04X b=0x%04X", static_cast<unsigned>(op.type), op.a, op.b);
102 switch (op.type) {
103 case OpType::CMD:
104 this->spi_cmd_(op.a);
105 break;
106 case OpType::WRITE_W:
107 this->spi_write_word_(op.a);
108 break;
110 this->spi_write_reg_(op.a, op.b);
111 break;
113 this->spi_read_dev_info_();
114 break;
116 this->read_result_ = this->spi_read_word_();
117 break;
119 this->op_check_lut_idle_();
120 break;
121 case OpType::SET_1BPP:
122 this->op_set_1bpp_();
123 break;
125 this->op_xfer_lisar_();
126 break;
128 this->spi_cmd_(TCON_LD_IMG_AREA);
129 break;
131 this->op_xfer_area_args_();
132 break;
134 // Stream rows into the single open LD_IMG_AREA load. The load stays open
135 // across loop iterations (CS toggles between bursts, matching the
136 // reference driver), so a partial slice just re-queues another XFER_ROWS
137 // pass to resume; only when all rows are sent do we close it with one
138 // LD_IMG_END. This avoids an LD_IMG_END / LD_IMG_AREA round-trip per slice.
139 if (this->op_xfer_rows_()) {
141 } else {
143 }
144 break;
146 this->op_xfer_area_end_();
147 break;
149 // Some panel firmwares (notably Seeed reTerminal E1003) silently drop
150 // I80_CMD_DPY_BUF_AREA (0x0037) — the LUT engine never starts and the
151 // host eventually times out after ~12s. Fall back to the basic
152 // I80_CMD_DPY_AREA (0x0034) for those panels; the buffer address is
153 // already programmed via LISAR during the transfer phase.
154 this->spi_cmd_(this->use_legacy_dpy_area_ ? I80_CMD_DPY_AREA : I80_CMD_DPY_BUF_AREA);
155 break;
157 this->op_dpy_buf_args_();
158 break;
160 if (this->reset_pin_ != nullptr)
161 this->reset_pin_->digital_write(false);
162 break;
164 if (this->reset_pin_ != nullptr)
165 this->reset_pin_->digital_write(true);
166 break;
167 case OpType::DELAY_MS:
168 this->delay_until_ = millis() + op.a;
169 break;
170 }
171}
172
174 ESP_LOGV(TAG, "Phase %u -> %u", static_cast<unsigned>(this->phase_), static_cast<unsigned>(next));
175 // Run the loop continuously for the whole active sequence, returning to normal
176 // throttling only at IDLE. Each queued op is processed one per loop iteration,
177 // so at the default ~16ms loop interval the dozens of small ops in the refresh
178 // and restore phases (register polls, 1bpp enable/restore, DPY) would dominate
179 // a partial update's latency. The LUT-idle polls are DELAY_MS-paced, so this
180 // doesn't hammer SPI — it only spends a little extra CPU during the (short,
181 // infrequent) update instead of sleeping between ops.
183 this->phase_ = next;
184 this->phase_started_at_ = millis();
185}
186
188 switch (this->phase_) {
189 case Phase::IDLE:
190 if (this->initialised_ && this->update_pending_) {
191 this->update_pending_ = false;
193 this->update_started_at_ = millis();
195 this->advance_phase_();
196 } else {
197 this->disable_loop();
198 }
199 break;
200
204 break;
205
207 if (this->dev_info_.panel_width == 0 || this->dev_info_.panel_width > 2048 || this->dev_info_.panel_height == 0 ||
208 this->dev_info_.panel_height > 2048 || this->dev_info_.panel_width == 0xFFFF ||
209 this->dev_info_.panel_height == 0xFFFF) {
210 if (++this->dev_info_attempts_ < 5) {
211 ESP_LOGW(TAG, "DevInfo attempt %u returned invalid data (W=%u H=%u), retrying...", this->dev_info_attempts_,
212 this->dev_info_.panel_width, this->dev_info_.panel_height);
213 // Give the controller more time, then re-read.
214 this->enqueue_(OpType::DELAY_MS, 100);
216 return;
217 }
218 ESP_LOGE(TAG, "DevInfo invalid after %u attempts (W=%u H=%u)", this->dev_info_attempts_,
219 this->dev_info_.panel_width, this->dev_info_.panel_height);
220 this->mark_failed(LOG_STR("Failed to read IT8951 device info"));
221 this->set_phase_(Phase::IDLE);
222 return;
223 }
224
225 if (this->dev_info_.panel_width != this->width_ || this->dev_info_.panel_height != this->height_) {
226 ESP_LOGE(TAG, "Panel dimension mismatch: configured=%ux%u, DevInfo=%ux%u. Check model/dimensions settings.",
227 this->width_, this->height_, this->dev_info_.panel_width, this->dev_info_.panel_height);
228 this->mark_failed(LOG_STR("IT8951 panel dimensions do not match DevInfo"));
229 this->set_phase_(Phase::IDLE);
230 return;
231 }
232
233 this->dev_info_attempts_ = 0;
234 this->row_width_ = this->compute_row_width_();
235 this->buffer_length_ = static_cast<size_t>(this->row_width_) * static_cast<size_t>(this->height_);
238 ESP_LOGI(TAG, "DevInfo: %ux%u, ImgBuf 0x%04X%04X", this->width_, this->height_, this->img_buf_addr_h_,
239 this->img_buf_addr_l_);
241 this->enqueue_init_vcom_();
242 break;
243
244 case Phase::INIT_VCOM:
246 if (this->force_temperature_set_) {
247 this->enqueue_init_temp_();
248 } else {
249 this->advance_phase_();
250 }
251 break;
252
253 case Phase::INIT_TEMP:
255 this->advance_phase_();
256 break;
257
258 case Phase::INIT_DONE:
259 if (this->configured_data_rate_ != 0 && this->configured_data_rate_ != this->data_rate_) {
260 this->spi_teardown();
262 this->spi_setup();
263 }
264 this->initialised_ = true;
265 this->recovery_attempts_ = 0;
266 ESP_LOGCONFIG(TAG, "IT8951 setup complete");
267 this->set_phase_(Phase::IDLE);
268 this->advance_phase_();
269 break;
270
272 this->do_update_();
274 if (!this->prepare_update_region_(mode)) {
275 ESP_LOGD(TAG, "Nothing to update");
276 this->set_phase_(Phase::IDLE);
277 this->advance_phase_();
278 return;
279 }
280 this->active_mode_ = mode;
283 break;
284 }
285
289 break;
290
292 // Fire-and-forget: don't block here waiting for the refresh to complete.
293 // The next update's pre-display LUT-idle poll (and the HW_RDY-gated
294 // TCON_SLEEP) wait as needed, so the refresh time stays off this update's
295 // critical path. The 1bpp display mode is left enabled rather than
296 // restored after every update: on a monochrome display every update
297 // (DU partials and the periodic GC16 cleans) runs in 1bpp mode, so the
298 // bit never needs clearing — and clearing it required a full
299 // refresh-length LUT-idle wait.
301 this->enqueue_update_sleep_();
302 break;
303
305 ESP_LOGV(TAG, "Update took %" PRIu32 "ms (mode=%u area=%ux%u@%u,%u)", millis() - this->update_started_at_,
306 static_cast<unsigned>(this->active_mode_), this->area_w_, this->area_h_, this->area_x_, this->area_y_);
307 this->set_phase_(Phase::IDLE);
308 this->advance_phase_();
309 break;
310
313 break;
314
316 this->disable_loop();
317 break;
318 }
319}
320
321// --- Setup -------------------------------------------------------------------
322
324 ESP_LOGCONFIG(TAG, "Setting up IT8951...");
325 this->configured_data_rate_ = this->data_rate_;
326 this->data_rate_ = SPI_PROBE_FREQUENCY;
327 this->spi_setup();
328
329 // Power on the panel before reset and the init handshake.
330 for (auto *pin : this->enable_pins_) {
331 setup_output_pin(pin, true);
332 }
333
334 setup_output_pin(this->reset_pin_, true);
335 if (this->busy_pin_ != nullptr) {
336 this->busy_pin_->setup();
337 }
338
340 this->reset_dirty_region_();
341
342 // Allocate the framebuffer now: its size is fixed by the configured pixel
343 // format and dimensions, so there's no need to defer to the async controller
344 // init. LVGL (and other writers) can push pixels via draw_pixels_at as soon
345 // as the component is set up — before init completes — and without a buffer
346 // those writes would dereference a null pointer and crash.
347 this->row_width_ = this->compute_row_width_();
348 this->buffer_length_ = static_cast<size_t>(this->row_width_) * static_cast<size_t>(this->height_);
349 RAMAllocator<uint8_t> allocator{};
350 this->buffer_ = allocator.allocate(this->buffer_length_);
351 if (!this->setup_check(this->buffer_ != nullptr, LOG_STR("Failed to allocate IT8951 framebuffer")))
352 return;
353 // The allocator does not zero memory; start blank (white) so undrawn regions
354 // (e.g. with auto_clear disabled) don't show garbage on the first update.
355 this->fill(Color::WHITE);
356
357 // Kick off async init via the queue. Reset pulse + boot delay + wake +
358 // packed-write enable; everything blocking lives as DELAY_MS Ops gated by
359 // the loop scheduler.
361 this->enqueue_init_reset_();
362 this->enable_loop();
363}
364
366 for (auto *pin : this->enable_pins_) {
367 pin->digital_write(false);
368 }
369}
370
371// --- Init op enqueuers -------------------------------------------------------
372
374 // A reset (including recovery) re-runs SYS_RUN below, so the controller is
375 // awake once this sequence completes.
376 this->asleep_ = false;
377 // Reset pulse: high -> low (reset_duration) -> high -> wait for ROM boot.
380 this->enqueue_(OpType::DELAY_MS, static_cast<uint16_t>(this->reset_duration_));
382 // SPI ROM boot. HW_RDY gating in loop() handles the actual wait, but a small
383 // floor avoids hammering SPI before HW_RDY has settled high. 300ms matches
384 // what most IT8951 reference drivers use for safety.
385 this->enqueue_(OpType::DELAY_MS, 300);
386 this->enqueue_(OpType::CMD, TCON_SYS_RUN);
387 this->enqueue_(OpType::DELAY_MS, 10); // clocks settle after SYS_RUN
388 this->enqueue_(OpType::CMD, TCON_REG_WR); // packed write mode
389 this->enqueue_(OpType::WRITE_REG, I80CPCR, 0x0001);
390}
391
393 // CMD triggers the controller to prepare DevInfo. HW_RDY drops while it works.
394 // The loop-level HW_RDY gate non-blockingly waits before dispatching READ_DEV_INFO.
395 this->enqueue_(OpType::CMD, I80_CMD_GET_DEV_INFO);
397}
398
400 // Always write configured VCOM. The IT8951 stores it in OTP-backed RAM;
401 // rewriting the same value is harmless. The VCOM SET selector is
402 // panel-specific (see I80_CMD_VCOM_WRITE / I80_CMD_VCOM_WRITE_ALT in
403 // it8951_defs.h) and is supplied via the model preset.
404 this->enqueue_(OpType::CMD, I80_CMD_VCOM);
406 this->enqueue_(OpType::WRITE_W, this->vcom_);
407}
408
410 // Force panel temperature (in degrees C) so the controller selects the
411 // correct waveform LUT. Some panels (e.g. Seeed reTerminal E1003) ship
412 // with auto-temperature disabled and rely on the host to declare the
413 // operating temperature; without this, grayscale waveforms run against
414 // a mismatched LUT and pixels do not visibly change even though the LUT
415 // engine completes a full cycle.
416 this->enqueue_(OpType::CMD, I80_CMD_FORCE_TEMP);
417 this->enqueue_(OpType::WRITE_W, I80_CMD_FORCE_TEMP_WRITE);
418 this->enqueue_(OpType::WRITE_W, static_cast<uint16_t>(this->force_temperature_));
419}
420
421// --- Update op enqueuers -----------------------------------------------------
422
424 // If the controller was put to sleep after the previous update, wake it
425 // before touching the display engine. TCON_SLEEP gates off all clocks; a
426 // register read (e.g. the LUTAFSR poll in UPDATE_REFRESH) returns a frozen
427 // value while asleep, so without this the next update stalls forever in
428 // op_check_lut_idle_(). SRAM/registers (packed-write mode, VCOM, LUT) are
429 // retained across sleep, so SYS_RUN + a short settle is all that's needed.
430 if (this->asleep_) {
431 this->enqueue_(OpType::CMD, TCON_SYS_RUN);
432 this->enqueue_(OpType::DELAY_MS, 10); // clocks settle after SYS_RUN
433 this->asleep_ = false;
434 }
435 this->transfer_row_ = 0;
436 // Open a single LD_IMG_AREA load for the whole region. XFER_ROWS streams into
437 // it across as many time-sliced passes as needed and emits the one matching
438 // LD_IMG_END when the last row is sent (see the XFER_ROWS handler).
443}
444
446 ESP_LOGV(TAG, "Enqueueing refresh ops: grayscale=%u", this->grayscale_);
448 if (!this->grayscale_) {
449 // Read UP1SR+2: CMD(REG_RD) → WRITE_W(UP1SR+2) → READ_WORD → SET_1BPP
450 this->enqueue_(OpType::CMD, TCON_REG_RD);
451 this->enqueue_(OpType::WRITE_W, static_cast<uint16_t>(UP1SR + 2));
454 }
457}
458
460 if (this->sleep_when_done_) {
461 // The panel supply may be cut once the controller is asleep, so let the refresh end first.
463 this->enqueue_(OpType::CMD, TCON_SLEEP);
464 // Remember that the controller is now asleep so the next update wakes it
465 // (see enqueue_update_transfer_) before polling any register.
466 this->asleep_ = true;
467 }
468}
469
471 // Read LUTAFSR; CHECK_LUT_IDLE repeats the read until the LUT engine is idle
472 this->enqueue_(OpType::CMD, TCON_REG_RD);
473 this->enqueue_(OpType::WRITE_W, LUTAFSR);
476}
477
478// --- SPI primitives ----------------------------------------------------------
479//
480// IT8951 SPI protocol: no DC pin. 16-bit preamble word identifies whether
481// the transaction is command (0x6000), write-data (0x0000), or read-data
482// (0x1000).
483//
484// All ops are fully non-blocking at the loop level. The loop-level HW_RDY gate
485// guarantees the controller is ready before any op is dispatched.
486//
487// Within a single CS-asserted transaction, the IT8951 requires HW_RDY to be
488// checked after the preamble word before sending the first data word. This
489// is a hardware protocol requirement — the controller needs a few clock
490// cycles to latch the preamble and configure its internal bus direction.
491// In practice this completes in <1µs for write ops; we use a short spin
492// (max ~50µs) that never triggers under normal operation.
493
494static constexpr uint32_t INTRA_CS_READY_TIMEOUT_US = 50;
495
496static inline void wait_for_hardware_ready(GPIOPin *busy_pin) {
497 if (busy_pin == nullptr)
498 return;
499 uint32_t waited = 0;
500 while (!busy_pin->digital_read()) {
501 if (waited >= INTRA_CS_READY_TIMEOUT_US)
502 return;
504 waited += 1;
505 }
506}
507
508void IT8951Display::spi_cmd_(uint16_t cmd) {
509 this->enable();
510 this->write_byte16(PACKET_TYPE_CMD);
511 wait_for_hardware_ready(this->busy_pin_);
512 this->write_byte16(cmd);
513 this->disable();
514}
515
517 this->enable();
518 this->write_byte16(PACKET_TYPE_WRITE);
519 wait_for_hardware_ready(this->busy_pin_);
520 this->write_byte16(value);
521 this->disable();
522}
523
524void IT8951Display::spi_write_reg_(uint16_t addr, uint16_t value) {
525 // Single CS transaction: WRITE preamble + addr + value.
526 // Caller must have already sent CMD(TCON_REG_WR) as a prior op.
527 this->enable();
528 this->write_byte16(PACKET_TYPE_WRITE);
529 wait_for_hardware_ready(this->busy_pin_);
530 this->write_byte16(addr);
531 this->write_byte16(value);
532 this->disable();
533}
534
535void IT8951Display::spi_write_args_(const uint16_t *args, uint16_t count) {
536 // Single CS transaction: WRITE preamble + N data words.
537 this->enable();
538 this->write_byte16(PACKET_TYPE_WRITE);
539 wait_for_hardware_ready(this->busy_pin_);
540 for (uint16_t i = 0; i < count; i++)
541 this->write_byte16(args[i]);
542 this->disable();
543}
544
546 // Single CS read transaction. HW_RDY was confirmed HIGH by the loop gate
547 // before this op was dispatched, so data is ready.
548 this->enable();
549 this->write_byte16(PACKET_TYPE_READ);
550 wait_for_hardware_ready(this->busy_pin_);
551 this->write_byte16(0x0000); // dummy — provides clock cycles for controller
552 wait_for_hardware_ready(this->busy_pin_);
553 // Read byte-by-byte: a 2-byte transfer_array can lose the low byte on
554 // ESP-IDF SPI DMA due to 4-byte alignment requirements.
555 const uint8_t hi = this->transfer_byte(0);
556 const uint8_t lo = this->transfer_byte(0);
557 this->disable();
558 return encode_uint16(hi, lo);
559}
560
562 // Read DevInfo struct. The CMD(GET_DEV_INFO) was already sent as a prior op,
563 // and the loop HW_RDY gate waited for the controller to prepare data.
564 std::memset(&this->dev_info_, 0, sizeof(this->dev_info_));
565 this->enable();
566 this->write_byte16(PACKET_TYPE_READ);
567 wait_for_hardware_ready(this->busy_pin_);
568 this->write_byte16(0x0000); // dummy
569 wait_for_hardware_ready(this->busy_pin_);
570 auto *words = reinterpret_cast<uint16_t *>(&this->dev_info_);
571 constexpr uint32_t word_count = sizeof(this->dev_info_) / sizeof(uint16_t);
572 for (uint32_t i = 0; i < word_count; i++) {
573 const uint8_t hi = this->transfer_byte(0);
574 const uint8_t lo = this->transfer_byte(0);
575 words[i] = encode_uint16(hi, lo);
576 }
577 this->disable();
578}
579
580// --- Compound Ops ------------------------------------------------------------
581
583 // Set image-buffer target address. Two register writes = 4 CS transactions.
584 // Push to FRONT in reverse order so they execute before the rest of the queue.
585 this->prepend_(OpType::WRITE_REG, LISAR, this->img_buf_addr_l_);
586 this->prepend_(OpType::CMD, TCON_REG_WR, 0);
587 this->prepend_(OpType::WRITE_REG, static_cast<uint16_t>(LISAR + 2), this->img_buf_addr_h_);
588 this->prepend_(OpType::CMD, TCON_REG_WR, 0);
589}
590
592 // Single CS transaction: WRITE preamble + 5 area-parameter words describing
593 // the full update region. Sent once when the load is opened (transfer_row_ is
594 // 0); XFER_ROWS then streams every row into this one area.
595 uint16_t args[5];
596 if (this->grayscale_) {
597 args[0] = static_cast<uint16_t>((LDIMG_B_ENDIAN << 8) | (PIXEL_4BPP << 4));
598 args[1] = this->area_x_;
599 args[2] = this->area_y_;
600 args[3] = this->area_w_;
601 args[4] = this->area_h_;
602 } else {
603 // Monochrome is loaded via the 8bpp-packed trick: x and width are expressed
604 // in bytes (8 pixels each) and the controller unpacks one bit per pixel.
605 args[0] = static_cast<uint16_t>((LDIMG_L_ENDIAN << 8) | (PIXEL_8BPP << 4));
606 args[1] = static_cast<uint16_t>(this->area_x_ / 8);
607 args[2] = this->area_y_;
608 args[3] = static_cast<uint16_t>(this->area_w_ / 8);
609 args[4] = this->area_h_;
610 }
611 this->spi_write_args_(args, 5);
612}
613
614void IT8951Display::op_xfer_area_end_() { this->spi_cmd_(TCON_LD_IMG_END); }
615
617 const uint32_t start_time = millis();
618 const uint16_t area_y = this->area_y_;
619 const uint16_t area_h = this->area_h_;
620
621 // Bytes per source row, and the byte offset of area_x within a row, in the
622 // framebuffer's native packing. These match the per-row byte count the
623 // controller expects from op_xfer_area_args_: area_w/2 for 4bpp grayscale,
624 // area_w/8 for the 1bpp-packed monochrome trick. area_x / area_w are
625 // 16-pixel aligned (see prepare_update_region_), so both divisions are exact.
626 const uint16_t bytes_per_row =
627 this->grayscale_ ? static_cast<uint16_t>(this->area_w_ >> 1) : static_cast<uint16_t>(this->area_w_ >> 3);
628 const uint16_t row_x_bytes =
629 this->grayscale_ ? static_cast<uint16_t>(this->area_x_ >> 1) : static_cast<uint16_t>(this->area_x_ >> 3);
630
631 // Single CS write transaction — HW_RDY was confirmed high by the loop gate.
632 this->enable();
633 this->write_byte16(PACKET_TYPE_WRITE);
634 wait_for_hardware_ready(this->busy_pin_);
635
636 // Each source row is a contiguous slice of the framebuffer in both formats —
637 // the buffer already holds the wire bytes — so stream it straight to SPI with
638 // no per-pixel packing or temporary buffer.
639 while (this->transfer_row_ < area_h) {
640 const uint32_t offset = (static_cast<uint32_t>(area_y) + this->transfer_row_) * this->row_width_ + row_x_bytes;
641 this->write_array(&this->buffer_[offset], bytes_per_row);
642 this->transfer_row_++;
643 if (millis() - start_time >= MAX_TRANSFER_TIME_MS)
644 break;
645 }
646
647 this->disable();
648 return this->transfer_row_ >= area_h;
649}
650
652 // I80_CMD_DPY_BUF_AREA (0x0037) takes 7 args (with explicit buffer addr).
653 // I80_CMD_DPY_AREA (0x0034) takes 5 args; the buffer address is taken
654 // from LISAR which we program during the transfer phase, so this is safe.
655 if (this->use_legacy_dpy_area_) {
656 const uint16_t args[5] = {
657 this->area_x_, this->area_y_, this->area_w_, this->area_h_, static_cast<uint16_t>(this->active_mode_),
658 };
659 this->spi_write_args_(args, 5);
660 return;
661 }
662 const uint16_t args[7] = {
663 this->area_x_,
664 this->area_y_,
665 this->area_w_,
666 this->area_h_,
667 static_cast<uint16_t>(this->active_mode_),
668 this->img_buf_addr_l_,
669 this->img_buf_addr_h_,
670 };
671 this->spi_write_args_(args, 7);
672}
673
675 ESP_LOGV(TAG, "Checking LUT idle, read_result_=0x%04X", this->read_result_);
676 // read_result_ holds LUTAFSR value from the preceding READ_WORD op.
677 if (this->read_result_ != 0) {
678 // LUT still busy — re-enqueue the full read sequence after a short delay.
679 this->prepend_(OpType::CHECK_LUT_IDLE, 0, 0);
680 this->prepend_(OpType::READ_WORD, 0, 0);
681 this->prepend_(OpType::WRITE_W, LUTAFSR, 0);
682 this->prepend_(OpType::CMD, TCON_REG_RD, 0);
683 this->prepend_(OpType::DELAY_MS, 5, 0);
684 }
685}
686
688 // read_result_ holds UP1SR+2 value. Set bit 2 and write back, then set BGVR.
689 // Push to FRONT in reverse order so they execute before DPY_BUF_CMD/ARGS
690 // that are already in the queue.
691 const uint16_t modified = static_cast<uint16_t>(this->read_result_ | (1U << 2));
692 this->prepend_(OpType::WRITE_REG, BGVR, 0xFF00);
693 this->prepend_(OpType::CMD, TCON_REG_WR, 0);
694 this->prepend_(OpType::WRITE_REG, UP1SR + 2, modified);
695 this->prepend_(OpType::CMD, TCON_REG_WR, 0);
696}
697
698// --- Update prep / public API ------------------------------------------------
699
701 this->partial_update_count_++;
702 const bool full_update = this->partial_update_count_ >= this->full_update_every_;
703 if (full_update) {
704 this->partial_update_count_ = 0;
705 mode = UPDATE_MODE_GC16;
706 this->x_low_ = 0;
707 this->y_low_ = 0;
708 this->x_high_ = this->width_;
709 this->y_high_ = this->height_;
710 } else {
711 // Align the partial region's X extent to 32 pixels. The IT8951's partial
712 // display refresh snaps the X start/width to a 32-pixel boundary (the panel
713 // source driver fetches 32-pixel chunks); refreshing a region whose X is
714 // only 16-aligned makes the panel snap it down to the previous boundary,
715 // shifting that update ~16px to the left. 32-alignment also satisfies the
716 // load constraints (4bpp X must be a multiple of 4; the 8bpp-packed mono
717 // load needs x/8 even, i.e. X a multiple of 16).
718 this->x_low_ &= 0xFFE0;
719 uint16_t temp_max = this->x_high_ > 0 ? static_cast<uint16_t>(this->x_high_ - 1) : 0;
720 temp_max = static_cast<uint16_t>(temp_max | 0x001F);
721 if (temp_max >= this->width_)
722 temp_max = static_cast<uint16_t>(this->width_ - 1);
723 this->x_high_ = static_cast<uint16_t>(temp_max + 1);
724 }
725
727 this->reset_dirty_region_();
728 return false;
729 }
730
731 const uint16_t x = this->x_low_;
732 const uint16_t y = this->y_low_;
733 const uint16_t width = static_cast<uint16_t>(this->x_high_ - this->x_low_);
734 const uint16_t height = static_cast<uint16_t>(this->y_high_ - this->y_low_);
735
736 if (x >= this->width_ || y >= this->height_ || (x + width) > this->width_ || (y + height) > this->height_) {
737 ESP_LOGE(TAG, "Dirty region (%u,%u %ux%u) out of bounds", x, y, width, height);
738 this->reset_dirty_region_();
739 return false;
740 }
741
742 this->area_x_ = x;
743 this->area_y_ = y;
744 this->area_w_ = width;
745 this->area_h_ = height;
746 this->transfer_row_ = 0;
747
748 // On non-full updates, downgrade monochrome frames from the full, flashy GC16
749 // clear to DU — a fast, low-flash absolute waveform — so full_update_every
750 // buys cheaper refreshes between the periodic GC16 cleans that clear
751 // accumulated ghosting.
752 //
753 // Grayscale frames are deliberately left on GC16: every reduced grayscale
754 // waveform this controller exposes (the non-flashing GL family GL16/GLR16/
755 // GLD16, and the 4-tone DU4) renders incorrectly on the supported panels —
756 // a white background is driven to grey rather than staying white. GC16 is the
757 // only waveform that reproduces grayscale faithfully, so we keep it.
758 //
759 // An explicitly configured non-GC16 update_mode is honoured as-is.
760 if (!full_update && mode == UPDATE_MODE_GC16 && !this->grayscale_)
761 mode = UPDATE_MODE_DU;
762
763 this->reset_dirty_region_();
764
765 ESP_LOGV(TAG, "Update: %ux%u@%u,%u mode=%u (%s)", width, height, x, y, static_cast<unsigned>(mode),
766 this->grayscale_ ? LOG_STR_LITERAL("grayscale") : LOG_STR_LITERAL("mono"));
767 return true;
768}
769
771 this->x_low_ = this->width_;
772 this->x_high_ = 0;
773 this->y_low_ = this->height_;
774 this->y_high_ = 0;
775}
776
778 if (this->phase_ == Phase::IDLE && this->initialised_) {
779 this->update_started_at_ = millis();
780 this->active_mode_ = mode;
782 this->enable_loop();
783 this->advance_phase_();
784 } else {
785 // Coalesce: latest pending mode wins.
786 this->update_pending_ = true;
788 this->enable_loop();
789 }
790}
791
793 if (!this->is_ready())
794 return;
797 return;
798 }
800}
801
803 if (mode == UPDATE_MODE_NONE) {
804 this->update();
805 return;
806 }
807 if (!this->is_ready())
808 return;
809 this->start_update_(mode);
810}
811
812// --- Recovery ----------------------------------------------------------------
813
815 if (++this->recovery_attempts_ > 3) {
816 ESP_LOGE(TAG, "Recovery failed after %u attempts; giving up. Check BUSY pin wiring and power.",
817 this->recovery_attempts_);
818 this->mark_failed(LOG_STR("IT8951 recovery exhausted"));
819 this->queue_.clear();
820 this->set_phase_(Phase::IDLE);
821 this->disable_loop();
822 return;
823 }
824 ESP_LOGW(TAG, "Recovering (attempt %u): hardware-resetting controller (was in phase %u)", this->recovery_attempts_,
825 static_cast<unsigned>(this->phase_));
826 this->queue_.clear();
827 this->update_pending_ = false;
828 this->transfer_row_ = 0;
829 this->initialised_ = false;
830 this->dev_info_attempts_ = 0;
831
832 // Drop SPI clock back to the safe probe rate for the re-init handshake.
833 if (this->configured_data_rate_ != 0 && this->data_rate_ != SPI_PROBE_FREQUENCY) {
834 this->spi_teardown();
835 this->set_data_rate(SPI_PROBE_FREQUENCY);
836 this->spi_setup();
837 }
838
839 // Force a full redraw on next opportunity.
840 this->x_low_ = 0;
841 this->y_low_ = 0;
842 this->x_high_ = this->width_;
843 this->y_high_ = this->height_;
844
846 this->enqueue_init_reset_();
847 this->update_pending_ = true;
849 this->enable_loop();
850}
851
852// --- Coordinate transform ----------------------------------------------------
853
855 switch (this->rotation_) {
857 this->effective_transform_ = this->transform_ ^ (TRANSFORM_SWAP_XY | TRANSFORM_MIRROR_X);
858 break;
860 this->effective_transform_ = this->transform_ ^ (TRANSFORM_MIRROR_Y | TRANSFORM_MIRROR_X);
861 break;
863 this->effective_transform_ = this->transform_ ^ (TRANSFORM_SWAP_XY | TRANSFORM_MIRROR_Y);
864 break;
865 default:
866 this->effective_transform_ = this->transform_;
867 break;
868 }
869}
870
871void IT8951Display::apply_transform_(int &x, int &y) const {
872 if (this->effective_transform_ & TRANSFORM_SWAP_XY)
873 std::swap(x, y);
874 if (this->effective_transform_ & TRANSFORM_MIRROR_X)
875 x = this->width_ - x - 1;
876 if (this->effective_transform_ & TRANSFORM_MIRROR_Y)
877 y = this->height_ - y - 1;
878}
879
881 if (this->is_point_clipped(x, y))
882 return false;
883 this->apply_transform_(x, y);
884 if (x >= this->width_ || y >= this->height_ || x < 0 || y < 0)
885 return false;
886 this->x_low_ = clamp_at_most(this->x_low_, x);
887 this->x_high_ = clamp_at_least(this->x_high_, x + 1);
888 this->y_low_ = clamp_at_most(this->y_low_, y);
889 this->y_high_ = clamp_at_least(this->y_high_, y + 1);
890 return true;
891}
892
893// --- Color / drawing ---------------------------------------------------------
894
895static uint8_t quantize_8bit_to_nibble(uint8_t value) {
896 uint8_t nibble = static_cast<uint8_t>((static_cast<uint16_t>(value) + 8) >> 4);
897 return nibble > 0x0F ? 0x0F : nibble;
898}
899
900static uint8_t color_to_nibble(const Color &color) {
901 // Grayscale images are emitted as Color(gray, gray, gray, 0xFF).
902 // Handle this shape first so endpoint values don't alias COLOR_ON/OFF.
903 if (color.w == 0xFF && color.r == color.g && color.g == color.b)
904 return quantize_8bit_to_nibble(color.r);
905
906 if (color.raw_32 == 0)
907 return 0x00; // black
908 if (color.raw_32 == 0xFFFFFFFF)
909 return 0x0F; // white
910
911 // Rec.601 luma is the standard for converting SDR images to grayscale and spreads saturated colours
912 // across the mid-range; Rec.709 instead crams them against white/black where the 16 panel levels are
913 // hard to tell apart.
914 return quantize_8bit_to_nibble(display::rec601_luma(color));
915}
916
917// 4x4 ordered (Bayer) dither threshold over the weighted-luma range (0..65535).
918// A pixel whose luma is below the threshold renders black, so lighter pixels
919// produce progressively sparser black dots instead of vanishing to white. The
920// matrix averages to 32768, matching the conventional monochrome cut, while the
921// per-pixel variation reproduces intermediate gray levels.
922static uint16_t dither_threshold(uint16_t x, uint16_t y) {
923 static const uint8_t BAYER4[16] = {0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5};
924 return static_cast<uint16_t>(BAYER4[((y & 3) << 2) | (x & 3)] * 4096u + 2048u);
925}
926
928 if (this->buffer_ == nullptr)
929 return;
930 if (this->get_clipping().is_set()) {
931 Display::fill(color);
932 return;
933 }
934 uint8_t packed = color_to_nibble(color);
935 if (this->invert_colors_)
936 packed = 0x0F - packed;
937 uint8_t fill_byte;
938 if (this->grayscale_) {
939 fill_byte = static_cast<uint8_t>((packed << 4) | packed);
940 } else {
941 fill_byte = (packed <= 0x07) ? 0xFF : 0x00;
942 }
943 memset(this->buffer_, fill_byte, this->buffer_length_);
944 this->x_low_ = 0;
945 this->y_low_ = 0;
946 this->x_high_ = this->width_;
947 this->y_high_ = this->height_;
948}
949
950void HOT IT8951Display::draw_pixel_at(int x, int y, Color color) {
951 if (this->buffer_ == nullptr)
952 return;
953 this->feed_wdt_per_pixel_();
954 if (!this->rotate_coordinates_(x, y))
955 return;
956 this->write_pixel_native_(static_cast<uint16_t>(x), static_cast<uint16_t>(y), color);
957}
958
959void HOT IT8951Display::write_pixel_native_(uint16_t x, uint16_t y, const Color &color) const {
960 if (this->grayscale_) {
961 uint8_t nibble = color_to_nibble(color);
962 if (this->invert_colors_)
963 nibble = static_cast<uint8_t>(0x0F - nibble);
964 this->set_gray_pixel_(x, y, nibble);
965 } else {
966 // Rec.601 luma (see color_to_nibble). Weights sum to 257 so white maps to
967 // exactly 65535, using the full 16-bit range without overflow.
968 auto lum = static_cast<uint16_t>(77u * color.r + 151u * color.g + 29u * color.b);
969 if (this->invert_colors_)
970 lum = static_cast<uint16_t>(65535u - lum);
971 // Set the bit (foreground/black) when this pixel is darker than its
972 // threshold. With dithering the threshold varies per pixel so pale colours
973 // render as visible texture; otherwise it's the fixed ~50% cut (r+g+b<32768).
974 const uint16_t threshold = this->dithering_ ? dither_threshold(x, y) : 32768;
975 this->set_mono_pixel_(x, y, lum < threshold);
976 }
977}
978
979void HOT IT8951Display::draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr,
981 int x_pad) {
982 // A writer (e.g. LVGL) may push pixels before the framebuffer is ready or
983 // after an allocation failure; ignore those rather than dereferencing null.
984 if (this->buffer_ == nullptr)
985 return;
986 // A clipping rectangle would need a per-pixel test; that's rare for the bulk
987 // blit callers (LVGL, images), so fall back to the base per-pixel path then.
988 if (this->get_clipping().is_set()) {
990 return;
991 }
992
993 const size_t line_stride = static_cast<size_t>(x_offset) + w + x_pad; // source line length in pixels
994 for (int y = 0; y < h; y++) {
995 App.feed_wdt();
996 size_t source_idx = (static_cast<size_t>(y_offset) + y) * line_stride + x_offset;
997 for (int x = 0; x < w; x++, source_idx++) {
998 uint32_t color_value;
999 switch (bitness) {
1000 case COLOR_BITNESS_565: {
1001 const size_t i = source_idx * 2;
1002 color_value = big_endian ? encode_uint16(ptr[i], ptr[i + 1]) : encode_value_le<uint16_t>(&ptr[i]);
1003 break;
1004 }
1005 case COLOR_BITNESS_888: {
1006 const size_t i = source_idx * 3;
1007 color_value = encode_uint24(ptr[i + 2], ptr[i + 1], ptr[i]);
1008 break;
1009 }
1010 default:
1011 color_value = ptr[source_idx];
1012 break;
1013 }
1014 int nx = x_start + x;
1015 int ny = y_start + y;
1016 this->apply_transform_(nx, ny);
1017 if (nx < 0 || ny < 0 || nx >= this->width_ || ny >= this->height_)
1018 continue;
1019 this->write_pixel_native_(static_cast<uint16_t>(nx), static_cast<uint16_t>(ny),
1020 ColorUtil::to_color(color_value, bitness));
1021 }
1022 }
1023
1024 // Expand the dirty bounding box once from the transformed block corners: the
1025 // image of an axis-aligned rectangle under swap/mirror is still axis-aligned,
1026 // so its two opposite corners bound it.
1027 int x0 = x_start, y0 = y_start;
1028 int x1 = x_start + w - 1, y1 = y_start + h - 1;
1029 this->apply_transform_(x0, y0);
1030 this->apply_transform_(x1, y1);
1031 const int nx_lo = std::max(0, std::min(x0, x1));
1032 const int ny_lo = std::max(0, std::min(y0, y1));
1033 const int nx_hi = std::min(this->width_ - 1, std::max(x0, x1));
1034 const int ny_hi = std::min(this->height_ - 1, std::max(y0, y1));
1035 if (nx_hi >= nx_lo && ny_hi >= ny_lo) {
1036 this->x_low_ = clamp_at_most(this->x_low_, nx_lo);
1037 this->x_high_ = clamp_at_least(this->x_high_, nx_hi + 1);
1038 this->y_low_ = clamp_at_most(this->y_low_, ny_lo);
1039 this->y_high_ = clamp_at_least(this->y_high_, ny_hi + 1);
1040 }
1041}
1042
1043void IT8951Display::set_mono_pixel_(uint16_t x, uint16_t y, bool value) const {
1044 // The monochrome framebuffer holds the exact bytes streamed to the
1045 // controller for the 8bpp-load / 1bpp-display trick (L_ENDIAN). Pixels are
1046 // grouped in 16s; on the wire the high byte (pixels 8..15) precedes the low
1047 // byte (pixels 0..7), and the bit index within a byte is the pixel's offset
1048 // (LSB = lowest x). Storing in that order lets op_xfer_rows_ copy rows
1049 // verbatim with no packing or byte-swapping.
1050 const uint16_t group = static_cast<uint16_t>(x >> 4);
1051 const uint8_t sub = static_cast<uint8_t>(x & 0x0F);
1052 const uint16_t byte_index = static_cast<uint16_t>(group * 2u + (sub < 8u ? 1u : 0u));
1053 const uint8_t mask = static_cast<uint8_t>(1u << (sub & 0x07));
1054 const uint32_t index = static_cast<uint32_t>(y) * this->row_width_ + byte_index;
1055 if (value) {
1056 this->buffer_[index] |= mask;
1057 } else {
1058 this->buffer_[index] &= static_cast<uint8_t>(~mask);
1059 }
1060}
1061
1062void IT8951Display::set_gray_pixel_(uint16_t x, uint16_t y, uint8_t nibble) const {
1063 const uint32_t index = static_cast<uint32_t>(y) * this->row_width_ + (static_cast<uint32_t>(x) >> 1);
1064 uint8_t buf = this->buffer_[index];
1065 buf = x & 0x1 ? (buf & 0xF0) | nibble : (buf & 0x0F) | static_cast<uint8_t>(nibble << 4);
1066 this->buffer_[index] = buf;
1067}
1068
1069// --- Diagnostics -------------------------------------------------------------
1070
1072 LOG_DISPLAY("", "IT8951 E-Paper", this);
1073 char force_temperature[24];
1074 if (this->force_temperature_set_) {
1075 snprintf(force_temperature, sizeof(force_temperature), "%d °C", this->force_temperature_);
1076 } else {
1077 strncpy(force_temperature, "(controller default)", sizeof(force_temperature));
1078 force_temperature[sizeof(force_temperature) - 1] = '\0';
1079 }
1080 ESP_LOGCONFIG(
1081 TAG,
1082 " Model preset: %s"
1083 "\n Dimensions: %dx%d"
1084 "\n Buffer: %u bytes"
1085 "\n Image buffer addr: 0x%04X%04X"
1086 "\n VCOM: %.02fV (set selector 0x%04X)"
1087 "\n Force temperature: %s"
1088 "\n Display command: %s"
1089 "\n Sleep when done: %s"
1090 "\n Full update every: %u"
1091 "\n Inverted colors: %s"
1092 "\n Pixel format: %s"
1093 "\n Reset duration: %" PRIu32 "ms",
1094 this->name_ != nullptr ? this->name_ : LOG_STR_LITERAL("(unknown)"), this->get_width_internal(),
1095 this->get_height_internal(), static_cast<unsigned>(this->buffer_length_), this->img_buf_addr_h_,
1096 this->img_buf_addr_l_, static_cast<float>(this->vcom_) / 1000.0f, this->vcom_register_, force_temperature,
1097 this->use_legacy_dpy_area_ ? LOG_STR_LITERAL("DPY_AREA (0x0034, legacy)")
1098 : LOG_STR_LITERAL("DPY_BUF_AREA (0x0037)"),
1099 YESNO(this->sleep_when_done_), this->full_update_every_, YESNO(this->invert_colors_),
1100 this->grayscale_ ? LOG_STR_LITERAL("4bpp grayscale") : LOG_STR_LITERAL("1bpp monochrome"), this->reset_duration_);
1101 LOG_PIN(" Reset Pin: ", this->reset_pin_);
1102 LOG_PIN(" Busy Pin: ", this->busy_pin_);
1103 LOG_PIN(" CS Pin: ", this->cs_);
1104 LOG_UPDATE_INTERVAL(this);
1105}
1106
1107} // namespace esphome::it8951
BedjetMode mode
BedJet operating mode.
void feed_wdt()
Feed the task watchdog.
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:288
bool is_ready() const
void enable_loop()
Enable this component's loop.
Definition component.h:262
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
Definition component.h:236
void disable_loop()
Disable this component's loop.
virtual void setup()=0
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
void set(bool active)
Run the loop continuously while active is true. Repeating the current value does nothing.
Definition helpers.cpp:863
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2670
T * allocate(size_t n)
Definition helpers.h:2697
static Color to_color(uint32_t colorcode, ColorBitness color_bitness=ColorBitness::COLOR_BITNESS_888, bool right_bit_aligned=true)
Unpacks a color of the given bitness, red in the most significant bits.
int int int const uint8_t ColorOrder ColorBitness bitness
Definition display.h:394
void ESPHOME_ALWAYS_INLINE feed_wdt_per_pixel_()
Watchdog feed for per pixel loops.
Definition display.h:847
int int int const uint8_t ColorOrder ColorBitness bool int int y_offset
Definition display.h:394
virtual void fill(Color color)
Fill the entire screen with the given color.
Definition display.cpp:16
int int int const uint8_t ColorOrder ColorBitness bool int int int x_pad
Definition display.h:394
int int int const uint8_t * ptr
Definition display.h:393
bool ESPHOME_ALWAYS_INLINE is_point_clipped(int x, int y) const
Whether (x, y) falls outside the active clipping rectangle.
Definition display.h:812
int int int const uint8_t ColorOrder ColorBitness bool big_endian
Definition display.h:394
Rect get_clipping() const
Get the current the clipping rectangle.
Definition display.cpp:815
int int int const uint8_t ColorOrder ColorBitness bool int x_offset
Definition display.h:394
DisplayRotation rotation_
Definition display.h:865
virtual void draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Draws a block for draw_pixels_at(); the parameters are the same.
Definition display.cpp:118
void on_powerdown() override
Definition it8951.cpp:365
void update_mode(UpdateMode mode)
Definition it8951.cpp:802
void start_update_(UpdateMode mode)
Definition it8951.cpp:777
void spi_write_args_(const uint16_t *args, uint16_t count)
Definition it8951.cpp:535
HighFrequencyLoopRequester high_freq_
Definition it8951.h:240
void set_phase_(Phase next)
Definition it8951.cpp:173
void spi_cmd_(uint16_t cmd)
Definition it8951.cpp:508
bool rotate_coordinates_(int &x, int &y)
Definition it8951.cpp:880
void enqueue_(OpType type, uint16_t a=0, uint16_t b=0)
Definition it8951.cpp:21
StaticRingBuffer< Op, OP_QUEUE_SIZE > queue_
Definition it8951.h:234
uint16_t compute_row_width_() const
Definition it8951.h:178
void spi_write_reg_(uint16_t addr, uint16_t value)
Definition it8951.cpp:524
void prepend_(OpType type, uint16_t a=0, uint16_t b=0)
Definition it8951.cpp:28
std::vector< GPIOPin * > enable_pins_
Definition it8951.h:290
int get_height_internal() override
Definition it8951.h:162
void draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override
Definition it8951.cpp:979
void set_mono_pixel_(uint16_t x, uint16_t y, bool value) const
Definition it8951.cpp:1043
void write_pixel_native_(uint16_t x, uint16_t y, const Color &color) const
Definition it8951.cpp:959
void apply_transform_(int &x, int &y) const
Definition it8951.cpp:871
void process_op_(const Op &op)
Definition it8951.cpp:100
void fill(Color color) override
Definition it8951.cpp:927
void spi_write_word_(uint16_t value)
Definition it8951.cpp:516
static constexpr uint32_t BUSY_TIMEOUT_MS
Definition it8951.h:232
bool prepare_update_region_(UpdateMode &mode)
Definition it8951.cpp:700
void set_gray_pixel_(uint16_t x, uint16_t y, uint8_t nibble) const
Definition it8951.cpp:1062
int get_width_internal() override
Definition it8951.h:163
void draw_pixel_at(int x, int y, Color color) override
Definition it8951.cpp:950
uint32_t data_rate_
Definition spi.h:425
uint8_t type
NameCopy * next
unsigned count
Definition gif.cpp:51
@ DISPLAY_ROTATION_270_DEGREES
Definition display.h:140
@ DISPLAY_ROTATION_180_DEGREES
Definition display.h:139
@ DISPLAY_ROTATION_90_DEGREES
Definition display.h:138
constexpr uint8_t rec601_luma(Color color)
Rec.601 luma of an RGB color, for optimum perceptual brightness.
static void int int int int const uint8_t ColorOrder ColorBitness bool big_endian
Definition display.cpp:100
static void int int int int const uint8_t ColorOrder ColorBitness bitness
Definition display.cpp:99
static void int x_start
Definition display.cpp:61
static void int int int int const uint8_t int x_offset
Definition display.cpp:62
static void int int y_start
Definition display.cpp:61
static void int int int int const uint8_t int int y_offset
Definition display.cpp:62
static void int int int w
Definition display.cpp:61
ESPHOME_LOG_TAG(TAG, "display")
static void int int int int h
Definition display.cpp:61
static void int int int int const uint8_t * ptr
Definition display.cpp:62
static void int int int int const uint8_t int int int x_pad
Definition display.cpp:62
T clamp_at_most(T value, U max)
Definition helpers.h:2859
uint32_t value
Definition hal.cpp:59
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
Definition helpers.h:1231
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
Definition helpers.h:1268
T clamp_at_least(T value, U min)
Definition helpers.h:2854
void setup_output_pin(GPIOPin *pin, bool level)
Set up pin and drive it to level. Does nothing when pin is null, so an optional pin needs no check.
Definition gpio.cpp:44
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:1227
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t
uint8_t w
Definition color.h:50
uint8_t g
Definition color.h:42
uint8_t b
Definition color.h:46
uint32_t raw_32
Definition color.h:55
static const Color WHITE
Definition color.h:168
uint8_t r
Definition color.h:38
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6