Arduino.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. // Minimal Arduino.h substitute for compiling GxEPD2 under ESP-IDF. GxEPD2's
  3. // vendored source calls down into a small, fixed set of Arduino primitives
  4. // (digitalWrite/pinMode/digitalRead on plain int16_t pin numbers, plus
  5. // delay/micros/yield) - this shim backs them with esphome::GPIOPin via
  6. // PinRegistry, so GxEPD2 compiles completely unmodified against it.
  7. #include <cstdint>
  8. #include "esphome/core/hal.h"
  9. #include "esphome/components/gxepd2/pin_registry.h"
  10. #ifndef ESP32
  11. #define ESP32
  12. #endif
  13. #define HIGH 1
  14. #define LOW 0
  15. #define INPUT 0
  16. #define OUTPUT 1
  17. #define INPUT_PULLUP 2
  18. inline void pinMode(int16_t pin, uint8_t mode) {}
  19. inline void digitalWrite(int16_t pin, uint8_t value) {
  20. if (auto *p = esphome::gxepd2::PinRegistry::get(pin))
  21. p->digital_write(value != 0);
  22. }
  23. inline int digitalRead(int16_t pin) {
  24. auto *p = esphome::gxepd2::PinRegistry::get(pin);
  25. return (p != nullptr && p->digital_read()) ? HIGH : LOW;
  26. }
  27. inline void delay(uint32_t ms) { esphome::delay(ms); }
  28. inline uint32_t micros() { return esphome::micros(); }
  29. inline void yield() { esphome::yield(); }
  30. #define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t *>(addr))
  31. // Stub: GxEPD2's serial diagnostics are opt-in and this component never
  32. // enables them.
  33. class GxEPD2SerialShim {
  34. public:
  35. void begin(uint32_t baud) {}
  36. template<typename T> void print(T) {}
  37. template<typename T> void println(T) {}
  38. void println() {}
  39. };
  40. inline GxEPD2SerialShim Serial; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)