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

◆ initializeControllerIfNeeded()

bool fl::SpiChannelEngineAdapter::initializeControllerIfNeeded ( ControllerInfo & ctrl,
int clockPin,
int dataPin )
private

Initialize controller if needed for this clock pin.

Parameters
ctrlController to initialize
clockPinClock pin for configuration
dataPinData pin for configuration
Returns
true on success, false on error

Definition at line 153 of file spi_channel_adapter.cpp.hpp.

154 {
155
156 if (ctrl.isInitialized) {
157 // Verify compatibility
158 for (int pin : ctrl.assignedClockPins) {
159 if (pin == clockPin) {
160 return true; // Already configured for this pin
161 }
162 }
163 FL_WARN("SpiChannelEngineAdapter: Controller " << ctrl.name << " already initialized with different clock pin");
164 return false;
165 }
166
167 // Initialize controller based on lane count
168 u8 lanes = ctrl.controller->getLaneCount();
169
170 if (lanes == 1) {
171 SpiHw1::Config config;
172 config.bus_num = static_cast<fl::u8>(ctrl.controller->getBusId());
173 config.clock_pin = clockPin;
174 config.data_pin = dataPin;
175 config.clock_speed_hz = 20000000; // 20 MHz for APA102
176 config.max_transfer_sz = 65536;
177
178 if (!ctrl.controller->begin(&config)) {
179 FL_WARN("SpiChannelEngineAdapter: Failed to initialize " << ctrl.name);
180 return false;
181 }
182 } else {
183 // TODO: Multi-lane initialization (SpiHw2/4/8/16)
184 FL_WARN("SpiChannelEngineAdapter: Multi-lane init not yet implemented");
185 return false;
186 }
187
188 ctrl.isInitialized = true;
189 ctrl.assignedClockPins.push_back(clockPin);
190
191 FL_DBG("SpiChannelEngineAdapter: Initialized " << ctrl.name << " with clock pin " << clockPin);
192
193 return true;
194}
#define FL_WARN(...)
Definition log.h:437
#define FL_DBG
Definition log.h:553
unsigned char u8
Definition stdint.h:131

References FL_DBG, fl::FL_NO_EXCEPT, and FL_WARN.

Referenced by transmitBatch().

+ Here is the caller graph for this function: