epd_command.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. uint8_t plane_count; // 1 (BW) or 2 (BW + one accent color)
  35. uint8_t plane_write_cmd[2]; // e.g. {0x24, 0x26}
  36. bool plane_invert[2]; // true if the byte must be bit-inverted on write
  37. const EpdCommand *refresh_sequence; // e.g. 0x22/0xF7 then trigger 0x20
  38. uint8_t refresh_sequence_len;
  39. };
  40. } // namespace esphome::gxepd2