FastLED 3.9.15
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1#pragma once
2
7
8#include "fl/stl/limits.h"
9#include "fl/stl/stdint.h"
10#include "fl/stl/unique_ptr.h"
11#include "fl/stl/optional.h"
12#include "fl/task/promise.h" // for fl::task::Error
15// IWYU pragma: begin_keep
16#include "platforms/shared/spi_types.h" // ok platform headers
17#include "fl/stl/noexcept.h"
18// IWYU pragma: end_keep // ok platform headers - DMABuffer, SPIError, TransmitMode
19
20namespace fl {
21namespace spi {
22
23// ============================================================================
24// Main Device Class
25// ============================================================================
26
48class Device {
49public:
52 explicit Device(const Config& config);
53
57
58 // ========== Initialization ==========
59
64
67 void end();
68
71 bool isReady() const;
72
73 // ========== Transaction API (Primary Interface) ==========
74
90 Result<Transaction> writeAsync(const u8* data, size_t size);
91
92 // ========== Zero-Copy DMA API (Expert) ==========
93
99 DMABuffer acquireBuffer(size_t size);
100
106 fl::optional<fl::task::Error> transmit(DMABuffer& buffer, bool async = true);
107
111 bool waitComplete(u32 timeout_ms = (fl::numeric_limits<u32>::max)());
112
115 bool isBusy() const;
116
117 // ========== Configuration ==========
118
125
128 const Config& getConfig() const;
129
130private:
131 friend class Transaction; // Allow Transaction to access Device internals
132
133 struct Impl; // Forward declaration (pImpl pattern)
135
136 // Non-copyable, non-movable (owns hardware resources)
137 Device(const Device&) FL_NOEXCEPT = delete;
139};
140
141} // namespace spi
142} // namespace fl
Device & operator=(const Device &) FL_NOEXCEPT=delete
bool isReady() const
Check if device is initialized and ready for use.
Device(const Device &) FL_NOEXCEPT=delete
fl::optional< fl::task::Error > begin()
Initialize the SPI hardware.
void end()
Shutdown the SPI hardware and release resources.
Result< Transaction > writeAsync(const u8 *data, size_t size)
Begin asynchronous write operation (returns immediately)
friend class Transaction
Definition device.h:131
fl::optional< fl::task::Error > transmit(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.
Device(const Config &config)
Construct SPI device with configuration.
fl::optional< fl::task::Error > setClockSpeed(u32 speed_hz)
Update clock speed.
fl::unique_ptr< Impl > pImpl
Definition device.h:134
~Device() FL_NOEXCEPT
Destructor - releases hardware resources.
DMABuffer acquireBuffer(size_t size)
Acquire DMA-capable buffer for zero-copy transmission.
const Config & getConfig() const
Get current configuration.
bool isBusy() const
Check if async operation is in progress.
Configuration structure for SPI communication.
fl::SpiConfig Config
Definition config.h:82
fl::result< T, SPIError > Result
Definition transaction.h:29
unsigned char u8
Definition stdint.h:131
Optional< T > optional
Definition optional.h:16
Base definition for an LED controller.
Definition crgb.hpp:179
Promise-based fluent API for FastLED - standalone async primitives.
#define FL_NOEXCEPT
static constexpr T max() FL_NOEXCEPT
Definition limits.h:108
Private implementation data for Device class.
Definition impl.h:19
Transaction class for asynchronous SPI operations.