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

Method addDevice

src/platforms/esp/32/drivers/spi/spi_peripheral_esp.cpp.hpp:159–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159bool SpiPeripheralESPImpl::addDevice(const SpiDeviceConfig& config) FL_NOEXCEPT {
160 if (!mBusInitialized) {
161 FL_WARN("SpiPeripheralESP: Cannot add device - bus not initialized");
162 return false;
163 }
164
165 if (mDeviceAdded) {
166 FL_WARN("SpiPeripheralESP: Device already added");
167 return false;
168 }
169
170 // Configure SPI device (maps directly to ESP-IDF structure)
171 ::spi_device_interface_config_t dev_config = {};
172 dev_config.mode = config.mode;
173 dev_config.clock_speed_hz = config.clock_speed_hz;
174 dev_config.queue_size = config.queue_size;
175 dev_config.flags = config.flags;
176 dev_config.spics_io_num = static_cast<gpio_num_t>(config.spics_io_num);
177
178 // Register post-transaction callback if set
179 if (mCallback != nullptr) {
180 dev_config.post_cb = reinterpret_cast<transaction_cb_t>(mCallback); // ok reinterpret cast
181 }
182
183 // Add device to bus (delegate to ESP-IDF)
184 esp_err_t err = ::spi_bus_add_device(mHost, &dev_config, &mDeviceHandle);
185 if (err != ESP_OK) {
186 FL_WARN("SpiPeripheralESP: Failed to add device: " << err);
187 return false;
188 }
189
190 mDeviceAdded = true;
191 FL_DBG("SpiPeripheralESP: Device added (clock=" << config.clock_speed_hz
192 << " Hz, queue=" << config.queue_size << ")");
193
194 return true;
195}
196
197bool SpiPeripheralESPImpl::removeDevice() FL_NOEXCEPT {
198 if (!mDeviceAdded) {

Callers 1

FL_TEST_FILEFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected