| 71 | } // namespace pin_port_table |
| 72 | |
| 73 | int pinToPort(int pin) { |
| 74 | if (pin < 0) return -1; |
| 75 | |
| 76 | if (!pin_port_table::allPortsNull()) { |
| 77 | auto ptr = pin_port_table::getPortPtr(pin); |
| 78 | if (ptr == nullptr) return -1; |
| 79 | |
| 80 | // Assign sequential port IDs by counting unique pointers before this one |
| 81 | const auto* table = pin_port_table::portTable(); |
| 82 | for (int i = 0; i < pin_port_table::TABLE_SIZE; ++i) { |
| 83 | if (table[i] == ptr) { |
| 84 | int id = 0; |
| 85 | for (int j = 0; j < i; ++j) { |
| 86 | bool unique = true; |
| 87 | for (int k = 0; k < j; ++k) { |
| 88 | if (table[k] == table[j]) { unique = false; break; } |
| 89 | } |
| 90 | if (unique && table[j] != nullptr) ++id; |
| 91 | } |
| 92 | return id; |
| 93 | } |
| 94 | } |
| 95 | return -1; |
| 96 | } |
| 97 | |
| 98 | // Stub/WASM fallback: all FastPin ports are null, group by pin / 32 |
| 99 | return pin / 32; |
| 100 | } |
| 101 | |
| 102 | #elif defined(FASTLED_NO_PINMAP) |
| 103 |
no test coverage detected