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

◆ transpose_generic_inline()

template<typename TSource>
void fl::transpose_generic_inline ( const TSource *const lanes[],
size_t num_lanes,
u8 * output,
size_t num_items )
inline

Generic bit-interleaving primitive for N lanes with M-bit source data (ISR-safe)

This is a generalized transposition function that can handle:

  • Variable number of lanes (1-16)
  • Variable source data width (8, 16, or 32 bits)

Use cases:

  • ESP32 PARLIO: 8 lanes × 32-bit waveforms → 32 output bytes per source position
  • Standard SPI: 8 lanes × 8-bit bytes → 8 output bytes per source position
Template Parameters
TSourceSource data type (uint8_t, uint16_t, or uint32_t)
Parameters
lanesArray of lane data pointers (cast to TSource*)
num_lanesNumber of lanes to transpose (1-16)
outputOutput buffer
num_itemsNumber of source items to transpose per lane
Note
Inline function - inlined at call site (including ISR contexts)
Output size is num_items * (sizeof(TSource) * 8) bytes
Handles lane counts < 8 by padding upper bits with zeros
Examples
/home/runner/work/FastLED/FastLED/src/fl/math/transposition.h.

Definition at line 473 of file transposition.h.

478 {
479 constexpr size_t bits_per_item = sizeof(TSource) * 8;
480
481 for (size_t item_idx = 0; item_idx < num_items; item_idx++) {
482 u8* dest = &output[item_idx * bits_per_item];
483
484 // Process each bit position in the source data (MSB to LSB)
485 for (size_t bit_pos = 0; bit_pos < bits_per_item; bit_pos++) {
486 size_t src_bit = (bits_per_item - 1) - bit_pos;
487 u8 output_byte = 0;
488
489 // Extract bit from each lane (up to 8 lanes per output byte)
490 for (size_t lane = 0; lane < num_lanes && lane < 8; lane++) {
491 TSource src_value = lanes[lane][item_idx];
492 u8 bit = (src_value >> src_bit) & 0x01;
493 output_byte |= (bit << (7 - lane));
494 }
495
496 dest[bit_pos] = output_byte;
497 }
498 }
499}
unsigned char u8
Definition stdint.h:131

References FL_NOEXCEPT.