#pragma once // GDEY0579F51 - HX8717 dual-chip, 792x272, 4-color, 2bpp packed (same // JD79667-family packing as GDEY029F51, see panel_290c_gdey029f51.h). // // Captured from the STOCK vendored driver // (third_party/GxEPD2/src/epd4c/GxEPD2_579c_GDEY0579F51.{h,cpp}) and kept // byte-for-byte stock EXCEPT the PSR source-scan bytes (see PSR_MASTER/ // PSR_SLAVE below) - those are swapped to Waveshare's orientation because // the stock values render this panel left-right mirrored on hardware. // // History worth not repeating: an earlier revision carried a pile of // hand-"fixes" from Waveshare's epd5in79g.cpp - swapped PSR, power-on under // select=Both, a changed BTST - all introduced together to chase mirrored // text AND a slave region that never converged. The bench (2026-10-18) // separated the two: the non-convergence was DRIVE-CURRENT STARVATION on // the bench MCU (not a driver bug - the same panel + firmware renders on an // adequately-powered board), so power-on-select and BTST were red herrings // and are back to stock here; only the PSR scan-direction swap was doing // real work (fixing the mirror) and is kept. Window + refresh are the fresh // capture, unchanged. // // Dual-region layer assembled by hand from the driver source, per // CONTRIBUTING.md "Limits - True dual-region command structure": the // emitter's segmentation doesn't model the 0xA2 master/slave region selects. // Window geometry and refresh were taken from the capture (byte-exact); // the init below transcribes the stock _InitDisplay() directly (the emitter // can't recover a dual-chip init - _InitDisplay runs during the earlier // writeScreenBuffer clear, so nothing is left in the writeImage pre-block). // // Region mapping: master = away from the FPC connector = region 0 (written // first), slave = near connector = region 1 (cross-checked against // GxEPD2_579_GDEY0579T93.cpp's own master/slave comments). "plane 0/1" in // the engine's terms are these two physical regions, not color planes; // window_per_plane gives each its own 0xA2-select window-set before its own // 0x10 byte burst. #include "epd_command.h" namespace esphome::gxepd2 { inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_MASTER[] = {0x01}; inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_SLAVE[] = {0x02}; inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_BOTH[] = {0x00}; // PSR source-scan (SHL) bytes are the ONE deviation from the stock driver: // stock is master {0x07,0x29} / slave {0x03,0x29}, which renders this panel // left-right MIRRORED (text backwards) on hardware. The two values differ // only in the source-scan-direction bit; swapping which half gets it (the // value Waveshare's epd5in79g.cpp uses) un-mirrors it - confirmed on the // bench 2026-10-18. This is a real per-panel orientation fix and is // unrelated to the drive-current issue that explained the old "slave won't // converge" symptom; everything else here stays stock. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_MASTER[] = {0x03, 0x29}; inline const uint8_t PANEL_579C_GDEY0579F51_PSR_SLAVE[] = {0x07, 0x29}; inline const uint8_t PANEL_579C_GDEY0579F51_BTST[] = {0x32, 0x32, 0x32, 0x32}; inline const uint8_t PANEL_579C_GDEY0579F51_TRES[] = {0x01, 0x8C, 0x01, 0x10}; // 396x272 - one region inline const uint8_t PANEL_579C_GDEY0579F51_CDI_INIT[] = {0x97}; // border white inline const uint8_t PANEL_579C_GDEY0579F51_E9[] = {0x01}; inline const uint8_t PANEL_579C_GDEY0579F51_E0[] = {0x01}; // Stock _InitDisplay(): PSR written to each region under its own select, // then BTST/TRES/CDI/E9/E0 under select=Both, then re-select MASTER and // power-on (0x04). This is the vendor's order and select-state exactly. inline const EpdCommand PANEL_579C_GDEY0579F51_INIT[] = { {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1}, {0x00, PANEL_579C_GDEY0579F51_PSR_MASTER, 2}, {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1}, {0x00, PANEL_579C_GDEY0579F51_PSR_SLAVE, 2}, {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1}, {0x06, PANEL_579C_GDEY0579F51_BTST, 4}, {0x61, PANEL_579C_GDEY0579F51_TRES, 4}, {0x50, PANEL_579C_GDEY0579F51_CDI_INIT, 1}, {0xE9, PANEL_579C_GDEY0579F51_E9, 1}, {0xE0, PANEL_579C_GDEY0579F51_E0, 1}, {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1}, {0x04, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true}, // power on }; // _setPartialRamArea*(0, 0, 396, 272) with partial_mode=true: both regions // are the same shape, differing only in the 0xA2 select byte sent first. inline const uint8_t PANEL_579C_GDEY0579F51_WINDOW_REGION[] = { 0x00, 0x00, // x = 0 0x01, 0x8B, // x+w-1 = 395 0x00, 0x00, // y = 0 0x01, 0x0F, // y+h-1 = 271 0x01, // partial_mode }; inline const EpdCommand PANEL_579C_GDEY0579F51_WINDOW_MASTER[] = { {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1}, {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9}, }; inline const EpdCommand PANEL_579C_GDEY0579F51_WINDOW_SLAVE[] = { {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1}, {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9}, }; // refresh(false): stock _setPartialRamAreaBoth(0,0,396,272) then _refresh: // CDI 0x50=0x37 (white), then 0x12 trigger (power-on 0x04 is skipped here - // already on from init). inline const uint8_t PANEL_579C_GDEY0579F51_CDI_REFRESH[] = {0x37}; inline const uint8_t PANEL_579C_GDEY0579F51_REFRESH_TRIGGER[] = {0x00}; inline const EpdCommand PANEL_579C_GDEY0579F51_REFRESH[] = { {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1}, {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9}, {0x50, PANEL_579C_GDEY0579F51_CDI_REFRESH, 1}, {0x12, PANEL_579C_GDEY0579F51_REFRESH_TRIGGER, 1, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true}, }; inline const EpdPanelDescriptor PANEL_579C_GDEY0579F51 = { .width = 792, // full logical panel - the canvas ESPHome draws into .height = 272, .busy_active_level = false, // GxEPD2_EPD(..., /*busy_level=*/LOW, ...) .busy_timeout_ms = 40000, // vendor full_refresh_time is 21000ms, but it's // a soft estimate (GxEPD2 polls BUSY past it); // give a 4-color refresh real headroom before // the engine hard-aborts .init_sequence = PANEL_579C_GDEY0579F51_INIT, .init_sequence_len = sizeof(PANEL_579C_GDEY0579F51_INIT) / sizeof(PANEL_579C_GDEY0579F51_INIT[0]), // plane 0 is the LEFT half of the canvas (draw_packed_ splits at // plane_width), plane 1 the RIGHT half. With the swapped PSR scan // direction, chip 0x02 (slave) drives the left of the glass and chip // 0x01 (master) the right, so route plane 0 -> slave-select window and // plane 1 -> master-select. Sending them in physical-chip order instead // put the left half on the right of the panel and vice versa // (bench-observed 2026-10-18). .window_sequence = {PANEL_579C_GDEY0579F51_WINDOW_SLAVE, PANEL_579C_GDEY0579F51_WINDOW_MASTER}, .window_sequence_len = {sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE[0]), sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER[0])}, .window_per_plane = true, .plane_count = 2, // plane 0 = left half -> chip 0x02; plane 1 = right half -> chip 0x01 .plane_write_cmd = {0x10, 0x10}, .plane_invert = {false, false}, .plane_width = 396, // each region's own local width .row_interleave = true, .bits_per_pixel = 2, .palette = GXEPD2_PALETTE_4C, .palette_len = GXEPD2_PALETTE_4C_LEN, .blank_code = 0x01, .refresh_sequence = PANEL_579C_GDEY0579F51_REFRESH, .refresh_sequence_len = sizeof(PANEL_579C_GDEY0579F51_REFRESH) / sizeof(PANEL_579C_GDEY0579F51_REFRESH[0]), }; } // namespace esphome::gxepd2