| 123456789101112131415161718192021222324252627282930313233343536 |
- #pragma once
- #include <vector>
- #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<size_t>(id) >= pins().size())
- pins().resize(id + 1, nullptr);
- pins()[id] = pin;
- pin->setup();
- }
- static GPIOPin *get(int16_t id) {
- if (id < 0 || static_cast<size_t>(id) >= pins().size())
- return nullptr;
- return pins()[id];
- }
- protected:
- static std::vector<GPIOPin *> &pins() {
- static std::vector<GPIOPin *> pins;
- return pins;
- }
- };
- } // namespace esphome::gxepd2
|