48 return (timing.t0h_max_ns + timing.t1h_min_ns) / 2u;
54 return high_ns >= 100u && high_ns <= 1500u;
60 u32 high_min, u32 high_max,
62 if (samples >= 16 && high_max > high_min + 200u) {
63 return (high_min + high_max) / 2u;
71 return (high_ns >= midpoint_ns) ? 1 : 0;
77 if (high_ns >= timing.t0h_min_ns && high_ns <= timing.t0h_max_ns) {
80 if (high_ns >= timing.t1h_min_ns && high_ns <= timing.t1h_max_ns) {
90 const u16 delta =
static_cast<u16
>(t1 - t0);
91 return static_cast<u32
>((
static_cast<u64>(delta) * ns_per_tick_q16) >> 16);
96 return static_cast<u32
>((
static_cast<u64>(1000000000ULL) << 16) / counter_hz);
void finish(const ChipsetTiming4Phase &timing) FL_NO_EXCEPT
Re-classify the recorded bits with the decode-time timing and write the partial final byte.
void classify(u32 high_ns, Mode mode) FL_NO_EXCEPT
ChipsetTiming4Phase mTiming
void flush() FL_NO_EXCEPT
End of capture: decode the final pair (HIGH only; its LOW is the reset) and fix the calibration.
void markOverrun() FL_NO_EXCEPT
Captures were lost (ring overwritten before decode).
void calibrate() FL_NO_EXCEPT
size_t diagEdgeCount() const FL_NO_EXCEPT
void pushBit(u32 high_ns, Mode mode) FL_NO_EXCEPT
void emitEdge(bool high, u32 ns) FL_NO_EXCEPT
void push(fl::span< const u16 > captures) FL_NO_EXCEPT
Consume capture pairs laid out as [rise0, fall0, rise1, fall1...].
void emitPair(u16 rise, u16 fall, bool has_low, u32 low_ns) FL_NO_EXCEPT
void record(u32 high_ns, Mode mode, bool stream_valid) FL_NO_EXCEPT
static constexpr u32 kMaxExceptions
Pending mPending[kCalibrationBits]
const Stats & stats() const FL_NO_EXCEPT
static constexpr u32 kExceptionBandNs
Bits within this distance of the calibrated threshold are recorded for re-classification against the ...
static constexpr u32 kCalibrationBits
Bits classified before the threshold is fixed. 64 bits = 8 bytes.
void reset(const ChipsetTiming4Phase &stream_timing, u32 ns_per_tick_q16, fl::span< u8 > out, fl::span< EdgeTime > diag_edges) FL_NO_EXCEPT
Start a frame.
void appendBit(int bit) FL_NO_EXCEPT
fl::span< EdgeTime > mDiag
Exception mExceptions[kMaxExceptions]
fl::result< u32, DecodeError > copyTo(fl::span< u8 > out) const FL_NO_EXCEPT
Copy the decoded frame into out with the batch decoder's result rules (overflow, >10% error rate,...
Streaming decoder over (rise, fall) capture pairs.
u32 pairs
capture pairs consumed
bool overrun
the owner reported lost captures
bool gapBitShift
a gap bit kept/dropped differs from decode timing
u32 exceptionsDropped
near-threshold bits that did not fit
u32 frameMidpointNs
whole-frame midpoint, set by finish()
u32 fullBytes
complete bytes decoded (may exceed capacity)
bool inexact
finish() could not guarantee batch equality
u32 errors
out-of-window bits (batch error_count)
u32 bits
bits classified (batch total_bits)
u32 exceptions
near-threshold bits recorded
fl::result< u32, DecodeError > decodeFlexPwmEdges(const ChipsetTiming4Phase &timing, fl::span< const EdgeTime > edges, fl::span< u8 > bytes_out) FL_NO_EXCEPT
Batch decoder over an edge list (HIGH, LOW, HIGH, ... with a LOW left out after a gap).
constexpr u32 kFlexPwmGapNs
A LOW longer than this ends the bit without a LOW edge (gap or reset).
bool flexPwmIsMidpointSample(u32 high_ns) FL_NO_EXCEPT
Whether a HIGH width contributes to the adaptive-midpoint pre-pass (idle and glitch widths are exclud...
u32 flexPwmNsPerTickQ16(u32 counter_hz) FL_NO_EXCEPT
Q16.16 ns-per-tick for a counter clock.
int flexPwmBitFromHigh(u32 high_ns, const ChipsetTiming4Phase &timing) FL_NO_EXCEPT
Bit from a HIGH whose LOW was a gap/reset or was not captured: range check against the T0H / T1H wind...
u32 flexPwmStaticMidpointNs(const ChipsetTiming4Phase &timing) FL_NO_EXCEPT
Static threshold between a 0 and a 1 HIGH: midpoint of T0H max / T1H min.
u32 flexPwmTickDeltaNs(u16 t0, u16 t1, u32 ns_per_tick_q16) FL_NO_EXCEPT
Convert a 16-bit capture-counter delta to ns.
int flexPwmBitFromMidpoint(u32 high_ns, u32 midpoint_ns) FL_NO_EXCEPT
Bit from a HIGH followed by a normal LOW: HIGH-only midpoint split.
u32 flexPwmAdaptiveMidpointNs(const ChipsetTiming4Phase &timing, u32 high_min, u32 high_max, u32 samples) FL_NO_EXCEPT
#3416 adaptive midpoint: (min + max) / 2 of the observed HIGH widths once there are enough samples sp...
u8 u8 fract8 blur_amount FL_NO_EXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
DecodeError
Error codes for RX decoder operations.
Base definition for an LED controller.
4-phase RX timing thresholds for chipset detection
result<T, E> type alias for fl::expected (Rust-style naming)
Common RX interfaces and shared types.