FastLED 3.10.8
Loading...
Searching...
No Matches
AutoResearchTest.h
Go to the documentation of this file.
1// AutoResearchTest.h - Generic LED autoresearch testing infrastructure
2// Driver-agnostic test functions that work with any FastLED driver (RMT, SPI, PARLIO)
3
4#pragma once
5
6#include <FastLED.h>
9
10namespace fl {
11
50
54 const char* driver_name;
55 const char* timing_name;
56 const char* rx_type_name;
57 const char* pattern_name;
63};
64
66struct LEDError {
76 bool has_white;
77
78 LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b,
79 uint8_t act_r, uint8_t act_g, uint8_t act_b)
80 : led_index(idx)
81 , expected_r(exp_r), expected_g(exp_g), expected_b(exp_b), expected_w(0)
82 , actual_r(act_r), actual_g(act_g), actual_b(act_b), actual_w(0)
83 , has_white(false) {}
84
85 LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b,
86 uint8_t exp_w, uint8_t act_r, uint8_t act_g, uint8_t act_b,
87 uint8_t act_w)
88 : led_index(idx)
89 , expected_r(exp_r), expected_g(exp_g), expected_b(exp_b)
90 , expected_w(exp_w)
91 , actual_r(act_r), actual_g(act_g), actual_b(act_b)
92 , actual_w(act_w)
93 , has_white(true) {}
94};
95
124
138
139// DriverTestResult is defined in fl/channels/validation.h (canonical definition)
140
141} // namespace fl
142
143// Capture transmitted LED data via RX loopback
144// - rx_channel: Shared pointer to RX device (persistent across calls)
145// - rx_buffer: Buffer to store received bytes
146// - expected_data_bytes: bytes in the current frame (bounds RP PIO DMA storage)
147// - tx_pin: GPIO driven by the tested TX controller
148// - timing: Chipset timing configuration for RX decoder
149// - driver_name: Name of the TX driver being tested (e.g., "RMT", "PARLIO")
150// Returns number of bytes captured, or 0 on error
152 fl::span<uint8_t> rx_buffer,
153 size_t expected_data_bytes,
154 int tx_pin,
155 const fl::ChipsetTimingConfig& timing,
156 const char* driver_name,
157 fl::RunResult* diagnostics = nullptr);
158
159// Generic driver-agnostic autoresearch test runner (single run)
160// Tests all channels using the specified configuration
161// @param test_name Test name for logging (e.g., "Solid Red", "Solid Green")
162// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
163// @param total Output parameter - total tests run (incremented)
164// @param passed Output parameter - tests passed (incremented)
165void runTest(const char* test_name,
167 int& total, int& passed);
168
169// Multi-run autoresearch test runner
170// Runs the same test multiple times and tracks errors across runs
171// @param test_name Test name for logging (e.g., "Pattern A", "Pattern B")
172// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
173// @param multi_config Multi-run configuration (num runs, print settings)
174// @param total Output parameter - total tests run (incremented)
175// @param passed Output parameter - tests passed (incremented)
176// @param out_results Optional output for per-run results with LED error details
177void runMultiTest(const char* test_name,
179 const fl::MultiRunConfig& multi_config,
180 int& total, int& passed,
181 fl::vector<fl::RunResult>* out_results = nullptr);
182
183// AutoResearch a specific chipset timing configuration
184// Creates channels, runs tests, destroys channels
185// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
186// @param total Output parameter - total tests run (incremented)
187// @param passed Output parameter - tests passed (incremented)
188// @param out_results Optional output for per-pattern results with LED error details
189// @param num_runs_per_pattern Consecutive captures per pattern (default 1). >=2 exposes
190// second-frame degradation bugs like SPI driver zeroing DMA buffer after first show().
192 int& total, int& passed,
193 uint32_t& out_show_duration_ms,
194 fl::vector<fl::RunResult>* out_results = nullptr,
195 int num_runs_per_pattern = 1);
196
197// AutoResearch using the legacy template addLeds API (supports multi-lane)
198// Uses LegacyClocklessProxy to map runtime pins and chipset names to public
199// CHIPSET<PIN> template instantiations.
200// @param config All autoresearch configuration (one or more tx_configs, pins must be 0-8)
201// @param total Output parameter - total tests run (incremented)
202// @param passed Output parameter - tests passed (incremented)
203// @param out_results Optional output for per-pattern results with LED error details
204// @param num_runs_per_pattern Consecutive captures per pattern (default 1).
206 int& total, int& passed,
207 uint32_t& out_show_duration_ms,
208 fl::vector<fl::RunResult>* out_results = nullptr,
209 int num_runs_per_pattern = 1);
210
211// Set mixed RGB bit patterns to test MSB vs LSB handling
212// @param leds LED array to fill with pattern
213// @param count Number of LEDs in array
214// @param pattern_id Pattern identifier (0-3):
215// 0 = Pattern A: R=0xF0, G=0x0F, B=0xAA (high nibble, low nibble, alternating)
216// 1 = Pattern B: R=0x55, G=0xFF, B=0x00 (alternating, all-high, all-low)
217// 2 = Pattern C: R=0x0F, G=0xAA, B=0xF0 (rotated nibbles)
218// 3 = Pattern D: Solid colors (Red/Green/Blue alternating every 3 LEDs)
219void setMixedBitPattern(CRGB* leds, size_t count, int pattern_id);
220
221// Get name of bit pattern for logging
222// @param pattern_id Pattern identifier (0-3)
223// @return Pattern name string
224const char* getBitPatternName(int pattern_id);
CRGB leds[1]
size_t capture(fl::shared_ptr< fl::RxChannel > rx_channel, fl::span< uint8_t > rx_buffer, size_t expected_data_bytes, int tx_pin, const fl::ChipsetTimingConfig &timing, const char *driver_name, fl::RunResult *diagnostics=nullptr)
void runMultiTest(const char *test_name, fl::AutoResearchConfig &config, const fl::MultiRunConfig &multi_config, int &total, int &passed, fl::vector< fl::RunResult > *out_results=nullptr)
void autoResearchChipsetTimingLegacy(fl::AutoResearchConfig &config, int &total, int &passed, uint32_t &out_show_duration_ms, fl::vector< fl::RunResult > *out_results=nullptr, int num_runs_per_pattern=1)
const char * getBitPatternName(int pattern_id)
void runTest(const char *test_name, fl::AutoResearchConfig &config, int &total, int &passed)
void autoResearchChipsetTiming(fl::AutoResearchConfig &config, int &total, int &passed, uint32_t &out_show_duration_ms, fl::vector< fl::RunResult > *out_results=nullptr, int num_runs_per_pattern=1)
void setMixedBitPattern(CRGB *leds, size_t count, int pattern_id)
fl::CRGB CRGB
Definition crgb.h:25
ClocklessEncoder
Identifies which encoder to use for clockless chipsets in the Channel API.
@ CLOCKLESS_ENCODER_WS2812
Default, no preamble (WS2812 and compatible)
RxDeviceType
RX device type enumeration.
Definition rx.h:164
Base definition for an LED controller.
Definition crgb.hpp:179
int num_leds
Number of LEDs in this lane.
const char * rx_type_name
RX device type name (e.g., "RMT", "ISR")
int base_strip_size
Base strip size (10 or 300 LEDs)
const char * driver_name
Driver name (e.g., "RMT", "SPI", "PARLIO")
const char * timing_name
Timing name (e.g., "WS2812B-V5")
int lane_index
Current lane index (0-15)
const char * pattern_name
Pattern name (e.g., "Pattern A (R=0xF0...)")
int lane_count
Total number of lanes (1-16)
int pin_number
TX pin number for this lane.
Test context for detailed error reporting Aggregates all test configuration parameters for error mess...
unsigned char uint8_t
Definition stdint.h:208
fl::u32 uint32_t
Definition stdint.h:218
const fl::ChipsetTimingConfig & timing
Chipset timing configuration to test.
fl::RxDeviceType rx_type
RX device type (RMT or ISR)
const char * timing_name
Timing name for logging (e.g., "WS2812B-V5")
const char * driver_name
Driver name for logging (e.g., "RMT", "SPI", "PARLIO")
int base_strip_size
Base strip size (10 or 300 LEDs)
bool legacy_rgbw
Enable RGBW on legacy controllers.
fl::span< fl::ChannelConfig > tx_configs
TX channel configurations to test (mutable for LED manipulation)
fl::ClocklessEncoder encoder
Encoder selector (peer of timing; see issue #2467)
fl::shared_ptr< fl::RxChannel > rx_channel
RX channel for loopback capture (created in .ino, passed in)
AutoResearchConfig(const fl::ChipsetTimingConfig &t, const char *tn, fl::span< fl::ChannelConfig > tc, const char *dn, fl::shared_ptr< fl::RxChannel > rc, fl::span< uint8_t > rb, int bss, fl::RxDeviceType rt, fl::ClocklessEncoder enc=fl::ClocklessEncoder::CLOCKLESS_ENCODER_WS2812, fl::span< const LegacyClocklessChipset > legacy=fl::span< const LegacyClocklessChipset >(), bool legacy_rgbw_enabled=false)
fl::span< uint8_t > rx_buffer
Buffer to store received bytes.
fl::span< const LegacyClocklessChipset > legacy_chipsets
Optional per-lane legacy templates.
Configuration for driver-agnostic autoresearch testing Contains all input parameters needed for autor...
Runtime bit-period timing for a clockless chipset.
uint8_t expected_b
Expected B value.
uint8_t expected_r
Expected R value.
uint8_t actual_w
Actual W value when has_white is true.
int led_index
LED index where error occurred.
LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b, uint8_t act_r, uint8_t act_g, uint8_t act_b)
uint8_t actual_r
Actual R value.
LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b, uint8_t exp_w, uint8_t act_r, uint8_t act_g, uint8_t act_b, uint8_t act_w)
uint8_t expected_g
Expected G value.
uint8_t expected_w
Expected W value when has_white is true.
uint8_t actual_b
Actual B value.
bool has_white
Whether this error contains an RGBW value.
uint8_t actual_g
Actual G value.
bool print_per_led_errors
Print every LED error (default: false)
int max_errors_per_run
Max errors to store per run (default: 5)
bool print_all_runs
Print all run results (default: only errors)
int num_runs
Number of runs to execute.
Multi-run test configuration.
int captureWaitResult
RxWaitResult value, or -1 before wait.
int decodeOutputCapacity
Output span size passed to decode()
fl::vector< LEDError > errors
First few errors (up to 10)
int total_leds
Total LEDs tested.
int rawEdgesAfterWait
Raw edges visible after RX wait/decode.
bool passed
True if no errors.
int decodeError
DecodeError value, or -1 when decode succeeded/not run.
int run_number
Run iteration number (1-based)
int totalBytes
Total bytes compared (3 or 4 per LED)
int mismatchedBytes
Number of individual bytes that differ.
fl::string rawEdgeSample
Compact first-edge sample for failures.
fl::string rxBeginError
Machine-readable reason when RX begin() fails.
int decodeBytes
Bytes reported directly by decode()
int capturedBytes
Bytes decoded from the RX channel.
int lsbOnlyErrors
Bytes where (expected ^ actual) == 0x01.
int mismatches
Number of LED mismatches.
int rpPioGpioTransitions
CPU-observed RX-pin transitions during RP PIO TX.
int decodeOk
1 if RX decode returned success, 0 on error, -1 before decode
bool captureFailed
True when RX produced no decodable bytes.
Single run result with error tracking.