FastLED 3.10.8
Loading...
Searching...
No Matches

◆ wait()

bool fl::spi::Transaction::wait ( u32 timeout_ms = (fl::numeric_limits<u32>::max)())

Wait for transaction to complete.

Parameters
timeout_msMaximum time to wait
Returns
true if completed, false on timeout

Definition at line 408 of file device.cpp.hpp.

408 {
409 if (!pImpl) {
410 return true; // Already completed (or invalid)
411 }
412
413 if (pImpl->completed) {
414 return true; // Already completed
415 }
416
417 if (pImpl->cancelled) {
418 pImpl->completed = true;
419 return false; // Was cancelled
420 }
421
422 // Check if device is still valid
423 if (!pImpl->device) {
424 pImpl->completed = true;
425 pImpl->result = fl::task::Error("Device pointer is null");
426 return false;
427 }
428
429 if (!pImpl->device->isReady()) {
430 pImpl->completed = true;
431 pImpl->result = fl::task::Error("Device not ready");
432 return false;
433 }
434
435#ifdef FASTLED_LOG_SPI_ENABLED
436 u32 start_time = fl::millis();
437#endif
438 // Wait for the hardware to complete
439 bool success = pImpl->device->waitComplete(timeout_ms);
440
441 if (success) {
442 // Clear async state in device
443 if (pImpl->device->pImpl) {
444 pImpl->device->pImpl->async_state.active = false;
445 }
446 pImpl->completed = true;
447 pImpl->result = fl::nullopt;
448
449#ifdef FASTLED_LOG_SPI_ENABLED
450 FL_LOG_SPI("Transaction: Completed successfully (waited " << (fl::millis() - start_time) << "ms)");
451#endif
452 return true;
453 } else {
454 // Timeout occurred
455 pImpl->completed = true;
456 pImpl->result = fl::task::Error("Transaction timeout");
457 FL_WARN("Transaction: Timeout after " << timeout_ms << "ms");
458 return false;
459 }
460}
fl::unique_ptr< Impl > pImpl
Definition transaction.h:78
#define FL_LOG_SPI(...)
Serial Peripheral Interface (SPI) logging Logs SPI configuration, initialization, and transfers.
Definition log.h:646
#define FL_WARN(...)
Definition log.h:437
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
constexpr nullopt_t nullopt
Definition optional.h:13

References FL_LOG_SPI, fl::FL_NO_EXCEPT, FL_WARN, fl::millis(), fl::nullopt, and pImpl.

Referenced by ~Transaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: