Transmit a batch of channels sharing one SPI configuration.
404 {
405 if (channels.
empty()) {
406 return true;
407 }
408
409
410 const auto& chipset = channels[0]->getChipset();
411 if (!chipset.is<SpiChipsetConfig>()) {
412 FL_WARN(
"SpiChannelEngineAdapter: Non-SPI chipset in transmitBatch");
413 return false;
414 }
415
416 const SpiChipsetConfig& spiConfig = chipset.get<SpiChipsetConfig>();
417 int clockPin = spiConfig.clockPin;
418 int dataPin = channels[0]->getPin();
419
420
422 if (controllerIndex < 0) {
423 FL_WARN(
"SpiChannelEngineAdapter: No available controller for clock pin " << clockPin);
424 return false;
425 }
426
428
429
431 spiConfig.timing.clock_hz)) {
432 return false;
433 }
434
435
436 for (const auto& channel : channels) {
437 if (!channel) {
438 continue;
439 }
440
441
442 channel->setInUse(true);
443
444
445 const auto& data = channel->getData();
446 if (data.empty()) {
447 FL_WARN(
"SpiChannelEngineAdapter: Empty channel data");
448 channel->setInUse(false);
449 continue;
450 }
451
452 FL_DBG(
"SpiChannelEngineAdapter: Transmitting channel via " << ctrl.name <<
" (pin " << channel->getPin() <<
", " << data.size() <<
" bytes)");
453
454 if (ctrl.controller->supportsStreaming()) {
455
456
457
458 if (!ctrl.controller->transmitStream(channel)) {
459 channel->setInUse(false);
460 return false;
461 }
462 return true;
463 }
464
465
466 DMABuffer dmaBuffer = ctrl.controller->acquireDMABuffer(data.size());
467 if (!dmaBuffer.ok()) {
468 FL_WARN(
"SpiChannelEngineAdapter: Failed to acquire DMA buffer (error " << (
static_cast<int>(dmaBuffer.error())) <<
")");
469 channel->setInUse(false);
470 return false;
471 }
472
473
474 fl::span<u8> buffer = dmaBuffer.data();
475 if (buffer.
size() < data.size()) {
476 FL_WARN(
"SpiChannelEngineAdapter: DMA buffer too small (" << buffer.
size() <<
" < " << data.size() <<
")");
477 channel->setInUse(false);
478 return false;
479 }
480
482
483
484 if (!ctrl.controller->transmit(TransmitMode::ASYNC)) {
485 FL_WARN(
"SpiChannelEngineAdapter: Transmission failed");
486 channel->setInUse(false);
487 return false;
488 }
489
490 FL_DBG(
"SpiChannelEngineAdapter: Transmission queued successfully");
491 }
492
493
494
495 if (!ctrl.controller->waitComplete(1000)) {
496 FL_WARN(
"SpiChannelEngineAdapter: Transmission timeout");
497 return false;
498 }
499
500 FL_DBG(
"SpiChannelEngineAdapter: Batch transmission complete");
501 return true;
502}
fl::vector< ControllerInfo > mControllers
All managed controllers.
bool initializeControllerIfNeeded(ControllerInfo &ctrl, int clockPin, int dataPin, u32 clockSpeedHz) FL_NO_EXCEPT
Initialize controller if needed for this clock pin.
int selectControllerForClockPin(int clockPin, Esp32SpiBus requestedBus) FL_NO_EXCEPT
Select best controller for a given clock pin.
constexpr bool empty() const FL_NO_EXCEPT
const T * data() const FL_NO_EXCEPT
constexpr fl::size size() const FL_NO_EXCEPT
FASTLED_FORCE_INLINE void * memcpy(void *dest, const void *src, size_t n) FL_NO_EXCEPT
Information about a registered SPI hardware controller.