20 const size_t edge_count = edges.size();
21 if (edge_count == 0) {
25 size_t bytes_written = 0;
31 while (i + 1 < edge_count) {
33 const EdgeTime low_edge = edges[i + 1];
35 if (!high_edge.
high || low_edge.
high) {
41 const u32 high_ns = high_edge.
ns;
42 const u32 low_ns = low_edge.
ns;
44 bool is_bit1 = (high_ns >= timing.t1h_min_ns && high_ns <= timing.t1h_max_ns &&
45 low_ns >= timing.t1l_min_ns && low_ns <= timing.t1l_max_ns);
46 bool is_bit0 = (high_ns >= timing.t0h_min_ns && high_ns <= timing.t0h_max_ns &&
47 low_ns >= timing.t0l_min_ns && low_ns <= timing.t0l_max_ns);
49 if (!is_bit0 && !is_bit1) {
50 if (low_ns >=
static_cast<u32
>(timing.reset_min_us) * 1000u) {
53 if (timing.gap_tolerance_ns > 0 && low_ns <= timing.gap_tolerance_ns) {
54 if (high_ns >= timing.t1h_min_ns && high_ns <= timing.t1h_max_ns) {
56 }
else if (high_ns >= timing.t0h_min_ns && high_ns <= timing.t0h_max_ns) {
60 if (!is_bit0 && !is_bit1) {
67 const u8 bit = is_bit1 ?
u8{1} :
u8{0};
68 current_byte =
static_cast<u8>((current_byte << 1) | bit);
72 if (bytes_written >= out.size()) {
75 out[bytes_written++] = current_byte;
83 if (bytes_written > 0 && error_count * 10 > bytes_written * 8) {
static expected failure(E err, const char *msg=nullptr) FL_NOEXCEPT
Create error result.
static expected success(T value) FL_NOEXCEPT
Create successful result.
Shared 4-phase WS2812 edge-pair -> byte decoder (declaration).
fl::result< u32, DecodeError > decodeWs2812Edges(const ChipsetTiming4Phase &timing, fl::span< const EdgeTime > edges, fl::span< u8 > out) FL_NOEXCEPT
Decode a WS2812 edge-pair stream into bytes.
expected< T, E > result
Alias for expected (Rust-style naming)
@ HIGH_ERROR_RATE
Symbol decode error rate too high (>10%)
@ BUFFER_OVERFLOW
Output buffer overflow.
@ INVALID_ARGUMENT
Invalid input arguments.
Base definition for an LED controller.
4-phase RX timing thresholds for chipset detection
u32 ns
Duration in nanoseconds (31 bits, max ~2.1s)
u32 high
High/low level (1 bit: 1=high, 0=low)
Universal edge timing representation (platform-agnostic)