run_harness.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. // Drives one vendor GxEPD2 driver through the same low-level calls the
  3. // GxEPD2_BW/GxEPD2_3C wrapper templates make for a single non-paged full
  4. // update (writeImage() then refresh()) - bypassing the wrapper templates
  5. // themselves (and their Adafruit_GFX dependency) since we only need the
  6. // driver-level trace, not drawing helpers.
  7. #include <cstdio>
  8. #include <cstring>
  9. #include "spy/Arduino.h"
  10. #include "spy/SPI.h"
  11. #include "trace.h"
  12. // Exposes GxEPD2_EPD's protected busy_level/reset_duration without needing
  13. // to parse anything - a subclass can read its own base class's protected
  14. // members directly.
  15. template<typename Driver> struct Peek : Driver {
  16. using Driver::Driver;
  17. int busy_level() const { return this->_busy_level; }
  18. uint16_t reset_duration() const { return this->_reset_duration; }
  19. };
  20. // planes=1 for monochrome drivers (color buffer still passed - harmless,
  21. // see e.g. GxEPD2_290_T94::writeImage(black,color,...) which just ignores
  22. // a non-null color pointer's absence).
  23. template<typename Driver> void run_harness(const char *name) {
  24. printf("=== %s: WIDTH=%u HEIGHT=%u ===\n", name, (unsigned) Driver::WIDTH, (unsigned) Driver::HEIGHT);
  25. constexpr int16_t CS = 10, DC = 11, RST = 12, BUSY = 13;
  26. Trace::set_dc_pin(DC);
  27. Peek<Driver> driver(CS, DC, RST, BUSY);
  28. printf("busy_level=%d reset_duration=%u\n", driver.busy_level(), driver.reset_duration());
  29. // digitalRead(BUSY) should report "released" immediately - opposite of
  30. // busy_level - so _waitWhileBusy()'s loop exits after one check.
  31. Trace::last_busy_release_value = driver.busy_level() == HIGH ? LOW : HIGH;
  32. driver.selectSPI(SPI, SPISettings());
  33. printf("--- init(0) ---\n");
  34. driver.init(0);
  35. const uint32_t plane_bytes = (static_cast<uint32_t>(Driver::WIDTH) * Driver::HEIGHT) / 8;
  36. auto *black = new uint8_t[plane_bytes];
  37. auto *color = new uint8_t[plane_bytes];
  38. // Distinctive, non-0x00/0xFF pattern - lets a plane's invert flag be
  39. // read directly off the trace (does the wire byte equal 0xA5 or 0x5A).
  40. memset(black, 0xA5, plane_bytes);
  41. memset(color, 0xA5, plane_bytes);
  42. printf("--- writeImage(black, color, 0, 0, WIDTH, HEIGHT) ---\n");
  43. driver.writeImage(black, color, 0, 0, Driver::WIDTH, Driver::HEIGHT);
  44. printf("--- refresh(false) ---\n");
  45. driver.refresh(false);
  46. delete[] black;
  47. delete[] color;
  48. }