FastLED 3.10.6
Loading...
Searching...
No Matches

◆ init()

void fl::DigitalMultiWrite16::init ( const Pins16 & pins)

Initialize from 16 pin numbers. -1 means "skip this bit position".

Definition at line 272 of file pins.cpp.hpp.

272 {
273 for (u8 i = 0; i < 16; ++i) {
274 mPins[i] = pins.pins[i];
275 }
276
277 // Find the majority port and disable pins on other ports.
278 int port_counts[64] = {};
279 int port_ids[16] = {};
280 int num_active = 0;
281 for (u8 i = 0; i < 16; ++i) {
282 if (mPins[i] < 0) {
283 port_ids[i] = -1;
284 continue;
285 }
286 int p = fl::pinToPort(mPins[i]);
287 port_ids[i] = p;
288 if (p >= 0 && p < 64) {
289 port_counts[p]++;
290 }
291 num_active++;
292 }
293
294 // Find the port with the highest pin count.
295 int best_port = -1;
296 int best_count = 0;
297 for (int p = 0; p < 64; ++p) {
298 if (port_counts[p] > best_count) {
299 best_count = port_counts[p];
300 best_port = p;
301 }
302 }
303
304 // Disable pins that aren't on the majority port and warn.
305 if (best_port >= 0 && best_count < num_active) {
306 for (u8 i = 0; i < 16; ++i) {
307 if (mPins[i] < 0) {
308 continue;
309 }
310 if (port_ids[i] != best_port) {
311 FL_WARN("digitalMultiWrite16: pin %s (port %s) disabled — not on majority port %s", mPins[i], port_ids[i], best_port);
312 mPins[i] = -1;
313 }
314 }
315 }
316
317 for (u8 n = 0; n < 4; ++n) {
318 buildNibbleLut(n * 4, mSetNib[n], mClrNib[n]);
319 }
320}
int pins[]
Definition Spi.ino:11
void buildNibbleLut(u8 bit_offset, PinList(&set_lut)[16], PinList(&clr_lut)[16])
Definition pins.cpp.hpp:348
PinList mSetNib[4][16]
Definition pins.h:123
PinList mClrNib[4][16]
Definition pins.h:124
#define FL_WARN(...)
Definition log.h:440
unsigned char u8
Definition stdint.h:131
int pinToPort(int pin)
Map a runtime pin number to an integer port ID using FastPin<N>::port().
Definition pins.cpp.hpp:150

References buildNibbleLut(), FL_WARN, mClrNib, mPins, mSetNib, pins, and fl::pinToPort().

Referenced by DigitalMultiWrite16(), and fl::digitalMultiWrite16().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: