FastLED 3.9.15
Loading...
Searching...
No Matches

◆ transpose16()

bool fl::SPITransposer::transpose16 ( const fl::optional< LaneData > lanes[16],
fl::span< u8 > output,
const char ** error = nullptr )
static

Transpose 16 lanes of data into interleaved hex-SPI format.

Parameters
lanesArray of 16 lane data (use fl::nullopt for unused lanes)
outputOutput buffer to write interleaved data (size must be divisible by 16)
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() / 16
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 240 of file transposition.cpp.hpp.

242 {
243 // Validate output buffer size (must be divisible by 16)
244 if (output.size() % 16 != 0) {
245 if (error) {
246 *error = "Output buffer size must be divisible by 16";
247 }
248 return false;
249 }
250
251 // Calculate max lane size from output buffer
252 const size_t max_size = output.size() / 16;
253
254 // Handle empty case
255 if (max_size == 0) {
256 if (error) {
257 *error = nullptr; // No error, just empty
258 }
259 return true;
260 }
261
262 // Determine default padding byte from first available lane
263 u8 default_padding = 0x00;
264 for (size_t i = 0; i < 16; i++) {
265 if (lanes[i].has_value() && !lanes[i]->padding_frame.empty()) {
266 default_padding = lanes[i]->padding_frame[0];
267 break;
268 }
269 }
270
271 // Gather all bytes from each lane into temporary buffers
272 fl::vector<u8> lane_buffers[16];
273 const u8* lane_ptrs[16];
274
275 for (size_t lane = 0; lane < 16; lane++) {
276 lane_buffers[lane].resize(max_size);
277 lane_ptrs[lane] = lane_buffers[lane].data();
278
279 for (size_t byte_idx = 0; byte_idx < max_size; byte_idx++) {
280 lane_buffers[lane][byte_idx] = lanes[lane].has_value() ?
281 getLaneByte(*lanes[lane], byte_idx, max_size) : default_padding;
282 }
283 }
284
285 // Perform transposition using ISR-safe primitive
286 transpose_16lane_inline(lane_ptrs, output.data(), max_size);
287
288 if (error) {
289 *error = nullptr; // Success, no error
290 }
291 return true;
292}
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.
T * data() FL_NOEXCEPT
Definition vector.h:619
void resize(fl::size n) FL_NOEXCEPT
Definition vector.h:593
unsigned char u8
Definition stdint.h:131
void transpose_16lane_inline(const u8 *const lanes[16], u8 *output, size_t num_bytes) FL_NOEXCEPT
Low-level bit-interleaving primitive for 16 lanes (ISR-safe)

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

+ Here is the call graph for this function: