FastLED 3.10.8
Loading...
Searching...
No Matches

◆ transpose2()

FL_DISABLE_WARNING_POP bool fl::SPITransposer::transpose2 ( const fl::optional< LaneData > & lane0,
const fl::optional< LaneData > & lane1,
fl::span< u8 > output,
const char ** error = nullptr )
static

Transpose 2 lanes of data into interleaved dual-SPI format.

Parameters
lane0Lane 0 data (use fl::nullopt for unused lane)
lane1Lane 1 data (use fl::nullopt for unused lane)
outputOutput buffer to write interleaved data (size must be divisible by 2)
errorOptional pointer to receive error message (set to nullptr if unused)
Returns
true on success, false if output buffer size is invalid
Note
Output buffer size determines max lane size: max_size = output.size() / 2
Shorter lanes are padded at the beginning with repeating padding_frame pattern
Empty lanes (nullopt) are filled with zeros or first lane's padding
Examples
/home/runner/work/FastLED/FastLED/src/fl/math/transposition.h.

Definition at line 54 of file transposition.cpp.hpp.

57 {
58 // Validate output buffer size (must be divisible by 2)
59 if (output.size() % 2 != 0) {
60 if (error) {
61 *error = "Output buffer size must be divisible by 2";
62 }
63 return false;
64 }
65
66 // Calculate max lane size from output buffer
67 const size_t max_size = output.size() / 2;
68
69 // Handle empty case
70 if (max_size == 0) {
71 if (error) {
72 *error = nullptr; // No error, just empty
73 }
74 return true;
75 }
76
77 // Create array of lane references for easier iteration
78 const fl::optional<LaneData>* lanes[2] = {&lane0, &lane1};
79
80 // Determine default padding byte from first available lane
81 u8 default_padding = 0x00;
82 for (size_t i = 0; i < 2; i++) {
83 if (lanes[i]->has_value() && !(*lanes[i])->padding_frame.empty()) {
84 default_padding = (*lanes[i])->padding_frame[0];
85 break;
86 }
87 }
88
89 // Gather all bytes from each lane into temporary buffers
90 fl::vector<u8> lane0_buffer(max_size);
91 fl::vector<u8> lane1_buffer(max_size);
92
93 for (size_t byte_idx = 0; byte_idx < max_size; byte_idx++) {
94 lane0_buffer[byte_idx] = lanes[0]->has_value() ?
95 getLaneByte(**lanes[0], byte_idx, max_size) : default_padding;
96 lane1_buffer[byte_idx] = lanes[1]->has_value() ?
97 getLaneByte(**lanes[1], byte_idx, max_size) : default_padding;
98 }
99
100 // Perform transposition using ISR-safe primitive
101 transpose_2lane_inline(lane0_buffer.data(), lane1_buffer.data(), output.data(), max_size);
102
103 if (error) {
104 *error = nullptr; // Success, no error
105 }
106 return true;
107}
bool has_value() const FL_NO_EXCEPT
Definition optional.h:42
static u8 getLaneByte(const LaneData &lane, size_t byte_idx, size_t max_size) FL_NO_EXCEPT
Get byte from lane at given index, handling padding automatically.
const T * data() const FL_NO_EXCEPT
Definition span.h:486
constexpr fl::size size() const FL_NO_EXCEPT
Definition span.h:483
unsigned char u8
Definition stdint.h:131
Optional< T > optional
Definition optional.h:16
void transpose_2lane_inline(const u8 *lane0_byte, const u8 *lane1_byte, u8 *output, size_t num_bytes) FL_NO_EXCEPT
Low-level bit-interleaving primitive for 2 lanes (ISR-safe)

References fl::vector< T >::data(), fl::Optional< T >::empty(), fl::FL_NO_EXCEPT, getLaneByte(), fl::Optional< T >::has_value(), and fl::transpose_2lane_inline().

Referenced by fl::spi::MultiLaneDevice::flush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: