FastLED 3.9.15
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 53 of file transposition.cpp.hpp.

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

References fl::vector< T >::data(), fl::Optional< T >::empty(), 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: