panel_579c_gdey0579f51.h 8.2 KB

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