MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/platforms/esp/32/drivers/parlio/parlio_driver.cpp:43–3063  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41#include "fl/stl/map.h"
42
43FL_TEST_FILE(FL_FILEPATH) {
44
45
46
47using namespace fl;
48
49//=============================================================================
50// WS2812 PARLIO Encoding (pure math, no mock needed)
51//=============================================================================
52
53namespace {
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).
65static 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
88FL_TEST_CASE("WS2812 PARLIO encoding - all zeros") {
89 uint32_t result = encodeLedByte(0x00);
90 FL_CHECK_EQ(result, 0x88888888);
91}
92
93FL_TEST_CASE("WS2812 PARLIO encoding - all ones") {
94 uint32_t result = encodeLedByte(0xFF);
95 FL_CHECK_EQ(result, 0xEEEEEEEE);
96}
97
98FL_TEST_CASE("WS2812 PARLIO encoding - alternating pattern 0xAA") {
99 uint32_t result = encodeLedByte(0xAA);
100 FL_CHECK_EQ(result, 0xE8E8E8E8);

Callers

nothing calls this directly

Calls 15

encodeLedByteFunction · 0.85
resetMockHistoryFunction · 0.85
resetMockFullFunction · 0.85
wave8Transpose_2Function · 0.85
canUseWave3Function · 0.85
createFunction · 0.85
waitForDriverReadyFunction · 0.85
wave3ClockFrequencyHzFunction · 0.85
wave3Function · 0.85
wave3Transpose_2Function · 0.85
wave3Untranspose_2Function · 0.85
wave3Transpose_4Function · 0.85

Tested by

no test coverage detected