epd_command.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <cstdint>
  3. namespace esphome::gxepd2 {
  4. // One command byte plus its (fixed, compile-time) data bytes, as sent by
  5. // GxEPD2_EPD::_writeCommand()/_writeData(). delay_before_ms/delay_after_ms
  6. // and wait_busy_after mirror the fixed delay()s and _waitWhileBusy() calls
  7. // bracketing specific commands in the vendor source (which command gets
  8. // which varies per panel - e.g. GxEPD2_213_Z98c delays 10ms on both sides
  9. // of its SWRESET, while GxEPD2_154_Z90c busy-waits after its SWRESET
  10. // instead). At most one of delay_after_ms/wait_busy_after is expected to be
  11. // set on any one command.
  12. struct EpdCommand {
  13. uint8_t cmd;
  14. const uint8_t *data; // nullptr if the command takes no data bytes
  15. uint8_t data_len;
  16. uint16_t delay_before_ms{0};
  17. uint16_t delay_after_ms{0};
  18. bool wait_busy_after{false};
  19. };
  20. // Everything CycleEngine needs to drive one panel, hand-derived from a
  21. // GxEPD2 vendor driver's .cpp/.h (see panel_154_z90c.h). Only what this
  22. // first slice's engine actually uses - the RAM-window-set command layout
  23. // (0x44/0x45/0x4E/0x4F) is common to every panel inspected so far and is
  24. // hardcoded in CycleEngine itself rather than made part of this struct;
  25. // revisit if/when the extraction-tooling phase finds a controller family
  26. // that lays it out differently.
  27. struct EpdPanelDescriptor {
  28. uint16_t width;
  29. uint16_t height;
  30. bool busy_active_level; // digitalRead() level meaning "still busy"
  31. uint32_t busy_timeout_ms; // ceiling for every busy wait (init and refresh alike)
  32. const EpdCommand *init_sequence; // run once, after the reset pulse
  33. uint8_t init_sequence_len;
  34. // Sets the (always full-frame, since this engine has no partial-window
  35. // support) RAM addressing window, run once after init_sequence and before
  36. // the first plane byte burst. Was hardcoded into CycleEngine assuming
  37. // every controller shares SSD1680's 0x44/0x45/0x4E/0x4F byte-column
  38. // layout - GxEPD2_426_GDEQ0426T82 (SSD1677) turned out to address in raw
  39. // pixels with reversed Y and re-issues its entry-mode command here, and
  40. // GxEPD2_583_GDEQ0583T31 (UC8179) uses one 0x90 command bracketed by
  41. // 0x91/0x92 markers instead. Made per-panel data, same as init/refresh,
  42. // rather than special-cased in the engine.
  43. const EpdCommand *window_sequence;
  44. uint8_t window_sequence_len;
  45. uint8_t plane_count; // 1 (BW) or 2 (BW + one accent color)
  46. uint8_t plane_write_cmd[2]; // e.g. {0x24, 0x26}
  47. bool plane_invert[2]; // true if the byte must be bit-inverted on write
  48. // true for the JD79667/HX8717-family 4-color panels (GDEY029F51,
  49. // GDEY0579F51): pixels are 2 bits each, 4 per byte, built from a
  50. // white/black/red classification at draw time - a fundamentally
  51. // different buffer shape than the 1-bit-per-pixel plane(s) above, not
  52. // just a different invert/command byte. When true, plane_count/
  53. // plane_invert are unused (always effectively 1 packed plane,
  54. // plane_write_cmd[0] still names the write command) and
  55. // GxEPD2Display's buffer is width*height/4 bytes instead of /8.
  56. bool packed_2bpp_plane{false};
  57. const EpdCommand *refresh_sequence; // e.g. 0x22/0xF7 then trigger 0x20
  58. uint8_t refresh_sequence_len;
  59. };
  60. } // namespace esphome::gxepd2