FastLED 3.10.10
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
54
58 const char* driver_name;
59 const char* timing_name;
60 const char* rx_type_name;
61 const char* pattern_name;
67};
68
70struct LEDError {
80 bool has_white;
81
82 LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b,
83 uint8_t act_r, uint8_t act_g, uint8_t act_b)
84 : led_index(idx)
85 , expected_r(exp_r), expected_g(exp_g), expected_b(exp_b), expected_w(0)
86 , actual_r(act_r), actual_g(act_g), actual_b(act_b), actual_w(0)
87 , has_white(false) {}
88
89 LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b,
90 uint8_t exp_w, uint8_t act_r, uint8_t act_g, uint8_t act_b,
91 uint8_t act_w)
92 : led_index(idx)
93 , expected_r(exp_r), expected_g(exp_g), expected_b(exp_b)
94 , expected_w(exp_w)
95 , actual_r(act_r), actual_g(act_g), actual_b(act_b)
96 , actual_w(act_w)
97 , has_white(true) {}
98};
99
134
148
149// DriverTestResult is defined in fl/channels/validation.h (canonical definition)
150
151} // namespace fl
152
153// Capture transmitted LED data via RX loopback
154// - rx_channel: Shared pointer to RX device (persistent across calls)
155// - rx_buffer: Buffer to store received bytes
156// - expected_data_bytes: bytes in the current frame (bounds RP PIO DMA storage)
157// - tx_pin: GPIO driven by the tested TX controller
158// - timing: Chipset timing configuration for RX decoder
159// - driver_name: Name of the TX driver being tested (e.g., "RMT", "PARLIO")
160// Returns number of bytes captured, or 0 on error
162 fl::span<uint8_t> rx_buffer,
163 size_t expected_data_bytes,
164 int tx_pin,
165 const fl::ChipsetTimingConfig& timing,
166 const char* driver_name,
167 fl::RunResult* diagnostics = nullptr);
168
169// Generic driver-agnostic autoresearch test runner (single run)
170// Tests all channels using the specified configuration
171// @param test_name Test name for logging (e.g., "Solid Red", "Solid Green")
172// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
173// @param total Output parameter - total tests run (incremented)
174// @param passed Output parameter - tests passed (incremented)
175void runTest(const char* test_name,
177 int& total, int& passed);
178
179// Multi-run autoresearch test runner
180// Runs the same test multiple times and tracks errors across runs
181// @param test_name Test name for logging (e.g., "Pattern A", "Pattern B")
182// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
183// @param multi_config Multi-run configuration (num runs, print settings)
184// @param total Output parameter - total tests run (incremented)
185// @param passed Output parameter - tests passed (incremented)
186// @param out_results Optional output for per-run results with LED error details
187void runMultiTest(const char* test_name,
189 const fl::MultiRunConfig& multi_config,
190 int& total, int& passed,
191 fl::vector<fl::RunResult>* out_results = nullptr);
192
193// AutoResearch a specific chipset timing configuration
194// Creates channels, runs tests, destroys channels
195// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
196// @param total Output parameter - total tests run (incremented)
197// @param passed Output parameter - tests passed (incremented)
198// @param out_results Optional output for per-pattern results with LED error details
199// @param num_runs_per_pattern Consecutive captures per pattern (default 1). >=2 exposes
200// second-frame degradation bugs like SPI driver zeroing DMA buffer after first show().
202 int& total, int& passed,
203 uint32_t& out_show_duration_ms,
204 fl::vector<fl::RunResult>* out_results = nullptr,
205 int num_runs_per_pattern = 1);
206
207// AutoResearch using the legacy template addLeds API (supports multi-lane)
208// Uses LegacyClocklessProxy to map runtime pins and chipset names to public
209// CHIPSET<PIN> template instantiations.
210// @param config All autoresearch configuration (one or more tx_configs, pins must be 0-8)
211// @param total Output parameter - total tests run (incremented)
212// @param passed Output parameter - tests passed (incremented)
213// @param out_results Optional output for per-pattern results with LED error details
214// @param num_runs_per_pattern Consecutive captures per pattern (default 1).
216 int& total, int& passed,
217 uint32_t& out_show_duration_ms,
218 fl::vector<fl::RunResult>* out_results = nullptr,
219 int num_runs_per_pattern = 1);
220
221// Set mixed RGB bit patterns to test MSB vs LSB handling
222// @param leds LED array to fill with pattern
223// @param count Number of LEDs in array
224// @param pattern_id Pattern identifier (0-3):
225// 0 = Pattern A: R=0xF0, G=0x0F, B=0xAA (high nibble, low nibble, alternating)
226// 1 = Pattern B: R=0x55, G=0xFF, B=0x00 (alternating, all-high, all-low)
227// 2 = Pattern C: R=0x0F, G=0xAA, B=0xF0 (rotated nibbles)
228// 3 = Pattern D: Solid colors (Red/Green/Blue alternating every 3 LEDs)
229void setMixedBitPattern(CRGB* leds, size_t count, int pattern_id);
230
231// Get name of bit pattern for logging
232// @param pattern_id Pattern identifier (0-3)
233// @return Pattern name string
234const 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)
fl::u32 uint32_t
Definition s16x16x4.h:219
RxDeviceType
RX device type enumeration.
Definition rx.h:164
unsigned char uint8_t
Definition s16x16x4.h:209
Base definition for an LED controller.
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...
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.
uint32_t max_power_mw
Power budget for FastLED.setMaxPowerInMilliWatts(); 0 = unlimited.
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.
uint32_t baselineMw
MCU + dark current (cannot be dimmed)
int rawEdgesAfterWait
Raw edges visible after RX wait/decode.
bool passed
True if no errors.
uint32_t sumRaw
Sum of source pixel bytes on lane 0.
int decodeError
DecodeError value, or -1 when decode succeeded/not run.
uint32_t fullDemandMw
Modeled demand at brightness 255, MCU included.
int run_number
Run iteration number (1-based)
int totalBytes
Total bytes compared (3 or 4 per LED)
int expectedScale
Brightness the limiter reported before show()
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.
uint32_t sumWire
Sum of captured wire bytes on lane 0.
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.