panel_579c_gdey0579f51.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. // Hand-derived from vendor/src/epd4c/GxEPD2_579c_GDEY0579F51.{h,cpp}
  3. // (GDEY0579F51, HX8717 controller, 792x272, same JD79667-family 2bpp/4-color
  4. // packing as GDEY029F51 - see panel_290c_gdey029f51.h). The real dual-
  5. // region version, superseding panel_579c_gdey0579f51_master_only.h's
  6. // deliberate single-region simplification - uses CycleEngine's
  7. // window_per_plane mechanism to give "master" and "slave" (0xA2-select
  8. // logical regions, not separate physical CS pins) their own window-set
  9. // before each one's own 0x10 byte burst, "plane 0"/"plane 1" in the
  10. // engine's terms even though they're physical regions here, not black/red
  11. // color planes - see EpdPanelDescriptor::window_per_plane.
  12. //
  13. // Region physical placement (2026-09-19, confirmed two independent ways):
  14. // GxEPD2_579_GDEY0579T93.cpp (SSD1683, same 792x272 panel family) comments
  15. // its own master/slave split explicitly - "near connector" = slave,
  16. // "opposite to connector" = master. User independently confirmed the same
  17. // physical mapping driving this actual panel with the GDEY0213F51 driver
  18. // (same underlying chip): master = away from the FPC connector. So master
  19. // is region 0 here (window_sequence[0], written first, right after init
  20. // leaves the controller select=master already) and slave is region 1.
  21. //
  22. // PSR values corrected (2026-09-19) against Waveshare's own epd5in79g.cpp
  23. // reference driver (extracted from their official demo archive for this
  24. // exact module) - GxEPD2's driver has master(0x01)->{0x07,0x29},
  25. // slave(0x02)->{0x03,0x29}; Waveshare's has them swapped:
  26. // master(0x01)->{0x03,0x29}, slave(0x02)->{0x07,0x29}. The two PSR values
  27. // differ only in the SHL bit (source/column scan-shift direction per the
  28. // HX8717 command table) - GxEPD2 apparently has this backwards for this
  29. // panel, which lines up with the left-right-mirrored text seen on
  30. // hardware. Followed Waveshare's reference here, not GxEPD2's.
  31. //
  32. // The master-only descriptor's single-region run showed real, correctly-
  33. // decoded content but compressed/duplicated within half the driven
  34. // region's own width, plus noise/black bands on the untouched slave half.
  35. // The noise was explained and fixed there (0x12's refresh trigger fires a
  36. // real electrical refresh across the WHOLE panel regardless of 0xA2
  37. // select, so refreshing with slave's RAM never written "developed" its
  38. // stale/undefined content) - this descriptor writes both regions before
  39. // refreshing, which should eliminate that on its own. The duplication
  40. // artifact's cause is still unconfirmed; writing both regions may or may
  41. // not resolve it - that's what this descriptor is for finding out.
  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. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_MASTER[] = {0x03, 0x29};
  48. inline const uint8_t PANEL_579C_GDEY0579F51_PSR_SLAVE[] = {0x07, 0x29};
  49. inline const uint8_t PANEL_579C_GDEY0579F51_BTST[] = {0x38, 0x38, 0x38, 0x00};
  50. inline const uint8_t PANEL_579C_GDEY0579F51_TRES[] = {0x01, 0x8C, 0x01, 0x10}; // 396x272 - one region's resolution
  51. inline const uint8_t PANEL_579C_GDEY0579F51_CDI_INIT[] = {0x97};
  52. inline const uint8_t PANEL_579C_GDEY0579F51_E9[] = {0x01};
  53. inline const uint8_t PANEL_579C_GDEY0579F51_E0[] = {0x01};
  54. // Init(), following Waveshare's own epd5in79g.cpp exactly (command order
  55. // and select state matter here, not just which bytes get sent): PSR
  56. // written to each side individually, then CDI/TRES/BTST/E9/E0 written
  57. // once under select=Both since they're genuinely shared/global registers
  58. // - and, critically, POWER-ON (0x04) is sent while select is STILL Both,
  59. // not re-selecting master first. This engine's first attempt added an
  60. // extra "reselect master" step before 0x04 that Waveshare's reference
  61. // does not have, meaning only master's chip was ever actually powered on
  62. // - a very plausible explanation for slave showing a persistent noise/
  63. // garbage artifact regardless of what data it's given (2026-09-19).
  64. inline const EpdCommand PANEL_579C_GDEY0579F51_INIT[] = {
  65. {0xA2, PANEL_579C_GDEY0579F51_SELECT_MASTER, 1},
  66. {0x00, PANEL_579C_GDEY0579F51_PSR_MASTER, 2},
  67. {0xA2, PANEL_579C_GDEY0579F51_SELECT_SLAVE, 1},
  68. {0x00, PANEL_579C_GDEY0579F51_PSR_SLAVE, 2},
  69. {0xA2, PANEL_579C_GDEY0579F51_SELECT_BOTH, 1},
  70. {0x50, PANEL_579C_GDEY0579F51_CDI_INIT, 1},
  71. {0x61, PANEL_579C_GDEY0579F51_TRES, 4},
  72. {0x06, PANEL_579C_GDEY0579F51_BTST, 4},
  73. {0xE9, PANEL_579C_GDEY0579F51_E9, 1},
  74. {0xE0, PANEL_579C_GDEY0579F51_E0, 1},
  75. {0x04, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true}, // power on, select=Both
  76. };
  77. // _setPartialRamAreaMaster/Slave(0, 0, 396, 272), default partial_mode=true
  78. // - both regions are the same shape, just a different select byte.
  79. inline const uint8_t PANEL_579C_GDEY0579F51_WINDOW_REGION[] = {
  80. 0x00, 0x00, // x/256, x%256 = 0
  81. 0x01, 0x8B, // xe/256, xe%256 = 395
  82. 0x00, 0x00, // y/256, y%256 = 0
  83. 0x01, 0x0F, // ye/256, ye%256 = 271
  84. 0x01,
  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): vendor's own _setPartialRamAreaBoth(0,0,396,272) then
  95. // _refresh(false) - select=Both is correct here (unlike the master-only
  96. // descriptor) since both regions' RAM genuinely holds real content now.
  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 EpdPanelDescriptor PANEL_579C_GDEY0579F51 = {
  107. .width = 792, // full logical panel - the canvas ESPHome draws into
  108. .height = 272,
  109. .busy_active_level = false, // GxEPD2_EPD(..., /*busy_level=*/LOW, ...)
  110. .busy_timeout_ms = 25000, // full_refresh_time is 21000ms
  111. .init_sequence = PANEL_579C_GDEY0579F51_INIT,
  112. .init_sequence_len = sizeof(PANEL_579C_GDEY0579F51_INIT) / sizeof(PANEL_579C_GDEY0579F51_INIT[0]),
  113. .window_sequence = {PANEL_579C_GDEY0579F51_WINDOW_MASTER, PANEL_579C_GDEY0579F51_WINDOW_SLAVE},
  114. .window_sequence_len = {sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_MASTER[0]),
  115. sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE) / sizeof(PANEL_579C_GDEY0579F51_WINDOW_SLAVE[0])},
  116. .window_per_plane = true,
  117. .plane_count = 2, // "plane" 0 = master region, "plane" 1 = slave region
  118. .plane_write_cmd = {0x10, 0x10},
  119. .plane_invert = {false, false},
  120. .plane_width = 396, // each region's own local width
  121. .row_interleave = true,
  122. .packed_2bpp_plane = true,
  123. .refresh_sequence = PANEL_579C_GDEY0579F51_REFRESH,
  124. .refresh_sequence_len = sizeof(PANEL_579C_GDEY0579F51_REFRESH) / sizeof(PANEL_579C_GDEY0579F51_REFRESH[0]),
  125. };
  126. } // namespace esphome::gxepd2