panel_579c_gdey0579f51.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #pragma once
  2. // GDEY0579F51 - HX8717 dual-chip, 792x272, 4-color, 2bpp packed (same
  3. // JD79667-family packing as GDEY029F51, see panel_290c_gdey029f51.h).
  4. //
  5. // Captured from the STOCK vendored driver
  6. // (third_party/GxEPD2/src/epd4c/GxEPD2_579c_GDEY0579F51.{h,cpp}) and kept
  7. // byte-for-byte stock EXCEPT the PSR source-scan bytes (see PSR_MASTER/
  8. // PSR_SLAVE below) - those are swapped to Waveshare's orientation because
  9. // the stock values render this panel left-right mirrored on hardware.
  10. //
  11. // History worth not repeating: an earlier revision carried a pile of
  12. // hand-"fixes" from Waveshare's epd5in79g.cpp - swapped PSR, power-on under
  13. // select=Both, a changed BTST - all introduced together to chase mirrored
  14. // text AND a slave region that never converged. The bench (2026-10-18)
  15. // separated the two: the non-convergence was DRIVE-CURRENT STARVATION on
  16. // the bench MCU (not a driver bug - the same panel + firmware renders on an
  17. // adequately-powered board), so power-on-select and BTST were red herrings
  18. // and are back to stock here; only the PSR scan-direction swap was doing
  19. // real work (fixing the mirror) and is kept. Window + refresh are the fresh
  20. // capture, unchanged.
  21. //
  22. // Dual-region layer assembled by hand from the driver source, per
  23. // CONTRIBUTING.md "Limits - True dual-region command structure": the
  24. // emitter's segmentation doesn't model the 0xA2 master/slave region selects.
  25. // Window geometry and refresh were taken from the capture (byte-exact);
  26. // the init below transcribes the stock _InitDisplay() directly (the emitter
  27. // can't recover a dual-chip init - _InitDisplay runs during the earlier
  28. // writeScreenBuffer clear, so nothing is left in the writeImage pre-block).
  29. //
  30. // Region mapping: master = away from the FPC connector = region 0 (written
  31. // first), slave = near connector = region 1 (cross-checked against
  32. // GxEPD2_579_GDEY0579T93.cpp's own master/slave comments). "plane 0/1" in
  33. // the engine's terms are these two physical regions, not color planes;
  34. // window_per_plane gives each its own 0xA2-select window-set before its own
  35. // 0x10 byte burst.
  36. #include "epd_command.h"
  37. namespace esphome::gxepd2 {
  38. inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_MASTER[] = {0x01};
  39. inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_SLAVE[] = {0x02};
  40. inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_BOTH[] = {0x00};
  41. // PSR source-scan (SHL) bytes are the ONE deviation from the stock driver:
  42. // stock is master {0x07,0x29} / slave {0x03,0x29}, which renders this panel
  43. // left-right MIRRORED (text backwards) on hardware. The two values differ
  44. // only in the source-scan-direction bit; swapping which half gets it (the
  45. // value Waveshare's epd5in79g.cpp uses) un-mirrors it - confirmed on the
  46. // bench 2026-10-18. This is a real per-panel orientation fix and is
  47. // unrelated to the drive-current issue that explained the old "slave won't
  48. // converge" symptom; everything else here stays stock.
  49. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_MASTER[] = {0x03, 0x29};
  50. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_SLAVE[] = {0x07, 0x29};
  51. inline const uint8_t PANEL_579C_GDEY0579F51_BTST[] = {0x32, 0x32, 0x32, 0x32};
  52. inline const uint8_t PANEL_579C_GDEY0579F51_TRES[] = {0x01, 0x8C, 0x01, 0x10}; // 396x272 - one region
  53. inline const uint8_t PANEL_579C_GDEY0579F51_CDI_INIT[] = {0x97}; // border white
  54. inline const uint8_t PANEL_579C_GDEY0579F51_E9[] = {0x01};
  55. inline const uint8_t PANEL_579C_GDEY0579F51_E0[] = {0x01};
  56. // Stock _InitDisplay(): PSR written to each region under its own select,
  57. // then BTST/TRES/CDI/E9/E0 under select=Both, then re-select MASTER and
  58. // power-on (0x04). This is the vendor's order and select-state exactly.
  59. inline const EpdCommand PANEL_579C_GDEY0579F51_INIT[] = {
  60. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  61. {0x00, PANEL_579C_GDEY0579F51_PSR_MASTER, 2},
  62. {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1},
  63. {0x00, PANEL_579C_GDEY0579F51_PSR_SLAVE, 2},
  64. {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1},
  65. {0x06, PANEL_579C_GDEY0579F51_BTST, 4},
  66. {0x61, PANEL_579C_GDEY0579F51_TRES, 4},
  67. {0x50, PANEL_579C_GDEY0579F51_CDI_INIT, 1},
  68. {0xE9, PANEL_579C_GDEY0579F51_E9, 1},
  69. {0xE0, PANEL_579C_GDEY0579F51_E0, 1},
  70. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  71. {0x04, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true}, // power on
  72. };
  73. // _setPartialRamArea*(0, 0, 396, 272) with partial_mode=true: both regions
  74. // are the same shape, differing only in the 0xA2 select byte sent first.
  75. inline const uint8_t PANEL_579C_GDEY0579F51_WINDOW_REGION[] = {
  76. 0x00, 0x00, // x = 0
  77. 0x01, 0x8B, // x+w-1 = 395
  78. 0x00, 0x00, // y = 0
  79. 0x01, 0x0F, // y+h-1 = 271
  80. 0x01, // partial_mode
  81. };
  82. inline const EpdCommand PANEL_579C_GDEY0579F51_WINDOW_MASTER[] = {
  83. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  84. {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9},
  85. };
  86. inline const EpdCommand PANEL_579C_GDEY0579F51_WINDOW_SLAVE[] = {
  87. {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1},
  88. {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9},
  89. };
  90. // refresh(false): stock _setPartialRamAreaBoth(0,0,396,272) then _refresh:
  91. // CDI 0x50=0x37 (white), then 0x12 trigger (power-on 0x04 is skipped here -
  92. // already on from init).
  93. inline const uint8_t PANEL_579C_GDEY0579F51_CDI_REFRESH[] = {0x37};
  94. inline const uint8_t PANEL_579C_GDEY0579F51_REFRESH_TRIGGER[] = {0x00};
  95. inline const EpdCommand PANEL_579C_GDEY0579F51_REFRESH[] = {
  96. {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1},
  97. {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9},
  98. {0x50, PANEL_579C_GDEY0579F51_CDI_REFRESH, 1},
  99. {0x12, PANEL_579C_GDEY0579F51_REFRESH_TRIGGER, 1, /*delay_before_ms=*/0, /*delay_after_ms=*/0,
  100. /*wait_busy_after=*/true},
  101. };
  102. inline const EpdPanelDescriptor PANEL_579C_GDEY0579F51 = {
  103. .width = 792, // full logical panel - the canvas ESPHome draws into
  104. .height = 272,
  105. .busy_active_level = false, // GxEPD2_EPD(..., /*busy_level=*/LOW, ...)
  106. .busy_timeout_ms = 40000, // vendor full_refresh_time is 21000ms, but it's
  107. // a soft estimate (GxEPD2 polls BUSY past it);
  108. // give a 4-color refresh real headroom before
  109. // the engine hard-aborts
  110. .init_sequence = PANEL_579C_GDEY0579F51_INIT,
  111. .init_sequence_len = sizeof(PANEL_579C_GDEY0579F51_INIT) / sizeof(PANEL_579C_GDEY0579F51_INIT[0]),
  112. // plane 0 is the LEFT half of the canvas (draw_packed_ splits at
  113. // plane_width), plane 1 the RIGHT half. With the swapped PSR scan
  114. // direction, chip 0x02 (slave) drives the left of the glass and chip
  115. // 0x01 (master) the right, so route plane 0 -> slave-select window and
  116. // plane 1 -> master-select. Sending them in physical-chip order instead
  117. // put the left half on the right of the panel and vice versa
  118. // (bench-observed 2026-10-18).
  119. .window_sequence = {PANEL_579C_GDEY0579F51_WINDOW_SLAVE, PANEL_579C_GDEY0579F51_WINDOW_MASTER},
  120. .window_sequence_len = {sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE[0]),
  121. sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER[0])},
  122. .window_per_plane = true,
  123. .plane_count = 2, // plane 0 = left half -> chip 0x02; plane 1 = right half -> chip 0x01
  124. .plane_write_cmd = {0x10, 0x10},
  125. .plane_invert = {false, false},
  126. .plane_width = 396, // each region's own local width
  127. .row_interleave = true,
  128. .bits_per_pixel = 2,
  129. .palette = GXEPD2_PALETTE_4C,
  130. .palette_len = GXEPD2_PALETTE_4C_LEN,
  131. .blank_code = 0x01,
  132. .refresh_sequence = PANEL_579C_GDEY0579F51_REFRESH,
  133. .refresh_sequence_len = sizeof(PANEL_579C_GDEY0579F51_REFRESH) / sizeof(PANEL_579C_GDEY0579F51_REFRESH[0]),
  134. };
  135. } // namespace esphome::gxepd2