FastLED 3.9.15
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>
8
9namespace fl {
10
43
47 const char* driver_name;
48 const char* timing_name;
49 const char* rx_type_name;
50 const char* pattern_name;
56};
57
59struct LEDError {
67
68 LEDError(int idx, uint8_t exp_r, uint8_t exp_g, uint8_t exp_b,
69 uint8_t act_r, uint8_t act_g, uint8_t act_b)
70 : led_index(idx)
71 , expected_r(exp_r), expected_g(exp_g), expected_b(exp_b)
72 , actual_r(act_r), actual_g(act_g), actual_b(act_b) {}
73};
74
90
104
105// DriverTestResult is defined in fl/channels/validation.h (canonical definition)
106
107} // namespace fl
108
109// Capture transmitted LED data via RX loopback
110// - rx_channel: Shared pointer to RX device (persistent across calls)
111// - rx_buffer: Buffer to store received bytes
112// - timing: Chipset timing configuration for RX decoder
113// - driver_name: Name of the TX driver being tested (e.g., "RMT", "PARLIO") - enables io_loop_back only for RMT
114// Returns number of bytes captured, or 0 on error
115size_t capture(fl::shared_ptr<fl::RxChannel> rx_channel, fl::span<uint8_t> rx_buffer, const fl::ChipsetTimingConfig& timing, const char* driver_name);
116
117// Generic driver-agnostic autoresearch test runner (single run)
118// Tests all channels using the specified configuration
119// @param test_name Test name for logging (e.g., "Solid Red", "Solid Green")
120// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
121// @param total Output parameter - total tests run (incremented)
122// @param passed Output parameter - tests passed (incremented)
123void runTest(const char* test_name,
125 int& total, int& passed);
126
127// Multi-run autoresearch test runner
128// Runs the same test multiple times and tracks errors across runs
129// @param test_name Test name for logging (e.g., "Pattern A", "Pattern B")
130// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
131// @param multi_config Multi-run configuration (num runs, print settings)
132// @param total Output parameter - total tests run (incremented)
133// @param passed Output parameter - tests passed (incremented)
134// @param out_results Optional output for per-run results with LED error details
135void runMultiTest(const char* test_name,
137 const fl::MultiRunConfig& multi_config,
138 int& total, int& passed,
139 fl::vector<fl::RunResult>* out_results = nullptr);
140
141// AutoResearch a specific chipset timing configuration
142// Creates channels, runs tests, destroys channels
143// @param config All autoresearch configuration (timing, channels, driver, RX, buffer) - non-const for LED manipulation
144// @param total Output parameter - total tests run (incremented)
145// @param passed Output parameter - tests passed (incremented)
146// @param out_results Optional output for per-pattern results with LED error details
147// @param num_runs_per_pattern Consecutive captures per pattern (default 1). >=2 exposes
148// second-frame degradation bugs like SPI driver zeroing DMA buffer after first show().
150 int& total, int& passed,
151 uint32_t& out_show_duration_ms,
152 fl::vector<fl::RunResult>* out_results = nullptr,
153 int num_runs_per_pattern = 1);
154
155// AutoResearch using the legacy template addLeds API (supports multi-lane)
156// Uses LegacyClocklessProxy to map runtime pin to WS2812B<PIN> template instantiation
157// @param config All autoresearch configuration (one or more tx_configs, pins must be 0-8)
158// @param total Output parameter - total tests run (incremented)
159// @param passed Output parameter - tests passed (incremented)
160// @param out_results Optional output for per-pattern results with LED error details
161// @param num_runs_per_pattern Consecutive captures per pattern (default 1).
163 int& total, int& passed,
164 uint32_t& out_show_duration_ms,
165 fl::vector<fl::RunResult>* out_results = nullptr,
166 int num_runs_per_pattern = 1);
167
168// Set mixed RGB bit patterns to test MSB vs LSB handling
169// @param leds LED array to fill with pattern
170// @param count Number of LEDs in array
171// @param pattern_id Pattern identifier (0-3):
172// 0 = Pattern A: R=0xF0, G=0x0F, B=0xAA (high nibble, low nibble, alternating)
173// 1 = Pattern B: R=0x55, G=0xFF, B=0x00 (alternating, all-high, all-low)
174// 2 = Pattern C: R=0x0F, G=0xAA, B=0xF0 (rotated nibbles)
175// 3 = Pattern D: Solid colors (Red/Green/Blue alternating every 3 LEDs)
176void setMixedBitPattern(CRGB* leds, size_t count, int pattern_id);
177
178// Get name of bit pattern for logging
179// @param pattern_id Pattern identifier (0-3)
180// @return Pattern name string
181const char* getBitPatternName(int pattern_id);
fl::CRGB leds[NUM_LEDS]
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)
size_t capture(fl::shared_ptr< fl::RxChannel > rx_channel, fl::span< uint8_t > rx_buffer, const fl::ChipsetTimingConfig &timing, const char *driver_name)
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:163
unsigned char uint8_t
Definition s16x16x4.h:209
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...
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)
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)
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::shared_ptr< fl::RxChannel > rx_channel
RX channel for loopback capture (created in .ino, passed in)
fl::span< uint8_t > rx_buffer
Buffer to store received bytes.
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.
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.
uint8_t expected_g
Expected G value.
uint8_t actual_b
Actual B 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.
fl::vector< LEDError > errors
First few errors (up to 10)
int total_leds
Total LEDs tested.
bool passed
True if no errors.
int run_number
Run iteration number (1-based)
int totalBytes
Total bytes compared (num_leds * 3)
int mismatchedBytes
Number of individual bytes that differ.
int lsbOnlyErrors
Bytes where (expected ^ actual) == 0x01.
int mismatches
Number of LED mismatches.