| 974 | } |
| 975 | |
| 976 | void SPIBusManager::releaseBusHardware(SPIBusInfo& bus) FL_NOEXCEPT { |
| 977 | FL_DBG("SPIBusManager: releaseBusHardware() called, is_initialized=" << (bus.is_initialized ? "true" : "false")); |
| 978 | if (!bus.is_initialized) { |
| 979 | FL_DBG("SPIBusManager: releaseBusHardware() bus not initialized, returning"); |
| 980 | return; // Nothing to release |
| 981 | } |
| 982 | |
| 983 | FL_DBG("SPIBusManager: releaseBusHardware() bus_type=" << static_cast<int>(bus.bus_type)); |
| 984 | // Release Single-SPI controller (runtime detection) |
| 985 | if (bus.bus_type == SPIBusType::SINGLE_SPI && bus.hw_controller) { |
| 986 | FL_DBG("SPIBusManager: releaseBusHardware() releasing SINGLE_SPI controller"); |
| 987 | SpiHw1* single = static_cast<SpiHw1*>(bus.hw_controller.get()); |
| 988 | FL_DBG("SPIBusManager: releaseBusHardware() calling single->end()"); |
| 989 | single->end(); // Shutdown SPI peripheral |
| 990 | FL_DBG("SPIBusManager: releaseBusHardware() nulling hw_controller"); |
| 991 | bus.hw_controller = nullptr; |
| 992 | } |
| 993 | |
| 994 | // Release Dual-SPI controller (runtime detection) |
| 995 | if (bus.bus_type == SPIBusType::DUAL_SPI && bus.hw_controller) { |
| 996 | SpiHw2* dual = static_cast<SpiHw2*>(bus.hw_controller.get()); |
| 997 | dual->end(); // Shutdown SPI/SERCOM peripheral |
| 998 | bus.hw_controller = nullptr; |
| 999 | } |
| 1000 | |
| 1001 | // Release Quad-SPI controller |
| 1002 | if (bus.bus_type == SPIBusType::QUAD_SPI && bus.hw_controller) { |
| 1003 | SpiHw4* quad = static_cast<SpiHw4*>(bus.hw_controller.get()); |
| 1004 | quad->end(); // Shutdown SPI peripheral |
| 1005 | bus.hw_controller = nullptr; |
| 1006 | } |
| 1007 | |
| 1008 | // Release Octal-SPI controller |
| 1009 | if (bus.bus_type == SPIBusType::OCTO_SPI && bus.hw_controller) { |
| 1010 | SpiHw8* octal = static_cast<SpiHw8*>(bus.hw_controller.get()); |
| 1011 | octal->end(); // Shutdown SPI peripheral |
| 1012 | bus.hw_controller = nullptr; |
| 1013 | } |
| 1014 | |
| 1015 | // Release Hexadeca-SPI controller |
| 1016 | if (bus.bus_type == SPIBusType::HEXADECA_SPI && bus.hw_controller) { |
| 1017 | SpiHw16* hexadeca = static_cast<SpiHw16*>(bus.hw_controller.get()); |
| 1018 | hexadeca->end(); // Shutdown SPI/I2S peripheral |
| 1019 | bus.hw_controller = nullptr; |
| 1020 | } |
| 1021 | |
| 1022 | // Clear lane buffers |
| 1023 | bus.lane_buffers.clear(); |
| 1024 | bus.interleaved_buffer.clear(); |
| 1025 | |
| 1026 | // Reset bus state |
| 1027 | bus.is_initialized = false; |
| 1028 | bus.bus_type = SPIBusType::SOFT_SPI; |
| 1029 | bus.num_devices = 0; // Reset device count to prevent stale state |
| 1030 | } |
| 1031 | |
| 1032 | void SPIBusManager::softwareSPIWrite(u8 clock_pin, u8 data_pin, const u8* data, size_t length) FL_NOEXCEPT { |
| 1033 | #if !defined(FASTLED_STUB_IMPL) && !defined(FL_IS_WASM) |