Transpose 2 lanes of data into interleaved dual-SPI format.
56 {
57
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
66 const size_t max_size =
output.size() / 2;
67
68
69 if (max_size == 0) {
70 if (error) {
71 *error = nullptr;
72 }
73 return true;
74 }
75
76
78
79
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
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
101
102 if (error) {
103 *error = nullptr;
104 }
105 return true;
106}
bool has_value() const FL_NOEXCEPT
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.
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)