FastLED 3.10.6
Loading...
Searching...
No Matches

◆ buildUartByte()

u8 fl::anonymous_namespace{uart_wave_encoder.cpp.hpp}::buildUartByte ( u8 pulses_a,
u8 pulses_b,
u8 pulses_per_bit = 5 )

Build a UART data byte from two LED bit pulse counts.

Constructs the 8-bit UART data value that, with TX inversion and LSB-first transmission, produces the desired wire waveform.

Wire model (10 bits with TX inversion): [START=H] [~D0] [~D1] [~D2] [~D3] [~D4] [~D5] [~D6] [~D7] [STOP=L]

LED bit A occupies positions 0-4 (START + D0..D3): START is always HIGH (1 pulse guaranteed) D0..D3 set HIGH for (pulses_a - 1) additional pulses, then LOW

LED bit B occupies positions 5-9 (D4..D7 + STOP): D4 must be HIGH for leading edge (1 pulse guaranteed) D5..D7 set HIGH for (pulses_b - 1) additional pulses, then LOW STOP is always LOW

Parameters
pulses_aHIGH pulse count for LED bit A [1, 4]
pulses_bHIGH pulse count for LED bit B [1, 4]
Returns
UART data byte value

Definition at line 66 of file uart_wave_encoder.cpp.hpp.

66 {
67 // Build the desired 2P-bit wire pattern (with TX inversion), where
68 // P = pulses_per_bit. Wire positions:
69 // [0=START] [1=~D0] ... [2P-2=~D(2P-3)] [2P-1=STOP]
70 //
71 // LED bit A (pos 0..P-1): pulses_a HIGH bits, then LOW
72 // LED bit B (pos P..2P-1): pulses_b HIGH bits, then LOW (STOP=L)
73
74 const int P = static_cast<int>(pulses_per_bit);
75 int wire[10]; // max frame = 10 (P=5)
76
77 // LED bit A: pulses_a HIGH bits starting from position 0
78 for (int i = 0; i < P; i++) {
79 wire[i] = (i < static_cast<int>(pulses_a)) ? 1 : 0;
80 }
81
82 // LED bit B: pulses_b HIGH bits starting from position P
83 for (int i = 0; i < P; i++) {
84 wire[P + i] = (i < static_cast<int>(pulses_b)) ? 1 : 0;
85 }
86
87 // Convert wire pattern back to UART data byte
88 // Wire[0] = START (inverted) = always H -> no control needed
89 // Wire[1..2P-2] = ~D0..~D(2P-3) (inverted data, LSB first)
90 // Wire[2P-1] = STOP (inverted) = always L -> no control needed
91 //
92 // So: wire[1+i] = ~D_i -> D_i = ~wire[1+i] = wire[1+i] ? 0 : 1
93 u8 byte_val = 0;
94 const int data_bits = 2 * P - 2;
95 for (int i = 0; i < data_bits; i++) {
96 int data_bit = wire[1 + i] ? 0 : 1; // Invert: wire HIGH -> data 0
97 byte_val |= static_cast<u8>(data_bit << i); // LSB first
98 }
99
100 return byte_val;
101}
Definition Luminova.h:46
unsigned char u8
Definition stdint.h:131
FASTLED_FORCE_INLINE fl::u8 P(fl::u8 x)

References buildUartByte(), fl::FL_NO_EXCEPT, and fl::P().

Referenced by buildUartByte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: