panel_579c_gdey0579f51.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // Faithful replay of the STOCK vendored driver
  6. // (third_party/GxEPD2/src/epd4c/GxEPD2_579c_GDEY0579F51.{h,cpp}): init, PSR,
  7. // BTST, window, refresh, master/slave split and plane order all match
  8. // GxEPD2's own on-wire behaviour. The only non-default engine setting is
  9. // line_order = PAIRED_EDGES, which reproduces GxEPD2 writeNative's doubled,
  10. // both-edges-to-middle line emission (544 lines/region) - a general engine
  11. // mechanism, not a panel hack. The user confirmed GxEPD2 itself drives this
  12. // panel correctly when run natively, so a byte-faithful replay is correct by
  13. // construction.
  14. //
  15. // History worth not repeating: an earlier revision carried hand-"fixes" from
  16. // Waveshare's epd5in79g.cpp (swapped PSR, power-on under select=Both, changed
  17. // BTST) plus, on 2026-10-18, a PSR scan-direction swap + window-order swap to
  18. // chase a left-right mirror and swapped halves. The bench showed those were
  19. // ALL compensating for two separate real issues, neither a driver bug:
  20. // - the "slave never converges" symptom was DRIVE-CURRENT STARVATION on the
  21. // bench MCU (same panel + firmware renders on an adequately-powered
  22. // board), so power-on-select and BTST are back to stock;
  23. // - the mirror + swapped halves were the engine sending ONE line per row
  24. // where GxEPD2 sends TWO (line_order below), so the PSR/window swaps are
  25. // gone too.
  26. // Only busy_timeout_ms is tuned (engine hard-aborts where GxEPD2 polls on).
  27. //
  28. // Dual-region layer assembled by hand from the driver source, per
  29. // CONTRIBUTING.md "Limits - True dual-region command structure": the
  30. // emitter's segmentation doesn't model the 0xA2 master/slave region selects.
  31. // Window geometry and refresh were taken from the capture (byte-exact);
  32. // the init below transcribes the stock _InitDisplay() directly (the emitter
  33. // can't recover a dual-chip init - _InitDisplay runs during the earlier
  34. // writeScreenBuffer clear, so nothing is left in the writeImage pre-block).
  35. //
  36. // Region mapping: master = away from the FPC connector = region 0 (written
  37. // first), slave = near connector = region 1 (cross-checked against
  38. // GxEPD2_579_GDEY0579T93.cpp's own master/slave comments). "plane 0/1" in
  39. // the engine's terms are these two physical regions, not color planes;
  40. // window_per_plane gives each its own 0xA2-select window-set before its own
  41. // 0x10 byte burst.
  42. #include "epd_command.h"
  43. namespace esphome::gxepd2 {
  44. inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_MASTER[] = {0x01};
  45. inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_SLAVE[] = {0x02};
  46. inline const uint8_t PANEL_579C_GDEY0579F51_SELECT_BOTH[] = {0x00};
  47. // Stock PSR values, matching GxEPD2's _InitDisplay() exactly: master
  48. // {0x07,0x29}, slave {0x03,0x29}. (A brief detour on 2026-10-18 swapped
  49. // these to "fix" a left-right mirror, but the mirror was an artifact of the
  50. // engine sending one line per row instead of GxEPD2's two - see line_order
  51. // below. With the line order faithful, the stock PSR is correct and the
  52. // swap is gone.)
  53. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_MASTER[] = {0x07, 0x29};
  54. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_SLAVE[] = {0x03, 0x29};
  55. inline const uint8_t PANEL_579C_GDEY0579F51_BTST[] = {0x32, 0x32, 0x32, 0x32};
  56. inline const uint8_t PANEL_579C_GDEY0579F51_TRES[] = {0x01, 0x8C, 0x01, 0x10}; // 396x272 - one region
  57. inline const uint8_t PANEL_579C_GDEY0579F51_CDI_INIT[] = {0x97}; // border white
  58. inline const uint8_t PANEL_579C_GDEY0579F51_E9[] = {0x01};
  59. inline const uint8_t PANEL_579C_GDEY0579F51_E0[] = {0x01};
  60. // Stock _InitDisplay(): PSR written to each region under its own select,
  61. // then BTST/TRES/CDI/E9/E0 under select=Both, then re-select MASTER and
  62. // power-on (0x04). This is the vendor's order and select-state exactly.
  63. inline const EpdCommand PANEL_579C_GDEY0579F51_INIT[] = {
  64. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  65. {0x00, PANEL_579C_GDEY0579F51_PSR_MASTER, 2},
  66. {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1},
  67. {0x00, PANEL_579C_GDEY0579F51_PSR_SLAVE, 2},
  68. {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1},
  69. {0x06, PANEL_579C_GDEY0579F51_BTST, 4},
  70. {0x61, PANEL_579C_GDEY0579F51_TRES, 4},
  71. {0x50, PANEL_579C_GDEY0579F51_CDI_INIT, 1},
  72. {0xE9, PANEL_579C_GDEY0579F51_E9, 1},
  73. {0xE0, PANEL_579C_GDEY0579F51_E0, 1},
  74. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  75. {0x04, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true}, // power on
  76. };
  77. // _setPartialRamArea*(0, 0, 396, 272) with partial_mode=true: both regions
  78. // are the same shape, differing only in the 0xA2 select byte sent first.
  79. inline const uint8_t PANEL_579C_GDEY0579F51_WINDOW_REGION[] = {
  80. 0x00, 0x00, // x = 0
  81. 0x01, 0x8B, // x+w-1 = 395
  82. 0x00, 0x00, // y = 0
  83. 0x01, 0x0F, // y+h-1 = 271
  84. 0x01, // partial_mode
  85. };
  86. inline const EpdCommand PANEL_579C_GDEY0579F51_WINDOW_MASTER[] = {
  87. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  88. {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9},
  89. };
  90. inline const EpdCommand PANEL_579C_GDEY0579F51_WINDOW_SLAVE[] = {
  91. {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1},
  92. {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9},
  93. };
  94. // refresh(false): stock _setPartialRamAreaBoth(0,0,396,272) then _refresh:
  95. // CDI 0x50=0x37 (white), then 0x12 trigger (power-on 0x04 is skipped here -
  96. // already on from init).
  97. inline const uint8_t PANEL_579C_GDEY0579F51_CDI_REFRESH[] = {0x37};
  98. inline const uint8_t PANEL_579C_GDEY0579F51_REFRESH_TRIGGER[] = {0x00};
  99. inline const EpdCommand PANEL_579C_GDEY0579F51_REFRESH[] = {
  100. {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1},
  101. {0x83, PANEL_579C_GDEY0579F51_WINDOW_REGION, 9},
  102. {0x50, PANEL_579C_GDEY0579F51_CDI_REFRESH, 1},
  103. {0x12, PANEL_579C_GDEY0579F51_REFRESH_TRIGGER, 1, /*delay_before_ms=*/0, /*delay_after_ms=*/0,
  104. /*wait_busy_after=*/true},
  105. };
  106. inline const uint8_t PANEL_579C_GDEY0579F51_POWER_OFF_0_02[] = {0x00};
  107. inline const EpdCommand PANEL_579C_GDEY0579F51_POWER_OFF[] = {
  108. {0x02, PANEL_579C_GDEY0579F51_POWER_OFF_0_02, 1, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true},
  109. };
  110. inline const uint8_t PANEL_579C_GDEY0579F51_HIBERNATE_0_07[] = {0xA5};
  111. inline const EpdCommand PANEL_579C_GDEY0579F51_HIBERNATE[] = {
  112. {0x07, PANEL_579C_GDEY0579F51_HIBERNATE_0_07, 1},
  113. };
  114. inline const EpdPanelDescriptor PANEL_579C_GDEY0579F51 = {
  115. .width = 792, // full logical panel - the canvas ESPHome draws into
  116. .height = 272,
  117. .busy_active_level = false, // GxEPD2_EPD(..., /*busy_level=*/LOW, ...)
  118. .busy_timeout_ms = 40000, // vendor full_refresh_time is 21000ms, but it's
  119. // a soft estimate (GxEPD2 polls BUSY past it);
  120. // give a 4-color refresh real headroom before
  121. // the engine hard-aborts
  122. .init_sequence = PANEL_579C_GDEY0579F51_INIT,
  123. .init_sequence_len = sizeof(PANEL_579C_GDEY0579F51_INIT) / sizeof(PANEL_579C_GDEY0579F51_INIT[0]),
  124. // plane 0 = LEFT canvas half -> master (chip 0x01), plane 1 = RIGHT half
  125. // -> slave (chip 0x02), matching GxEPD2 writeNative's MasterSide/SlaveSide
  126. // split (left<WIDTH/2 -> master). (The 2026-10-18 detour swapped this to
  127. // compensate for the one-line-per-row bug; with line_order faithful it's
  128. // back to GxEPD2's own order.)
  129. .window_sequence = {PANEL_579C_GDEY0579F51_WINDOW_MASTER, PANEL_579C_GDEY0579F51_WINDOW_SLAVE},
  130. .window_sequence_len = {sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER[0]),
  131. sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE[0])},
  132. .window_per_plane = true,
  133. .plane_count = 2, // plane 0 = left half -> chip 0x01 (master); plane 1 = right half -> chip 0x02 (slave)
  134. .plane_write_cmd = {0x10, 0x10},
  135. .plane_invert = {false, false},
  136. .plane_width = 396, // each region's own local width
  137. // GxEPD2 writeNative sends each region as 544 lines (2x272) in paired
  138. // top/bottom-from-edges order, filling a 2x-height RAM - reproduce that
  139. // exactly rather than one line per row. This is what makes the stock PSR
  140. // and window order render correctly; the earlier swaps were compensating
  141. // for not doing it.
  142. .line_order = LineOrder::PAIRED_EDGES,
  143. .bits_per_pixel = 2,
  144. .palette = GXEPD2_PALETTE_4C,
  145. .palette_len = GXEPD2_PALETTE_4C_LEN,
  146. .blank_code = 0x01,
  147. .refresh_sequence = PANEL_579C_GDEY0579F51_REFRESH,
  148. .refresh_sequence_len = sizeof(PANEL_579C_GDEY0579F51_REFRESH) / sizeof(PANEL_579C_GDEY0579F51_REFRESH[0]),
  149. .power_off_sequence = PANEL_579C_GDEY0579F51_POWER_OFF,
  150. .power_off_sequence_len = sizeof(PANEL_579C_GDEY0579F51_POWER_OFF) / sizeof(PANEL_579C_GDEY0579F51_POWER_OFF[0]),
  151. .hibernate_sequence = PANEL_579C_GDEY0579F51_HIBERNATE,
  152. .hibernate_sequence_len = sizeof(PANEL_579C_GDEY0579F51_HIBERNATE) / sizeof(PANEL_579C_GDEY0579F51_HIBERNATE[0]),
  153. };
  154. } // namespace esphome::gxepd2