Transpose 16 lanes of data into interleaved hex-SPI format.
242 {
243
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
252 const size_t max_size =
output.size() / 16;
253
254
255 if (max_size == 0) {
256 if (error) {
257 *error = nullptr;
258 }
259 return true;
260 }
261
262
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
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
287
288 if (error) {
289 *error = nullptr;
290 }
291 return true;
292}
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 resize(fl::size n) FL_NOEXCEPT
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)