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

157 {
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}
int pins[]
Definition Spi.ino:11
PinList mClrLo[16]
Definition pins.h:71
PinList mSetHi[16]
Definition pins.h:72
void buildNibbleLut(u8 bit_offset, PinList(&set_lut)[16], PinList(&clr_lut)[16])
Definition pins.cpp.hpp:235
PinList mSetLo[16]
Definition pins.h:70
PinList mClrHi[16]
Definition pins.h:73
#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, 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: