run_wrapper_harness.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. // Drives a real GxEPD2_BW<Driver,H>/GxEPD2_3C<Driver,H> wrapper template -
  3. // the actual class GxEPD2 example sketches (and the pre-rewrite gxepd2
  4. // component) instantiate - through one full-screen update via its real
  5. // public API (init/setFullWindow/firstPage/fillScreen+drawPixel/nextPage),
  6. // instead of calling the bare driver's writeImage()/refresh() ourselves.
  7. // This is what actually exercises whatever the wrapper's own firstPage()/
  8. // nextPage() do internally (writeImageForFullRefresh, embedded priming,
  9. // etc.) - which run_harness.h's direct calls don't necessarily match.
  10. #include <cstdio>
  11. #include "spy/Adafruit_GFX.h"
  12. #include "spy/Arduino.h"
  13. #include "spy/SPI.h"
  14. #include "trace.h"
  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. // WrapperT: GxEPD2_BW<PeekDriverT, H> or GxEPD2_3C<PeekDriverT, H> -
  21. // the caller picks which, since that's a fact about the panel (its
  22. // catalog.json "wrapper" field), not something this harness infers.
  23. // PeekDriverT: the same Peek<Driver> passed as WrapperT's first template
  24. // argument - repeated here since GxEPD2_BW/3C don't expose it as a nested
  25. // typedef we could pull back out.
  26. template<typename WrapperT, typename PeekDriverT> void run_wrapper_harness(const char *name, bool three_color) {
  27. printf("=== %s (via wrapper template) ===\n", name);
  28. constexpr int16_t CS = 10, DC = 11, RST = 12, BUSY = 13;
  29. Trace::set_dc_pin(DC);
  30. WrapperT display(PeekDriverT(CS, DC, RST, BUSY));
  31. printf("busy_level=%d reset_duration=%u\n", display.epd2.busy_level(), display.epd2.reset_duration());
  32. Trace::last_busy_release_value = display.epd2.busy_level() == HIGH ? LOW : HIGH;
  33. display.epd2.selectSPI(SPI, SPISettings());
  34. printf("--- init(0) ---\n");
  35. display.init(0);
  36. printf("--- setFullWindow/firstPage/fillScreen+drawPixel/nextPage ---\n");
  37. display.setFullWindow();
  38. display.firstPage();
  39. do {
  40. display.fillScreen(GxEPD_WHITE);
  41. display.drawPixel(0, 0, GxEPD_BLACK);
  42. if (three_color)
  43. display.drawPixel(1, 0, GxEPD_RED);
  44. } while (display.nextPage());
  45. }