FastLED 3.9.15
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);
66
69
70 // Disable copy/move
72 MultiLaneDevice& operator=(const MultiLaneDevice&) FL_NOEXCEPT = delete;
75
76 // ========== Initialization ==========
77
82
85 void end();
86
89 bool isReady() const;
90
91 // ========== Lane Access ==========
92
97 Lane& lane(size_t lane_id);
98
101 size_t numLanes() const;
102
103 // ========== Transmission ==========
104
112 Result<void> flush();
113
117 bool waitComplete(u32 timeout_ms = (fl::numeric_limits<u32>::max)());
118
122 bool wait() { return waitComplete(); }
123
126 bool isBusy() const;
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) {
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;
188
189private:
195
196 struct Impl;
198};
199
200} // namespace spi
201} // namespace fl
void push_back(const T &value) FL_NOEXCEPT
Definition vector.h:191
Single lane in a multi-lane SPI device.
Definition lane.h:24
~MultiLaneDevice() FL_NOEXCEPT
Destructor - releases hardware resources.
bool waitComplete(u32 timeout_ms=(fl::numeric_limits< u32 >::max)())
Wait for pending transmission to complete.
bool isReady() const
Check if device is initialized.
WriteResult writeImpl(fl::span< const fl::span< const u8 > > lane_data)
Internal implementation - write all lanes atomically.
Lane & lane(size_t lane_id)
Get access to a specific lane.
void end()
Shutdown hardware and release resources.
const Config & getConfig() const
Get current configuration.
fl::optional< fl::task::Error > begin()
Initialize hardware.
fl::unique_ptr< Impl > pImpl
Result< void > flush()
Flush all lanes (transpose and transmit)
size_t numLanes() const
Get number of lanes.
MultiLaneDevice(const Config &config)
Construct multi-lane device.
WriteResult write(Spans &&... lanes)
Convenience method - write multiple lanes in parallel (variadic template)
bool isBusy() const
Check if transmission is in progress.
bool wait()
Convenience method - wait for transmission to complete.
Configuration structure for SPI communication.
constexpr T && forward(typename remove_reference< T >::type &t) FL_NOEXCEPT
Definition s16x16x4.h:234
fl::SpiConfig Config
Definition config.h:82
fl::result< T, SPIError > Result
Definition transaction.h:29
unsigned char u8
Definition stdint.h:131
constexpr size_t MAX_SPI_LANES
Maximum number of SPI lanes supported (hardware: 1-8, software: up to 32)
Definition config.h:18
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
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
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.