FastLED 3.9.15
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 275 of file pins.cpp.hpp.

275 {
276 for (u8 i = 0; i < 16; ++i) {
277 mPins[i] = pins.pins[i];
278 }
279
280 // Find the majority port and disable pins on other ports.
281 int port_counts[64] = {};
282 int port_ids[16] = {};
283 int num_active = 0;
284 for (u8 i = 0; i < 16; ++i) {
285 if (mPins[i] < 0) {
286 port_ids[i] = -1;
287 continue;
288 }
289 int p = fl::pinToPort(mPins[i]);
290 port_ids[i] = p;
291 if (p >= 0 && p < 64) {
292 port_counts[p]++;
293 }
294 num_active++;
295 }
296
297 // Find the port with the highest pin count.
298 int best_port = -1;
299 int best_count = 0;
300 for (int p = 0; p < 64; ++p) {
301 if (port_counts[p] > best_count) {
302 best_count = port_counts[p];
303 best_port = p;
304 }
305 }
306
307 // Disable pins that aren't on the majority port and warn.
308 if (best_port >= 0 && best_count < num_active) {
309 for (u8 i = 0; i < 16; ++i) {
310 if (mPins[i] < 0) {
311 continue;
312 }
313 if (port_ids[i] != best_port) {
314 FL_WARN("digitalMultiWrite16: pin "
315 << mPins[i] << " (port " << port_ids[i]
316 << ") disabled — not on majority port "
317 << best_port);
318 mPins[i] = -1;
319 }
320 }
321 }
322
323 for (u8 n = 0; n < 4; ++n) {
324 buildNibbleLut(n * 4, mSetNib[n], mClrNib[n]);
325 }
326}
int pins[]
Definition Spi.ino:11
void buildNibbleLut(u8 bit_offset, PinList(&set_lut)[16], PinList(&clr_lut)[16])
Definition pins.cpp.hpp:354
PinList mSetNib[4][16]
Definition pins.h:123
PinList mClrNib[4][16]
Definition pins.h:124
#define FL_WARN(X)
Definition log.h:276
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: