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

Method promoteToMultiSPI

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

Source from the content-addressed store, hash-verified

639}
640
641bool SPIBusManager::promoteToMultiSPI(SPIBusInfo& bus) FL_NOEXCEPT {
642 SPIBusType max_type = getMaxSupportedSPIType();
643
644 // Determine which multi-SPI type to use
645 if (bus.num_devices == 2 && static_cast<u8>(max_type) >= static_cast<u8>(SPIBusType::DUAL_SPI)) {
646 bus.bus_type = SPIBusType::DUAL_SPI;
647
648 // Get available Dual-SPI controllers and find one we can use (runtime detection)
649 const auto& controllers = SpiHw2::getAll();
650 if (controllers.empty()) {
651 bus.error_message = "No Dual-SPI controllers available on this platform";
652 return false;
653 }
654
655 // Try each controller until we find one that works
656 fl::shared_ptr<SpiHw2> dual_ctrl;
657 for (const auto& ctrl : controllers) {
658 if (!ctrl->isInitialized()) {
659 dual_ctrl = ctrl;
660 break;
661 }
662 }
663
664 if (!dual_ctrl) {
665 bus.error_message = "All Dual-SPI controllers already in use";
666 return false;
667 }
668
669 // Configure Dual-SPI
670 SpiHw2::Config config;
671 config.bus_num = static_cast<u8>(dual_ctrl->getBusId());
672 config.clock_speed_hz = selectBusSpeed(bus); // Use slowest requested speed
673 config.clock_pin = bus.clock_pin;
674 config.data0_pin = bus.devices[0].data_pin;
675 config.data1_pin = (bus.num_devices > 1) ? bus.devices[1].data_pin : -1;
676
677 // Initialize the controller
678 if (!dual_ctrl->begin(config)) {
679 bus.error_message = "Failed to initialize Dual-SPI controller";
680 return false;
681 }
682
683 FL_DBG("SPI: Initialized Dual-SPI controller '" << dual_ctrl->getName()
684 << "' (bus " << config.bus_num << ") at " << config.clock_speed_hz << " Hz");
685
686 // Store controller pointer and SPI bus number
687 bus.hw_controller = dual_ctrl;
688 bus.spi_bus_num = config.bus_num;
689
690 // Initialize lane buffers
691 bus.lane_buffers.resize(bus.num_devices);
692
693 bus.is_initialized = true;
694 return true;
695
696 } else if (bus.num_devices >= 3 && bus.num_devices <= 4 &&
697 static_cast<u8>(max_type) >= static_cast<u8>(SPIBusType::QUAD_SPI)) {
698 bus.bus_type = SPIBusType::QUAD_SPI;

Callers

nothing calls this directly

Calls 6

emptyMethod · 0.45
isInitializedMethod · 0.45
getBusIdMethod · 0.45
beginMethod · 0.45
getNameMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected