trace.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. // Flat, ungrouped event log the spy Arduino.h/SPI.h shims append to as a
  3. // real vendor GxEPD2 driver runs. Deliberately NOT grouped into
  4. // EpdCommand-shaped entries here - this exploratory pass prints the raw
  5. // observed event stream and compares it against the hand-written
  6. // panel_213_z98c.h by eye, to learn what the trace actually looks like
  7. // before building a grouping/JSON-emitting post-processor.
  8. #include <cstdint>
  9. #include <cstdio>
  10. enum class EventKind { PIN_MODE, DIGITAL_WRITE, DIGITAL_READ, DELAY, SPI_BEGIN_TXN, SPI_TRANSFER, SPI_SETTINGS };
  11. struct Trace {
  12. static void pin_mode(int pin, int mode) { printf("pinMode(%d, %d)\n", pin, mode); }
  13. static void digital_write(int pin, int value) { printf("digitalWrite(%d, %d)\n", pin, value); }
  14. // Every digitalRead() in these drivers is a busy-pin poll - there's
  15. // nothing else wired as an input. Log it as such and always report
  16. // "released" so _waitWhileBusy()'s loop exits after one check; we
  17. // don't need real timing, just to observe *that* a wait happened here.
  18. static int digital_read(int pin) {
  19. printf("digitalRead(%d) -> busy-check, reporting released\n", pin);
  20. return last_busy_release_value;
  21. }
  22. static void delay_ms(unsigned long ms) { printf("delay(%lu)\n", ms); }
  23. static void spi_settings(uint32_t clock_hz, uint8_t bit_order, uint8_t data_mode) {
  24. printf("SPISettings(clock_hz=%u, bit_order=%u, data_mode=%u)\n", (unsigned) clock_hz, bit_order, data_mode);
  25. }
  26. // dc_state: current logical level of the DC pin at the moment of this
  27. // transfer, as last set via digital_write() on the pin number the
  28. // harness tells us is DC (see set_dc_pin()). true = command byte,
  29. // false = data byte - matches GxEPD2_EPD::_writeCommand()/_writeData()
  30. // exactly (DC low while the command byte goes out, high for data).
  31. static uint8_t spi_transfer(uint8_t byte) {
  32. printf("SPI.transfer(0x%02X) dc=%s\n", byte, dc_is_low ? "LOW(cmd)" : "HIGH(data)");
  33. return 0;
  34. }
  35. static void set_dc_pin(int pin) { dc_pin = pin; }
  36. static void note_digital_write_for_dc(int pin, int value) {
  37. if (pin == dc_pin)
  38. dc_is_low = (value == 0);
  39. }
  40. static inline int dc_pin = -1;
  41. static inline bool dc_is_low = false;
  42. static inline int last_busy_release_value = 0; // overwritten by harness once busy_level is known
  43. };