#pragma once #include #include "esphome/core/gpio.h" namespace esphome::gxepd2 { // Maps GxEPD2's plain int16_t pin numbers back to the real esphome::GPIOPin // each one stands for. IDs are assigned in Python at codegen time, not via // any runtime allocation call, so there's no construction-order hazard. class PinRegistry { public: static void set(int16_t id, GPIOPin *pin) { if (id < 0 || pin == nullptr) return; if (static_cast(id) >= pins().size()) pins().resize(id + 1, nullptr); pins()[id] = pin; pin->setup(); } static GPIOPin *get(int16_t id) { if (id < 0 || static_cast(id) >= pins().size()) return nullptr; return pins()[id]; } protected: static std::vector &pins() { static std::vector pins; return pins; } }; } // namespace esphome::gxepd2