| 155 | #endif // FASTLED_ALL_PINS_VALID |
| 156 | |
| 157 | void DigitalMultiWrite8::init(const Pins8& pins) { |
| 158 | for (u8 i = 0; i < 8; ++i) { |
| 159 | mPins[i] = pins.pins[i]; |
| 160 | } |
| 161 | |
| 162 | // Find the majority port and disable pins on other ports. |
| 163 | int port_counts[32] = {}; |
| 164 | int port_ids[8] = {}; |
| 165 | int num_active = 0; |
| 166 | for (u8 i = 0; i < 8; ++i) { |
| 167 | if (mPins[i] < 0) { |
| 168 | port_ids[i] = -1; |
| 169 | continue; |
| 170 | } |
| 171 | int p = fl::pinToPort(mPins[i]); |
| 172 | port_ids[i] = p; |
| 173 | if (p >= 0 && p < 32) { |
| 174 | port_counts[p]++; |
| 175 | } |
| 176 | num_active++; |
| 177 | } |
| 178 | |
| 179 | // Find the port with the highest pin count. |
| 180 | int best_port = -1; |
| 181 | int best_count = 0; |
| 182 | for (int p = 0; p < 32; ++p) { |
| 183 | if (port_counts[p] > best_count) { |
| 184 | best_count = port_counts[p]; |
| 185 | best_port = p; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // Disable pins that aren't on the majority port and warn. |
| 190 | if (best_port >= 0 && best_count < num_active) { |
| 191 | for (u8 i = 0; i < 8; ++i) { |
| 192 | if (mPins[i] < 0) { |
| 193 | continue; |
| 194 | } |
| 195 | if (port_ids[i] != best_port) { |
| 196 | FL_WARN("digitalMultiWrite8: pin " |
| 197 | << mPins[i] << " (port " << port_ids[i] |
| 198 | << ") disabled — not on majority port " |
| 199 | << best_port); |
| 200 | mPins[i] = -1; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | buildNibbleLut(0, mSetLo, mClrLo); // bits 0-3 |
| 206 | buildNibbleLut(4, mSetHi, mClrHi); // bits 4-7 |
| 207 | } |
| 208 | |
| 209 | void DigitalMultiWrite8::write(fl::span<const u8> pin_data) const { |
| 210 | for (fl::size i = 0; i < pin_data.size(); ++i) { |
no test coverage detected