Arduino.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. // Minimal standalone Arduino.h stand-in for compiling one vendor GxEPD2
  3. // driver on a dev machine (plain g++/clang, not the ESP-IDF toolchain) so
  4. // its real command/data byte trace can be observed directly, instead of
  5. // statically parsed. Shape mirrors ../../third_party/arduino_compat/
  6. // Arduino.h (same symbols GxEPD2 needs), but every call here logs to
  7. // ../trace.h instead of touching real hardware via esphome.
  8. #include <cstdint>
  9. #include <cstdio>
  10. #include <sstream>
  11. #include <string>
  12. #include "../trace.h"
  13. // Vendor source branches on this to pick <pgmspace.h> over <avr/pgmspace.h>
  14. // - defining it is simpler than providing a fake avr/ include directory.
  15. #ifndef ESP32
  16. #define ESP32
  17. #endif
  18. #define HIGH 1
  19. #define LOW 0
  20. #define INPUT 0
  21. #define OUTPUT 1
  22. #define INPUT_PULLUP 2
  23. inline void pinMode(int16_t pin, uint8_t mode) { Trace::pin_mode(pin, mode); }
  24. inline void digitalWrite(int16_t pin, uint8_t value) {
  25. Trace::digital_write(pin, value);
  26. Trace::note_digital_write_for_dc(pin, value);
  27. }
  28. inline int digitalRead(int16_t pin) { return Trace::digital_read(pin); }
  29. inline void delay(uint32_t ms) { Trace::delay_ms(ms); }
  30. inline uint32_t millis() { return 0; }
  31. inline uint32_t micros() { return 0; }
  32. inline void yield() {}
  33. #define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t *>(addr))
  34. // No PROGMEM distinction on a dev machine - expands to nothing, so vendor
  35. // definitions like `const unsigned char Cls::lut[] PROGMEM = {...}` (used by
  36. // the partial-refresh LUT tables in several drivers, e.g. GDEY075T7) compile
  37. // host-side. Harmless for drivers that don't use it.
  38. #define PROGMEM
  39. // GxEPD2_EPD::_waitWhileBusy()'s diagnostic prints (opt-in, never enabled
  40. // here since the harness passes serial_diag_bitrate=0 to init()) and the
  41. // unconditional "Busy Timeout!" warning both go through this - harmless to
  42. // drop for this pass, we already observe the busy-check via digitalRead().
  43. class HarnessSerialShim {
  44. public:
  45. void begin(uint32_t) {}
  46. template<typename T> void print(T value) {}
  47. template<typename T> void println(T value) {}
  48. void println() {}
  49. };
  50. inline HarnessSerialShim Serial;