FastLED 3.10.8
Loading...
Searching...
No Matches

◆ init()

void fl::DigitalMultiWrite8::init ( const Pins8 & pins)

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

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

158 {
159 for (u8 i = 0; i < 8; ++i) {
160 mPins[i] = pins.pins[i];
161 }
162
163 // Find the majority port and disable pins on other ports.
164 int port_counts[32] = {};
165 int port_ids[8] = {};
166 int num_active = 0;
167 for (u8 i = 0; i < 8; ++i) {
168 if (mPins[i] < 0) {
169 port_ids[i] = -1;
170 continue;
171 }
172 int p = fl::pinToPort(mPins[i]);
173 port_ids[i] = p;
174 if (p >= 0 && p < 32) {
175 port_counts[p]++;
176 }
177 num_active++;
178 }
179
180 // Find the port with the highest pin count.
181 int best_port = -1;
182 int best_count = 0;
183 for (int p = 0; p < 32; ++p) {
184 if (port_counts[p] > best_count) {
185 best_count = port_counts[p];
186 best_port = p;
187 }
188 }
189
190 // Disable pins that aren't on the majority port and warn.
191 if (best_port >= 0 && best_count < num_active) {
192 for (u8 i = 0; i < 8; ++i) {
193 if (mPins[i] < 0) {
194 continue;
195 }
196 if (port_ids[i] != best_port) {
197 FL_WARN("digitalMultiWrite8: pin " << mPins[i] << " (port " << port_ids[i] << ") disabled — not on majority port " << best_port);
198 mPins[i] = -1;
199 }
200 }
201 }
202
203 buildNibbleLut(0, mSetLo, mClrLo); // bits 0-3
204 buildNibbleLut(4, mSetHi, mClrHi); // bits 4-7
205}
int pins[]
Definition Spi.ino:11
void buildNibbleLut(u8 bit_offset, PinList(&set_lut)[16], PinList(&clr_lut)[16]) FL_NO_EXCEPT
Definition pins.cpp.hpp:233
PinList mClrLo[16]
Definition pins.h:71
PinList mSetHi[16]
Definition pins.h:72
PinList mSetLo[16]
Definition pins.h:70
PinList mClrHi[16]
Definition pins.h:73
#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, mClrHi, mClrLo, mPins, mSetHi, mSetLo, pins, and fl::pinToPort().

Referenced by DigitalMultiWrite8(), and fl::digitalMultiWrite8().

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