FastLED 3.10.8
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 273 of file pins.cpp.hpp.

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

References buildNibbleLut(), fl::FL_NO_EXCEPT, 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: