| 41 | #include "fl/stl/map.h" |
| 42 | |
| 43 | FL_TEST_FILE(FL_FILEPATH) { |
| 44 | |
| 45 | |
| 46 | |
| 47 | using namespace fl; |
| 48 | |
| 49 | //============================================================================= |
| 50 | // WS2812 PARLIO Encoding (pure math, no mock needed) |
| 51 | //============================================================================= |
| 52 | |
| 53 | namespace { |
| 54 | |
| 55 | /// @brief Encode a single LED byte (0x00-0xFF) into 32-bit PARLIO waveform |
| 56 | /// @param byte LED color byte to encode (R, G, or B value) |
| 57 | /// @return 32-bit waveform for PARLIO transmission |
| 58 | /// |
| 59 | /// WS2812 timing with PARLIO 4-tick encoding: |
| 60 | /// - Bit 0: 0b1000 (312.5ns high, 937.5ns low) |
| 61 | /// - Bit 1: 0b1110 (937.5ns high, 312.5ns low) |
| 62 | /// |
| 63 | /// Each byte produces 8 x 4 = 32 bits of output. |
| 64 | /// MSB is transmitted first (standard WS2812 protocol). |
| 65 | static uint32_t encodeLedByte(uint8_t byte) { |
| 66 | uint32_t result = 0; |
| 67 | |
| 68 | // Process each bit (MSB first) |
| 69 | for (int i = 7; i >= 0; i--) { |
| 70 | // Shift result to make room for 4 new bits |
| 71 | result <<= 4; |
| 72 | |
| 73 | // Check bit value |
| 74 | if (byte & (1 << i)) { |
| 75 | // Bit is 1: encode as 0b1110 (hex: 0xE) |
| 76 | result |= 0xE; |
| 77 | } else { |
| 78 | // Bit is 0: encode as 0b1000 (hex: 0x8) |
| 79 | result |= 0x8; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return result; |
| 84 | } |
| 85 | |
| 86 | } // anonymous namespace |
| 87 | |
| 88 | FL_TEST_CASE("WS2812 PARLIO encoding - all zeros") { |
| 89 | uint32_t result = encodeLedByte(0x00); |
| 90 | FL_CHECK_EQ(result, 0x88888888); |
| 91 | } |
| 92 | |
| 93 | FL_TEST_CASE("WS2812 PARLIO encoding - all ones") { |
| 94 | uint32_t result = encodeLedByte(0xFF); |
| 95 | FL_CHECK_EQ(result, 0xEEEEEEEE); |
| 96 | } |
| 97 | |
| 98 | FL_TEST_CASE("WS2812 PARLIO encoding - alternating pattern 0xAA") { |
| 99 | uint32_t result = encodeLedByte(0xAA); |
| 100 | FL_CHECK_EQ(result, 0xE8E8E8E8); |
nothing calls this directly
no test coverage detected