@brief UCS7604-style padding generator Writes source data to destination with padding inserted after the 15-byte preamble. Layout: [PREAMBLE (15 bytes)][PADDING (zeros)][LED DATA]
| 46 | /// Writes source data to destination with padding inserted after the 15-byte preamble. |
| 47 | /// Layout: [PREAMBLE (15 bytes)][PADDING (zeros)][LED DATA] |
| 48 | void ucs7604PaddingGenerator(fl::span<const uint8_t> src, fl::span<uint8_t> dst) { |
| 49 | constexpr size_t PREAMBLE_LEN = 15; |
| 50 | |
| 51 | size_t srcSize = src.size(); |
| 52 | size_t dstSize = dst.size(); |
| 53 | |
| 54 | if (dstSize < srcSize) { |
| 55 | return; // Invalid: destination too small |
| 56 | } |
| 57 | |
| 58 | size_t paddingSize = dstSize - srcSize; |
| 59 | |
| 60 | // Copy preamble (first 15 bytes) |
| 61 | size_t preambleBytes = (srcSize < PREAMBLE_LEN) ? srcSize : PREAMBLE_LEN; |
| 62 | fl::memcopy(dst.data(), src.data(), preambleBytes); |
| 63 | |
| 64 | // Insert padding zeros after preamble |
| 65 | if (paddingSize > 0 && srcSize >= PREAMBLE_LEN) { |
| 66 | fl::fill(dst.begin() + PREAMBLE_LEN, dst.begin() + PREAMBLE_LEN + paddingSize, uint8_t(0)); |
| 67 | } |
| 68 | |
| 69 | // Copy LED data after padding |
| 70 | if (srcSize > PREAMBLE_LEN) { |
| 71 | size_t ledDataSize = srcSize - PREAMBLE_LEN; |
| 72 | fl::memcopy(dst.data() + PREAMBLE_LEN + paddingSize, src.data() + PREAMBLE_LEN, ledDataSize); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | } // anonymous namespace |
| 77 |