FastLED 3.10.8
Loading...
Searching...
No Matches
multi_lane_device.h
Go to the documentation of this file.
1#pragma once
2
5
6#include "fl/stl/stdint.h"
7#include "fl/stl/vector.h"
8#include "fl/stl/unique_ptr.h"
9#include "fl/stl/optional.h"
10#include "fl/task/promise.h" // for fl::task::Error
14// IWYU pragma: begin_keep
15#include "platforms/shared/spi_types.h" // ok platform headers
16#include "fl/stl/noexcept.h"
17// IWYU pragma: end_keep // ok platform headers
18
19namespace fl {
20namespace spi {
21
22// ============================================================================
23// MultiLaneDevice - 1-8 independent data streams (HW transposed)
24// ============================================================================
25
52public:
62
65 explicit MultiLaneDevice(const Config& config) FL_NO_EXCEPT;
66
69
70 // Disable copy/move
72 MultiLaneDevice& operator=(const MultiLaneDevice&) FL_NO_EXCEPT = delete;
75
76 // ========== Initialization ==========
77
82
85 void end() FL_NO_EXCEPT;
86
89 bool isReady() const FL_NO_EXCEPT;
90
91 // ========== Lane Access ==========
92
97 Lane& lane(size_t lane_id) FL_NO_EXCEPT;
98
101 size_t numLanes() const FL_NO_EXCEPT;
102
103 // ========== Transmission ==========
104
112 Result<void> flush() FL_NO_EXCEPT;
113
117 bool waitComplete(u32 timeout_ms = (fl::numeric_limits<u32>::max)()) FL_NO_EXCEPT;
118
122 bool wait() FL_NO_EXCEPT { return waitComplete(); }
123
126 bool isBusy() const FL_NO_EXCEPT;
127
128 // ========== High-Level Write API ==========
129 // This method provides a simple, type-safe way to write to multiple lanes
130 // simultaneously. Each lane can have a different buffer size.
131 //
132 // Usage: auto result = spi->write(lane0, lane1, lane2, lane3);
133 //
134 // Accepts fl::span<const uint8_t> or any type convertible to it (arrays, vectors, etc.)
135 //
136 // This method automatically:
137 // 1. Waits for any previous transmission to complete (waitComplete)
138 // 2. Writes all lane data atomically (single call to writeImpl)
139 // 3. Flushes to start the transmission **asynchronously**
140 //
141 // Transmission happens in the background. Call wait() to block until complete.
142
168 template<typename... Spans>
169 WriteResult write(Spans&&... lanes) FL_NO_EXCEPT {
170 // Unpack variadic template into stack-allocated FixedVector
171 fl::span<const u8> lane_spans[] = {fl::forward<Spans>(lanes)...};
173
174 // Copy spans into vector
175 for (size_t i = 0; i < sizeof...(lanes); i++) {
176 lane_vec.push_back(lane_spans[i]);
177 }
178
179 // Single atomic write operation
180 return writeImpl(lane_vec);
181 }
182
183 // ========== Configuration ==========
184
187 const Config& getConfig() const FL_NO_EXCEPT;
188
189private:
194 WriteResult writeImpl(fl::span<const fl::span<const u8>> lane_data) FL_NO_EXCEPT;
195
196 struct Impl;
198};
199
200} // namespace spi
201} // namespace fl
void push_back(const T &value) FL_NO_EXCEPT
Definition vector.h:191
Single lane in a multi-lane SPI device.
Definition lane.h:25
bool waitComplete(u32 timeout_ms=(fl::numeric_limits< u32 >::max)()) FL_NO_EXCEPT
Wait for pending transmission to complete.
WriteResult write(Spans &&... lanes) FL_NO_EXCEPT
Convenience method - write multiple lanes in parallel (variadic template)
MultiLaneDevice(const Config &config) FL_NO_EXCEPT
Construct multi-lane device.
const Config & getConfig() const FL_NO_EXCEPT
Get current configuration.
bool wait() FL_NO_EXCEPT
Convenience method - wait for transmission to complete.
Lane & lane(size_t lane_id) FL_NO_EXCEPT
Get access to a specific lane.
Result< void > flush() FL_NO_EXCEPT
Flush all lanes (transpose and transmit)
bool isBusy() const FL_NO_EXCEPT
Check if transmission is in progress.
fl::unique_ptr< Impl > pImpl
void end() FL_NO_EXCEPT
Shutdown hardware and release resources.
size_t numLanes() const FL_NO_EXCEPT
Get number of lanes.
WriteResult writeImpl(fl::span< const fl::span< const u8 > > lane_data) FL_NO_EXCEPT
Internal implementation - write all lanes atomically.
fl::optional< fl::task::Error > begin() FL_NO_EXCEPT
Initialize hardware.
~MultiLaneDevice() FL_NO_EXCEPT
Destructor - releases hardware resources.
bool isReady() const FL_NO_EXCEPT
Check if device is initialized.
Configuration structure for SPI communication.
constexpr T && forward(typename remove_reference< T >::type &t) FL_NO_EXCEPT
fl::SpiConfig Config
Definition config.h:82
fl::result< T, SPIError > Result
Definition transaction.h:29
unsigned char u8
Definition stdint.h:131
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
constexpr size_t MAX_SPI_LANES
Maximum number of SPI lanes supported (hardware: 1-8, software: up to 32)
Definition config.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
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.
Result of a write operation.
u32 clock_speed_hz
Clock speed in Hz (0xffffffff = as fast as possible)
u8 clock_pin
Shared clock pin (SCK)
fl::vector< u8 > data_pins
Data pins (1-8 pins)
Transaction class for asynchronous SPI operations.
Result type for SPI write operations.