FastLED 3.9.15
Loading...
Searching...
No Matches
fl::spi::Device Class Reference

Detailed Description

Single-channel SPI device interface (TX-only, transaction-based, optimized for FastLED)

Provides easy-to-use API for SPI communication with two levels:

  1. Transaction API (writeAsync) - Primary interface, returns Transaction handles
  2. Zero-Copy DMA (acquireBuffer/transmit) - Expert API for maximum performance

TX-Only, Transaction-Based Design: This SPI implementation is optimized for LED strip output (WS2812, APA102, SK6812, etc.) and only supports transmission (MOSI). Read operations (MISO) are not supported because:

  • LED strips are receive-only devices (no status/readback)
  • Removing RX support simplifies hardware configuration
  • Allows more efficient DMA and buffer management

Transaction API (Simpler Implementation): All operations use the transaction-based API (writeAsync()) which returns a Transaction handle. This provides a single, consistent interface that's easier to implement and use:

  • Async by default, but can be made blocking by calling wait() immediately
  • Consistent error handling through Result<Transaction>
  • Natural fit for DMA-based hardware
Note
This class uses RAII - hardware is released on destruction
Non-copyable, non-movable (owns hardware resources)

Definition at line 48 of file device.h.

#include <device.h>

+ Collaboration diagram for fl::spi::Device:

Classes

struct  Impl
 Private implementation data for Device class. More...
 

Public Member Functions

 Device (const Config &config)
 Construct SPI device with configuration.
 
 ~Device () FL_NOEXCEPT
 Destructor - releases hardware resources.
 
DMABuffer acquireBuffer (size_t size)
 Acquire DMA-capable buffer for zero-copy transmission.
 
fl::optional< fl::task::Errorbegin ()
 Initialize the SPI hardware.
 
void end ()
 Shutdown the SPI hardware and release resources.
 
const ConfiggetConfig () const
 Get current configuration.
 
bool isBusy () const
 Check if async operation is in progress.
 
bool isReady () const
 Check if device is initialized and ready for use.
 
fl::optional< fl::task::ErrorsetClockSpeed (u32 speed_hz)
 Update clock speed.
 
fl::optional< fl::task::Errortransmit (DMABuffer &buffer, bool async=true)
 Transmit from previously acquired DMA buffer.
 
bool waitComplete (u32 timeout_ms=(fl::numeric_limits< u32 >::max)())
 Wait for pending async operation to complete.
 
Result< TransactionwriteAsync (const u8 *data, size_t size)
 Begin asynchronous write operation (returns immediately)
 

Private Member Functions

 Device (const Device &) FL_NOEXCEPT=delete
 
Deviceoperator= (const Device &) FL_NOEXCEPT=delete
 

Private Attributes

fl::unique_ptr< ImplpImpl
 

Friends

class Transaction
 

The documentation for this class was generated from the following files: