panel_213_z98c.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. // Hand-derived from vendor/src/epd3c/GxEPD2_213_Z98c.{h,cpp} (GDEY0213Z98,
  3. // SSD1680 controller, 128x250 RAM window (122 columns visible), black +
  4. // red). This is the panel actually on the bench for this first slice of the
  5. // native chunked engine; see the plan this was implemented from (and
  6. // gxepd2_task_watchdog_status in project memory) for why GxEPD2's own
  7. // control flow is being dropped in favor of just its per-panel data.
  8. #include "epd_command.h"
  9. namespace esphome::gxepd2 {
  10. // GxEPD2_213_Z98c::_InitDisplay(). Unlike GxEPD2_154_Z90c (the panel this
  11. // slice originally targeted), this controller's SWRESET is bracketed by
  12. // fixed 10ms delays rather than a busy-pin wait, and it has an extra
  13. // "Display update control" command (0x21) 154_Z90c doesn't. Minus the
  14. // trailing _setPartialRamArea() - CycleEngine's SET_WINDOW state (used for
  15. // every write, not just init) covers that.
  16. inline const uint8_t PANEL_213_Z98C_DRIVER_OUTPUT_CONTROL[] = {0xF9, 0x00, 0x00};
  17. inline const uint8_t PANEL_213_Z98C_DATA_ENTRY_MODE[] = {0x03};
  18. inline const uint8_t PANEL_213_Z98C_BORDER_WAVEFORM[] = {0x05};
  19. inline const uint8_t PANEL_213_Z98C_TEMP_SENSOR[] = {0x80};
  20. // GxEPD2's vendor source sends {0x00, 0x80} here, but the whole panel came
  21. // out solid black regardless of RAM content with that value on real
  22. // hardware. The known-working epaper_spi driver on this exact same panel/
  23. // wiring (waveshare-2.13in-bv4, see device/epaper-nametag.yaml) sends
  24. // {0x80, 0x80} instead - this register controls per-plane RAM bypass
  25. // options, so a wrong bypass bit here would force a plane to a constant
  26. // value irrespective of what's actually written to it, matching the
  27. // symptom exactly.
  28. inline const uint8_t PANEL_213_Z98C_DISPLAY_UPDATE_CONTROL[] = {0x80, 0x80};
  29. inline const EpdCommand PANEL_213_Z98C_INIT[] = {
  30. {0x12, nullptr, 0, /*delay_before_ms=*/10, /*delay_after_ms=*/10, /*wait_busy_after=*/false}, // SWRESET
  31. {0x01, PANEL_213_Z98C_DRIVER_OUTPUT_CONTROL, 3},
  32. {0x11, PANEL_213_Z98C_DATA_ENTRY_MODE, 1},
  33. {0x3C, PANEL_213_Z98C_BORDER_WAVEFORM, 1},
  34. {0x18, PANEL_213_Z98C_TEMP_SENSOR, 1},
  35. {0x21, PANEL_213_Z98C_DISPLAY_UPDATE_CONTROL, 2},
  36. };
  37. // GxEPD2_213_Z98c::_Update_Full()/_Update_Part() fire a single combined
  38. // trigger (0x22/0xF7 + 0x20) and assume it handles power internally. That
  39. // matched neither hardware symptom we saw (solid black, then solid red) -
  40. // busy genuinely engaged and cleared each time, consistent with a waveform
  41. // that ran without properly stabilized power, not a hang. The known-working
  42. // epaper_spi driver for this exact panel instead brackets the refresh with
  43. // explicit power-on/off triggers, each with its own busy-wait, and resets
  44. // the RAM counters again immediately before the refresh trigger itself:
  45. // POWER_ON (0x22/0xF8 + 0x20, wait busy)
  46. // reset RAM counters (0x4E/0x4F back to 0,0)
  47. // REFRESH (0x22/0xF7 + 0x20, wait busy)
  48. // POWER_OFF (0x22/0x83 + 0x20, wait busy)
  49. // Mirroring that sequence here since GxEPD2's shortcut is what's unproven
  50. // on this specific panel/FPC revision.
  51. inline const uint8_t PANEL_213_Z98C_POWER_ON_MODE[] = {0xF8};
  52. inline const uint8_t PANEL_213_Z98C_UPDATE_MODE[] = {0xF7};
  53. inline const uint8_t PANEL_213_Z98C_POWER_OFF_MODE[] = {0x83};
  54. inline const uint8_t PANEL_213_Z98C_RESET_X_COUNTER[] = {0x00};
  55. inline const uint8_t PANEL_213_Z98C_RESET_Y_COUNTER[] = {0x00, 0x00};
  56. inline const EpdCommand PANEL_213_Z98C_REFRESH[] = {
  57. {0x22, PANEL_213_Z98C_POWER_ON_MODE, 1},
  58. {0x20, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true},
  59. {0x4E, PANEL_213_Z98C_RESET_X_COUNTER, 1},
  60. {0x4F, PANEL_213_Z98C_RESET_Y_COUNTER, 2},
  61. {0x22, PANEL_213_Z98C_UPDATE_MODE, 1},
  62. {0x20, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true},
  63. {0x22, PANEL_213_Z98C_POWER_OFF_MODE, 1},
  64. {0x20, nullptr, 0, /*delay_before_ms=*/0, /*delay_after_ms=*/0, /*wait_busy_after=*/true},
  65. };
  66. // full_refresh_time/partial_refresh_time from the vendor header are both
  67. // 15000ms; used as the ceiling for every busy wait in this slice, not just
  68. // the refresh one it was measured for - simpler than carrying a separate
  69. // timeout per wait site, and erring long only delays reporting a genuine
  70. // timeout, it doesn't cause one.
  71. inline const EpdPanelDescriptor PANEL_213_Z98C = {
  72. .width = 128, // RAM window width - _setPartialRamArea works in this, not WIDTH_VISIBLE (122)
  73. .height = 250,
  74. .busy_active_level = true, // GxEPD2_EPD(..., /*busy_level=*/HIGH, ...)
  75. .busy_timeout_ms = 60000, // temporarily generous - diagnosing a busy-never-clears hang, see commit message
  76. .init_sequence = PANEL_213_Z98C_INIT,
  77. .init_sequence_len = sizeof(PANEL_213_Z98C_INIT) / sizeof(PANEL_213_Z98C_INIT[0]),
  78. .plane_count = 2,
  79. .plane_write_cmd = {0x24, 0x26},
  80. .plane_invert = {false, true}, // color plane written as ~data - see writeImage()
  81. .refresh_sequence = PANEL_213_Z98C_REFRESH,
  82. .refresh_sequence_len = sizeof(PANEL_213_Z98C_REFRESH) / sizeof(PANEL_213_Z98C_REFRESH[0]),
  83. };
  84. } // namespace esphome::gxepd2