MCPcopy Create free account
hub / github.com/FastLED/FastLED / initializeBus

Method initializeBus

src/platforms/shared/spi_manager.cpp.hpp:592–639  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592bool SPIBusManager::initializeBus(SPIBusInfo& bus) FL_NOEXCEPT {
593 // No devices? Skip initialization (bus was released)
594 if (bus.num_devices == 0) {
595 return true; // Not an error, just nothing to initialize
596 }
597
598 // Check for forced software SPI mode
599#if defined(FASTLED_FORCE_SOFTWARE_SPI)
600 // User explicitly requested software SPI - skip hardware attempts
601 bus.bus_type = SPIBusType::SOFT_SPI;
602 bus.is_initialized = true;
603 FL_DBG("SPI: Forcing software SPI (FASTLED_FORCE_SOFTWARE_SPI defined)");
604 return true;
605#endif
606
607 // Single device? Use standard single-line SPI
608 if (bus.num_devices == 1) {
609 bus.bus_type = SPIBusType::SINGLE_SPI;
610 return createSingleSPI(bus);
611 }
612
613 // Multiple devices? Try to promote to multi-line SPI
614 if (bus.num_devices >= 2 && bus.num_devices <= 16) {
615 if (promoteToMultiSPI(bus)) {
616 const char* type_name = "Unknown";
617 switch (bus.bus_type) {
618 case SPIBusType::DUAL_SPI: type_name = "Dual-SPI"; break;
619 case SPIBusType::QUAD_SPI: type_name = "Quad-SPI"; break;
620 case SPIBusType::OCTO_SPI: type_name = "Octo-SPI"; break;
621 case SPIBusType::HEXADECA_SPI: type_name = "Hexadeca-SPI"; break;
622 default: break;
623 }
624 (void)type_name; // Suppress unused variable warning when FL_WARN is a no-op
625 FL_WARN_FMT("SPI Manager: Promoted clock pin " << bus.clock_pin << " to " << type_name << " (" << bus.num_devices << " devices)");
626 return true;
627 } else {
628 // Promotion failed - disable conflicting devices
629 FL_WARN_FMT("SPI Manager: Cannot promote clock pin " << bus.clock_pin << " (platform limitation)");
630 disableConflictingDevices(bus);
631 return false;
632 }
633 }
634
635 // Too many devices (>16)
636 FL_WARN_FMT("SPI Manager: Too many devices on clock pin " << bus.clock_pin << " (" << bus.num_devices << " devices, max 16)");
637 disableConflictingDevices(bus);
638 return false;
639}
640
641bool SPIBusManager::promoteToMultiSPI(SPIBusInfo& bus) FL_NOEXCEPT {
642 SPIBusType max_type = getMaxSupportedSPIType();

Callers 1

FL_TEST_FILEFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected