FastLED 3.10.8
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) FL_NO_EXCEPT
 Construct SPI device with configuration.
 
 ~Device () FL_NO_EXCEPT
 Destructor - releases hardware resources.
 
DMABuffer acquireBuffer (size_t size) FL_NO_EXCEPT
 Acquire DMA-capable buffer for zero-copy transmission.
 
fl::optional< fl::task::Error > begin () FL_NO_EXCEPT
 Initialize the SPI hardware.
 
void end () FL_NO_EXCEPT
 Shutdown the SPI hardware and release resources.
 
const Config & getConfig () const FL_NO_EXCEPT
 Get current configuration.
 
bool isBusy () const FL_NO_EXCEPT
 Check if async operation is in progress.
 
bool isReady () const FL_NO_EXCEPT
 Check if device is initialized and ready for use.
 
fl::optional< fl::task::Error > setClockSpeed (u32 speed_hz) FL_NO_EXCEPT
 Update clock speed.
 
fl::optional< fl::task::Error > transmit (DMABuffer &buffer, bool async=true) FL_NO_EXCEPT
 Transmit from previously acquired DMA buffer.
 
bool waitComplete (u32 timeout_ms=(fl::numeric_limits< u32 >::max)()) FL_NO_EXCEPT
 Wait for pending async operation to complete.
 
Result< Transaction > writeAsync (const u8 *data, size_t size) FL_NO_EXCEPT
 Begin asynchronous write operation (returns immediately)
 

Private Member Functions

 Device (const Device &) FL_NO_EXCEPT=delete
 
Device & operator= (const Device &) FL_NO_EXCEPT=delete
 

Private Attributes

fl::unique_ptr< Impl > pImpl
 

Friends

class Transaction
 

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